@forwardimpact/libcodegen 0.1.28 → 0.1.29
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/bin/fit-codegen.js +20 -7
- package/package.json +5 -5
- package/types.js +13 -4
package/bin/fit-codegen.js
CHANGED
|
@@ -4,7 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import fsAsync from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import {
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
|
|
10
10
|
import protoLoader from "@grpc/proto-loader";
|
|
@@ -42,12 +42,17 @@ async function createBundle(sourcePath) {
|
|
|
42
42
|
|
|
43
43
|
// Create tar.gz archive using system tar command
|
|
44
44
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
execFileSync(
|
|
46
|
+
"tar",
|
|
47
|
+
["-czf", bundlePath, "-C", sourcePath, ...directories],
|
|
48
|
+
{
|
|
49
|
+
stdio: "pipe",
|
|
50
|
+
},
|
|
51
|
+
);
|
|
49
52
|
} catch (error) {
|
|
50
|
-
throw new Error(`Failed to create bundle: ${error.message}
|
|
53
|
+
throw new Error(`Failed to create bundle: ${error.message}`, {
|
|
54
|
+
cause: error,
|
|
55
|
+
});
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -122,8 +127,16 @@ function parseFlags() {
|
|
|
122
127
|
*/
|
|
123
128
|
function createCodegen(projectRoot, path, mustache, protoLoader, fs) {
|
|
124
129
|
const base = new CodegenBase(projectRoot, path, mustache, protoLoader, fs);
|
|
130
|
+
const pbjsPath = path.resolve(
|
|
131
|
+
__dirname,
|
|
132
|
+
"..",
|
|
133
|
+
"node_modules",
|
|
134
|
+
"protobufjs-cli",
|
|
135
|
+
"bin",
|
|
136
|
+
"pbjs",
|
|
137
|
+
);
|
|
125
138
|
return {
|
|
126
|
-
types: new CodegenTypes(base),
|
|
139
|
+
types: new CodegenTypes(base, pbjsPath),
|
|
127
140
|
services: new CodegenServices(base),
|
|
128
141
|
definitions: new CodegenDefinitions(base),
|
|
129
142
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forwardimpact/libcodegen",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Protocol Buffer code generation utilities for Guide",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "D. Olsson <hi@senzilla.io>",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@grpc/proto-loader": "^0.8.0",
|
|
20
|
-
"mustache": "^4.2.0"
|
|
21
|
-
"protobufjs": "^7.5.4",
|
|
22
|
-
"protobufjs-cli": "^1.2.0"
|
|
20
|
+
"mustache": "^4.2.0"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
25
|
-
"@forwardimpact/libharness": "^0.1.5"
|
|
23
|
+
"@forwardimpact/libharness": "^0.1.5",
|
|
24
|
+
"protobufjs": "^7.5.4",
|
|
25
|
+
"protobufjs-cli": "^2.0.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
package/types.js
CHANGED
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export class CodegenTypes {
|
|
6
6
|
#base;
|
|
7
|
+
#pbjsPath;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Creates a new types generator with base functionality
|
|
10
11
|
* @param {object} base - CodegenBase instance providing shared utilities
|
|
12
|
+
* @param {string} [pbjsPath] - Absolute path to the pbjs binary (resolved from protobufjs-cli)
|
|
11
13
|
*/
|
|
12
|
-
constructor(base) {
|
|
14
|
+
constructor(base, pbjsPath) {
|
|
13
15
|
if (!base) throw new Error("CodegenBase instance is required");
|
|
14
16
|
this.#base = base;
|
|
17
|
+
this.#pbjsPath = pbjsPath || null;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
/**
|
|
@@ -85,8 +88,14 @@ export class CodegenTypes {
|
|
|
85
88
|
...protoFiles,
|
|
86
89
|
];
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
if (this.#pbjsPath) {
|
|
92
|
+
await this.#base.run(process.execPath, [this.#pbjsPath, ...args], {
|
|
93
|
+
cwd: this.#base.projectRoot,
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
await this.#base.run("npx", ["pbjs", ...args], {
|
|
97
|
+
cwd: this.#base.projectRoot,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
}
|