@mnci/cli 1.9.1 → 1.10.0
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 +41 -3
- package/dist/cli.js +213 -80
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(cli_exports);
|
|
|
38
38
|
var import_commander = require("commander");
|
|
39
39
|
|
|
40
40
|
// src/commands/add.ts
|
|
41
|
-
var
|
|
41
|
+
var import_node_path9 = require("path");
|
|
42
42
|
var import_prompts4 = require("@inquirer/prompts");
|
|
43
43
|
|
|
44
44
|
// src/nx.ts
|
|
@@ -164,7 +164,11 @@ function assertValidProjectName(name, label) {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
// src/commands/add/flutter.ts
|
|
168
|
+
var import_node_path3 = require("path");
|
|
169
|
+
|
|
167
170
|
// src/commands/add/shared.ts
|
|
171
|
+
var import_node_fs2 = require("fs");
|
|
168
172
|
var import_node_path2 = require("path");
|
|
169
173
|
function hasPlugin(workspaceRoot, packageName) {
|
|
170
174
|
const manifest = readJson((0, import_node_path2.join)(workspaceRoot, "package.json"));
|
|
@@ -198,8 +202,79 @@ function addNxTargets(manifestPath, newTargets) {
|
|
|
198
202
|
toJson({ ...manifest, nx: { ...nx, targets: { ...targets, ...newTargets } } })
|
|
199
203
|
);
|
|
200
204
|
}
|
|
205
|
+
function findCodeWorkspaceFile(workspaceRoot) {
|
|
206
|
+
try {
|
|
207
|
+
const entry = (0, import_node_fs2.readdirSync)(workspaceRoot).find((file) => file.endsWith(".code-workspace"));
|
|
208
|
+
return entry ? (0, import_node_path2.join)(workspaceRoot, entry) : void 0;
|
|
209
|
+
} catch {
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function readCodeWorkspaceFile(path) {
|
|
214
|
+
const contents = (0, import_node_fs2.readFileSync)(path, "utf8").replaceAll(/,(\s*[}\]])/g, "$1");
|
|
215
|
+
return JSON.parse(contents);
|
|
216
|
+
}
|
|
217
|
+
function projectTask(name, kind) {
|
|
218
|
+
const script = `${name}:${kind}`;
|
|
219
|
+
const base = { label: `${name}: ${kind}`, type: "npm", script, problemMatcher: [] };
|
|
220
|
+
return kind === "start" ? { ...base, isBackground: true } : { ...base, group: kind };
|
|
221
|
+
}
|
|
222
|
+
function registerProjectCommands(workspaceRoot, name, commands) {
|
|
223
|
+
const scripts = {
|
|
224
|
+
[`${name}:qa`]: `nx run ${name}:lint && nx run ${name}:test`
|
|
225
|
+
};
|
|
226
|
+
if (commands.build) {
|
|
227
|
+
scripts[`${name}:build`] = `nx run ${name}:build`;
|
|
228
|
+
}
|
|
229
|
+
if (commands.start) {
|
|
230
|
+
scripts[`${name}:start`] = commands.start;
|
|
231
|
+
}
|
|
232
|
+
const manifestPath = (0, import_node_path2.join)(workspaceRoot, "package.json");
|
|
233
|
+
const manifest = readJson(manifestPath);
|
|
234
|
+
const existingScripts = manifest.scripts ?? {};
|
|
235
|
+
writeFileEnsured(
|
|
236
|
+
manifestPath,
|
|
237
|
+
toJson({ ...manifest, scripts: { ...existingScripts, ...scripts } })
|
|
238
|
+
);
|
|
239
|
+
const codeWorkspacePath = findCodeWorkspaceFile(workspaceRoot);
|
|
240
|
+
if (!codeWorkspacePath) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const workspaceFile = readCodeWorkspaceFile(codeWorkspacePath);
|
|
244
|
+
const label = (task) => task.label ?? "";
|
|
245
|
+
const existingTasks = (workspaceFile.tasks?.tasks ?? []).filter(
|
|
246
|
+
(task) => !label(task).startsWith(`${name}: `)
|
|
247
|
+
);
|
|
248
|
+
const newTasks = [
|
|
249
|
+
projectTask(name, "qa"),
|
|
250
|
+
...commands.build ? [projectTask(name, "build")] : [],
|
|
251
|
+
...commands.start ? [projectTask(name, "start")] : []
|
|
252
|
+
];
|
|
253
|
+
writeFileEnsured(
|
|
254
|
+
codeWorkspacePath,
|
|
255
|
+
toJson({
|
|
256
|
+
...workspaceFile,
|
|
257
|
+
tasks: {
|
|
258
|
+
version: workspaceFile.tasks?.version ?? "2.0.0",
|
|
259
|
+
tasks: [...existingTasks, ...newTasks]
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
);
|
|
263
|
+
}
|
|
201
264
|
|
|
202
265
|
// src/commands/add/flutter.ts
|
|
266
|
+
function addProjectJsonTargets(projectJsonPath, newTargets) {
|
|
267
|
+
const project = readJson(projectJsonPath);
|
|
268
|
+
const targets = project.targets ?? {};
|
|
269
|
+
writeFileEnsured(projectJsonPath, toJson({ ...project, targets: { ...targets, ...newTargets } }));
|
|
270
|
+
}
|
|
271
|
+
function flutterAppStartTarget(name) {
|
|
272
|
+
return {
|
|
273
|
+
executor: "nx:run-commands",
|
|
274
|
+
continuous: true,
|
|
275
|
+
options: { command: "flutter run -d chrome", cwd: `apps/${name}` }
|
|
276
|
+
};
|
|
277
|
+
}
|
|
203
278
|
function ensureFlutter(workspaceRoot) {
|
|
204
279
|
if (runShell("flutter", ["--version"], workspaceRoot) !== 0) {
|
|
205
280
|
throw new Error(
|
|
@@ -228,19 +303,25 @@ function addFlutterApp(workspaceRoot, name) {
|
|
|
228
303
|
prepareFlutter(workspaceRoot);
|
|
229
304
|
ensureAdmZip(workspaceRoot);
|
|
230
305
|
runNx(["g", "@mnci/nx-flutter:application", name, "--no-interactive"], workspaceRoot);
|
|
306
|
+
addProjectJsonTargets((0, import_node_path3.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
307
|
+
start: flutterAppStartTarget(name)
|
|
308
|
+
});
|
|
309
|
+
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:start` });
|
|
231
310
|
}
|
|
232
311
|
function addFlutterLib(workspaceRoot, name) {
|
|
233
312
|
prepareFlutter(workspaceRoot);
|
|
234
313
|
runNx(["g", "@mnci/nx-flutter:library", name, "--no-interactive"], workspaceRoot);
|
|
314
|
+
registerProjectCommands(workspaceRoot, name, { build: false });
|
|
235
315
|
}
|
|
236
316
|
function addFlutterInternalLib(workspaceRoot, name) {
|
|
237
317
|
prepareFlutter(workspaceRoot);
|
|
238
318
|
runNx(["g", "@mnci/nx-flutter:internal-library", name, "--no-interactive"], workspaceRoot);
|
|
319
|
+
registerProjectCommands(workspaceRoot, name, { build: false });
|
|
239
320
|
}
|
|
240
321
|
|
|
241
322
|
// src/commands/add/go.ts
|
|
242
|
-
var
|
|
243
|
-
var
|
|
323
|
+
var import_node_fs3 = require("fs");
|
|
324
|
+
var import_node_path4 = require("path");
|
|
244
325
|
function ensureGo(workspaceRoot) {
|
|
245
326
|
if (runShell("go", ["version"], workspaceRoot) !== 0) {
|
|
246
327
|
throw new Error("Go not found. Install Go 1.21+ first: https://go.dev/dl/");
|
|
@@ -267,7 +348,7 @@ function ensureNxGoPlugin(workspaceRoot) {
|
|
|
267
348
|
}
|
|
268
349
|
}
|
|
269
350
|
function ensureGoModule(workspaceRoot) {
|
|
270
|
-
if (fileExists((0,
|
|
351
|
+
if (fileExists((0, import_node_path4.join)(workspaceRoot, "go.mod"))) {
|
|
271
352
|
return;
|
|
272
353
|
}
|
|
273
354
|
logger.step("Bootstrapping the workspace Go module (single root go.mod)");
|
|
@@ -276,13 +357,13 @@ function ensureGoModule(workspaceRoot) {
|
|
|
276
357
|
}
|
|
277
358
|
function goModulePath(workspaceRoot) {
|
|
278
359
|
try {
|
|
279
|
-
const contents = (0,
|
|
360
|
+
const contents = (0, import_node_fs3.readFileSync)((0, import_node_path4.join)(workspaceRoot, "go.mod"), "utf8");
|
|
280
361
|
return /^module\s+(\S+)/m.exec(contents)?.[1];
|
|
281
362
|
} catch {
|
|
282
363
|
return void 0;
|
|
283
364
|
}
|
|
284
365
|
}
|
|
285
|
-
function
|
|
366
|
+
function addProjectJsonTargets2(projectJsonPath, newTargets) {
|
|
286
367
|
const project = readJson(projectJsonPath);
|
|
287
368
|
const targets = project.targets ?? {};
|
|
288
369
|
writeFileEnsured(projectJsonPath, toJson({ ...project, targets: { ...targets, ...newTargets } }));
|
|
@@ -312,6 +393,13 @@ function goPackageTarget(tag, name) {
|
|
|
312
393
|
options: { command }
|
|
313
394
|
};
|
|
314
395
|
}
|
|
396
|
+
function goStartTarget(name) {
|
|
397
|
+
return {
|
|
398
|
+
executor: "nx:run-commands",
|
|
399
|
+
continuous: true,
|
|
400
|
+
options: { command: "go run .", cwd: `apps/${name}` }
|
|
401
|
+
};
|
|
402
|
+
}
|
|
315
403
|
function prepareGo(workspaceRoot) {
|
|
316
404
|
ensureGo(workspaceRoot);
|
|
317
405
|
warnIfNoGolangciLint(workspaceRoot);
|
|
@@ -332,12 +420,14 @@ function addGoApp(workspaceRoot, name) {
|
|
|
332
420
|
],
|
|
333
421
|
workspaceRoot
|
|
334
422
|
);
|
|
335
|
-
|
|
423
|
+
addProjectJsonTargets2((0, import_node_path4.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
336
424
|
build: goBuildTarget(name),
|
|
337
425
|
test: goTestTarget(),
|
|
338
426
|
lint: goLintTarget(),
|
|
339
|
-
package: goPackageTarget("go-app", name)
|
|
427
|
+
package: goPackageTarget("go-app", name),
|
|
428
|
+
start: goStartTarget(name)
|
|
340
429
|
});
|
|
430
|
+
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:start` });
|
|
341
431
|
}
|
|
342
432
|
function addGoFunctionApp(workspaceRoot, name) {
|
|
343
433
|
prepareGo(workspaceRoot);
|
|
@@ -353,12 +443,13 @@ function addGoFunctionApp(workspaceRoot, name) {
|
|
|
353
443
|
],
|
|
354
444
|
workspaceRoot
|
|
355
445
|
);
|
|
356
|
-
|
|
446
|
+
addProjectJsonTargets2((0, import_node_path4.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
357
447
|
build: goBuildTarget(name),
|
|
358
448
|
test: goTestTarget(),
|
|
359
449
|
lint: goLintTarget(),
|
|
360
450
|
package: goPackageTarget("go-function-app", name)
|
|
361
451
|
});
|
|
452
|
+
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
362
453
|
}
|
|
363
454
|
function addGoLib(workspaceRoot, name) {
|
|
364
455
|
prepareGo(workspaceRoot);
|
|
@@ -373,10 +464,11 @@ function addGoLib(workspaceRoot, name) {
|
|
|
373
464
|
],
|
|
374
465
|
workspaceRoot
|
|
375
466
|
);
|
|
376
|
-
|
|
467
|
+
addProjectJsonTargets2((0, import_node_path4.join)(workspaceRoot, "packages", name, "project.json"), {
|
|
377
468
|
test: goTestTarget(),
|
|
378
469
|
lint: goLintTarget()
|
|
379
470
|
});
|
|
471
|
+
registerProjectCommands(workspaceRoot, name, { build: false });
|
|
380
472
|
const module2 = goModulePath(workspaceRoot);
|
|
381
473
|
if (module2) {
|
|
382
474
|
logger.step(`Import it as ${module2}/packages/${name}`);
|
|
@@ -395,10 +487,11 @@ function addGoInternalLib(workspaceRoot, name) {
|
|
|
395
487
|
],
|
|
396
488
|
workspaceRoot
|
|
397
489
|
);
|
|
398
|
-
|
|
490
|
+
addProjectJsonTargets2((0, import_node_path4.join)(workspaceRoot, "libs", name, "project.json"), {
|
|
399
491
|
test: goTestTarget(),
|
|
400
492
|
lint: goLintTarget()
|
|
401
493
|
});
|
|
494
|
+
registerProjectCommands(workspaceRoot, name, { build: false });
|
|
402
495
|
const module2 = goModulePath(workspaceRoot);
|
|
403
496
|
if (module2) {
|
|
404
497
|
logger.step(`Import it as ${module2}/libs/${name}`);
|
|
@@ -406,7 +499,7 @@ function addGoInternalLib(workspaceRoot, name) {
|
|
|
406
499
|
}
|
|
407
500
|
|
|
408
501
|
// src/commands/add/node.ts
|
|
409
|
-
var
|
|
502
|
+
var import_node_path5 = require("path");
|
|
410
503
|
function ensurePlugin(workspaceRoot, packageName) {
|
|
411
504
|
if (hasPlugin(workspaceRoot, packageName)) {
|
|
412
505
|
return;
|
|
@@ -445,9 +538,10 @@ function nodeAppPackageTarget(name) {
|
|
|
445
538
|
function addNodeApp(workspaceRoot, name, stack, framework = "none") {
|
|
446
539
|
runNodeApp(workspaceRoot, name, stack, framework);
|
|
447
540
|
ensureAdmZip(workspaceRoot);
|
|
448
|
-
addNxTargets((0,
|
|
541
|
+
addNxTargets((0, import_node_path5.join)(workspaceRoot, "apps", name, "package.json"), {
|
|
449
542
|
package: nodeAppPackageTarget(name)
|
|
450
543
|
});
|
|
544
|
+
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:serve` });
|
|
451
545
|
}
|
|
452
546
|
function ensureAzureFunctionsPackage(workspaceRoot) {
|
|
453
547
|
if (hasPlugin(workspaceRoot, "@azure/functions")) {
|
|
@@ -498,17 +592,17 @@ describe('buildGreeting', () => {
|
|
|
498
592
|
})
|
|
499
593
|
`;
|
|
500
594
|
function repairNodeFunctionAppManifest(nodeFunctionAppRoot, workspaceRoot) {
|
|
501
|
-
const manifestPath = (0,
|
|
595
|
+
const manifestPath = (0, import_node_path5.join)(nodeFunctionAppRoot, "package.json");
|
|
502
596
|
const manifest = readJson(manifestPath);
|
|
503
597
|
const azureFunctionsVersion = readJson(
|
|
504
|
-
(0,
|
|
598
|
+
(0, import_node_path5.join)(workspaceRoot, "node_modules/@azure/functions/package.json")
|
|
505
599
|
).version;
|
|
506
600
|
const dependencies = manifest.dependencies ?? {};
|
|
507
601
|
writeFileEnsured(
|
|
508
602
|
manifestPath,
|
|
509
603
|
toJson({
|
|
510
604
|
...manifest,
|
|
511
|
-
main: "main.js",
|
|
605
|
+
main: "dist/main.js",
|
|
512
606
|
dependencies: { ...dependencies, "@azure/functions": `^${azureFunctionsVersion}` }
|
|
513
607
|
})
|
|
514
608
|
);
|
|
@@ -516,7 +610,7 @@ function repairNodeFunctionAppManifest(nodeFunctionAppRoot, workspaceRoot) {
|
|
|
516
610
|
function nodeFunctionAppPackageTarget(name) {
|
|
517
611
|
const zip = `dist/drop/node-function-app-${name}.zip`;
|
|
518
612
|
const root = `apps/${name}`;
|
|
519
|
-
const command = `node -e "const fs=require('node:fs');fs.mkdirSync('dist/drop',{recursive:true});const A=require('adm-zip');const z=new A();z.addLocalFolder('${root}/dist');z.addLocalFile('${root}/host.json');z.addLocalFile('${root}/package.json');z.writeZip('${zip}')"`;
|
|
613
|
+
const command = `node -e "const fs=require('node:fs');fs.mkdirSync('dist/drop',{recursive:true});const A=require('adm-zip');const z=new A();z.addLocalFolder('${root}/dist','dist');z.addLocalFile('${root}/host.json');z.addLocalFile('${root}/package.json');z.writeZip('${zip}')"`;
|
|
520
614
|
return {
|
|
521
615
|
executor: "nx:run-commands",
|
|
522
616
|
dependsOn: ["build"],
|
|
@@ -525,30 +619,40 @@ function nodeFunctionAppPackageTarget(name) {
|
|
|
525
619
|
options: { command }
|
|
526
620
|
};
|
|
527
621
|
}
|
|
622
|
+
function nodeFunctionAppStartTarget(name) {
|
|
623
|
+
return {
|
|
624
|
+
executor: "nx:run-commands",
|
|
625
|
+
dependsOn: ["build"],
|
|
626
|
+
continuous: true,
|
|
627
|
+
options: { command: "func start", cwd: `apps/${name}` }
|
|
628
|
+
};
|
|
629
|
+
}
|
|
528
630
|
function addNodeFunctionApp(workspaceRoot, name, stack) {
|
|
529
631
|
runNodeApp(workspaceRoot, name, stack, "none");
|
|
530
632
|
ensureAzureFunctionsPackage(workspaceRoot);
|
|
531
|
-
const nodeFunctionAppRoot = (0,
|
|
532
|
-
writeFileEnsured((0,
|
|
533
|
-
writeFileEnsured((0,
|
|
633
|
+
const nodeFunctionAppRoot = (0, import_node_path5.join)(workspaceRoot, "apps", name);
|
|
634
|
+
writeFileEnsured((0, import_node_path5.join)(nodeFunctionAppRoot, "src/main.ts"), NODE_FUNCTION_APP_MAIN);
|
|
635
|
+
writeFileEnsured((0, import_node_path5.join)(nodeFunctionAppRoot, "src/functions/hello.ts"), NODE_FUNCTION_APP_HELLO);
|
|
534
636
|
writeFileEnsured(
|
|
535
|
-
(0,
|
|
637
|
+
(0, import_node_path5.join)(nodeFunctionAppRoot, "src/functions/greeting.ts"),
|
|
536
638
|
NODE_FUNCTION_APP_GREETING
|
|
537
639
|
);
|
|
538
640
|
writeFileEnsured(
|
|
539
|
-
(0,
|
|
641
|
+
(0, import_node_path5.join)(nodeFunctionAppRoot, "src/functions/greeting.spec.ts"),
|
|
540
642
|
NODE_FUNCTION_APP_GREETING_SPEC
|
|
541
643
|
);
|
|
542
|
-
writeFileEnsured((0,
|
|
644
|
+
writeFileEnsured((0, import_node_path5.join)(nodeFunctionAppRoot, "host.json"), NODE_FUNCTION_APP_HOST_JSON);
|
|
543
645
|
repairNodeFunctionAppManifest(nodeFunctionAppRoot, workspaceRoot);
|
|
544
646
|
ensureAdmZip(workspaceRoot);
|
|
545
|
-
addNxTargets((0,
|
|
546
|
-
package: nodeFunctionAppPackageTarget(name)
|
|
647
|
+
addNxTargets((0, import_node_path5.join)(nodeFunctionAppRoot, "package.json"), {
|
|
648
|
+
package: nodeFunctionAppPackageTarget(name),
|
|
649
|
+
start: nodeFunctionAppStartTarget(name)
|
|
547
650
|
});
|
|
651
|
+
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:start` });
|
|
548
652
|
}
|
|
549
653
|
|
|
550
654
|
// src/commands/add/npmLib.ts
|
|
551
|
-
var
|
|
655
|
+
var import_node_path6 = require("path");
|
|
552
656
|
var NPM_LIB_ESLINT_CONFIG = `import { globSync, readFileSync } from 'node:fs';
|
|
553
657
|
import { dirname, join } from 'node:path';
|
|
554
658
|
import { fileURLToPath } from 'node:url';
|
|
@@ -616,11 +720,12 @@ async function addNpmLib(workspaceRoot, name, options, kindProvided, stack) {
|
|
|
616
720
|
],
|
|
617
721
|
workspaceRoot
|
|
618
722
|
);
|
|
619
|
-
markPublic((0,
|
|
723
|
+
markPublic((0, import_node_path6.join)(workspaceRoot, "packages", name, "package.json"));
|
|
620
724
|
writeFileEnsured(
|
|
621
|
-
(0,
|
|
725
|
+
(0, import_node_path6.join)(workspaceRoot, "packages", name, "eslint.config.mjs"),
|
|
622
726
|
NPM_LIB_ESLINT_CONFIG
|
|
623
727
|
);
|
|
728
|
+
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
624
729
|
}
|
|
625
730
|
function markPublic(manifestPath) {
|
|
626
731
|
const manifest = readJson(manifestPath);
|
|
@@ -628,8 +733,8 @@ function markPublic(manifestPath) {
|
|
|
628
733
|
}
|
|
629
734
|
|
|
630
735
|
// src/commands/add/python.ts
|
|
631
|
-
var
|
|
632
|
-
var
|
|
736
|
+
var import_node_fs4 = require("fs");
|
|
737
|
+
var import_node_path7 = require("path");
|
|
633
738
|
function ensurePython(workspaceRoot) {
|
|
634
739
|
const hasPython = runShell("python3", ["--version"], workspaceRoot) === 0 || runShell("python", ["--version"], workspaceRoot) === 0;
|
|
635
740
|
if (!hasPython) {
|
|
@@ -658,7 +763,7 @@ pytest
|
|
|
658
763
|
pip-audit
|
|
659
764
|
`;
|
|
660
765
|
function ensureRequirementsDev(workspaceRoot) {
|
|
661
|
-
const requirementsDevPath = (0,
|
|
766
|
+
const requirementsDevPath = (0, import_node_path7.join)(workspaceRoot, "requirements-dev.txt");
|
|
662
767
|
if (!fileExists(requirementsDevPath)) {
|
|
663
768
|
writeFileEnsured(requirementsDevPath, PYTHON_REQUIREMENTS_DEV);
|
|
664
769
|
}
|
|
@@ -666,11 +771,34 @@ function ensureRequirementsDev(workspaceRoot) {
|
|
|
666
771
|
function pythonModuleDirectory(name) {
|
|
667
772
|
return name.replaceAll("-", "_");
|
|
668
773
|
}
|
|
669
|
-
function
|
|
774
|
+
function addProjectJsonTargets3(projectJsonPath, newTargets) {
|
|
670
775
|
const project = readJson(projectJsonPath);
|
|
671
776
|
const targets = project.targets ?? {};
|
|
672
777
|
writeFileEnsured(projectJsonPath, toJson({ ...project, targets: { ...targets, ...newTargets } }));
|
|
673
778
|
}
|
|
779
|
+
function pythonAppMain(name) {
|
|
780
|
+
return `def main() -> None:
|
|
781
|
+
print('${name} is running')
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
if __name__ == '__main__':
|
|
785
|
+
main()
|
|
786
|
+
`;
|
|
787
|
+
}
|
|
788
|
+
function pythonAppStartTarget(name) {
|
|
789
|
+
return {
|
|
790
|
+
executor: "nx:run-commands",
|
|
791
|
+
continuous: true,
|
|
792
|
+
options: { command: "python3 main.py", cwd: `apps/${name}` }
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function pythonFunctionAppStartTarget(name) {
|
|
796
|
+
return {
|
|
797
|
+
executor: "nx:run-commands",
|
|
798
|
+
continuous: true,
|
|
799
|
+
options: { command: "func start", cwd: `apps/${name}` }
|
|
800
|
+
};
|
|
801
|
+
}
|
|
674
802
|
function pythonAppPackageTarget(name) {
|
|
675
803
|
const zip = `dist/drop/python-app-${name}.zip`;
|
|
676
804
|
const command = `node -e "const fs=require('node:fs');fs.mkdirSync('dist/drop',{recursive:true});const A=require('adm-zip');const z=new A();z.addLocalFolder('apps/${name}/dist');z.writeZip('${zip}')"`;
|
|
@@ -702,9 +830,12 @@ function addPythonApp(workspaceRoot, name) {
|
|
|
702
830
|
["g", "@mnci/nx-python-pip:application", name, `--directory=apps/${name}`, "--no-interactive"],
|
|
703
831
|
workspaceRoot
|
|
704
832
|
);
|
|
705
|
-
|
|
706
|
-
|
|
833
|
+
writeFileEnsured((0, import_node_path7.join)(workspaceRoot, "apps", name, "main.py"), pythonAppMain(name));
|
|
834
|
+
addProjectJsonTargets3((0, import_node_path7.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
835
|
+
package: pythonAppPackageTarget(name),
|
|
836
|
+
start: pythonAppStartTarget(name)
|
|
707
837
|
});
|
|
838
|
+
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:start` });
|
|
708
839
|
}
|
|
709
840
|
function addPythonFunctionApp(workspaceRoot, name) {
|
|
710
841
|
ensurePython(workspaceRoot);
|
|
@@ -722,9 +853,11 @@ function addPythonFunctionApp(workspaceRoot, name) {
|
|
|
722
853
|
workspaceRoot
|
|
723
854
|
);
|
|
724
855
|
const moduleDirectory = pythonModuleDirectory(name);
|
|
725
|
-
|
|
726
|
-
package: pythonFunctionAppPackageTarget(name, moduleDirectory)
|
|
856
|
+
addProjectJsonTargets3((0, import_node_path7.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
857
|
+
package: pythonFunctionAppPackageTarget(name, moduleDirectory),
|
|
858
|
+
start: pythonFunctionAppStartTarget(name)
|
|
727
859
|
});
|
|
860
|
+
registerProjectCommands(workspaceRoot, name, { build: false, start: `nx run ${name}:start` });
|
|
728
861
|
}
|
|
729
862
|
function addPythonLib(workspaceRoot, name) {
|
|
730
863
|
ensurePython(workspaceRoot);
|
|
@@ -740,6 +873,7 @@ function addPythonLib(workspaceRoot, name) {
|
|
|
740
873
|
],
|
|
741
874
|
workspaceRoot
|
|
742
875
|
);
|
|
876
|
+
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
743
877
|
}
|
|
744
878
|
function addPythonInternalLib(workspaceRoot, name) {
|
|
745
879
|
ensurePython(workspaceRoot);
|
|
@@ -755,11 +889,12 @@ function addPythonInternalLib(workspaceRoot, name) {
|
|
|
755
889
|
],
|
|
756
890
|
workspaceRoot
|
|
757
891
|
);
|
|
892
|
+
registerProjectCommands(workspaceRoot, name, { build: false });
|
|
758
893
|
}
|
|
759
894
|
var PYTHON_PROJECT_DIRS = ["apps", "python-packages", "libs"];
|
|
760
895
|
function findPythonProjectDirectory(workspaceRoot, name) {
|
|
761
896
|
return PYTHON_PROJECT_DIRS.find(
|
|
762
|
-
(directory) => fileExists((0,
|
|
897
|
+
(directory) => fileExists((0, import_node_path7.join)(workspaceRoot, directory, name, "pyproject.toml"))
|
|
763
898
|
);
|
|
764
899
|
}
|
|
765
900
|
function parseVendorEntries(pyprojectToml) {
|
|
@@ -798,7 +933,7 @@ async function addPythonVendor(workspaceRoot, consumer, options, kindProvided) {
|
|
|
798
933
|
`No Python project named '${consumer}' with a pyproject.toml found (checked apps/, python-packages/, libs/). A Python function app has no pyproject.toml \u2014 there is nothing to vendor into.`
|
|
799
934
|
);
|
|
800
935
|
}
|
|
801
|
-
if (!fileExists((0,
|
|
936
|
+
if (!fileExists((0, import_node_path7.join)(workspaceRoot, "libs", lib, "pyproject.toml"))) {
|
|
802
937
|
throw new Error(
|
|
803
938
|
`No internal Python library named '${lib}' found at libs/${lib}/pyproject.toml. Only an internal library (added via 'mnci add python-internal-lib') can be vendored.`
|
|
804
939
|
);
|
|
@@ -806,8 +941,8 @@ async function addPythonVendor(workspaceRoot, consumer, options, kindProvided) {
|
|
|
806
941
|
if (consumerDirectory === "libs" && consumer === lib) {
|
|
807
942
|
throw new Error(`'${consumer}' cannot vendor itself.`);
|
|
808
943
|
}
|
|
809
|
-
const pyprojectPath = (0,
|
|
810
|
-
const pyprojectToml = (0,
|
|
944
|
+
const pyprojectPath = (0, import_node_path7.join)(workspaceRoot, consumerDirectory, consumer, "pyproject.toml");
|
|
945
|
+
const pyprojectToml = (0, import_node_fs4.readFileSync)(pyprojectPath, "utf8");
|
|
811
946
|
if (parseVendorEntries(pyprojectToml).includes(lib)) {
|
|
812
947
|
logger.info(`'${consumer}' already vendors '${lib}' \u2014 nothing to do.`);
|
|
813
948
|
return;
|
|
@@ -819,8 +954,8 @@ async function addPythonVendor(workspaceRoot, consumer, options, kindProvided) {
|
|
|
819
954
|
}
|
|
820
955
|
|
|
821
956
|
// src/commands/add/reactApp.ts
|
|
822
|
-
var
|
|
823
|
-
var
|
|
957
|
+
var import_node_fs5 = require("fs");
|
|
958
|
+
var import_node_path8 = require("path");
|
|
824
959
|
function ensurePlugin2(workspaceRoot, packageName) {
|
|
825
960
|
if (hasPlugin(workspaceRoot, packageName)) {
|
|
826
961
|
return;
|
|
@@ -866,12 +1001,12 @@ function reactAppTargets(name) {
|
|
|
866
1001
|
return targets;
|
|
867
1002
|
}
|
|
868
1003
|
function allowEnvFiles(workspaceRoot) {
|
|
869
|
-
const gitignorePath = (0,
|
|
1004
|
+
const gitignorePath = (0, import_node_path8.join)(workspaceRoot, ".gitignore");
|
|
870
1005
|
if (!fileExists(gitignorePath)) {
|
|
871
1006
|
return;
|
|
872
1007
|
}
|
|
873
1008
|
const marker = "# MoNecromanCI: keep the committed per-environment Vite config (public VITE_ values)";
|
|
874
|
-
const current = (0,
|
|
1009
|
+
const current = (0, import_node_fs5.readFileSync)(gitignorePath, "utf8");
|
|
875
1010
|
if (current.includes(marker)) {
|
|
876
1011
|
return;
|
|
877
1012
|
}
|
|
@@ -898,12 +1033,13 @@ function addReactApp(workspaceRoot, name, stack) {
|
|
|
898
1033
|
workspaceRoot
|
|
899
1034
|
);
|
|
900
1035
|
ensureAdmZip(workspaceRoot);
|
|
901
|
-
const reactAppRoot = (0,
|
|
1036
|
+
const reactAppRoot = (0, import_node_path8.join)(workspaceRoot, "apps", name);
|
|
902
1037
|
for (const environment of REACT_ENVIRONMENTS) {
|
|
903
|
-
writeFileEnsured((0,
|
|
1038
|
+
writeFileEnsured((0, import_node_path8.join)(reactAppRoot, `.env.${environment}`), reactEnvironmentFile(environment));
|
|
904
1039
|
}
|
|
905
1040
|
allowEnvFiles(workspaceRoot);
|
|
906
|
-
addNxTargets((0,
|
|
1041
|
+
addNxTargets((0, import_node_path8.join)(reactAppRoot, "package.json"), reactAppTargets(name));
|
|
1042
|
+
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:serve` });
|
|
907
1043
|
}
|
|
908
1044
|
|
|
909
1045
|
// src/commands/add.ts
|
|
@@ -928,7 +1064,7 @@ var PROJECT_KINDS = [
|
|
|
928
1064
|
];
|
|
929
1065
|
async function runAdd(kind, name, options) {
|
|
930
1066
|
const workspaceRoot = process.cwd();
|
|
931
|
-
if (!fileExists((0,
|
|
1067
|
+
if (!fileExists((0, import_node_path9.join)(workspaceRoot, "nx.json"))) {
|
|
932
1068
|
throw new Error("No nx.json found here. Run `add` from the workspace root.");
|
|
933
1069
|
}
|
|
934
1070
|
const stack = readWorkspaceStack(workspaceRoot);
|
|
@@ -969,7 +1105,8 @@ async function runAdd(kind, name, options) {
|
|
|
969
1105
|
],
|
|
970
1106
|
workspaceRoot
|
|
971
1107
|
);
|
|
972
|
-
markPrivate((0,
|
|
1108
|
+
markPrivate((0, import_node_path9.join)(workspaceRoot, "libs", resolvedName, "package.json"));
|
|
1109
|
+
registerProjectCommands(workspaceRoot, resolvedName, { build: true });
|
|
973
1110
|
break;
|
|
974
1111
|
}
|
|
975
1112
|
case "python-app": {
|
|
@@ -1041,7 +1178,7 @@ function syncProjectReferences(workspaceRoot) {
|
|
|
1041
1178
|
}
|
|
1042
1179
|
function readWorkspaceStack(workspaceRoot) {
|
|
1043
1180
|
const nxJson = readJson(
|
|
1044
|
-
(0,
|
|
1181
|
+
(0, import_node_path9.join)(workspaceRoot, "nx.json")
|
|
1045
1182
|
);
|
|
1046
1183
|
const stack = nxJson.mnci?.stack;
|
|
1047
1184
|
return {
|
|
@@ -1054,14 +1191,14 @@ function markPrivate(manifestPath) {
|
|
|
1054
1191
|
}
|
|
1055
1192
|
|
|
1056
1193
|
// src/commands/interactive.ts
|
|
1057
|
-
var
|
|
1194
|
+
var import_node_path13 = require("path");
|
|
1058
1195
|
var import_prompts7 = require("@inquirer/prompts");
|
|
1059
1196
|
|
|
1060
1197
|
// src/commands/new.ts
|
|
1061
|
-
var
|
|
1198
|
+
var import_node_path11 = require("path");
|
|
1062
1199
|
|
|
1063
1200
|
// src/overlay.ts
|
|
1064
|
-
var
|
|
1201
|
+
var import_node_path10 = require("path");
|
|
1065
1202
|
var DEFAULT_STACK = { testRunner: "jest" };
|
|
1066
1203
|
var PRETTIER_VERSION = "^3.8.1";
|
|
1067
1204
|
var TS_COMPILER_DEPENDENCIES = {
|
|
@@ -1155,12 +1292,7 @@ package-lock.json
|
|
|
1155
1292
|
function vscodeWorkspace(workspaceName) {
|
|
1156
1293
|
return JSON.stringify(
|
|
1157
1294
|
{
|
|
1158
|
-
folders: [
|
|
1159
|
-
{ path: ".", name: workspaceName },
|
|
1160
|
-
{ path: "packages/cli", name: "@mnci/cli" },
|
|
1161
|
-
{ path: "packages/nx-python-pip", name: "@mnci/nx-python-pip" },
|
|
1162
|
-
{ path: "libs/monecromanci-v2", name: "@mnci/monecromanci" }
|
|
1163
|
-
],
|
|
1295
|
+
folders: [{ path: ".", name: workspaceName }],
|
|
1164
1296
|
settings: {
|
|
1165
1297
|
"eslint.validate": [
|
|
1166
1298
|
"javascript",
|
|
@@ -1194,7 +1326,8 @@ function vscodeWorkspace(workspaceName) {
|
|
|
1194
1326
|
"nrwl.angular-console",
|
|
1195
1327
|
"firsttris.vscode-jest-runner"
|
|
1196
1328
|
]
|
|
1197
|
-
}
|
|
1329
|
+
},
|
|
1330
|
+
tasks: { version: "2.0.0", tasks: [] }
|
|
1198
1331
|
},
|
|
1199
1332
|
null,
|
|
1200
1333
|
2
|
|
@@ -1239,7 +1372,7 @@ function mnciConfig(options) {
|
|
|
1239
1372
|
};
|
|
1240
1373
|
}
|
|
1241
1374
|
function readMnciConfig(workspaceRoot) {
|
|
1242
|
-
const nxJson = readJson((0,
|
|
1375
|
+
const nxJson = readJson((0, import_node_path10.join)(workspaceRoot, "nx.json"));
|
|
1243
1376
|
return nxJson.mnci ?? {};
|
|
1244
1377
|
}
|
|
1245
1378
|
function pythonPublishUrl(registry) {
|
|
@@ -1665,7 +1798,7 @@ updates:
|
|
|
1665
1798
|
interval: weekly
|
|
1666
1799
|
`;
|
|
1667
1800
|
function applyOverlay(workspaceRoot, options) {
|
|
1668
|
-
const nxJsonPath = (0,
|
|
1801
|
+
const nxJsonPath = (0, import_node_path10.join)(workspaceRoot, "nx.json");
|
|
1669
1802
|
const nxJson = readJson(nxJsonPath);
|
|
1670
1803
|
const generators = {
|
|
1671
1804
|
...nxJson.generators,
|
|
@@ -1677,7 +1810,7 @@ function applyOverlay(workspaceRoot, options) {
|
|
|
1677
1810
|
nxJsonPath,
|
|
1678
1811
|
toJson({ ...withReleaseConfig(nxJson, options.ci), generators, sync, mnci })
|
|
1679
1812
|
);
|
|
1680
|
-
const manifestPath = (0,
|
|
1813
|
+
const manifestPath = (0, import_node_path10.join)(workspaceRoot, "package.json");
|
|
1681
1814
|
const manifest = readJson(manifestPath);
|
|
1682
1815
|
const scripts = {
|
|
1683
1816
|
...manifest.scripts,
|
|
@@ -1692,30 +1825,30 @@ function applyOverlay(workspaceRoot, options) {
|
|
|
1692
1825
|
manifestPath,
|
|
1693
1826
|
toJson({ ...manifest, name: `${options.scope}/source`, scripts, devDependencies: devDeps })
|
|
1694
1827
|
);
|
|
1695
|
-
writeFileEnsured((0,
|
|
1696
|
-
writeFileEnsured((0,
|
|
1697
|
-
const hookPath = (0,
|
|
1828
|
+
writeFileEnsured((0, import_node_path10.join)(workspaceRoot, ".npmrc"), npmrcContent(options.registry, options.scope));
|
|
1829
|
+
writeFileEnsured((0, import_node_path10.join)(workspaceRoot, "commitlint.config.mjs"), COMMITLINT_CONFIG);
|
|
1830
|
+
const hookPath = (0, import_node_path10.join)(workspaceRoot, ".husky/commit-msg");
|
|
1698
1831
|
writeFileEnsured(hookPath, COMMIT_MSG_HOOK);
|
|
1699
1832
|
markExecutable(hookPath);
|
|
1700
|
-
writeFileEnsured((0,
|
|
1701
|
-
writeFileEnsured((0,
|
|
1833
|
+
writeFileEnsured((0, import_node_path10.join)(workspaceRoot, ".prettierrc.json"), PRETTIER_CONFIG);
|
|
1834
|
+
writeFileEnsured((0, import_node_path10.join)(workspaceRoot, ".prettierignore"), PRETTIER_IGNORE);
|
|
1702
1835
|
writeFileEnsured(
|
|
1703
|
-
(0,
|
|
1836
|
+
(0, import_node_path10.join)(workspaceRoot, `${options.workspaceName}.code-workspace`),
|
|
1704
1837
|
vscodeWorkspace(options.workspaceName)
|
|
1705
1838
|
);
|
|
1706
1839
|
const publishUrl = pythonPublishUrl(options.registry);
|
|
1707
1840
|
if (options.ci === "azure" || options.ci === "both") {
|
|
1708
1841
|
writeFileEnsured(
|
|
1709
|
-
(0,
|
|
1842
|
+
(0, import_node_path10.join)(workspaceRoot, "azure-pipelines.yml"),
|
|
1710
1843
|
azurePipelinesYaml(options.agent, options.variableGroup, publishUrl, options.registry.kind)
|
|
1711
1844
|
);
|
|
1712
1845
|
}
|
|
1713
1846
|
if (options.ci === "github" || options.ci === "both") {
|
|
1714
1847
|
writeFileEnsured(
|
|
1715
|
-
(0,
|
|
1848
|
+
(0, import_node_path10.join)(workspaceRoot, ".github/workflows/ci.yml"),
|
|
1716
1849
|
githubActionsYaml(options.agent, publishUrl, options.registry.kind, options.ci)
|
|
1717
1850
|
);
|
|
1718
|
-
writeFileEnsured((0,
|
|
1851
|
+
writeFileEnsured((0, import_node_path10.join)(workspaceRoot, ".github/dependabot.yml"), DEPENDABOT_CONFIG);
|
|
1719
1852
|
}
|
|
1720
1853
|
}
|
|
1721
1854
|
|
|
@@ -1784,7 +1917,7 @@ async function runNew(name, options) {
|
|
|
1784
1917
|
],
|
|
1785
1918
|
process.cwd()
|
|
1786
1919
|
);
|
|
1787
|
-
const workspaceRoot = (0,
|
|
1920
|
+
const workspaceRoot = (0, import_node_path11.join)(process.cwd(), workspaceName);
|
|
1788
1921
|
logger.step(
|
|
1789
1922
|
"Applying MoNecromanCI overlay (VS Code workspace, release config, .npmrc, commitlint, pipeline, stack)"
|
|
1790
1923
|
);
|
|
@@ -1817,7 +1950,7 @@ async function runNew(name, options) {
|
|
|
1817
1950
|
}
|
|
1818
1951
|
|
|
1819
1952
|
// src/commands/upgrade.ts
|
|
1820
|
-
var
|
|
1953
|
+
var import_node_path12 = require("path");
|
|
1821
1954
|
function resolveRegistry2(options, persisted) {
|
|
1822
1955
|
if (options.registry === "azure-artifacts" || options.organization && options.artifactsFeed) {
|
|
1823
1956
|
const persistedAzure = persisted?.kind === "azure-artifacts" ? persisted : void 0;
|
|
@@ -1869,7 +2002,7 @@ function resolveOverlayOptions(options, persisted) {
|
|
|
1869
2002
|
return { scope, registry, agent, variableGroup, ci, stack: { testRunner } };
|
|
1870
2003
|
}
|
|
1871
2004
|
function runUpgrade(workspaceRoot, options) {
|
|
1872
|
-
if (!fileExists((0,
|
|
2005
|
+
if (!fileExists((0, import_node_path12.join)(workspaceRoot, "nx.json"))) {
|
|
1873
2006
|
throw new Error(
|
|
1874
2007
|
`No nx.json found in ${workspaceRoot} \u2014 this does not look like an Nx workspace. Run 'mnci upgrade' from the workspace root.`
|
|
1875
2008
|
);
|
|
@@ -1885,7 +2018,7 @@ function runUpgrade(workspaceRoot, options) {
|
|
|
1885
2018
|
|
|
1886
2019
|
// src/commands/interactive.ts
|
|
1887
2020
|
async function runInteractive() {
|
|
1888
|
-
const inWorkspace = fileExists((0,
|
|
2021
|
+
const inWorkspace = fileExists((0, import_node_path13.join)(process.cwd(), "nx.json"));
|
|
1889
2022
|
const newChoice = { name: "Create a new monorepo", value: "new" };
|
|
1890
2023
|
const addChoice = { name: "Add a project to this workspace", value: "add" };
|
|
1891
2024
|
const upgradeChoice = {
|
|
@@ -1906,8 +2039,8 @@ async function runInteractive() {
|
|
|
1906
2039
|
}
|
|
1907
2040
|
|
|
1908
2041
|
// src/util/versionChecker.ts
|
|
1909
|
-
var
|
|
1910
|
-
var
|
|
2042
|
+
var import_node_fs6 = require("fs");
|
|
2043
|
+
var import_node_path14 = require("path");
|
|
1911
2044
|
var import_cross_spawn2 = __toESM(require("cross-spawn"));
|
|
1912
2045
|
var PACKAGE_NAME = "@mnci/cli";
|
|
1913
2046
|
var REGISTRY_TIMEOUT_MS = 2e3;
|
|
@@ -1963,8 +2096,8 @@ function releaseTriple(version) {
|
|
|
1963
2096
|
}
|
|
1964
2097
|
function readCliVersion(packageDirectory) {
|
|
1965
2098
|
try {
|
|
1966
|
-
const manifestPath = (0,
|
|
1967
|
-
const manifest = JSON.parse((0,
|
|
2099
|
+
const manifestPath = (0, import_node_path14.join)(packageDirectory, "..", "package.json");
|
|
2100
|
+
const manifest = JSON.parse((0, import_node_fs6.readFileSync)(manifestPath, "utf8"));
|
|
1968
2101
|
return manifest.version ?? "0.0.0";
|
|
1969
2102
|
} catch {
|
|
1970
2103
|
return "0.0.0";
|