@forwardimpact/libcodegen 0.1.37 → 0.1.39
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 +69 -0
- package/package.json +1 -1
package/bin/fit-codegen.js
CHANGED
|
@@ -179,6 +179,63 @@ function createCodegen(
|
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Count files recursively in a directory
|
|
184
|
+
* @param {string} dirPath - Directory to count files in
|
|
185
|
+
* @returns {number} Total file count
|
|
186
|
+
*/
|
|
187
|
+
function countFiles(dirPath) {
|
|
188
|
+
let count = 0;
|
|
189
|
+
if (!fs.existsSync(dirPath)) return count;
|
|
190
|
+
for (const entry of fs.readdirSync(dirPath, { withFileTypes: true })) {
|
|
191
|
+
if (entry.isDirectory()) {
|
|
192
|
+
count += countFiles(path.join(dirPath, entry.name));
|
|
193
|
+
} else if (!entry.name.endsWith(".tar.gz")) {
|
|
194
|
+
count++;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return count;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Print a summary of generated code
|
|
202
|
+
* @param {string} sourcePath - Path to generated directory
|
|
203
|
+
* @param {object} flags - Parsed generation flags
|
|
204
|
+
*/
|
|
205
|
+
function printSummary(sourcePath, flags) {
|
|
206
|
+
const totalFiles = countFiles(sourcePath);
|
|
207
|
+
const relPath = path.relative(process.cwd(), sourcePath);
|
|
208
|
+
const lines = [`Generated ${totalFiles} files in ./${relPath}/`];
|
|
209
|
+
|
|
210
|
+
const dirLabels = {
|
|
211
|
+
types: "Protocol Buffer types",
|
|
212
|
+
proto: "Proto source files",
|
|
213
|
+
services: "Service bases and clients",
|
|
214
|
+
definitions: "Service definitions",
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
if (fs.existsSync(sourcePath)) {
|
|
218
|
+
const dirs = fs
|
|
219
|
+
.readdirSync(sourcePath, { withFileTypes: true })
|
|
220
|
+
.filter((e) => e.isDirectory());
|
|
221
|
+
|
|
222
|
+
for (const dir of dirs) {
|
|
223
|
+
const label = dirLabels[dir.name];
|
|
224
|
+
if (label) lines.push(` ${dir.name}/ — ${label}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const generated = [
|
|
229
|
+
flags.doTypes && "types",
|
|
230
|
+
flags.doServices && "services",
|
|
231
|
+
flags.doClients && "clients",
|
|
232
|
+
flags.doDefinitions && "definitions",
|
|
233
|
+
].filter(Boolean);
|
|
234
|
+
lines.push(`\nCode generation complete (${generated.join(", ")}).`);
|
|
235
|
+
|
|
236
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
237
|
+
}
|
|
238
|
+
|
|
182
239
|
/**
|
|
183
240
|
* Execute code generation tasks
|
|
184
241
|
* @param {object} codegens - Codegen instances
|
|
@@ -239,6 +296,16 @@ async function runCodegen(protoDirs, projectRoot, finder) {
|
|
|
239
296
|
|
|
240
297
|
await generatedStorage.ensureBucket();
|
|
241
298
|
|
|
299
|
+
// Write package.json with "type": "module" so Node.js treats generated
|
|
300
|
+
// ES module files correctly and avoids MODULE_TYPELESS_PACKAGE_JSON warnings.
|
|
301
|
+
const generatedPkgPath = path.join(sourcePath, "package.json");
|
|
302
|
+
if (!fs.existsSync(generatedPkgPath)) {
|
|
303
|
+
fs.writeFileSync(
|
|
304
|
+
generatedPkgPath,
|
|
305
|
+
JSON.stringify({ type: "module" }, null, 2) + "\n",
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
242
309
|
const codegens = createCodegen(
|
|
243
310
|
protoDirs,
|
|
244
311
|
projectRoot,
|
|
@@ -251,6 +318,8 @@ async function runCodegen(protoDirs, projectRoot, finder) {
|
|
|
251
318
|
|
|
252
319
|
await finder.createPackageSymlinks(sourcePath);
|
|
253
320
|
await createBundle(sourcePath);
|
|
321
|
+
|
|
322
|
+
printSummary(sourcePath, parsedFlags);
|
|
254
323
|
}
|
|
255
324
|
|
|
256
325
|
/**
|