@tahminator/pipeline 1.0.76-beta.4076a21f → 1.0.76-beta.6560b5dd

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
@@ -38,10 +38,7 @@ import {
38
38
  EnvClient,
39
39
  GitHubClient,
40
40
  NPMClient,
41
- ProtobufCompilerBackend,
42
41
  ProtobufCompilerClient,
43
- ProtobufSourceLanguage,
44
- ProtobufTargetLanguage,
45
42
  PulumiClient,
46
43
  SonarScannerClient,
47
44
  Utils,
@@ -185,25 +182,24 @@ await client.promoteDockerImage({
185
182
 
186
183
  ### `ProtobufCompilerClient`
187
184
 
188
- Generate protobuf clients with the [Buf CLI](https://buf.build/docs/installation/) and its remote plugins. Java and Rust targets can be published to Artifact Keeper with Maven, Gradle, or Cargo. The client installs Buf globally with npm when necessary.
185
+ Generate protobuf clients with the [Buf CLI](https://buf.build/docs/installation/) and its remote plugins, then optionally upload them to a GitHub repository path. The client installs Buf globally with npm when necessary.
189
186
 
190
187
  ```ts
191
- const protobuf = new ProtobufCompilerClient();
188
+ const gh = await GitHubClient.createWithGithubAppToken({
189
+ appId: process.env.GH_APP_ID!,
190
+ privateKey: await Utils.decodeBase64EncodedString(
191
+ process.env.GH_PRIVATE_KEY_B64!,
192
+ ),
193
+ installationId: process.env.GH_INSTALLATION_ID!,
194
+ });
195
+ const protobuf = new ProtobufCompilerClient(gh);
192
196
 
193
197
  await protobuf.compile({
194
- backend: {
195
- type: ProtobufCompilerBackend.ARTIFACT_KEEPER,
196
- token: process.env.ARTIFACT_KEEPER_TOKEN!,
197
- url: process.env.ARTIFACT_KEEPER_URL!,
198
- username: process.env.ARTIFACT_KEEPER_USERNAME!,
199
- },
200
198
  sourceLanguage: ProtobufSourceLanguage.RUST,
201
199
  bufToken: process.env.BUF_TOKEN,
202
200
  targetLanguages: {
203
201
  [ProtobufTargetLanguage.JAVA]: {
204
- artifactId: "hello-world-grpc-service",
205
- groupId: "org.my-org",
206
- version: "1.0.0",
202
+ uploadLocation: "Patina-Network/proto-clients/java",
207
203
  },
208
204
  },
209
205
  protoFilesLocation: "./proto",
@@ -392,7 +388,6 @@ Utilities to compute the next semver tag from GitHub and update versions in code
392
388
  ```ts
393
389
  const gh = await GitHubClient.createWithDefaultCiToken();
394
390
 
395
- // available strategies: JSTS, JAVA_MAVEN, RUST_CARGO, NONE
396
391
  const versioning = new VersioningClient(gh, VersionUpdatingStrategy.JSTS);
397
392
 
398
393
  // if your repo has no tags yet, this will return `1.0.0`
@@ -1,10 +1,16 @@
1
+ import type { GitHubClient } from "../gh";
1
2
  import { type ProtobufCompilerCompileArgs, type ProtobufCompilerCompileResult } from "./types";
2
3
  export declare class ProtobufCompilerClient {
3
- compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }: ProtobufCompilerCompileArgs): Promise<ProtobufCompilerCompileResult>;
4
+ private readonly githubClient;
5
+ constructor(githubClient: GitHubClient);
6
+ compile({ bufToken, targetLanguages, protoFilesLocation, outputDirectory, }: ProtobufCompilerCompileArgs): Promise<ProtobufCompilerCompileResult>;
4
7
  installToolchains(): Promise<void>;
5
8
  private generateWithBuf;
6
9
  private getCompilationTargets;
7
10
  private getConfiguredTargetLanguages;
11
+ private getTargetLanguageStrategy;
8
12
  private getBufGenerateInput;
9
13
  private findBufModuleDirectory;
14
+ private uploadGeneratedDirectory;
15
+ private parseGitHubRepository;
10
16
  }
@@ -4,21 +4,18 @@ import { tmpdir } from "node:os";
4
4
  import path from "node:path";
5
5
  import yaml from "yaml";
6
6
  import { isCmdAvailable } from "../utils/cmd";
7
- import { createProtobufCompilerBackendStrategy } from "./backend";
8
7
  import { GoProtobufTargetLanguageStrategy, JavaProtobufTargetLanguageStrategy, RustProtobufTargetLanguageStrategy, } from "./strategy";
9
8
  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
9
  export class ProtobufCompilerClient {
16
- async compile({ backend, bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
10
+ githubClient;
11
+ constructor(githubClient) {
12
+ this.githubClient = githubClient;
13
+ }
14
+ async compile({ bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
17
15
  await this.installToolchains();
18
16
  const outputDirectoryPath = path.resolve(outputDirectory ??
19
17
  (await mkdtemp(path.join(tmpdir(), "protobuf-compiler-"))));
20
18
  const targets = this.getCompilationTargets(targetLanguages);
21
- const compilerBackend = backend ? createProtobufCompilerBackendStrategy(backend) : undefined;
22
19
  await mkdir(outputDirectoryPath, { recursive: true });
23
20
  await this.generateWithBuf({
24
21
  bufToken,
@@ -30,18 +27,17 @@ export class ProtobufCompilerClient {
30
27
  for (const { language, strategy } of targets) {
31
28
  generatedDirectories[language] = path.join(outputDirectoryPath, strategy.outputDirectoryName);
32
29
  }
33
- if (compilerBackend) {
34
- for (const { language, options } of targets) {
35
- const generatedDirectory = generatedDirectories[language];
36
- if (!generatedDirectory) {
37
- throw new Error("Generated code directory was not created.");
38
- }
39
- await compilerBackend.publish({
40
- generatedDirectory,
41
- options,
42
- targetLanguage: language,
43
- });
30
+ for (const { language, options } of targets) {
31
+ if (!options.uploadLocation)
32
+ continue;
33
+ const generatedDirectory = generatedDirectories[language];
34
+ if (!generatedDirectory) {
35
+ throw new Error("Generated code directory was not created.");
44
36
  }
37
+ await this.uploadGeneratedDirectory({
38
+ generatedDirectory,
39
+ options,
40
+ });
45
41
  }
46
42
  return { generatedDirectories, outputDirectory: outputDirectoryPath };
47
43
  }
@@ -80,11 +76,27 @@ export class ProtobufCompilerClient {
80
76
  return this.getConfiguredTargetLanguages(targetLanguages).map(([language, options]) => ({
81
77
  language,
82
78
  options,
83
- strategy: TARGET_LANGUAGE_STRATEGY_FACTORIES[language](),
79
+ strategy: this.getTargetLanguageStrategy(language),
84
80
  }));
85
81
  }
86
82
  getConfiguredTargetLanguages(targetLanguages) {
87
- return Object.entries(targetLanguages).flatMap(([language, options]) => options ? [[Number(language), options]] : []);
83
+ const targets = [];
84
+ for (const [language, options] of Object.entries(targetLanguages)) {
85
+ if (!options)
86
+ continue;
87
+ targets.push([Number(language), options]);
88
+ }
89
+ return targets;
90
+ }
91
+ getTargetLanguageStrategy(targetLanguage) {
92
+ switch (targetLanguage) {
93
+ case ProtobufTargetLanguage.JAVA:
94
+ return new JavaProtobufTargetLanguageStrategy();
95
+ case ProtobufTargetLanguage.GO:
96
+ return new GoProtobufTargetLanguageStrategy();
97
+ case ProtobufTargetLanguage.RUST:
98
+ return new RustProtobufTargetLanguageStrategy();
99
+ }
88
100
  }
89
101
  async getBufGenerateInput(protoFilesLocation) {
90
102
  const resolvedLocation = path.resolve(protoFilesLocation);
@@ -112,4 +124,31 @@ export class ProtobufCompilerClient {
112
124
  currentDirectory = parentDirectory;
113
125
  }
114
126
  }
127
+ async uploadGeneratedDirectory({ generatedDirectory, options, }) {
128
+ if (!options.uploadLocation) {
129
+ throw new Error("An upload location is required to upload generated code.");
130
+ }
131
+ const repository = this.parseGitHubRepository(options.uploadLocation, options.directory);
132
+ await this.githubClient.DANGEROUS__uploadDirectoryContents({
133
+ owner: repository.owner,
134
+ repository: repository.repository,
135
+ directory: repository.directory,
136
+ sourceDirectory: generatedDirectory,
137
+ message: options.commitMessage ?? "chore: update generated protobuf clients",
138
+ branch: options.branch,
139
+ });
140
+ }
141
+ parseGitHubRepository(uploadLocation, directory) {
142
+ const [owner, repository, ...pathParts] = uploadLocation
143
+ .split("/")
144
+ .filter(Boolean);
145
+ if (!owner || !repository) {
146
+ throw new Error("GitHub upload location must be in the form `owner/repo` or `owner/repo/path`.");
147
+ }
148
+ return {
149
+ directory: directory ?? pathParts.join("/"),
150
+ owner,
151
+ repository,
152
+ };
153
+ }
115
154
  }
@@ -1,6 +1,3 @@
1
- export declare enum ProtobufCompilerBackend {
2
- ARTIFACT_KEEPER = 0
3
- }
4
1
  export declare enum ProtobufSourceLanguage {
5
2
  RUST = 0
6
3
  }
@@ -9,41 +6,35 @@ export declare enum ProtobufTargetLanguage {
9
6
  RUST = 1,
10
7
  GO = 2
11
8
  }
12
- export interface ProtobufArtifactKeeperBackend {
13
- type: ProtobufCompilerBackend.ARTIFACT_KEEPER;
14
- url: string;
15
- username: string;
16
- token: string;
17
- }
18
- export type ProtobufCompilerBackendConfig = ProtobufArtifactKeeperBackend;
19
- export interface ProtobufJavaTargetLanguageOptions {
20
- groupId: string;
21
- artifactId: string;
22
- version: string;
23
- buildTool?: "maven" | "gradle";
24
- protobufJavaVersion?: string;
25
- }
26
- export interface ProtobufRustTargetLanguageOptions {
27
- crateName: string;
28
- version: string;
29
- prostVersion?: string;
30
- }
31
- export interface ProtobufGoTargetLanguageOptions {
32
- modulePath: string;
33
- version: string;
34
- }
35
- export type ProtobufTargetLanguageOptions = ProtobufGoTargetLanguageOptions | ProtobufJavaTargetLanguageOptions | ProtobufRustTargetLanguageOptions;
36
- export type ProtobufTargetLanguages = {
37
- [ProtobufTargetLanguage.JAVA]?: ProtobufJavaTargetLanguageOptions;
38
- [ProtobufTargetLanguage.RUST]?: ProtobufRustTargetLanguageOptions;
39
- [ProtobufTargetLanguage.GO]?: ProtobufGoTargetLanguageOptions;
40
- };
9
+ export interface ProtobufTargetLanguageOptions {
10
+ /**
11
+ * Either `owner/repo` or `owner/repo/path/inside/repo`.
12
+ *
13
+ * @example "Patina-Network/proto-clients/java"
14
+ */
15
+ uploadLocation?: string;
16
+ /** Overrides the path parsed from `uploadLocation`. */
17
+ directory?: string;
18
+ branch?: string;
19
+ commitMessage?: string;
20
+ }
21
+ export type ProtobufTargetLanguages = Partial<Record<ProtobufTargetLanguage, ProtobufTargetLanguageOptions>>;
41
22
  export interface ProtobufCompilerCompileArgs {
42
- /** All targets are published through this one backend. */
43
- backend?: ProtobufCompilerBackendConfig;
44
23
  sourceLanguage: ProtobufSourceLanguage;
45
24
  /** Optional BSR API token used for Buf remote plugins. */
46
25
  bufToken?: string;
26
+ /**
27
+ * A map of target language to target-specific options.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * {
32
+ * [ProtobufTargetLanguage.JAVA]: {
33
+ * uploadLocation: "Patina-Network/proto-clients/java",
34
+ * },
35
+ * }
36
+ * ```
37
+ */
47
38
  targetLanguages: ProtobufTargetLanguages;
48
39
  /** Directory containing proto files, or one specific `.proto` file. */
49
40
  protoFilesLocation: string;
@@ -1,7 +1,3 @@
1
- export var ProtobufCompilerBackend;
2
- (function (ProtobufCompilerBackend) {
3
- ProtobufCompilerBackend[ProtobufCompilerBackend["ARTIFACT_KEEPER"] = 0] = "ARTIFACT_KEEPER";
4
- })(ProtobufCompilerBackend || (ProtobufCompilerBackend = {}));
5
1
  export var ProtobufSourceLanguage;
6
2
  (function (ProtobufSourceLanguage) {
7
3
  ProtobufSourceLanguage[ProtobufSourceLanguage["RUST"] = 0] = "RUST";
package/dist/utils/cmd.js CHANGED
@@ -3,7 +3,7 @@ import { fromPromise } from "neverthrow";
3
3
  const GENERIC_ERROR = 1;
4
4
  const SUCCESS = 0;
5
5
  export async function isCmdAvailable(cmd) {
6
- return ((await fromPromise($ `which ${cmd}`.quiet(), (e) => e)
6
+ return ((await fromPromise($ `which -v ${cmd}`.quiet(), (e) => e)
7
7
  .map((s) => s.exitCode)
8
8
  .unwrapOr(GENERIC_ERROR)) === SUCCESS);
9
9
  }
@@ -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.4076a21f",
6
+ "version": "1.0.76-beta.6560b5dd",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -1,22 +0,0 @@
1
- import type { IProtobufCompilerBackendStrategy, ProtobufCompilerBackendPublishArgs } from "./types";
2
- import { type ProtobufArtifactKeeperBackend } from "../types";
3
- export declare class ArtifactKeeperProtobufCompilerBackend implements IProtobufCompilerBackendStrategy {
4
- private readonly config;
5
- constructor(config: ProtobufArtifactKeeperBackend);
6
- publish({ generatedDirectory, targetLanguage, options, }: ProtobufCompilerBackendPublishArgs): Promise<void>;
7
- private publishJava;
8
- private publishMaven;
9
- private publishGradle;
10
- private publishRust;
11
- private moveJavaSources;
12
- private findRustFiles;
13
- private createMavenPom;
14
- private createMavenSettings;
15
- private createGradleBuild;
16
- private createCargoToml;
17
- private createRustLibrary;
18
- private escapeXml;
19
- private get artifactKeeperUrl();
20
- private get mavenRepositoryUrl();
21
- private get cargoIndexUrl();
22
- }
@@ -1,233 +0,0 @@
1
- import { $ } from "bun";
2
- import { mkdir, mkdtemp, readdir, rename, rm, writeFile, } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import path from "node:path";
5
- import { ProtobufTargetLanguage, } from "../types";
6
- const DEFAULT_PROTOBUF_JAVA_VERSION = "4.32.1";
7
- const DEFAULT_PROST_VERSION = "0.14";
8
- export class ArtifactKeeperProtobufCompilerBackend {
9
- config;
10
- constructor(config) {
11
- this.config = config;
12
- }
13
- async publish({ generatedDirectory, targetLanguage, options, }) {
14
- switch (targetLanguage) {
15
- case ProtobufTargetLanguage.JAVA:
16
- await this.publishJava({
17
- generatedDirectory,
18
- options: options,
19
- });
20
- return;
21
- case ProtobufTargetLanguage.RUST:
22
- await this.publishRust({
23
- generatedDirectory,
24
- options: options,
25
- });
26
- return;
27
- case ProtobufTargetLanguage.GO:
28
- throw new Error("Artifact Keeper Go module publishing requires its upload workflow; only Go module consumption has been configured.");
29
- }
30
- }
31
- async publishJava({ generatedDirectory, options, }) {
32
- await this.moveJavaSources(generatedDirectory);
33
- if (options.buildTool === "gradle") {
34
- await this.publishGradle({ generatedDirectory, options });
35
- return;
36
- }
37
- await this.publishMaven({ generatedDirectory, options });
38
- }
39
- async publishMaven({ generatedDirectory, options, }) {
40
- await writeFile(path.join(generatedDirectory, "pom.xml"), this.createMavenPom(options));
41
- const settingsDirectory = await mkdtemp(path.join(tmpdir(), "artifact-keeper-maven-"));
42
- const settingsPath = path.join(settingsDirectory, "settings.xml");
43
- await writeFile(settingsPath, this.createMavenSettings());
44
- try {
45
- await $ `mvn --settings ${settingsPath} deploy`.cwd(generatedDirectory);
46
- }
47
- finally {
48
- await rm(settingsDirectory, { force: true, recursive: true });
49
- }
50
- }
51
- async publishGradle({ generatedDirectory, options, }) {
52
- await Promise.all([
53
- writeFile(path.join(generatedDirectory, "build.gradle"), this.createGradleBuild(options)),
54
- writeFile(path.join(generatedDirectory, "settings.gradle"), `rootProject.name = "${options.artifactId}"\n`),
55
- ]);
56
- await $ `gradle -PmavenUsername=${this.config.username} -PmavenPassword=${this.config.token} publish`.cwd(generatedDirectory);
57
- }
58
- async publishRust({ generatedDirectory, options, }) {
59
- const generatedFiles = await this.findRustFiles(generatedDirectory);
60
- await mkdir(path.join(generatedDirectory, "src"), { recursive: true });
61
- await Promise.all([
62
- writeFile(path.join(generatedDirectory, "Cargo.toml"), this.createCargoToml(options)),
63
- writeFile(path.join(generatedDirectory, "src", "lib.rs"), this.createRustLibrary(generatedFiles)),
64
- ]);
65
- await $ `cargo publish --registry cargo --token ${this.config.token} --config ${`registries.cargo.index=${this.cargoIndexUrl}`}`.cwd(generatedDirectory);
66
- }
67
- async moveJavaSources(generatedDirectory) {
68
- const sourceDirectory = path.join(generatedDirectory, "src", "main", "java");
69
- await mkdir(sourceDirectory, { recursive: true });
70
- for (const entry of await readdir(generatedDirectory, {
71
- withFileTypes: true,
72
- })) {
73
- if (entry.name === "src" ||
74
- entry.name === "pom.xml" ||
75
- entry.name === "build.gradle" ||
76
- entry.name === "settings.gradle") {
77
- continue;
78
- }
79
- await rename(path.join(generatedDirectory, entry.name), path.join(sourceDirectory, entry.name));
80
- }
81
- }
82
- async findRustFiles(directory, baseDirectory = directory) {
83
- const files = [];
84
- for (const entry of await readdir(directory, { withFileTypes: true })) {
85
- const filePath = path.join(directory, entry.name);
86
- if (entry.isDirectory()) {
87
- if (entry.name === "src")
88
- continue;
89
- files.push(...(await this.findRustFiles(filePath, baseDirectory)));
90
- continue;
91
- }
92
- if (entry.isFile() && entry.name.endsWith(".rs")) {
93
- files.push(path.relative(baseDirectory, filePath).split(path.sep).join("/"));
94
- }
95
- }
96
- return files;
97
- }
98
- createMavenPom(options) {
99
- const protobufVersion = options.protobufJavaVersion ?? DEFAULT_PROTOBUF_JAVA_VERSION;
100
- return `<?xml version="1.0" encoding="UTF-8"?>
101
- <project xmlns="http://maven.apache.org/POM/4.0.0"
102
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
103
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
104
- <modelVersion>4.0.0</modelVersion>
105
- <groupId>${this.escapeXml(options.groupId)}</groupId>
106
- <artifactId>${this.escapeXml(options.artifactId)}</artifactId>
107
- <version>${this.escapeXml(options.version)}</version>
108
- <properties>
109
- <maven.compiler.release>17</maven.compiler.release>
110
- </properties>
111
- <dependencies>
112
- <dependency>
113
- <groupId>com.google.protobuf</groupId>
114
- <artifactId>protobuf-java</artifactId>
115
- <version>${this.escapeXml(protobufVersion)}</version>
116
- </dependency>
117
- </dependencies>
118
- <distributionManagement>
119
- <repository>
120
- <id>maven</id>
121
- <url>${this.escapeXml(this.mavenRepositoryUrl)}</url>
122
- </repository>
123
- </distributionManagement>
124
- </project>
125
- `;
126
- }
127
- createMavenSettings() {
128
- return `<settings>
129
- <servers>
130
- <server>
131
- <id>maven</id>
132
- <username>${this.escapeXml(this.config.username)}</username>
133
- <password>${this.escapeXml(this.config.token)}</password>
134
- </server>
135
- </servers>
136
- </settings>
137
- `;
138
- }
139
- createGradleBuild(options) {
140
- const protobufVersion = options.protobufJavaVersion ?? DEFAULT_PROTOBUF_JAVA_VERSION;
141
- return `plugins {
142
- id "java"
143
- id "maven-publish"
144
- }
145
-
146
- group = "${options.groupId}"
147
- version = "${options.version}"
148
-
149
- repositories {
150
- mavenCentral()
151
- }
152
-
153
- dependencies {
154
- implementation "com.google.protobuf:protobuf-java:${protobufVersion}"
155
- }
156
-
157
- java {
158
- toolchain {
159
- languageVersion = JavaLanguageVersion.of(17)
160
- }
161
- }
162
-
163
- publishing {
164
- publications {
165
- mavenJava(MavenPublication) {
166
- from components.java
167
- artifactId = "${options.artifactId}"
168
- }
169
- }
170
- repositories {
171
- maven {
172
- url = uri("${this.mavenRepositoryUrl}")
173
- credentials {
174
- username = project.findProperty("mavenUsername")
175
- password = project.findProperty("mavenPassword")
176
- }
177
- }
178
- }
179
- }
180
- `;
181
- }
182
- createCargoToml(options) {
183
- const prostVersion = options.prostVersion ?? DEFAULT_PROST_VERSION;
184
- return `[package]
185
- name = "${options.crateName}"
186
- version = "${options.version}"
187
- edition = "2021"
188
-
189
- [dependencies]
190
- prost = "${prostVersion}"
191
- `;
192
- }
193
- createRustLibrary(generatedFiles) {
194
- return generatedFiles
195
- .map((relativePath) => {
196
- const moduleName = relativePath
197
- .replace(/\.rs$/, "")
198
- .replace(/[^a-zA-Z0-9_]/g, "_");
199
- return `pub mod ${moduleName} {
200
- include!(concat!(env!("CARGO_MANIFEST_DIR"), "/${relativePath}"));
201
- }
202
- `;
203
- })
204
- .join("\n");
205
- }
206
- escapeXml(value) {
207
- return value.replace(/[<>&'"]/g, (character) => {
208
- switch (character) {
209
- case "<":
210
- return "&lt;";
211
- case ">":
212
- return "&gt;";
213
- case "&":
214
- return "&amp;";
215
- case "'":
216
- return "&apos;";
217
- case '"':
218
- return "&quot;";
219
- default:
220
- return character;
221
- }
222
- });
223
- }
224
- get artifactKeeperUrl() {
225
- return this.config.url.replace(/\/$/, "");
226
- }
227
- get mavenRepositoryUrl() {
228
- return `${this.artifactKeeperUrl}/maven/maven/`;
229
- }
230
- get cargoIndexUrl() {
231
- return `${this.artifactKeeperUrl}/cargo/cargo/index`;
232
- }
233
- }
@@ -1,5 +0,0 @@
1
- import type { IProtobufCompilerBackendStrategy } from "./types";
2
- import { type ProtobufCompilerBackendConfig } from "../types";
3
- export * from "./artifact-keeper";
4
- export * from "./types";
5
- export declare function createProtobufCompilerBackendStrategy(backend: ProtobufCompilerBackendConfig): IProtobufCompilerBackendStrategy;
@@ -1,10 +0,0 @@
1
- import { ProtobufCompilerBackend, } from "../types";
2
- import { ArtifactKeeperProtobufCompilerBackend } from "./artifact-keeper";
3
- export * from "./artifact-keeper";
4
- export * from "./types";
5
- const BACKEND_STRATEGY_FACTORIES = {
6
- [ProtobufCompilerBackend.ARTIFACT_KEEPER]: (backend) => new ArtifactKeeperProtobufCompilerBackend(backend),
7
- };
8
- export function createProtobufCompilerBackendStrategy(backend) {
9
- return BACKEND_STRATEGY_FACTORIES[backend.type](backend);
10
- }
@@ -1,9 +0,0 @@
1
- import type { ProtobufTargetLanguage, ProtobufTargetLanguageOptions } from "../types";
2
- export interface ProtobufCompilerBackendPublishArgs {
3
- generatedDirectory: string;
4
- targetLanguage: ProtobufTargetLanguage;
5
- options: ProtobufTargetLanguageOptions;
6
- }
7
- export interface IProtobufCompilerBackendStrategy {
8
- publish(args: ProtobufCompilerBackendPublishArgs): Promise<void>;
9
- }
File without changes
@@ -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
- }