@tahminator/pipeline 1.0.76-beta.7c6d310b → 1.0.76-beta.9003fd90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -392,7 +392,6 @@ Utilities to compute the next semver tag from GitHub and update versions in code
392
392
  ```ts
393
393
  const gh = await GitHubClient.createWithDefaultCiToken();
394
394
 
395
- // available strategies: JSTS, JAVA_MAVEN, RUST_CARGO, NONE
396
395
  const versioning = new VersioningClient(gh, VersionUpdatingStrategy.JSTS);
397
396
 
398
397
  // if your repo has no tags yet, this will return `1.0.0`
@@ -2,9 +2,9 @@ import { ProtobufCompilerBackend, } from "../types";
2
2
  import { ArtifactKeeperProtobufCompilerBackend } from "./artifact-keeper";
3
3
  export * from "./artifact-keeper";
4
4
  export * from "./types";
5
- const BACKEND_STRATEGY_FACTORIES = {
6
- [ProtobufCompilerBackend.ARTIFACT_KEEPER]: (backend) => new ArtifactKeeperProtobufCompilerBackend(backend),
7
- };
8
5
  export function createProtobufCompilerBackendStrategy(backend) {
9
- return BACKEND_STRATEGY_FACTORIES[backend.type](backend);
6
+ switch (backend.type) {
7
+ case ProtobufCompilerBackend.ARTIFACT_KEEPER:
8
+ return new ArtifactKeeperProtobufCompilerBackend(backend);
9
+ }
10
10
  }
@@ -5,6 +5,7 @@ export declare class ProtobufCompilerClient {
5
5
  private generateWithBuf;
6
6
  private getCompilationTargets;
7
7
  private getConfiguredTargetLanguages;
8
+ private getTargetLanguageStrategy;
8
9
  private getBufGenerateInput;
9
10
  private findBufModuleDirectory;
10
11
  }
@@ -7,11 +7,6 @@ import { isCmdAvailable } from "../utils/cmd";
7
7
  import { createProtobufCompilerBackendStrategy } from "./backend";
8
8
  import { GoProtobufTargetLanguageStrategy, JavaProtobufTargetLanguageStrategy, RustProtobufTargetLanguageStrategy, } from "./strategy";
9
9
  import { ProtobufTargetLanguage, } from "./types";
10
- const TARGET_LANGUAGE_STRATEGY_FACTORIES = {
11
- [ProtobufTargetLanguage.JAVA]: () => new JavaProtobufTargetLanguageStrategy(),
12
- [ProtobufTargetLanguage.GO]: () => new GoProtobufTargetLanguageStrategy(),
13
- [ProtobufTargetLanguage.RUST]: () => new RustProtobufTargetLanguageStrategy(),
14
- };
15
10
  export class ProtobufCompilerClient {
16
11
  async compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
17
12
  await this.installToolchains();
@@ -80,11 +75,27 @@ export class ProtobufCompilerClient {
80
75
  return this.getConfiguredTargetLanguages(targetLanguages).map(([language, options]) => ({
81
76
  language,
82
77
  options,
83
- strategy: TARGET_LANGUAGE_STRATEGY_FACTORIES[language](),
78
+ strategy: this.getTargetLanguageStrategy(language),
84
79
  }));
85
80
  }
86
81
  getConfiguredTargetLanguages(targetLanguages) {
87
- return Object.entries(targetLanguages).flatMap(([language, options]) => options ? [[Number(language), options]] : []);
82
+ const targets = [];
83
+ for (const [language, options] of Object.entries(targetLanguages)) {
84
+ if (!options)
85
+ continue;
86
+ targets.push([Number(language), options]);
87
+ }
88
+ return targets;
89
+ }
90
+ getTargetLanguageStrategy(targetLanguage) {
91
+ switch (targetLanguage) {
92
+ case ProtobufTargetLanguage.JAVA:
93
+ return new JavaProtobufTargetLanguageStrategy();
94
+ case ProtobufTargetLanguage.GO:
95
+ return new GoProtobufTargetLanguageStrategy();
96
+ case ProtobufTargetLanguage.RUST:
97
+ return new RustProtobufTargetLanguageStrategy();
98
+ }
88
99
  }
89
100
  async getBufGenerateInput(protoFilesLocation) {
90
101
  const resolvedLocation = path.resolve(protoFilesLocation);
@@ -3,7 +3,6 @@ import { VersionUpdatingStrategy, } from "./types";
3
3
  import { JavaMavenVersioningClient } from "./updating/java/maven";
4
4
  import { JavascriptPackageJsonVersioningClient } from "./updating/jsts";
5
5
  import { NoneVersioningClient } from "./updating/none";
6
- import { RustCargoVersioningClient } from "./updating/rust/cargo";
7
6
  export class VersioningClient {
8
7
  githubClient;
9
8
  static INITIAL_VERSION = "1.0.0";
@@ -18,8 +17,6 @@ export class VersioningClient {
18
17
  return new JavascriptPackageJsonVersioningClient();
19
18
  case VersionUpdatingStrategy.JAVA_MAVEN:
20
19
  return new JavaMavenVersioningClient();
21
- case VersionUpdatingStrategy.RUST_CARGO:
22
- return new RustCargoVersioningClient();
23
20
  case VersionUpdatingStrategy.NONE:
24
21
  return new NoneVersioningClient();
25
22
  }
@@ -1,8 +1,7 @@
1
1
  export declare enum VersionUpdatingStrategy {
2
2
  JSTS = 0,
3
3
  JAVA_MAVEN = 1,
4
- RUST_CARGO = 2,
5
- NONE = 3
4
+ NONE = 2
6
5
  }
7
6
  export interface IVersionUpdatingClient {
8
7
  update(version: string): Promise<void>;
@@ -38,5 +37,3 @@ export interface IJavascriptPackageJsonVersionUpdatingClient extends IVersionUpd
38
37
  }
39
38
  export interface IJavaMavenVersionUpdatingClient extends IVersionUpdatingClient {
40
39
  }
41
- export interface IRustCargoVersionUpdatingClient extends IVersionUpdatingClient {
42
- }
@@ -2,6 +2,5 @@ export var VersionUpdatingStrategy;
2
2
  (function (VersionUpdatingStrategy) {
3
3
  VersionUpdatingStrategy[VersionUpdatingStrategy["JSTS"] = 0] = "JSTS";
4
4
  VersionUpdatingStrategy[VersionUpdatingStrategy["JAVA_MAVEN"] = 1] = "JAVA_MAVEN";
5
- VersionUpdatingStrategy[VersionUpdatingStrategy["RUST_CARGO"] = 2] = "RUST_CARGO";
6
- VersionUpdatingStrategy[VersionUpdatingStrategy["NONE"] = 3] = "NONE";
5
+ VersionUpdatingStrategy[VersionUpdatingStrategy["NONE"] = 2] = "NONE";
7
6
  })(VersionUpdatingStrategy || (VersionUpdatingStrategy = {}));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "author": "Tahmid Ahmed",
5
5
  "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
6
- "version": "1.0.76-beta.7c6d310b",
6
+ "version": "1.0.76-beta.9003fd90",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -1,6 +0,0 @@
1
- import type { IRustCargoVersionUpdatingClient } from "../../../types";
2
- import { BaseVersionUpdatingClient } from "../../base";
3
- export declare class RustCargoVersioningClient extends BaseVersionUpdatingClient implements IRustCargoVersionUpdatingClient {
4
- update(version: string): Promise<void>;
5
- private updatePackageVersionInCargoToml;
6
- }
@@ -1,50 +0,0 @@
1
- import { BaseVersionUpdatingClient } from "../../base";
2
- export class RustCargoVersioningClient extends BaseVersionUpdatingClient {
3
- async update(version) {
4
- const files = await this.findFiles("**/Cargo.toml");
5
- for (const fileLocation of files) {
6
- const file = Bun.file(fileLocation);
7
- const oldCargoToml = await file.text();
8
- const newCargoToml = this.updatePackageVersionInCargoToml(oldCargoToml, version);
9
- if (!newCargoToml) {
10
- continue;
11
- }
12
- await Bun.write(fileLocation, newCargoToml);
13
- this.logFileLocationUpdated(fileLocation, version);
14
- }
15
- }
16
- updatePackageVersionInCargoToml(cargoToml, version) {
17
- const lines = cargoToml.split("\n");
18
- let insidePackageSection = false;
19
- let packageSectionFound = false;
20
- let packageVersionLineIndex = -1;
21
- for (let index = 0; index < lines.length; index++) {
22
- const line = lines[index];
23
- if (!line)
24
- continue;
25
- const sectionMatch = line.match(/^\s*\[(.+)\]\s*$/);
26
- if (sectionMatch) {
27
- const sectionName = sectionMatch[1]?.trim();
28
- insidePackageSection = sectionName === "package";
29
- if (insidePackageSection) {
30
- packageSectionFound = true;
31
- }
32
- continue;
33
- }
34
- if (!insidePackageSection)
35
- continue;
36
- if (/^\s*version(?:\.[A-Za-z0-9_-]+)?\s*=/.test(line)) {
37
- packageVersionLineIndex = index;
38
- break;
39
- }
40
- }
41
- if (!packageSectionFound) {
42
- return null;
43
- }
44
- if (packageVersionLineIndex === -1) {
45
- throw new Error("Can't find version key inside of package section in Cargo.toml");
46
- }
47
- lines[packageVersionLineIndex] = `version = "${version}"`;
48
- return `${lines.join("\n").replace(/\n*$/, "\n")}`;
49
- }
50
- }