nx-factory-cli 2.1.10 → 2.1.18
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/dist/commands/add-app.d.ts +1 -1
- package/dist/commands/add-app.d.ts.map +1 -1
- package/dist/commands/add-app.js +130 -61
- package/dist/commands/add-app.js.map +1 -1
- package/dist/commands/add-auth.d.ts.map +1 -1
- package/dist/commands/add-auth.js +112 -48
- package/dist/commands/add-auth.js.map +1 -1
- package/dist/commands/add-component.d.ts.map +1 -1
- package/dist/commands/add-component.js +78 -22
- package/dist/commands/add-component.js.map +1 -1
- package/dist/commands/add-lib.d.ts.map +1 -1
- package/dist/commands/add-lib.js +38 -31
- package/dist/commands/add-lib.js.map +1 -1
- package/dist/commands/add-storybook.d.ts.map +1 -1
- package/dist/commands/add-storybook.js +29 -14
- package/dist/commands/add-storybook.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +136 -43
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +267 -122
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +15 -8
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +36 -10
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/remove-component.d.ts.map +1 -1
- package/dist/commands/remove-component.js +24 -5
- package/dist/commands/remove-component.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +18 -5
- package/dist/commands/update.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -1
- package/dist/index.js +0 -0
- package/dist/setups/auth/base.d.ts +1 -2
- package/dist/setups/auth/base.d.ts.map +1 -1
- package/dist/setups/auth/base.js +7 -26
- package/dist/setups/auth/base.js.map +1 -1
- package/dist/setups/auth/types.d.ts +2 -1
- package/dist/setups/auth/types.d.ts.map +1 -1
- package/package.json +47 -43
package/dist/commands/add-lib.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { pathExists, writeJson, writeFile, ensureDir } from "../files.js";
|
|
4
|
-
import { loadConfig } from "../config.js";
|
|
4
|
+
import { loadConfig, resolveScope, scopedPackageName } from "../config.js";
|
|
5
5
|
import { detectPackageManager } from "../exec.js";
|
|
6
|
-
import { c, q, detected, createStepRunner, printSection, printSuccess, printError } from "../ui.js";
|
|
6
|
+
import { c, q, detected, createStepRunner, printSection, printSuccess, printError, } from "../ui.js";
|
|
7
7
|
const LIB_TYPES = ["utils", "hooks", "config", "types", "api"];
|
|
8
8
|
export async function addLibCommand(options) {
|
|
9
9
|
// Verify monorepo root
|
|
@@ -11,12 +11,15 @@ export async function addLibCommand(options) {
|
|
|
11
11
|
printError({
|
|
12
12
|
title: "No package.json found",
|
|
13
13
|
detail: "Run this command from the monorepo root.",
|
|
14
|
-
recovery: [
|
|
14
|
+
recovery: [
|
|
15
|
+
{ label: "", cmd: "cd <monorepo-root> && nx-factory-cli add-lib" },
|
|
16
|
+
],
|
|
15
17
|
});
|
|
16
18
|
process.exit(1);
|
|
17
19
|
return;
|
|
18
20
|
}
|
|
19
21
|
const cfg = await loadConfig();
|
|
22
|
+
const scope = resolveScope(cfg);
|
|
20
23
|
const detectedPm = await detectPackageManager();
|
|
21
24
|
const defaults = {
|
|
22
25
|
libName: options.name ?? "shared",
|
|
@@ -31,7 +34,8 @@ export async function addLibCommand(options) {
|
|
|
31
34
|
name: "libName",
|
|
32
35
|
message: q("Library name", "lives at packages/<n>"),
|
|
33
36
|
default: defaults.libName,
|
|
34
|
-
validate: (v) => /^[a-z0-9-]+$/.test(v) ||
|
|
37
|
+
validate: (v) => /^[a-z0-9-]+$/.test(v) ||
|
|
38
|
+
c.red("Only lowercase letters, numbers, and dashes"),
|
|
35
39
|
},
|
|
36
40
|
{
|
|
37
41
|
type: "list",
|
|
@@ -62,7 +66,12 @@ export async function addLibCommand(options) {
|
|
|
62
66
|
if (await pathExists(libDir)) {
|
|
63
67
|
printError({
|
|
64
68
|
title: `packages/${libName} already exists`,
|
|
65
|
-
recovery: [
|
|
69
|
+
recovery: [
|
|
70
|
+
{
|
|
71
|
+
label: "Choose a different name:",
|
|
72
|
+
cmd: `nx-factory-cli add-lib --name ${libName}-2`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
66
75
|
});
|
|
67
76
|
process.exit(1);
|
|
68
77
|
return;
|
|
@@ -72,7 +81,7 @@ export async function addLibCommand(options) {
|
|
|
72
81
|
await step("Scaffold package structure", async () => {
|
|
73
82
|
await ensureDir(path.join(libDir, "."));
|
|
74
83
|
await writeJson(path.join(libDir, "package.json"), {
|
|
75
|
-
name:
|
|
84
|
+
name: scopedPackageName(scope, libName),
|
|
76
85
|
version: "0.0.1",
|
|
77
86
|
private: true,
|
|
78
87
|
type: "module",
|
|
@@ -85,11 +94,11 @@ export async function addLibCommand(options) {
|
|
|
85
94
|
main: "./dist/index.js",
|
|
86
95
|
types: "./dist/index.d.ts",
|
|
87
96
|
scripts: {
|
|
88
|
-
build: "
|
|
89
|
-
"build:watch": "
|
|
97
|
+
build: "tsc -p tsconfig.json",
|
|
98
|
+
"build:watch": "tsc -p tsconfig.json --watch",
|
|
99
|
+
typecheck: "tsc --noEmit",
|
|
90
100
|
},
|
|
91
101
|
devDependencies: {
|
|
92
|
-
tsup: "^8.3.0",
|
|
93
102
|
typescript: "^5.6.0",
|
|
94
103
|
},
|
|
95
104
|
});
|
|
@@ -110,21 +119,10 @@ export async function addLibCommand(options) {
|
|
|
110
119
|
include: ["**/*"],
|
|
111
120
|
exclude: ["node_modules", "dist"],
|
|
112
121
|
});
|
|
113
|
-
await writeFile(path.join(libDir, "tsup.config.ts"), `import { defineConfig } from "tsup";
|
|
114
|
-
|
|
115
|
-
export default defineConfig({
|
|
116
|
-
entry: ["index.ts"],
|
|
117
|
-
format: ["esm"],
|
|
118
|
-
dts: true,
|
|
119
|
-
sourcemap: true,
|
|
120
|
-
clean: true,
|
|
121
|
-
treeshake: true,
|
|
122
|
-
});
|
|
123
|
-
`);
|
|
124
122
|
// Seed index.ts based on lib type
|
|
125
|
-
await writeFile(path.join(libDir, "index.ts"), getIndexContent(libName, libType));
|
|
123
|
+
await writeFile(path.join(libDir, "index.ts"), getIndexContent(libName, libType, scope));
|
|
126
124
|
});
|
|
127
|
-
await step(`Add
|
|
125
|
+
await step(`Add ${scopedPackageName(scope, libName)} to workspace`, async () => {
|
|
128
126
|
// For pnpm: pnpm-workspace.yaml is already written by init.
|
|
129
127
|
// For npm: the workspaces field in root package.json covers packages/*.
|
|
130
128
|
// Nothing extra to do — the new directory is picked up automatically.
|
|
@@ -134,18 +132,27 @@ export default defineConfig({
|
|
|
134
132
|
printSuccess({
|
|
135
133
|
title: `packages/${libName} created`,
|
|
136
134
|
commands: [
|
|
137
|
-
{
|
|
138
|
-
|
|
135
|
+
{
|
|
136
|
+
cmd: `import { ... } from "${scopedPackageName(scope, libName)}";`,
|
|
137
|
+
comment: "use in any app",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
cmd: `${pm} nx build ${scopedPackageName(scope, libName)}`,
|
|
141
|
+
comment: "build the package",
|
|
142
|
+
},
|
|
139
143
|
],
|
|
140
144
|
tips: [
|
|
141
|
-
{
|
|
145
|
+
{
|
|
146
|
+
label: "Add to an app's dependencies:",
|
|
147
|
+
cmd: `"${scopedPackageName(scope, libName)}": "${pm === "npm" ? "*" : "workspace:*"}"`,
|
|
148
|
+
},
|
|
142
149
|
],
|
|
143
150
|
});
|
|
144
151
|
}
|
|
145
|
-
function getIndexContent(name, type) {
|
|
152
|
+
function getIndexContent(name, type, scope) {
|
|
146
153
|
switch (type) {
|
|
147
154
|
case "utils":
|
|
148
|
-
return `//
|
|
155
|
+
return `// ${scopedPackageName(scope, name)} — shared utility functions
|
|
149
156
|
|
|
150
157
|
export function noop(): void {}
|
|
151
158
|
|
|
@@ -154,20 +161,20 @@ export function sleep(ms: number): Promise<void> {
|
|
|
154
161
|
}
|
|
155
162
|
`;
|
|
156
163
|
case "hooks":
|
|
157
|
-
return `//
|
|
164
|
+
return `// ${scopedPackageName(scope, name)} — shared React hooks
|
|
158
165
|
// Note: add react as a peerDependency if you use hooks
|
|
159
166
|
|
|
160
167
|
export function useNoop(): void {}
|
|
161
168
|
`;
|
|
162
169
|
case "config":
|
|
163
|
-
return `//
|
|
170
|
+
return `// ${scopedPackageName(scope, name)} — shared configuration
|
|
164
171
|
|
|
165
172
|
export const config = {
|
|
166
173
|
env: process.env.NODE_ENV ?? "development",
|
|
167
174
|
} as const;
|
|
168
175
|
`;
|
|
169
176
|
case "types":
|
|
170
|
-
return `//
|
|
177
|
+
return `// ${scopedPackageName(scope, name)} — shared TypeScript types
|
|
171
178
|
|
|
172
179
|
export type ID = string;
|
|
173
180
|
|
|
@@ -177,7 +184,7 @@ export interface Timestamps {
|
|
|
177
184
|
}
|
|
178
185
|
`;
|
|
179
186
|
case "api":
|
|
180
|
-
return `//
|
|
187
|
+
return `// ${scopedPackageName(scope, name)} — shared API client
|
|
181
188
|
|
|
182
189
|
export async function apiFetch<T>(url: string, init?: RequestInit): Promise<T> {
|
|
183
190
|
const res = await fetch(url, init);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-lib.js","sourceRoot":"","sources":["../../src/commands/add-lib.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"add-lib.js","sourceRoot":"","sources":["../../src/commands/add-l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AC;IACD,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-storybook.d.ts","sourceRoot":"","sources":["../../src/commands/add-storybook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add-storybook.d.ts","sourceRoot":"","sources":["../../src/commands/add-storybook.ts"],"names":[],"mappings":"AAYA,UAAU,mBAAmB;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,mBAAmB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAyKf"}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { pathExists, writeFile, ensureDir } from "../files.js";
|
|
3
|
-
import { loadConfig } from "../config.js";
|
|
3
|
+
import { loadConfig, resolveScope, scopedPackageName } from "../config.js";
|
|
4
4
|
import { run, pmAdd, detectPackageManager } from "../exec.js";
|
|
5
|
-
import { createStepRunner, printSection, printSuccess, printError, printWarn } from "../ui.js";
|
|
5
|
+
import { createStepRunner, printSection, printSuccess, printError, printWarn, } from "../ui.js";
|
|
6
6
|
export async function addStorybookCommand(options) {
|
|
7
7
|
const cfg = await loadConfig();
|
|
8
|
+
const scope = resolveScope(cfg);
|
|
8
9
|
const uiPkgDir = await detectUiPackageDir(cfg?.uiPackage);
|
|
9
10
|
if (!uiPkgDir) {
|
|
10
11
|
printError({
|
|
11
12
|
title: "UI package not found",
|
|
12
13
|
detail: "Run from the monorepo root.",
|
|
13
|
-
recovery: [
|
|
14
|
+
recovery: [
|
|
15
|
+
{
|
|
16
|
+
label: "",
|
|
17
|
+
cmd: "cd <monorepo-root> && nx-factory-cli add-storybook",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
14
20
|
});
|
|
15
21
|
process.exit(1);
|
|
16
22
|
return;
|
|
@@ -23,12 +29,14 @@ export async function addStorybookCommand(options) {
|
|
|
23
29
|
}
|
|
24
30
|
const pm = (await detectPackageManager()) ?? cfg?.pkgManager ?? "pnpm";
|
|
25
31
|
const pkgName = cfg?.uiPackage ?? path.basename(uiPkgDir);
|
|
32
|
+
const uiPackageName = scopedPackageName(scope, pkgName);
|
|
26
33
|
const installed = await getInstalledComponents(uiPkgDir);
|
|
27
34
|
printSection(`${options.dryRun ? "[dry run] " : ""}Adding Storybook to packages/${pkgName}`);
|
|
28
35
|
const step = createStepRunner(4, options.dryRun);
|
|
29
36
|
await step("Install Storybook deps", async () => {
|
|
30
37
|
await run(pm, [
|
|
31
|
-
pmAdd(pm),
|
|
38
|
+
pmAdd(pm),
|
|
39
|
+
"--save-dev",
|
|
32
40
|
"@storybook/react-vite",
|
|
33
41
|
"@storybook/react",
|
|
34
42
|
"@storybook/addon-essentials",
|
|
@@ -91,7 +99,7 @@ export default preview;
|
|
|
91
99
|
// Don't overwrite existing stories
|
|
92
100
|
if (await pathExists(storyPath))
|
|
93
101
|
continue;
|
|
94
|
-
await writeFile(storyPath, buildStory(compName,
|
|
102
|
+
await writeFile(storyPath, buildStory(compName, uiPackageName));
|
|
95
103
|
}
|
|
96
104
|
// Write an index story if no components installed yet
|
|
97
105
|
if (installed.length === 0) {
|
|
@@ -99,7 +107,7 @@ export default preview;
|
|
|
99
107
|
|
|
100
108
|
const Welcome = () => (
|
|
101
109
|
<div style={{ padding: "2rem", fontFamily: "sans-serif" }}>
|
|
102
|
-
<h1>Welcome to
|
|
110
|
+
<h1>Welcome to ${uiPackageName}</h1>
|
|
103
111
|
<p>Add components with: <code>nx-factory-cli add-component button</code></p>
|
|
104
112
|
</div>
|
|
105
113
|
);
|
|
@@ -118,20 +126,24 @@ export const Default: Story = {};
|
|
|
118
126
|
printSuccess({
|
|
119
127
|
title: `Storybook added to packages/${pkgName}`,
|
|
120
128
|
commands: [
|
|
121
|
-
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
{
|
|
129
|
+
{
|
|
130
|
+
cmd: `${pm} nx run ${pkgName}:storybook`,
|
|
131
|
+
comment: "start Storybook on :6006",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
cmd: `${pm} nx run ${pkgName}:build-storybook`,
|
|
135
|
+
comment: "build static output",
|
|
136
|
+
},
|
|
126
137
|
],
|
|
138
|
+
tips: [{ label: "Stories live at:", cmd: `packages/${pkgName}/stories/` }],
|
|
127
139
|
});
|
|
128
140
|
}
|
|
129
141
|
// ─── Story template ──────────────────────────────────────────────────────────
|
|
130
|
-
function buildStory(compName,
|
|
142
|
+
function buildStory(compName, uiPackageName) {
|
|
131
143
|
// Simple stories work for all components; complex ones (e.g. Dialog) would
|
|
132
144
|
// need customisation — we generate a useful default that compiles cleanly.
|
|
133
145
|
return `import type { Meta, StoryObj } from "@storybook/react";
|
|
134
|
-
import { ${compName} } from "
|
|
146
|
+
import { ${compName} } from "${uiPackageName}";
|
|
135
147
|
|
|
136
148
|
const meta: Meta<typeof ${compName}> = {
|
|
137
149
|
title: "ui/${compName}",
|
|
@@ -176,6 +188,9 @@ async function detectUiPackageDir(uiPackage) {
|
|
|
176
188
|
return null;
|
|
177
189
|
}
|
|
178
190
|
function toComponentName(kebab) {
|
|
179
|
-
return kebab
|
|
191
|
+
return kebab
|
|
192
|
+
.split("-")
|
|
193
|
+
.map((p) => p.charAt(0).toUpperCase() + p.slice(1))
|
|
194
|
+
.join("");
|
|
180
195
|
}
|
|
181
196
|
//# sourceMappingURL=add-storybook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-storybook.js","sourceRoot":"","sources":["../../src/commands/add-storybook.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"add-storybook.js","sourceRoot":"","sources":["../../src/commands/add-storybook.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CA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-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAWA,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAWA,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAwUnD"}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { pathExists, writeFile } from "../files.js";
|
|
3
|
-
import { loadConfig } from "../config.js";
|
|
3
|
+
import { loadConfig, resolveScope, scopedPackageName } from "../config.js";
|
|
4
4
|
import { c, printSuccess, printError, printWarn } from "../ui.js";
|
|
5
5
|
export async function doctorCommand() {
|
|
6
6
|
const cfg = await loadConfig();
|
|
7
|
+
const scope = resolveScope(cfg);
|
|
7
8
|
console.log(`\n ${c.dim("─".repeat(44))}`);
|
|
8
9
|
console.log(` ${c.whiteBold("nx-factory-cli doctor")} ${c.dim("workspace health check")}`);
|
|
9
10
|
console.log(` ${c.dim("─".repeat(44))}\n`);
|
|
@@ -11,9 +12,21 @@ export async function doctorCommand() {
|
|
|
11
12
|
const { default: fs } = await import("fs-extra");
|
|
12
13
|
// ─── 1. Config file present ────────────────────────────────────────────────
|
|
13
14
|
if (cfg) {
|
|
14
|
-
checks.push({
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
checks.push({
|
|
16
|
+
name: "Config file",
|
|
17
|
+
status: "pass",
|
|
18
|
+
detail: "nx-factory.config.json found",
|
|
19
|
+
});
|
|
20
|
+
checks.push({
|
|
21
|
+
name: "Package manager",
|
|
22
|
+
status: "pass",
|
|
23
|
+
detail: cfg.pkgManager,
|
|
24
|
+
});
|
|
25
|
+
checks.push({
|
|
26
|
+
name: "UI package",
|
|
27
|
+
status: "pass",
|
|
28
|
+
detail: `packages/${cfg.uiPackage}`,
|
|
29
|
+
});
|
|
17
30
|
}
|
|
18
31
|
else {
|
|
19
32
|
checks.push({
|
|
@@ -27,7 +40,11 @@ export async function doctorCommand() {
|
|
|
27
40
|
const uiPkgDir = path.join(process.cwd(), "packages", uiPkgName);
|
|
28
41
|
const hasUiPkg = await pathExists(uiPkgDir);
|
|
29
42
|
if (!hasUiPkg) {
|
|
30
|
-
checks.push({
|
|
43
|
+
checks.push({
|
|
44
|
+
name: "UI package dir",
|
|
45
|
+
status: "fail",
|
|
46
|
+
detail: `packages/${uiPkgName} not found`,
|
|
47
|
+
});
|
|
31
48
|
renderChecks(checks);
|
|
32
49
|
printError({
|
|
33
50
|
title: "Critical: UI package directory missing",
|
|
@@ -35,7 +52,11 @@ export async function doctorCommand() {
|
|
|
35
52
|
});
|
|
36
53
|
return;
|
|
37
54
|
}
|
|
38
|
-
checks.push({
|
|
55
|
+
checks.push({
|
|
56
|
+
name: "UI package dir",
|
|
57
|
+
status: "pass",
|
|
58
|
+
detail: `packages/${uiPkgName} exists`,
|
|
59
|
+
});
|
|
39
60
|
// ─── 3. components.json ───────────────────────────────────────────────────
|
|
40
61
|
const compJsonPath = path.join(uiPkgDir, "components.json");
|
|
41
62
|
if (await pathExists(compJsonPath)) {
|
|
@@ -43,53 +64,94 @@ export async function doctorCommand() {
|
|
|
43
64
|
const compJson = await fs.readJson(compJsonPath);
|
|
44
65
|
const style = compJson?.style ?? "unknown";
|
|
45
66
|
const aliases = compJson?.aliases ?? {};
|
|
46
|
-
// Auto-fix: if aliases use relative paths (./...) swap them to
|
|
67
|
+
// Auto-fix: if aliases use relative paths (./...) swap them to @<scope>/<uiPkgName>/... style
|
|
47
68
|
const hasRelativePaths = Object.values(aliases).some((v) => typeof v === "string" && v.startsWith("./"));
|
|
48
69
|
if (hasRelativePaths) {
|
|
49
70
|
const fixed = {
|
|
50
71
|
...compJson,
|
|
51
72
|
aliases: {
|
|
52
|
-
components:
|
|
53
|
-
utils:
|
|
54
|
-
ui:
|
|
55
|
-
lib:
|
|
56
|
-
hooks:
|
|
73
|
+
components: `${scopedPackageName(scope, uiPkgName)}/components`,
|
|
74
|
+
utils: `${scopedPackageName(scope, uiPkgName)}/lib/utils`,
|
|
75
|
+
ui: `${scopedPackageName(scope, uiPkgName)}/components/ui`,
|
|
76
|
+
lib: `${scopedPackageName(scope, uiPkgName)}/lib`,
|
|
77
|
+
hooks: `${scopedPackageName(scope, uiPkgName)}/hooks`,
|
|
57
78
|
},
|
|
58
79
|
};
|
|
59
80
|
await fs.writeJson(compJsonPath, fixed, { spaces: 2 });
|
|
60
81
|
checks.push({
|
|
61
82
|
name: "components.json",
|
|
62
83
|
status: "fix",
|
|
63
|
-
detail: `aliases rewritten from ./... to
|
|
84
|
+
detail: `aliases rewritten from ./... to ${scopedPackageName(scope, uiPkgName)}/...`,
|
|
64
85
|
});
|
|
65
86
|
}
|
|
66
87
|
else {
|
|
67
|
-
checks.push({
|
|
88
|
+
checks.push({
|
|
89
|
+
name: "components.json",
|
|
90
|
+
status: "pass",
|
|
91
|
+
detail: `style: ${style}`,
|
|
92
|
+
});
|
|
68
93
|
}
|
|
69
94
|
}
|
|
70
95
|
catch {
|
|
71
|
-
checks.push({
|
|
96
|
+
checks.push({
|
|
97
|
+
name: "components.json",
|
|
98
|
+
status: "fail",
|
|
99
|
+
detail: "invalid JSON",
|
|
100
|
+
});
|
|
72
101
|
}
|
|
73
102
|
}
|
|
74
103
|
else {
|
|
75
|
-
checks.push({
|
|
104
|
+
checks.push({
|
|
105
|
+
name: "components.json",
|
|
106
|
+
status: "fail",
|
|
107
|
+
detail: "missing — shadcn commands will not work",
|
|
108
|
+
});
|
|
76
109
|
}
|
|
77
|
-
// ─── 4.
|
|
78
|
-
const
|
|
110
|
+
// ─── 4. TypeScript build setup ────────────────────────────────────────────
|
|
111
|
+
const pkgJsonPath = path.join(uiPkgDir, "package.json");
|
|
79
112
|
const barrelPath = path.join(uiPkgDir, "index.ts");
|
|
80
|
-
if (await pathExists(
|
|
81
|
-
|
|
113
|
+
if (await pathExists(pkgJsonPath)) {
|
|
114
|
+
try {
|
|
115
|
+
const pkgJson = await fs.readJson(pkgJsonPath);
|
|
116
|
+
const buildScript = pkgJson?.scripts?.build;
|
|
117
|
+
if (typeof buildScript === "string" && buildScript.includes("tsc")) {
|
|
118
|
+
checks.push({
|
|
119
|
+
name: "build script",
|
|
120
|
+
status: "pass",
|
|
121
|
+
detail: "tsc build script present",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
checks.push({
|
|
126
|
+
name: "build script",
|
|
127
|
+
status: "warn",
|
|
128
|
+
detail: "missing tsc build script in package.json",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
checks.push({
|
|
134
|
+
name: "build script",
|
|
135
|
+
status: "warn",
|
|
136
|
+
detail: "could not parse package.json",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
82
139
|
}
|
|
83
140
|
else {
|
|
84
|
-
checks.push({
|
|
141
|
+
checks.push({
|
|
142
|
+
name: "build script",
|
|
143
|
+
status: "warn",
|
|
144
|
+
detail: "package.json missing in UI package",
|
|
145
|
+
});
|
|
85
146
|
}
|
|
86
|
-
// ─── 4b. tsconfig paths (
|
|
147
|
+
// ─── 4b. tsconfig paths (scoped alias required by this CLI setup) ─────
|
|
87
148
|
const tsconfigPath = path.join(uiPkgDir, "tsconfig.json");
|
|
88
149
|
if (await pathExists(tsconfigPath)) {
|
|
89
150
|
try {
|
|
90
151
|
const tsconfig = await fs.readJson(tsconfigPath);
|
|
91
152
|
const paths = tsconfig?.compilerOptions?.paths ?? {};
|
|
92
|
-
const hasAlias =
|
|
153
|
+
const hasAlias = `${scopedPackageName(scope, uiPkgName)}/*` in paths ||
|
|
154
|
+
`@${scope}/*` in paths;
|
|
93
155
|
if (!hasAlias) {
|
|
94
156
|
// Auto-fix: inject baseUrl + paths
|
|
95
157
|
tsconfig.compilerOptions = {
|
|
@@ -97,28 +159,40 @@ export async function doctorCommand() {
|
|
|
97
159
|
baseUrl: ".",
|
|
98
160
|
paths: {
|
|
99
161
|
...(tsconfig.compilerOptions?.paths ?? {}),
|
|
100
|
-
|
|
101
|
-
[
|
|
102
|
-
[
|
|
162
|
+
[`@${scope}/*`]: ["../../packages/*"],
|
|
163
|
+
[scopedPackageName(scope, uiPkgName)]: ["./index.tsx"],
|
|
164
|
+
[`${scopedPackageName(scope, uiPkgName)}/*`]: ["./*"],
|
|
103
165
|
},
|
|
104
166
|
};
|
|
105
167
|
await fs.writeJson(tsconfigPath, tsconfig, { spaces: 2 });
|
|
106
168
|
checks.push({
|
|
107
169
|
name: "tsconfig paths",
|
|
108
170
|
status: "fix",
|
|
109
|
-
detail: `added
|
|
171
|
+
detail: `added @${scope} aliases for ${uiPkgName}`,
|
|
110
172
|
});
|
|
111
173
|
}
|
|
112
174
|
else {
|
|
113
|
-
checks.push({
|
|
175
|
+
checks.push({
|
|
176
|
+
name: "tsconfig paths",
|
|
177
|
+
status: "pass",
|
|
178
|
+
detail: `@${scope} alias present`,
|
|
179
|
+
});
|
|
114
180
|
}
|
|
115
181
|
}
|
|
116
182
|
catch {
|
|
117
|
-
checks.push({
|
|
183
|
+
checks.push({
|
|
184
|
+
name: "tsconfig paths",
|
|
185
|
+
status: "warn",
|
|
186
|
+
detail: "could not parse tsconfig.json",
|
|
187
|
+
});
|
|
118
188
|
}
|
|
119
189
|
}
|
|
120
190
|
else {
|
|
121
|
-
checks.push({
|
|
191
|
+
checks.push({
|
|
192
|
+
name: "tsconfig paths",
|
|
193
|
+
status: "warn",
|
|
194
|
+
detail: "tsconfig.json missing in UI package",
|
|
195
|
+
});
|
|
122
196
|
}
|
|
123
197
|
// ─── 5. Barrel export sync ────────────────────────────────────────────────
|
|
124
198
|
const uiComponentsDir = path.join(uiPkgDir, "components/ui");
|
|
@@ -145,7 +219,9 @@ export async function doctorCommand() {
|
|
|
145
219
|
}
|
|
146
220
|
else {
|
|
147
221
|
// Auto-fix: append missing exports
|
|
148
|
-
const newLines = missing
|
|
222
|
+
const newLines = missing
|
|
223
|
+
.map((c) => `export * from "./components/ui/${c}";`)
|
|
224
|
+
.join("\n");
|
|
149
225
|
const updated = barrelContent.endsWith("\n")
|
|
150
226
|
? barrelContent + newLines + "\n"
|
|
151
227
|
: barrelContent + "\n" + newLines + "\n";
|
|
@@ -169,19 +245,23 @@ export async function doctorCommand() {
|
|
|
169
245
|
continue;
|
|
170
246
|
try {
|
|
171
247
|
const pkgJson = await fs.readJson(pkgPath);
|
|
172
|
-
const dep = pkgJson?.dependencies?.[
|
|
248
|
+
const dep = pkgJson?.dependencies?.[scopedPackageName(scope, uiPkgName)];
|
|
173
249
|
if (dep !== undefined) {
|
|
174
|
-
const isCorrect = cfg.pkgManager === "npm"
|
|
175
|
-
? dep === "*"
|
|
176
|
-
: dep === "workspace:*";
|
|
250
|
+
const isCorrect = cfg.pkgManager === "npm" ? dep === "*" : dep === "workspace:*";
|
|
177
251
|
if (!isCorrect)
|
|
178
252
|
wrongProtocol.push(`${app} (has "${dep}", expected ${expected})`);
|
|
179
253
|
}
|
|
180
254
|
}
|
|
181
|
-
catch {
|
|
255
|
+
catch {
|
|
256
|
+
/* skip */
|
|
257
|
+
}
|
|
182
258
|
}
|
|
183
259
|
if (wrongProtocol.length === 0) {
|
|
184
|
-
checks.push({
|
|
260
|
+
checks.push({
|
|
261
|
+
name: "Workspace protocol",
|
|
262
|
+
status: "pass",
|
|
263
|
+
detail: `${expected} used correctly`,
|
|
264
|
+
});
|
|
185
265
|
}
|
|
186
266
|
else {
|
|
187
267
|
checks.push({
|
|
@@ -201,8 +281,18 @@ export async function doctorCommand() {
|
|
|
201
281
|
printSuccess({
|
|
202
282
|
title: "All checks passed",
|
|
203
283
|
commands: fixes.length > 0
|
|
204
|
-
? [
|
|
205
|
-
|
|
284
|
+
? [
|
|
285
|
+
{
|
|
286
|
+
cmd: "index.ts updated",
|
|
287
|
+
comment: "barrel exports were fixed automatically",
|
|
288
|
+
},
|
|
289
|
+
]
|
|
290
|
+
: [
|
|
291
|
+
{
|
|
292
|
+
cmd: "nx-factory-cli list",
|
|
293
|
+
comment: "view installed components",
|
|
294
|
+
},
|
|
295
|
+
],
|
|
206
296
|
});
|
|
207
297
|
}
|
|
208
298
|
else {
|
|
@@ -216,10 +306,13 @@ export async function doctorCommand() {
|
|
|
216
306
|
}
|
|
217
307
|
function renderChecks(checks) {
|
|
218
308
|
for (const ch of checks) {
|
|
219
|
-
const icon = ch.status === "pass"
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
309
|
+
const icon = ch.status === "pass"
|
|
310
|
+
? c.green("✓")
|
|
311
|
+
: ch.status === "fix"
|
|
312
|
+
? c.cyan("↻")
|
|
313
|
+
: ch.status === "warn"
|
|
314
|
+
? c.yellow("⚠")
|
|
315
|
+
: c.red("✗");
|
|
223
316
|
const label = c.white(ch.name.padEnd(22));
|
|
224
317
|
const detail = ch.status === "fix"
|
|
225
318
|
? c.cyan(ch.detail)
|