@tahminator/pipeline 1.0.76-beta.9003fd90 → 1.0.76-beta.ffbeee6f
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 +10 -14
- package/dist/protobuf/client.d.ts +6 -1
- package/dist/protobuf/client.js +42 -14
- package/dist/protobuf/types.d.ts +25 -34
- package/dist/protobuf/types.js +0 -4
- package/dist/utils/cmd.js +1 -1
- package/package.json +1 -1
- package/dist/protobuf/backend/artifact-keeper.d.ts +0 -22
- package/dist/protobuf/backend/artifact-keeper.js +0 -233
- package/dist/protobuf/backend/index.d.ts +0 -5
- package/dist/protobuf/backend/index.js +0 -10
- package/dist/protobuf/backend/types.d.ts +0 -9
- package/dist/protobuf/backend/types.js +0 -0
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
|
|
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
|
|
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
|
-
|
|
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",
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { GitHubClient } from "../gh";
|
|
1
2
|
import { type ProtobufCompilerCompileArgs, type ProtobufCompilerCompileResult } from "./types";
|
|
2
3
|
export declare class ProtobufCompilerClient {
|
|
3
|
-
|
|
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;
|
|
@@ -8,4 +11,6 @@ export declare class ProtobufCompilerClient {
|
|
|
8
11
|
private getTargetLanguageStrategy;
|
|
9
12
|
private getBufGenerateInput;
|
|
10
13
|
private findBufModuleDirectory;
|
|
14
|
+
private uploadGeneratedDirectory;
|
|
15
|
+
private parseGitHubRepository;
|
|
11
16
|
}
|
package/dist/protobuf/client.js
CHANGED
|
@@ -4,16 +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
9
|
export class ProtobufCompilerClient {
|
|
11
|
-
|
|
10
|
+
githubClient;
|
|
11
|
+
constructor(githubClient) {
|
|
12
|
+
this.githubClient = githubClient;
|
|
13
|
+
}
|
|
14
|
+
async compile({ bufToken, targetLanguages, protoFilesLocation, outputDirectory, }) {
|
|
12
15
|
await this.installToolchains();
|
|
13
16
|
const outputDirectoryPath = path.resolve(outputDirectory ??
|
|
14
17
|
(await mkdtemp(path.join(tmpdir(), "protobuf-compiler-"))));
|
|
15
18
|
const targets = this.getCompilationTargets(targetLanguages);
|
|
16
|
-
const compilerBackend = backend ? createProtobufCompilerBackendStrategy(backend) : undefined;
|
|
17
19
|
await mkdir(outputDirectoryPath, { recursive: true });
|
|
18
20
|
await this.generateWithBuf({
|
|
19
21
|
bufToken,
|
|
@@ -25,18 +27,17 @@ export class ProtobufCompilerClient {
|
|
|
25
27
|
for (const { language, strategy } of targets) {
|
|
26
28
|
generatedDirectories[language] = path.join(outputDirectoryPath, strategy.outputDirectoryName);
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
await compilerBackend.publish({
|
|
35
|
-
generatedDirectory,
|
|
36
|
-
options,
|
|
37
|
-
targetLanguage: language,
|
|
38
|
-
});
|
|
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.");
|
|
39
36
|
}
|
|
37
|
+
await this.uploadGeneratedDirectory({
|
|
38
|
+
generatedDirectory,
|
|
39
|
+
options,
|
|
40
|
+
});
|
|
40
41
|
}
|
|
41
42
|
return { generatedDirectories, outputDirectory: outputDirectoryPath };
|
|
42
43
|
}
|
|
@@ -123,4 +124,31 @@ export class ProtobufCompilerClient {
|
|
|
123
124
|
currentDirectory = parentDirectory;
|
|
124
125
|
}
|
|
125
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
|
+
}
|
|
126
154
|
}
|
package/dist/protobuf/types.d.ts
CHANGED
|
@@ -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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
package/dist/protobuf/types.js
CHANGED
|
@@ -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
|
}
|
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.
|
|
6
|
+
"version": "1.0.76-beta.ffbeee6f",
|
|
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 "<";
|
|
211
|
-
case ">":
|
|
212
|
-
return ">";
|
|
213
|
-
case "&":
|
|
214
|
-
return "&";
|
|
215
|
-
case "'":
|
|
216
|
-
return "'";
|
|
217
|
-
case '"':
|
|
218
|
-
return """;
|
|
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
|
-
export function createProtobufCompilerBackendStrategy(backend) {
|
|
6
|
-
switch (backend.type) {
|
|
7
|
-
case ProtobufCompilerBackend.ARTIFACT_KEEPER:
|
|
8
|
-
return new ArtifactKeeperProtobufCompilerBackend(backend);
|
|
9
|
-
}
|
|
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
|