@mnci/cli 4.23.1 → 4.25.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 +1 -0
- package/dist/cli.js +77 -11
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,6 +87,7 @@ cd my-repo
|
|
|
87
87
|
mnci add react-app web # @nx/react (Vite + Jest)
|
|
88
88
|
mnci add node-app svc # @nx/node (plain Node app, esbuild)
|
|
89
89
|
mnci add node-app api --framework express # ...or fastify | koa | nest
|
|
90
|
+
mnci add npm-lib core --empty # slice skeleton only, no sample (also internal-lib, react-lib, react-internal-lib)
|
|
90
91
|
mnci add node-function-app api # @nx/node + an Azure Functions v4 overlay
|
|
91
92
|
mnci add npm-lib sdk # @nx/js publishable lib -> packages/
|
|
92
93
|
mnci add internal-lib utils # @nx/js private lib -> libs/
|
package/dist/cli.js
CHANGED
|
@@ -2672,11 +2672,11 @@ function projectTask(name, kind) {
|
|
|
2672
2672
|
const base = { label: `${name}: ${kind}`, type: "npm", script, problemMatcher: [] };
|
|
2673
2673
|
return kind === "start" ? { ...base, isBackground: true } : { ...base, group: kind };
|
|
2674
2674
|
}
|
|
2675
|
-
function renameScaffoldPlaceholder(projectRoot, name) {
|
|
2676
|
-
reshapeScaffoldSlice(projectRoot, name, "ts", "use-case");
|
|
2675
|
+
function renameScaffoldPlaceholder(projectRoot, name, empty = false) {
|
|
2676
|
+
reshapeScaffoldSlice(projectRoot, name, "ts", "use-case", empty);
|
|
2677
2677
|
}
|
|
2678
|
-
function reshapeReactScaffold(projectRoot, name) {
|
|
2679
|
-
reshapeScaffoldSlice(projectRoot, name, "tsx", "component");
|
|
2678
|
+
function reshapeReactScaffold(projectRoot, name, empty = false) {
|
|
2679
|
+
reshapeScaffoldSlice(projectRoot, name, "tsx", "component", empty);
|
|
2680
2680
|
}
|
|
2681
2681
|
function reshapeReactAppScaffold(projectRoot) {
|
|
2682
2682
|
const appDir = (0, import_node_path5.join)(projectRoot, "src", "app");
|
|
@@ -2705,7 +2705,14 @@ function reshapeReactAppScaffold(projectRoot) {
|
|
|
2705
2705
|
"export * from './app.component'\nexport { default } from './app.component'\n"
|
|
2706
2706
|
);
|
|
2707
2707
|
}
|
|
2708
|
-
function
|
|
2708
|
+
function emptySlice(projectRoot, sliceDir) {
|
|
2709
|
+
for (const entry of (0, import_node_fs5.readdirSync)(sliceDir)) {
|
|
2710
|
+
(0, import_node_fs5.rmSync)((0, import_node_path5.join)(sliceDir, entry), { recursive: true, force: true });
|
|
2711
|
+
}
|
|
2712
|
+
writeFileEnsured((0, import_node_path5.join)(sliceDir, "index.ts"), "export {}\n");
|
|
2713
|
+
addNxTargets((0, import_node_path5.join)(projectRoot, "package.json"), { test: { options: { passWithNoTests: true } } });
|
|
2714
|
+
}
|
|
2715
|
+
function reshapeScaffoldSlice(projectRoot, name, extension, role, empty) {
|
|
2709
2716
|
const sourceDir = (0, import_node_path5.join)(projectRoot, "src");
|
|
2710
2717
|
const libDir = (0, import_node_path5.join)(sourceDir, "lib");
|
|
2711
2718
|
if (!(0, import_node_fs5.existsSync)((0, import_node_path5.join)(libDir, `${name}.${extension}`))) {
|
|
@@ -2735,6 +2742,58 @@ function reshapeScaffoldSlice(projectRoot, name, extension, role) {
|
|
|
2735
2742
|
);
|
|
2736
2743
|
}
|
|
2737
2744
|
(0, import_node_fs5.rmSync)(libDir, { recursive: true, force: true });
|
|
2745
|
+
if (empty) {
|
|
2746
|
+
emptySlice(projectRoot, sliceDir);
|
|
2747
|
+
} else if (role === "use-case") {
|
|
2748
|
+
writeWorkedExample(sliceDir, name, esm);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
function writeWorkedExample(sliceDir, name, esm) {
|
|
2752
|
+
const suffix = esm ? ".js" : "";
|
|
2753
|
+
writeFileEnsured(
|
|
2754
|
+
(0, import_node_path5.join)(sliceDir, `${name}.contract.ts`),
|
|
2755
|
+
`/** What greeting someone returns. */
|
|
2756
|
+
export interface Greeting {
|
|
2757
|
+
readonly message: string
|
|
2758
|
+
}
|
|
2759
|
+
`
|
|
2760
|
+
);
|
|
2761
|
+
writeFileEnsured(
|
|
2762
|
+
(0, import_node_path5.join)(sliceDir, `${name}.use-case.ts`),
|
|
2763
|
+
`import type { Greeting } from './${name}.contract${suffix}'
|
|
2764
|
+
|
|
2765
|
+
/**
|
|
2766
|
+
* Greets someone by name.
|
|
2767
|
+
*
|
|
2768
|
+
* @remarks
|
|
2769
|
+
* A worked example of a use case: one outcome, returning a contract. Replace it
|
|
2770
|
+
* with your own.
|
|
2771
|
+
*
|
|
2772
|
+
* @param name - Who to greet.
|
|
2773
|
+
* @returns The greeting.
|
|
2774
|
+
*/
|
|
2775
|
+
export function greet (name: string): Greeting {
|
|
2776
|
+
return { message: 'Hello, ' + name + '!' }
|
|
2777
|
+
}
|
|
2778
|
+
`
|
|
2779
|
+
);
|
|
2780
|
+
writeFileEnsured(
|
|
2781
|
+
(0, import_node_path5.join)(sliceDir, `${name}.use-case.spec.ts`),
|
|
2782
|
+
`import { greet } from './${name}.use-case${suffix}'
|
|
2783
|
+
|
|
2784
|
+
describe('greet', () => {
|
|
2785
|
+
it('greets by name', () => {
|
|
2786
|
+
expect(greet('world')).toEqual({ message: 'Hello, world!' })
|
|
2787
|
+
})
|
|
2788
|
+
})
|
|
2789
|
+
`
|
|
2790
|
+
);
|
|
2791
|
+
writeFileEnsured(
|
|
2792
|
+
(0, import_node_path5.join)(sliceDir, "index.ts"),
|
|
2793
|
+
`export * from './${name}.contract${suffix}'
|
|
2794
|
+
export * from './${name}.use-case${suffix}'
|
|
2795
|
+
`
|
|
2796
|
+
);
|
|
2738
2797
|
}
|
|
2739
2798
|
function repointSpecifier(source, from, to) {
|
|
2740
2799
|
let result = source;
|
|
@@ -4450,7 +4509,7 @@ async function addNpmLib(workspaceRoot, name, options, kindProvided, stack) {
|
|
|
4450
4509
|
repairPublishableManifest(manifestPath);
|
|
4451
4510
|
repairDeclarationSpecifiers(projectRoot);
|
|
4452
4511
|
writeProjectReadme(projectRoot, `${scope}/${name}`, stack.testRunner);
|
|
4453
|
-
renameScaffoldPlaceholder(projectRoot, name);
|
|
4512
|
+
renameScaffoldPlaceholder(projectRoot, name, options.empty === true);
|
|
4454
4513
|
removeGeneratedEslintConfig(workspaceRoot, `packages/${name}`);
|
|
4455
4514
|
removeLocalRegistryScaffolding(workspaceRoot);
|
|
4456
4515
|
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
@@ -4799,14 +4858,14 @@ async function addReactLib(workspaceRoot, name, options, kindProvided, stack) {
|
|
|
4799
4858
|
repairPublishableManifest(publishableManifest);
|
|
4800
4859
|
repairDeclarationSpecifiers(projectRoot);
|
|
4801
4860
|
writeProjectReadme(projectRoot, `${scope}/${name}`, stack.testRunner);
|
|
4802
|
-
reshapeReactScaffold(projectRoot, name);
|
|
4861
|
+
reshapeReactScaffold(projectRoot, name, options.empty === true);
|
|
4803
4862
|
removeGeneratedEslintConfig(workspaceRoot, `packages/${name}`);
|
|
4804
4863
|
removeLocalRegistryScaffolding(workspaceRoot);
|
|
4805
4864
|
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
4806
4865
|
}
|
|
4807
4866
|
);
|
|
4808
4867
|
}
|
|
4809
|
-
function addReactInternalLib(workspaceRoot, name, stack) {
|
|
4868
|
+
function addReactInternalLib(workspaceRoot, name, stack, empty = false) {
|
|
4810
4869
|
ensurePlugin(workspaceRoot, "@nx/react");
|
|
4811
4870
|
const projectRoot = (0, import_node_path19.join)(workspaceRoot, "libs", name);
|
|
4812
4871
|
const privateManifest = (0, import_node_path19.join)(projectRoot, "package.json");
|
|
@@ -4828,7 +4887,7 @@ function addReactInternalLib(workspaceRoot, name, stack) {
|
|
|
4828
4887
|
repairPublishableManifest(privateManifest);
|
|
4829
4888
|
repairDeclarationSpecifiers(projectRoot);
|
|
4830
4889
|
writeProjectReadme(projectRoot, name, stack.testRunner);
|
|
4831
|
-
reshapeReactScaffold(projectRoot, name);
|
|
4890
|
+
reshapeReactScaffold(projectRoot, name, empty);
|
|
4832
4891
|
removeGeneratedEslintConfig(workspaceRoot, `libs/${name}`);
|
|
4833
4892
|
registerProjectCommands(workspaceRoot, name, { build: true });
|
|
4834
4893
|
}
|
|
@@ -6483,6 +6542,7 @@ var PROJECT_KINDS = [
|
|
|
6483
6542
|
"csharp-internal-lib",
|
|
6484
6543
|
"vscode-extension"
|
|
6485
6544
|
];
|
|
6545
|
+
var EMPTY_KINDS = /* @__PURE__ */ new Set(["npm-lib", "internal-lib", "react-lib", "react-internal-lib"]);
|
|
6486
6546
|
async function runAdd(kind, name, options) {
|
|
6487
6547
|
const workspaceRoot = process.cwd();
|
|
6488
6548
|
if (!fileExists((0, import_node_path25.join)(workspaceRoot, "nx.json"))) {
|
|
@@ -6503,6 +6563,9 @@ async function runAdd(kind, name, options) {
|
|
|
6503
6563
|
throw new Error(`${flag} applies to go-app only, not ${resolvedKind}.`);
|
|
6504
6564
|
}
|
|
6505
6565
|
}
|
|
6566
|
+
if (options.empty === true && !EMPTY_KINDS.has(resolvedKind)) {
|
|
6567
|
+
throw new Error(`--empty applies to ${[...EMPTY_KINDS].join(", ")}, not ${resolvedKind}.`);
|
|
6568
|
+
}
|
|
6506
6569
|
const resolvedName = name ?? await promptText("Project name");
|
|
6507
6570
|
assertValidProjectName(resolvedName, "Project name");
|
|
6508
6571
|
const rootDependenciesBefore = rootRuntimeDependencies(workspaceRoot);
|
|
@@ -6517,7 +6580,7 @@ async function runAdd(kind, name, options) {
|
|
|
6517
6580
|
break;
|
|
6518
6581
|
}
|
|
6519
6582
|
case "react-internal-lib": {
|
|
6520
|
-
addReactInternalLib(workspaceRoot, resolvedName, stack);
|
|
6583
|
+
addReactInternalLib(workspaceRoot, resolvedName, stack, options.empty === true);
|
|
6521
6584
|
break;
|
|
6522
6585
|
}
|
|
6523
6586
|
case "node-app": {
|
|
@@ -6546,7 +6609,7 @@ async function runAdd(kind, name, options) {
|
|
|
6546
6609
|
workspaceRoot
|
|
6547
6610
|
);
|
|
6548
6611
|
markPrivate((0, import_node_path25.join)(workspaceRoot, "libs", resolvedName, "package.json"));
|
|
6549
|
-
renameScaffoldPlaceholder((0, import_node_path25.join)(workspaceRoot, "libs", resolvedName), resolvedName);
|
|
6612
|
+
renameScaffoldPlaceholder((0, import_node_path25.join)(workspaceRoot, "libs", resolvedName), resolvedName, options.empty === true);
|
|
6550
6613
|
removeGeneratedEslintConfig(workspaceRoot, `libs/${resolvedName}`);
|
|
6551
6614
|
registerProjectCommands(workspaceRoot, resolvedName, { build: true });
|
|
6552
6615
|
break;
|
|
@@ -7641,6 +7704,9 @@ function buildProgram(cliVersion) {
|
|
|
7641
7704
|
program.command("add").addArgument(new import_commander.Argument("[kind]", "project kind").choices(PROJECT_KINDS)).argument("[name]", "project name").description("Add a project by delegating to the matching Nx plugin generator").option("--scope <scope>", "npm scope for a publishable lib (defaults to @<workspace name>)").option(
|
|
7642
7705
|
"--framework <framework>",
|
|
7643
7706
|
"node-app only: express | fastify | koa | nest | none (default: none)"
|
|
7707
|
+
).option(
|
|
7708
|
+
"--empty",
|
|
7709
|
+
"npm-lib, internal-lib, react-lib, react-internal-lib: scaffold the slice skeleton only, with no sample code or spec"
|
|
7644
7710
|
).option(
|
|
7645
7711
|
"--lib <name>",
|
|
7646
7712
|
"python-vendor only: the internal Python library (libs/<name>) to vendor into <name>"
|