@fragments-sdk/cli 0.6.0 → 0.7.1
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/bin.js +529 -285
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-F7ITZPDJ.js → chunk-32VIEOQY.js} +18 -18
- package/dist/chunk-32VIEOQY.js.map +1 -0
- package/dist/{chunk-SSLQXHNX.js → chunk-5ITIP3ES.js} +27 -27
- package/dist/chunk-5ITIP3ES.js.map +1 -0
- package/dist/{chunk-RVRTRESS.js → chunk-DQHWLAUV.js} +29 -29
- package/dist/chunk-DQHWLAUV.js.map +1 -0
- package/dist/{chunk-Q7GOHVOK.js → chunk-GCZMFLDI.js} +67 -32
- package/dist/chunk-GCZMFLDI.js.map +1 -0
- package/dist/{chunk-6JBGU74P.js → chunk-GHYYFAQN.js} +23 -23
- package/dist/chunk-GHYYFAQN.js.map +1 -0
- package/dist/{chunk-NWQ4CJOQ.js → chunk-GKX2HPZ6.js} +40 -40
- package/dist/chunk-GKX2HPZ6.js.map +1 -0
- package/dist/{chunk-D35RGPAG.js → chunk-U6VTHBNI.js} +499 -83
- package/dist/chunk-U6VTHBNI.js.map +1 -0
- package/dist/{core-SKRPJQZG.js → core-SFHPYR5H.js} +24 -26
- package/dist/{generate-7AF7WRVK.js → generate-54GJAWUY.js} +5 -5
- package/dist/generate-54GJAWUY.js.map +1 -0
- package/dist/index.d.ts +23 -27
- package/dist/index.js +10 -10
- package/dist/{init-WKGDPYI4.js → init-EIM5WNMP.js} +5 -5
- package/dist/{init-WKGDPYI4.js.map → init-EIM5WNMP.js.map} +1 -1
- package/dist/mcp-bin.js +73 -73
- package/dist/mcp-bin.js.map +1 -1
- package/dist/scan-KQBKUS64.js +12 -0
- package/dist/{service-F3E4JJM7.js → service-ED2LNCTU.js} +6 -6
- package/dist/{static-viewer-4LQZ5AGA.js → static-viewer-Q4F4QP5M.js} +4 -4
- package/dist/{test-CJDNJTPZ.js → test-6VN2DA3S.js} +19 -19
- package/dist/test-6VN2DA3S.js.map +1 -0
- package/dist/{tokens-JAJABYXP.js → tokens-P2B7ZAM3.js} +5 -5
- package/dist/{viewer-R3Q6WAMJ.js → viewer-GM7IQPPB.js} +199 -199
- package/dist/viewer-GM7IQPPB.js.map +1 -0
- package/package.json +2 -2
- package/src/ai.ts +5 -5
- package/src/analyze.ts +11 -11
- package/src/bin.ts +24 -1
- package/src/build.ts +64 -21
- package/src/commands/a11y.ts +6 -6
- package/src/commands/add.ts +11 -11
- package/src/commands/audit.ts +4 -4
- package/src/commands/baseline.ts +3 -3
- package/src/commands/build.ts +8 -8
- package/src/commands/compare.ts +20 -20
- package/src/commands/context.ts +16 -16
- package/src/commands/enhance.ts +36 -36
- package/src/commands/generate.ts +1 -1
- package/src/commands/graph.ts +274 -0
- package/src/commands/init.ts +1 -1
- package/src/commands/link/figma.ts +82 -82
- package/src/commands/link/index.ts +3 -3
- package/src/commands/link/storybook.ts +9 -9
- package/src/commands/list.ts +2 -2
- package/src/commands/reset.ts +15 -15
- package/src/commands/scan.ts +27 -27
- package/src/commands/storygen.ts +24 -24
- package/src/commands/validate.ts +2 -2
- package/src/commands/verify.ts +8 -8
- package/src/core/auto-props.ts +4 -4
- package/src/core/composition.test.ts +36 -36
- package/src/core/composition.ts +83 -20
- package/src/core/config.ts +6 -6
- package/src/core/{defineSegment.ts → defineFragment.ts} +16 -22
- package/src/core/discovery.ts +6 -6
- package/src/core/figma.ts +2 -2
- package/src/core/graph-extractor.test.ts +542 -0
- package/src/core/graph-extractor.ts +601 -0
- package/src/core/importAnalyzer.ts +6 -1
- package/src/core/index.ts +22 -23
- package/src/core/loader.ts +22 -22
- package/src/core/node.ts +5 -5
- package/src/core/parser.ts +31 -31
- package/src/core/previewLoader.ts +1 -1
- package/src/core/schema.ts +16 -16
- package/src/core/storyAdapter.test.ts +87 -87
- package/src/core/storyAdapter.ts +16 -16
- package/src/core/types.ts +21 -26
- package/src/diff.ts +22 -22
- package/src/index.ts +2 -2
- package/src/mcp/server.ts +80 -80
- package/src/migrate/__tests__/utils/utils.test.ts +3 -3
- package/src/migrate/bin.ts +4 -4
- package/src/migrate/converter.ts +16 -16
- package/src/migrate/index.ts +3 -3
- package/src/migrate/migrate.ts +3 -3
- package/src/migrate/parser.ts +8 -8
- package/src/migrate/report.ts +2 -2
- package/src/migrate/types.ts +4 -4
- package/src/screenshot.ts +22 -22
- package/src/service/__tests__/props-extractor.test.ts +15 -15
- package/src/service/analytics.ts +39 -39
- package/src/service/enhance/codebase-scanner.ts +1 -1
- package/src/service/enhance/index.ts +1 -1
- package/src/service/enhance/props-extractor.ts +2 -2
- package/src/service/enhance/types.ts +2 -2
- package/src/service/index.ts +2 -2
- package/src/service/metrics-store.ts +1 -1
- package/src/service/patch-generator.ts +1 -1
- package/src/setup.ts +52 -52
- package/src/shared/dev-server-client.ts +7 -7
- package/src/shared/fragment-loader.ts +59 -0
- package/src/shared/index.ts +1 -1
- package/src/shared/types.ts +4 -4
- package/src/static-viewer.ts +35 -35
- package/src/test/discovery.ts +6 -6
- package/src/test/index.ts +5 -5
- package/src/test/reporters/console.ts +1 -1
- package/src/test/reporters/junit.ts +1 -1
- package/src/test/runner.ts +7 -7
- package/src/test/types.ts +3 -3
- package/src/test/watch.ts +9 -9
- package/src/validators.ts +26 -26
- package/src/viewer/__tests__/render-utils.test.ts +28 -28
- package/src/viewer/__tests__/viewer-integration.test.ts +4 -4
- package/src/viewer/cli/health.ts +26 -26
- package/src/viewer/components/App.tsx +201 -103
- package/src/viewer/components/BottomPanel.tsx +17 -17
- package/src/viewer/components/CodePanel.tsx +3 -3
- package/src/viewer/components/CommandPalette.tsx +11 -11
- package/src/viewer/components/ComponentGraph.tsx +28 -28
- package/src/viewer/components/ComponentHeader.tsx +2 -2
- package/src/viewer/components/ContractPanel.tsx +6 -6
- package/src/viewer/components/FigmaEmbed.tsx +9 -9
- package/src/viewer/components/HealthDashboard.tsx +17 -17
- package/src/viewer/components/Icons.tsx +53 -1
- package/src/viewer/components/InteractionsPanel.tsx +2 -2
- package/src/viewer/components/IsolatedPreviewFrame.tsx +6 -6
- package/src/viewer/components/IsolatedRender.tsx +10 -10
- package/src/viewer/components/Layout.tsx +7 -3
- package/src/viewer/components/LeftSidebar.tsx +92 -114
- package/src/viewer/components/MultiViewportPreview.tsx +14 -14
- package/src/viewer/components/PreviewArea.tsx +11 -11
- package/src/viewer/components/PreviewFrameHost.tsx +77 -48
- package/src/viewer/components/PreviewToolbar.tsx +57 -10
- package/src/viewer/components/RightSidebar.tsx +9 -9
- package/src/viewer/components/Sidebar.tsx +17 -17
- package/src/viewer/components/StoryRenderer.tsx +2 -2
- package/src/viewer/components/TokenStylePanel.tsx +1 -1
- package/src/viewer/components/UsageSection.tsx +2 -2
- package/src/viewer/components/VariantMatrix.tsx +11 -11
- package/src/viewer/components/VariantRenderer.tsx +3 -3
- package/src/viewer/components/VariantTabs.tsx +2 -2
- package/src/viewer/components/ViewportSelector.tsx +56 -45
- package/src/viewer/components/_future/CreatePage.tsx +6 -6
- package/src/viewer/composition-renderer.ts +11 -11
- package/src/viewer/constants/ui.ts +4 -4
- package/src/viewer/entry.tsx +40 -40
- package/src/viewer/hooks/useFigmaIntegration.ts +1 -1
- package/src/viewer/hooks/usePreviewBridge.ts +5 -5
- package/src/viewer/hooks/useUrlState.ts +6 -6
- package/src/viewer/index.ts +2 -2
- package/src/viewer/intelligence/healthReport.ts +17 -17
- package/src/viewer/intelligence/styleDrift.ts +1 -1
- package/src/viewer/intelligence/usageScanner.ts +1 -1
- package/src/viewer/preview-frame.html +22 -13
- package/src/viewer/render-template.html +1 -1
- package/src/viewer/render-utils.ts +21 -21
- package/src/viewer/server.ts +18 -18
- package/src/viewer/styles/globals.css +42 -81
- package/src/viewer/utils/detectRelationships.ts +22 -22
- package/src/viewer/vite-plugin.ts +213 -213
- package/dist/chunk-6JBGU74P.js.map +0 -1
- package/dist/chunk-D35RGPAG.js.map +0 -1
- package/dist/chunk-F7ITZPDJ.js.map +0 -1
- package/dist/chunk-NWQ4CJOQ.js.map +0 -1
- package/dist/chunk-Q7GOHVOK.js.map +0 -1
- package/dist/chunk-RVRTRESS.js.map +0 -1
- package/dist/chunk-SSLQXHNX.js.map +0 -1
- package/dist/generate-7AF7WRVK.js.map +0 -1
- package/dist/scan-K6JNMCGM.js +0 -12
- package/dist/test-CJDNJTPZ.js.map +0 -1
- package/dist/viewer-R3Q6WAMJ.js.map +0 -1
- package/src/shared/segment-loader.ts +0 -59
- /package/dist/{core-SKRPJQZG.js.map → core-SFHPYR5H.js.map} +0 -0
- /package/dist/{scan-K6JNMCGM.js.map → scan-KQBKUS64.js.map} +0 -0
- /package/dist/{service-F3E4JJM7.js.map → service-ED2LNCTU.js.map} +0 -0
- /package/dist/{static-viewer-4LQZ5AGA.js.map → static-viewer-Q4F4QP5M.js.map} +0 -0
- /package/dist/{tokens-JAJABYXP.js.map → tokens-P2B7ZAM3.js.map} +0 -0
package/dist/bin.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
|
+
buildFragments,
|
|
4
5
|
buildFragmentsDir,
|
|
5
|
-
buildSegments,
|
|
6
6
|
runAnalyzeCommand,
|
|
7
7
|
runDiffCommand,
|
|
8
8
|
runScreenshotCommand,
|
|
9
9
|
validateAll,
|
|
10
10
|
validateCoverage,
|
|
11
11
|
validateSchema
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-U6VTHBNI.js";
|
|
13
13
|
import {
|
|
14
14
|
scan
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-32VIEOQY.js";
|
|
16
16
|
import {
|
|
17
17
|
FigmaClient,
|
|
18
18
|
StorageManager,
|
|
@@ -28,22 +28,22 @@ import {
|
|
|
28
28
|
renderAllComponentVariants,
|
|
29
29
|
scanCodebase,
|
|
30
30
|
shutdownSharedPool
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-GKX2HPZ6.js";
|
|
32
32
|
import {
|
|
33
|
-
|
|
33
|
+
discoverFragmentFiles,
|
|
34
34
|
loadConfig,
|
|
35
|
-
|
|
36
|
-
} from "./chunk-
|
|
35
|
+
loadFragmentFile
|
|
36
|
+
} from "./chunk-5ITIP3ES.js";
|
|
37
37
|
import {
|
|
38
38
|
generateContext
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-GCZMFLDI.js";
|
|
40
40
|
import {
|
|
41
41
|
BRAND
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-GHYYFAQN.js";
|
|
43
43
|
|
|
44
44
|
// src/bin.ts
|
|
45
45
|
import { Command } from "commander";
|
|
46
|
-
import
|
|
46
|
+
import pc21 from "picocolors";
|
|
47
47
|
import { readFileSync } from "fs";
|
|
48
48
|
import { fileURLToPath } from "url";
|
|
49
49
|
import { dirname as dirname4, join as join10 } from "path";
|
|
@@ -116,7 +116,7 @@ ${BRAND.name} Build (from source)
|
|
|
116
116
|
});
|
|
117
117
|
return {
|
|
118
118
|
success: scanResult.success,
|
|
119
|
-
|
|
119
|
+
fragmentCount: scanResult.componentCount,
|
|
120
120
|
outputPath: scanResult.outputPath,
|
|
121
121
|
errors: scanResult.errors.map((e) => ({ file: e.component, error: e.error }))
|
|
122
122
|
};
|
|
@@ -129,14 +129,14 @@ ${BRAND.name} Build (from source)
|
|
|
129
129
|
${BRAND.name} Build
|
|
130
130
|
`));
|
|
131
131
|
const errors = [];
|
|
132
|
-
let
|
|
132
|
+
let fragmentCount;
|
|
133
133
|
let outputPath;
|
|
134
134
|
let componentCount;
|
|
135
135
|
let registryPath;
|
|
136
136
|
let contextPath;
|
|
137
137
|
if (!options.registryOnly) {
|
|
138
138
|
console.log(pc2.dim("Compiling fragments...\n"));
|
|
139
|
-
const result = await
|
|
139
|
+
const result = await buildFragments(config, configDir);
|
|
140
140
|
if (result.errors.length > 0) {
|
|
141
141
|
console.log(pc2.yellow("Build completed with errors:\n"));
|
|
142
142
|
for (const error of result.errors) {
|
|
@@ -152,9 +152,9 @@ ${BRAND.name} Build
|
|
|
152
152
|
}
|
|
153
153
|
console.log();
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
fragmentCount = result.fragmentCount;
|
|
156
156
|
outputPath = result.outputPath;
|
|
157
|
-
console.log(pc2.green(`\u2713 Built ${result.
|
|
157
|
+
console.log(pc2.green(`\u2713 Built ${result.fragmentCount} fragment(s)`));
|
|
158
158
|
console.log(pc2.dim(` Output: ${result.outputPath}
|
|
159
159
|
`));
|
|
160
160
|
}
|
|
@@ -186,7 +186,7 @@ ${BRAND.name} Build
|
|
|
186
186
|
}
|
|
187
187
|
return {
|
|
188
188
|
success: errors.length === 0,
|
|
189
|
-
|
|
189
|
+
fragmentCount,
|
|
190
190
|
outputPath,
|
|
191
191
|
componentCount,
|
|
192
192
|
registryPath,
|
|
@@ -207,28 +207,28 @@ async function context(options = {}) {
|
|
|
207
207
|
includeRelations = false,
|
|
208
208
|
tokensOnly = false
|
|
209
209
|
} = options;
|
|
210
|
-
let
|
|
210
|
+
let fragments;
|
|
211
211
|
if (options.input) {
|
|
212
212
|
const inputPath = resolve(process.cwd(), options.input);
|
|
213
213
|
const content2 = await readFile(inputPath, "utf-8");
|
|
214
214
|
const data = JSON.parse(content2);
|
|
215
|
-
|
|
215
|
+
fragments = Object.values(data.fragments);
|
|
216
216
|
} else {
|
|
217
217
|
const { config, configDir } = await loadConfig(options.config);
|
|
218
|
-
const result = await
|
|
219
|
-
if (result.errors.length > 0 && result.
|
|
220
|
-
console.error(pc3.red("Error: No
|
|
218
|
+
const result = await buildFragments(config, configDir);
|
|
219
|
+
if (result.errors.length > 0 && result.fragmentCount === 0) {
|
|
220
|
+
console.error(pc3.red("Error: No fragments found. Run `fragments build` first or fix errors."));
|
|
221
221
|
return { success: false, tokenEstimate: 0 };
|
|
222
222
|
}
|
|
223
223
|
const content2 = await readFile(result.outputPath, "utf-8");
|
|
224
224
|
const data = JSON.parse(content2);
|
|
225
|
-
|
|
225
|
+
fragments = Object.values(data.fragments);
|
|
226
226
|
}
|
|
227
|
-
if (
|
|
228
|
-
console.error(pc3.red("No
|
|
227
|
+
if (fragments.length === 0) {
|
|
228
|
+
console.error(pc3.red("No fragments found."));
|
|
229
229
|
return { success: false, tokenEstimate: 0 };
|
|
230
230
|
}
|
|
231
|
-
const { content, tokenEstimate } = generateContext(
|
|
231
|
+
const { content, tokenEstimate } = generateContext(fragments, {
|
|
232
232
|
format,
|
|
233
233
|
compact,
|
|
234
234
|
include: {
|
|
@@ -254,7 +254,7 @@ async function context(options = {}) {
|
|
|
254
254
|
import pc4 from "picocolors";
|
|
255
255
|
async function list(options = {}) {
|
|
256
256
|
const { config, configDir } = await loadConfig(options.config);
|
|
257
|
-
const files = await
|
|
257
|
+
const files = await discoverFragmentFiles(config, configDir);
|
|
258
258
|
console.log(pc4.cyan(`
|
|
259
259
|
${BRAND.name} - Discovered Fragments
|
|
260
260
|
`));
|
|
@@ -293,7 +293,7 @@ ${BRAND.name} Reset
|
|
|
293
293
|
}
|
|
294
294
|
} catch {
|
|
295
295
|
}
|
|
296
|
-
const defaultOutFile = join(projectRoot, "
|
|
296
|
+
const defaultOutFile = join(projectRoot, "fragments.json");
|
|
297
297
|
try {
|
|
298
298
|
const fileStat = await stat(defaultOutFile);
|
|
299
299
|
if (fileStat.isFile()) {
|
|
@@ -301,10 +301,10 @@ ${BRAND.name} Reset
|
|
|
301
301
|
}
|
|
302
302
|
} catch {
|
|
303
303
|
}
|
|
304
|
-
let
|
|
304
|
+
let fragmentPatterns = [`**/*${BRAND.fileExtension}`];
|
|
305
305
|
try {
|
|
306
306
|
const { config } = await loadConfig();
|
|
307
|
-
if (config.outFile && config.outFile !== "
|
|
307
|
+
if (config.outFile && config.outFile !== "fragments.json") {
|
|
308
308
|
const customOutFile = join(projectRoot, config.outFile);
|
|
309
309
|
try {
|
|
310
310
|
const fileStat = await stat(customOutFile);
|
|
@@ -315,12 +315,12 @@ ${BRAND.name} Reset
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
if (config.include && config.include.length > 0) {
|
|
318
|
-
|
|
318
|
+
fragmentPatterns = config.include;
|
|
319
319
|
}
|
|
320
320
|
} catch {
|
|
321
321
|
}
|
|
322
322
|
console.log(pc5.dim("Scanning for generated files...\n"));
|
|
323
|
-
for (const pattern of
|
|
323
|
+
for (const pattern of fragmentPatterns) {
|
|
324
324
|
const matches = await fg(pattern, {
|
|
325
325
|
cwd: projectRoot,
|
|
326
326
|
ignore: ["**/node_modules/**"],
|
|
@@ -351,22 +351,22 @@ ${BRAND.name} Reset
|
|
|
351
351
|
const relativePath = relative(projectRoot, dir);
|
|
352
352
|
console.log(` \u{1F4C1} ${relativePath}/`);
|
|
353
353
|
}
|
|
354
|
-
const
|
|
354
|
+
const fragmentFiles = filesToDelete.filter((f) => f.endsWith(BRAND.fileExtension));
|
|
355
355
|
const mdxFilesFound = filesToDelete.filter((f) => f.endsWith(".mdx"));
|
|
356
356
|
const otherFiles = filesToDelete.filter(
|
|
357
357
|
(f) => !f.endsWith(BRAND.fileExtension) && !f.endsWith(".mdx")
|
|
358
358
|
);
|
|
359
|
-
if (
|
|
360
|
-
console.log(` \u{1F4C4} ${
|
|
361
|
-
if (
|
|
362
|
-
for (const f of
|
|
359
|
+
if (fragmentFiles.length > 0) {
|
|
360
|
+
console.log(` \u{1F4C4} ${fragmentFiles.length} fragment file(s) (*${BRAND.fileExtension})`);
|
|
361
|
+
if (fragmentFiles.length <= 5) {
|
|
362
|
+
for (const f of fragmentFiles) {
|
|
363
363
|
console.log(pc5.dim(` ${relative(projectRoot, f)}`));
|
|
364
364
|
}
|
|
365
365
|
} else {
|
|
366
|
-
for (const f of
|
|
366
|
+
for (const f of fragmentFiles.slice(0, 3)) {
|
|
367
367
|
console.log(pc5.dim(` ${relative(projectRoot, f)}`));
|
|
368
368
|
}
|
|
369
|
-
console.log(pc5.dim(` ... and ${
|
|
369
|
+
console.log(pc5.dim(` ... and ${fragmentFiles.length - 3} more`));
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
if (mdxFilesFound.length > 0) {
|
|
@@ -565,8 +565,8 @@ function parseMeta(content, filePath, warnings) {
|
|
|
565
565
|
const selectedTitle = componentPathTitle ?? titleMatches[0];
|
|
566
566
|
if (selectedTitle) {
|
|
567
567
|
result.title = selectedTitle;
|
|
568
|
-
const
|
|
569
|
-
result.componentName =
|
|
568
|
+
const fragments = result.title.split("/");
|
|
569
|
+
result.componentName = fragments[fragments.length - 1];
|
|
570
570
|
}
|
|
571
571
|
const componentMatch = content.match(/component:\s*(\w+)/);
|
|
572
572
|
if (componentMatch) {
|
|
@@ -1127,9 +1127,9 @@ function storyNameToTitle(name) {
|
|
|
1127
1127
|
return name.replace(/([A-Z])/g, " $1").trim().replace(/\s+/g, " ");
|
|
1128
1128
|
}
|
|
1129
1129
|
function extractCategory(title) {
|
|
1130
|
-
const
|
|
1131
|
-
if (
|
|
1132
|
-
const category =
|
|
1130
|
+
const fragments = title.split("/");
|
|
1131
|
+
if (fragments.length >= 2) {
|
|
1132
|
+
const category = fragments[fragments.length - 2];
|
|
1133
1133
|
return category.toLowerCase();
|
|
1134
1134
|
}
|
|
1135
1135
|
return "components";
|
|
@@ -1139,14 +1139,14 @@ function extractCategory(title) {
|
|
|
1139
1139
|
function sanitizeComponentName(name) {
|
|
1140
1140
|
return name.split(/[\s-_]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
1141
1141
|
}
|
|
1142
|
-
function
|
|
1142
|
+
function convertToFragment(parsed) {
|
|
1143
1143
|
const warnings = [...parsed.warnings];
|
|
1144
1144
|
const todos = [];
|
|
1145
1145
|
const category = extractCategory(parsed.meta.title);
|
|
1146
1146
|
const componentName = sanitizeComponentName(parsed.meta.componentName);
|
|
1147
1147
|
if (!parsed.meta.componentImport) {
|
|
1148
1148
|
warnings.push(`No importable component found - story may define component locally`);
|
|
1149
|
-
const outputFile2 = parsed.filePath.replace(/\.stories\.(tsx?|jsx?|mdx)$/, ".
|
|
1149
|
+
const outputFile2 = parsed.filePath.replace(/\.stories\.(tsx?|jsx?|mdx)$/, ".fragment.tsx");
|
|
1150
1150
|
return {
|
|
1151
1151
|
sourceFile: parsed.filePath,
|
|
1152
1152
|
outputFile: outputFile2,
|
|
@@ -1174,7 +1174,7 @@ function convertToSegment(parsed) {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
}
|
|
1176
1176
|
const skippedVariants = variants.filter((v) => v.needsManualReview && v.skipReason).map((v) => ({ name: v.name, reason: v.skipReason }));
|
|
1177
|
-
const code =
|
|
1177
|
+
const code = generateFragmentCode({
|
|
1178
1178
|
componentName,
|
|
1179
1179
|
componentImport: parsed.meta.componentImport,
|
|
1180
1180
|
description: parsed.meta.description,
|
|
@@ -1191,7 +1191,7 @@ function convertToSegment(parsed) {
|
|
|
1191
1191
|
skippedVariants: skippedVariants.length > 0 ? skippedVariants : void 0
|
|
1192
1192
|
}
|
|
1193
1193
|
});
|
|
1194
|
-
const outputFile = parsed.filePath.replace(/\.stories\.(tsx?|jsx?|mdx)$/, ".
|
|
1194
|
+
const outputFile = parsed.filePath.replace(/\.stories\.(tsx?|jsx?|mdx)$/, ".fragment.tsx");
|
|
1195
1195
|
return {
|
|
1196
1196
|
sourceFile: parsed.filePath,
|
|
1197
1197
|
outputFile,
|
|
@@ -1408,7 +1408,7 @@ function formatValueForObject(value) {
|
|
|
1408
1408
|
}
|
|
1409
1409
|
return JSON.stringify(value);
|
|
1410
1410
|
}
|
|
1411
|
-
function
|
|
1411
|
+
function generateFragmentCode(options) {
|
|
1412
1412
|
const {
|
|
1413
1413
|
componentName,
|
|
1414
1414
|
componentImport,
|
|
@@ -1439,10 +1439,10 @@ ${generated.skippedVariants.map((sv) => ` { name: "${escapeString(sv.name)}
|
|
|
1439
1439
|
},
|
|
1440
1440
|
`;
|
|
1441
1441
|
}
|
|
1442
|
-
return `import {
|
|
1442
|
+
return `import { defineFragment } from "@fragments/core";
|
|
1443
1443
|
import { ${componentName} } from "${componentImport}";
|
|
1444
1444
|
|
|
1445
|
-
export default
|
|
1445
|
+
export default defineFragment({
|
|
1446
1446
|
component: ${componentName},
|
|
1447
1447
|
|
|
1448
1448
|
meta: {
|
|
@@ -1627,21 +1627,21 @@ async function discoverStoryFiles(projectRoot, patterns) {
|
|
|
1627
1627
|
}
|
|
1628
1628
|
|
|
1629
1629
|
// src/setup.ts
|
|
1630
|
-
async function
|
|
1630
|
+
async function isFragmentsJsonStale(configDir, outFile) {
|
|
1631
1631
|
const fs2 = await import("fs/promises");
|
|
1632
1632
|
const path = await import("path");
|
|
1633
1633
|
const fg4 = await import("fast-glob");
|
|
1634
|
-
const
|
|
1634
|
+
const fragmentsJsonPath = path.join(configDir, outFile);
|
|
1635
1635
|
try {
|
|
1636
|
-
const
|
|
1637
|
-
const
|
|
1636
|
+
const fragmentsJsonStat = await fs2.stat(fragmentsJsonPath);
|
|
1637
|
+
const fragmentFiles = await fg4.default(`**/*${BRAND.fileExtension}`, {
|
|
1638
1638
|
cwd: configDir,
|
|
1639
1639
|
ignore: ["**/node_modules/**"],
|
|
1640
1640
|
absolute: true
|
|
1641
1641
|
});
|
|
1642
|
-
for (const file of
|
|
1642
|
+
for (const file of fragmentFiles) {
|
|
1643
1643
|
const stat3 = await fs2.stat(file);
|
|
1644
|
-
if (stat3.mtimeMs >
|
|
1644
|
+
if (stat3.mtimeMs > fragmentsJsonStat.mtimeMs) {
|
|
1645
1645
|
return { stale: true, missing: false };
|
|
1646
1646
|
}
|
|
1647
1647
|
}
|
|
@@ -1650,16 +1650,16 @@ async function isSegmentsJsonStale(configDir, outFile) {
|
|
|
1650
1650
|
return { stale: false, missing: true };
|
|
1651
1651
|
}
|
|
1652
1652
|
}
|
|
1653
|
-
async function
|
|
1653
|
+
async function loadFragmentInfo(fragmentFiles) {
|
|
1654
1654
|
const fs2 = await import("fs/promises");
|
|
1655
|
-
const
|
|
1656
|
-
for (const file of
|
|
1655
|
+
const fragments = [];
|
|
1656
|
+
for (const file of fragmentFiles) {
|
|
1657
1657
|
try {
|
|
1658
1658
|
const content = await fs2.readFile(file.absolutePath, "utf-8");
|
|
1659
1659
|
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
|
|
1660
1660
|
const hasFigma = /meta:\s*\{[^}]*figma:\s*['"]https?:/.test(content);
|
|
1661
1661
|
if (nameMatch) {
|
|
1662
|
-
|
|
1662
|
+
fragments.push({
|
|
1663
1663
|
name: nameMatch[1],
|
|
1664
1664
|
filePath: file.absolutePath,
|
|
1665
1665
|
hasFigma
|
|
@@ -1668,14 +1668,14 @@ async function loadSegmentInfo(segmentFiles) {
|
|
|
1668
1668
|
} catch {
|
|
1669
1669
|
}
|
|
1670
1670
|
}
|
|
1671
|
-
return
|
|
1671
|
+
return fragments;
|
|
1672
1672
|
}
|
|
1673
1673
|
async function runSetup(options = {}) {
|
|
1674
1674
|
const fs2 = await import("fs/promises");
|
|
1675
1675
|
const path = await import("path");
|
|
1676
1676
|
const result = {
|
|
1677
|
-
|
|
1678
|
-
|
|
1677
|
+
fragmentFilesCreated: 0,
|
|
1678
|
+
fragmentsBuilt: 0,
|
|
1679
1679
|
figmaLinked: 0,
|
|
1680
1680
|
errors: []
|
|
1681
1681
|
};
|
|
@@ -1685,8 +1685,8 @@ async function runSetup(options = {}) {
|
|
|
1685
1685
|
try {
|
|
1686
1686
|
const { config, configDir } = await loadConfig(options.configPath);
|
|
1687
1687
|
log(pc6.dim("Checking for fragment files..."));
|
|
1688
|
-
let
|
|
1689
|
-
if (
|
|
1688
|
+
let fragmentFiles = await discoverFragmentFiles(config, configDir);
|
|
1689
|
+
if (fragmentFiles.length === 0 && !options.skipStorybook) {
|
|
1690
1690
|
log(pc6.yellow("\n No fragment files found"));
|
|
1691
1691
|
const sbConfig = await detectStorybookConfig(configDir);
|
|
1692
1692
|
if (sbConfig) {
|
|
@@ -1698,40 +1698,40 @@ async function runSetup(options = {}) {
|
|
|
1698
1698
|
for (const storyFile of storyFiles) {
|
|
1699
1699
|
try {
|
|
1700
1700
|
const parsed = await parseStoryFile(storyFile);
|
|
1701
|
-
const
|
|
1702
|
-
await fs2.mkdir(path.dirname(
|
|
1703
|
-
await fs2.writeFile(
|
|
1701
|
+
const fragmentResult = convertToFragment(parsed);
|
|
1702
|
+
await fs2.mkdir(path.dirname(fragmentResult.outputFile), { recursive: true });
|
|
1703
|
+
await fs2.writeFile(fragmentResult.outputFile, fragmentResult.code);
|
|
1704
1704
|
converted++;
|
|
1705
1705
|
} catch {
|
|
1706
1706
|
}
|
|
1707
1707
|
}
|
|
1708
|
-
result.
|
|
1708
|
+
result.fragmentFilesCreated = converted;
|
|
1709
1709
|
log(pc6.green(` Generated ${converted} fragment file(s)`));
|
|
1710
|
-
|
|
1710
|
+
fragmentFiles = await discoverFragmentFiles(config, configDir);
|
|
1711
1711
|
}
|
|
1712
1712
|
} else {
|
|
1713
1713
|
log(pc6.dim(" No Storybook config found"));
|
|
1714
1714
|
log(pc6.dim(` Run ${pc6.cyan(`${BRAND.cliCommand} add <ComponentName>`)} to create your first fragment`));
|
|
1715
1715
|
}
|
|
1716
|
-
} else if (
|
|
1717
|
-
log(pc6.green(` Found ${
|
|
1716
|
+
} else if (fragmentFiles.length > 0) {
|
|
1717
|
+
log(pc6.green(` Found ${fragmentFiles.length} fragment file(s)`));
|
|
1718
1718
|
}
|
|
1719
|
-
if (
|
|
1719
|
+
if (fragmentFiles.length > 0 && !options.skipBuild) {
|
|
1720
1720
|
const outFile = config.outFile || BRAND.outFile;
|
|
1721
|
-
const { stale, missing } = await
|
|
1721
|
+
const { stale, missing } = await isFragmentsJsonStale(configDir, outFile);
|
|
1722
1722
|
if (missing || stale) {
|
|
1723
1723
|
const reason = missing ? "Building" : "Rebuilding";
|
|
1724
1724
|
log(pc6.dim(`
|
|
1725
1725
|
${reason} ${BRAND.outFile}...`));
|
|
1726
1726
|
try {
|
|
1727
|
-
const buildResult = await
|
|
1728
|
-
result.
|
|
1727
|
+
const buildResult = await buildFragments(config, configDir);
|
|
1728
|
+
result.fragmentsBuilt = buildResult.fragmentCount;
|
|
1729
1729
|
if (buildResult.errors.length > 0) {
|
|
1730
1730
|
for (const err of buildResult.errors) {
|
|
1731
1731
|
result.errors.push(`${err.file}: ${err.error}`);
|
|
1732
1732
|
}
|
|
1733
1733
|
}
|
|
1734
|
-
log(pc6.green(` Built ${buildResult.
|
|
1734
|
+
log(pc6.green(` Built ${buildResult.fragmentCount} fragment(s)`));
|
|
1735
1735
|
} catch (error) {
|
|
1736
1736
|
result.errors.push(`Build failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1737
1737
|
}
|
|
@@ -1741,14 +1741,14 @@ ${reason} ${BRAND.outFile}...`));
|
|
|
1741
1741
|
}
|
|
1742
1742
|
}
|
|
1743
1743
|
if (!options.skipFigma && config.figmaFile && process.env.FIGMA_ACCESS_TOKEN) {
|
|
1744
|
-
const
|
|
1745
|
-
const linkedCount =
|
|
1746
|
-
if (linkedCount === 0 &&
|
|
1744
|
+
const fragments = await loadFragmentInfo(fragmentFiles);
|
|
1745
|
+
const linkedCount = fragments.filter((s) => s.hasFigma).length;
|
|
1746
|
+
if (linkedCount === 0 && fragments.length > 0) {
|
|
1747
1747
|
log(pc6.dim("\n Figma configured but no fragments linked"));
|
|
1748
1748
|
log(pc6.dim(` Run ${pc6.cyan(`${BRAND.cliCommand} link figma --auto`)} to auto-link components`));
|
|
1749
1749
|
} else if (linkedCount > 0) {
|
|
1750
1750
|
log(pc6.dim(`
|
|
1751
|
-
${linkedCount}/${
|
|
1751
|
+
${linkedCount}/${fragments.length} fragment(s) linked to Figma`));
|
|
1752
1752
|
}
|
|
1753
1753
|
} else if (!options.skipFigma && config.figmaFile && !process.env.FIGMA_ACCESS_TOKEN) {
|
|
1754
1754
|
log(pc6.dim("\n Figma file configured but FIGMA_ACCESS_TOKEN not set"));
|
|
@@ -1785,7 +1785,7 @@ ${BRAND.name} Dev Server
|
|
|
1785
1785
|
}
|
|
1786
1786
|
}
|
|
1787
1787
|
}
|
|
1788
|
-
const { createDevServer } = await import("./viewer-
|
|
1788
|
+
const { createDevServer } = await import("./viewer-GM7IQPPB.js");
|
|
1789
1789
|
console.log(pc7.dim("\nStarting dev server..."));
|
|
1790
1790
|
const parsedPort = typeof port === "string" ? parseInt(port, 10) : port;
|
|
1791
1791
|
try {
|
|
@@ -1871,7 +1871,7 @@ ${BRAND.name} Design Verification
|
|
|
1871
1871
|
let passed = 0;
|
|
1872
1872
|
let failed = 0;
|
|
1873
1873
|
for (const comp of componentsToCompare) {
|
|
1874
|
-
const response = await fetch(`${baseUrl}/
|
|
1874
|
+
const response = await fetch(`${baseUrl}/fragments/compare`, {
|
|
1875
1875
|
method: "POST",
|
|
1876
1876
|
headers: { "Content-Type": "application/json" },
|
|
1877
1877
|
body: JSON.stringify({
|
|
@@ -1921,35 +1921,35 @@ ${pc8.green(`${passed} passed`)}, ${pc8.red(`${failed} failed`)}
|
|
|
1921
1921
|
}
|
|
1922
1922
|
async function compareAll(baseUrl, threshold, output) {
|
|
1923
1923
|
console.log(pc8.dim("Comparing all components with Figma links...\n"));
|
|
1924
|
-
const contextResp = await fetch(`${baseUrl}/
|
|
1924
|
+
const contextResp = await fetch(`${baseUrl}/fragments/context?format=json`);
|
|
1925
1925
|
if (!contextResp.ok) {
|
|
1926
|
-
throw new Error("Failed to fetch
|
|
1926
|
+
throw new Error("Failed to fetch fragments. Make sure dev server is running.");
|
|
1927
1927
|
}
|
|
1928
1928
|
const contextText = await contextResp.text();
|
|
1929
|
-
let
|
|
1929
|
+
let fragments = [];
|
|
1930
1930
|
try {
|
|
1931
1931
|
const contextData = JSON.parse(contextText);
|
|
1932
|
-
|
|
1932
|
+
fragments = contextData.components || [];
|
|
1933
1933
|
} catch {
|
|
1934
|
-
|
|
1934
|
+
fragments = [];
|
|
1935
1935
|
}
|
|
1936
|
-
if (
|
|
1936
|
+
if (fragments.length === 0) {
|
|
1937
1937
|
console.log(pc8.yellow("No components found with Figma links."));
|
|
1938
|
-
console.log(pc8.dim("Add figma field to your
|
|
1938
|
+
console.log(pc8.dim("Add figma field to your fragment definitions:"));
|
|
1939
1939
|
console.log(pc8.dim(' meta: { figma: "https://figma.com/file/..." }'));
|
|
1940
1940
|
return { success: true, passed: 0, failed: 0, skipped: 0 };
|
|
1941
1941
|
}
|
|
1942
1942
|
let passed = 0;
|
|
1943
1943
|
let failed = 0;
|
|
1944
1944
|
let skipped = 0;
|
|
1945
|
-
for (const seg of
|
|
1945
|
+
for (const seg of fragments) {
|
|
1946
1946
|
if (!seg.figma) {
|
|
1947
1947
|
skipped++;
|
|
1948
1948
|
console.log(`${pc8.dim("\u23ED\uFE0F")} ${pc8.dim(seg.name)} ${pc8.dim("(no figma link)")}`);
|
|
1949
1949
|
continue;
|
|
1950
1950
|
}
|
|
1951
1951
|
try {
|
|
1952
|
-
const response = await fetch(`${baseUrl}/
|
|
1952
|
+
const response = await fetch(`${baseUrl}/fragments/compare`, {
|
|
1953
1953
|
method: "POST",
|
|
1954
1954
|
headers: { "Content-Type": "application/json" },
|
|
1955
1955
|
body: JSON.stringify({
|
|
@@ -1995,27 +1995,27 @@ ${pc8.green(`${passed} passed`)}, ${pc8.red(`${failed} failed`)}, ${pc8.dim(`${s
|
|
|
1995
1995
|
}
|
|
1996
1996
|
async function selectComponents(baseUrl) {
|
|
1997
1997
|
console.log(pc8.dim("Fetching components with Figma links...\n"));
|
|
1998
|
-
const contextResp = await fetch(`${baseUrl}/
|
|
1998
|
+
const contextResp = await fetch(`${baseUrl}/fragments/context?format=json`);
|
|
1999
1999
|
if (!contextResp.ok) {
|
|
2000
|
-
throw new Error("Failed to fetch
|
|
2000
|
+
throw new Error("Failed to fetch fragments. Make sure dev server is running.");
|
|
2001
2001
|
}
|
|
2002
2002
|
const contextText = await contextResp.text();
|
|
2003
|
-
let
|
|
2003
|
+
let fragments = [];
|
|
2004
2004
|
try {
|
|
2005
2005
|
const contextData = JSON.parse(contextText);
|
|
2006
|
-
|
|
2006
|
+
fragments = (contextData.components || []).filter((s) => s.figma);
|
|
2007
2007
|
} catch {
|
|
2008
|
-
|
|
2008
|
+
fragments = [];
|
|
2009
2009
|
}
|
|
2010
|
-
if (
|
|
2010
|
+
if (fragments.length === 0) {
|
|
2011
2011
|
console.log(pc8.yellow("No components found with Figma links."));
|
|
2012
|
-
console.log(pc8.dim("Add figma field to your
|
|
2012
|
+
console.log(pc8.dim("Add figma field to your fragment definitions:"));
|
|
2013
2013
|
console.log(pc8.dim(' meta: { figma: "https://figma.com/file/..." }'));
|
|
2014
2014
|
return [];
|
|
2015
2015
|
}
|
|
2016
2016
|
const { checkbox } = await import("@inquirer/prompts");
|
|
2017
2017
|
try {
|
|
2018
|
-
const choices =
|
|
2018
|
+
const choices = fragments.map((seg) => ({
|
|
2019
2019
|
name: seg.name,
|
|
2020
2020
|
value: seg.name,
|
|
2021
2021
|
checked: true
|
|
@@ -2066,7 +2066,7 @@ var DevServerClient = class {
|
|
|
2066
2066
|
try {
|
|
2067
2067
|
const controller = new AbortController();
|
|
2068
2068
|
const timeoutId = setTimeout(() => controller.abort(), 5e3);
|
|
2069
|
-
const response = await fetch(`${this.baseUrl}/
|
|
2069
|
+
const response = await fetch(`${this.baseUrl}/fragments/context?format=json`, {
|
|
2070
2070
|
signal: controller.signal
|
|
2071
2071
|
});
|
|
2072
2072
|
clearTimeout(timeoutId);
|
|
@@ -2076,10 +2076,10 @@ var DevServerClient = class {
|
|
|
2076
2076
|
}
|
|
2077
2077
|
}
|
|
2078
2078
|
/**
|
|
2079
|
-
* Get all
|
|
2079
|
+
* Get all fragments from the context endpoint
|
|
2080
2080
|
*/
|
|
2081
|
-
async
|
|
2082
|
-
const response = await this.fetch("/
|
|
2081
|
+
async getFragments() {
|
|
2082
|
+
const response = await this.fetch("/fragments/context?format=json");
|
|
2083
2083
|
const data = await response.json();
|
|
2084
2084
|
const components = data.components || {};
|
|
2085
2085
|
return Object.entries(components).map(([name, info]) => ({
|
|
@@ -2094,7 +2094,7 @@ var DevServerClient = class {
|
|
|
2094
2094
|
* Get compliance data for a component
|
|
2095
2095
|
*/
|
|
2096
2096
|
async getCompliance(request) {
|
|
2097
|
-
const response = await this.fetch("/
|
|
2097
|
+
const response = await this.fetch("/fragments/compliance", {
|
|
2098
2098
|
method: "POST",
|
|
2099
2099
|
headers: { "Content-Type": "application/json" },
|
|
2100
2100
|
body: JSON.stringify(request)
|
|
@@ -2198,12 +2198,12 @@ ${BRAND.name} Compliance Verification
|
|
|
2198
2198
|
`http://localhost:${port}`
|
|
2199
2199
|
);
|
|
2200
2200
|
}
|
|
2201
|
-
let
|
|
2201
|
+
let fragments = await client.getFragments();
|
|
2202
2202
|
if (component) {
|
|
2203
|
-
|
|
2203
|
+
fragments = fragments.filter(
|
|
2204
2204
|
(s) => s.name.toLowerCase() === component.toLowerCase()
|
|
2205
2205
|
);
|
|
2206
|
-
if (
|
|
2206
|
+
if (fragments.length === 0) {
|
|
2207
2207
|
const error = { error: `Component "${component}" not found` };
|
|
2208
2208
|
if (ci) {
|
|
2209
2209
|
console.log(JSON.stringify(error));
|
|
@@ -2213,7 +2213,7 @@ ${BRAND.name} Compliance Verification
|
|
|
2213
2213
|
process.exit(1);
|
|
2214
2214
|
}
|
|
2215
2215
|
}
|
|
2216
|
-
for (const seg of
|
|
2216
|
+
for (const seg of fragments) {
|
|
2217
2217
|
try {
|
|
2218
2218
|
const complianceResult = await client.getCompliance({
|
|
2219
2219
|
component: seg.name
|
|
@@ -2316,8 +2316,8 @@ ${BRAND.name} Design System Audit
|
|
|
2316
2316
|
`http://localhost:${port}`
|
|
2317
2317
|
);
|
|
2318
2318
|
}
|
|
2319
|
-
const
|
|
2320
|
-
if (
|
|
2319
|
+
const fragments = await client.getFragments();
|
|
2320
|
+
if (fragments.length === 0) {
|
|
2321
2321
|
if (json) {
|
|
2322
2322
|
console.log(JSON.stringify({ error: "No fragments found", components: [] }));
|
|
2323
2323
|
} else {
|
|
@@ -2336,10 +2336,10 @@ ${BRAND.name} Design System Audit
|
|
|
2336
2336
|
};
|
|
2337
2337
|
}
|
|
2338
2338
|
if (!json) {
|
|
2339
|
-
console.log(pc11.dim(`Auditing ${
|
|
2339
|
+
console.log(pc11.dim(`Auditing ${fragments.length} component(s)...
|
|
2340
2340
|
`));
|
|
2341
2341
|
}
|
|
2342
|
-
for (const seg of
|
|
2342
|
+
for (const seg of fragments) {
|
|
2343
2343
|
try {
|
|
2344
2344
|
const complianceResult = await client.getCompliance({
|
|
2345
2345
|
component: seg.name
|
|
@@ -3057,8 +3057,8 @@ ${BRAND.name} Accessibility Report
|
|
|
3057
3057
|
`http://localhost:${port}`
|
|
3058
3058
|
);
|
|
3059
3059
|
}
|
|
3060
|
-
const
|
|
3061
|
-
if (
|
|
3060
|
+
const fragments = await client.getFragments();
|
|
3061
|
+
if (fragments.length === 0) {
|
|
3062
3062
|
if (isJsonOutput) {
|
|
3063
3063
|
console.log(JSON.stringify({ error: "No fragments found", components: [] }));
|
|
3064
3064
|
} else {
|
|
@@ -3077,9 +3077,9 @@ ${BRAND.name} Accessibility Report
|
|
|
3077
3077
|
passed: true
|
|
3078
3078
|
};
|
|
3079
3079
|
}
|
|
3080
|
-
const componentsToCheck = component ?
|
|
3080
|
+
const componentsToCheck = component ? fragments.filter((s) => s.name.toLowerCase() === component.toLowerCase()) : fragments;
|
|
3081
3081
|
if (component && componentsToCheck.length === 0) {
|
|
3082
|
-
const error = `Component '${component}' not found. Available: ${
|
|
3082
|
+
const error = `Component '${component}' not found. Available: ${fragments.map((s) => s.name).join(", ")}`;
|
|
3083
3083
|
if (isJsonOutput) {
|
|
3084
3084
|
console.log(JSON.stringify({ error }));
|
|
3085
3085
|
} else {
|
|
@@ -3230,9 +3230,9 @@ async function storygen(options = {}) {
|
|
|
3230
3230
|
console.log(pc13.cyan(`
|
|
3231
3231
|
${BRAND.name} Story Generator
|
|
3232
3232
|
`));
|
|
3233
|
-
const
|
|
3234
|
-
if (
|
|
3235
|
-
console.log(pc13.yellow("No
|
|
3233
|
+
const fragmentFiles = await discoverFragmentFiles(config, configDir);
|
|
3234
|
+
if (fragmentFiles.length === 0) {
|
|
3235
|
+
console.log(pc13.yellow("No fragment files found.\n"));
|
|
3236
3236
|
return { success: true, generated: 0, outputDir: output };
|
|
3237
3237
|
}
|
|
3238
3238
|
const outputDir = resolve3(configDir, output);
|
|
@@ -3240,10 +3240,10 @@ ${BRAND.name} Story Generator
|
|
|
3240
3240
|
let generated = 0;
|
|
3241
3241
|
const generateStory = async (file) => {
|
|
3242
3242
|
try {
|
|
3243
|
-
const
|
|
3244
|
-
if (!
|
|
3245
|
-
const storyContent = generateCSF3Story(
|
|
3246
|
-
const storyName = `${
|
|
3243
|
+
const fragment = await loadFragmentFile(file.absolutePath);
|
|
3244
|
+
if (!fragment) return false;
|
|
3245
|
+
const storyContent = generateCSF3Story(fragment, file.relativePath);
|
|
3246
|
+
const storyName = `${fragment.meta.name}.stories.tsx`;
|
|
3247
3247
|
const storyPath = join5(outputDir, storyName);
|
|
3248
3248
|
await writeFile3(storyPath, storyContent);
|
|
3249
3249
|
console.log(`${pc13.green("\u2713")} Generated ${storyName}`);
|
|
@@ -3255,7 +3255,7 @@ ${BRAND.name} Story Generator
|
|
|
3255
3255
|
};
|
|
3256
3256
|
console.log(pc13.dim(`Generating stories to ${relative3(process.cwd(), outputDir)}/
|
|
3257
3257
|
`));
|
|
3258
|
-
for (const file of
|
|
3258
|
+
for (const file of fragmentFiles) {
|
|
3259
3259
|
if (await generateStory(file)) {
|
|
3260
3260
|
generated++;
|
|
3261
3261
|
}
|
|
@@ -3264,15 +3264,15 @@ ${BRAND.name} Story Generator
|
|
|
3264
3264
|
console.log(pc13.green(`\u2713 Generated ${generated} story file(s)
|
|
3265
3265
|
`));
|
|
3266
3266
|
if (watch) {
|
|
3267
|
-
console.log(pc13.dim("Watching for
|
|
3267
|
+
console.log(pc13.dim("Watching for fragment changes... (Ctrl+C to stop)\n"));
|
|
3268
3268
|
const chokidar = await import("chokidar");
|
|
3269
|
-
const patterns =
|
|
3269
|
+
const patterns = fragmentFiles.map((f) => f.absolutePath);
|
|
3270
3270
|
const watcher = chokidar.watch(patterns, {
|
|
3271
3271
|
ignoreInitial: true,
|
|
3272
3272
|
awaitWriteFinish: { stabilityThreshold: 100 }
|
|
3273
3273
|
});
|
|
3274
3274
|
watcher.on("change", async (changedPath) => {
|
|
3275
|
-
const file =
|
|
3275
|
+
const file = fragmentFiles.find((f) => f.absolutePath === changedPath);
|
|
3276
3276
|
if (file) {
|
|
3277
3277
|
console.log(pc13.dim(`
|
|
3278
3278
|
Changed: ${relative3(process.cwd(), changedPath)}`));
|
|
@@ -3282,10 +3282,10 @@ Changed: ${relative3(process.cwd(), changedPath)}`));
|
|
|
3282
3282
|
watcher.on("add", async (addedPath) => {
|
|
3283
3283
|
console.log(pc13.dim(`
|
|
3284
3284
|
Added: ${relative3(process.cwd(), addedPath)}`));
|
|
3285
|
-
const newFiles = await
|
|
3285
|
+
const newFiles = await discoverFragmentFiles(config, configDir);
|
|
3286
3286
|
const file = newFiles.find((f) => f.absolutePath === addedPath);
|
|
3287
3287
|
if (file) {
|
|
3288
|
-
|
|
3288
|
+
fragmentFiles.push(file);
|
|
3289
3289
|
await generateStory(file);
|
|
3290
3290
|
}
|
|
3291
3291
|
});
|
|
@@ -3294,8 +3294,8 @@ Added: ${relative3(process.cwd(), addedPath)}`));
|
|
|
3294
3294
|
}
|
|
3295
3295
|
return { success: true, generated, outputDir };
|
|
3296
3296
|
}
|
|
3297
|
-
function generateCSF3Story(
|
|
3298
|
-
const { meta, variants, props, usage } =
|
|
3297
|
+
function generateCSF3Story(fragment, relativePath) {
|
|
3298
|
+
const { meta, variants, props, usage } = fragment;
|
|
3299
3299
|
const componentName = meta.name;
|
|
3300
3300
|
const argTypes = [];
|
|
3301
3301
|
if (props) {
|
|
@@ -3335,11 +3335,11 @@ ${usage.whenNot?.map((w) => `- ${w}`).join("\n") || ""}` : "";
|
|
|
3335
3335
|
return `/**
|
|
3336
3336
|
* Auto-generated Storybook stories from ${relativePath}
|
|
3337
3337
|
*
|
|
3338
|
-
* DO NOT EDIT - regenerate with:
|
|
3338
|
+
* DO NOT EDIT - regenerate with: fragments storygen
|
|
3339
3339
|
*/
|
|
3340
3340
|
|
|
3341
3341
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3342
|
-
import { ${componentName} } from '${relativePath.replace(/\.
|
|
3342
|
+
import { ${componentName} } from '${relativePath.replace(/\.fragment\.tsx$/, "/index.js")}';
|
|
3343
3343
|
|
|
3344
3344
|
const meta: Meta<typeof ${componentName}> = {
|
|
3345
3345
|
title: '${meta.category ? `${meta.category.charAt(0).toUpperCase() + meta.category.slice(1)}/` : ""}${componentName}',
|
|
@@ -3450,14 +3450,14 @@ async function updateBaseline(component, options, config, configDir, baseUrl) {
|
|
|
3450
3450
|
throw new Error("Failed to fetch fragments. Make sure dev server is running.");
|
|
3451
3451
|
}
|
|
3452
3452
|
const contextData = JSON.parse(await contextResp.text());
|
|
3453
|
-
const
|
|
3454
|
-
if (
|
|
3453
|
+
const fragments = contextData.components || [];
|
|
3454
|
+
if (fragments.length === 0) {
|
|
3455
3455
|
console.log(pc15.yellow("No components found.\n"));
|
|
3456
3456
|
return { success: true, action: "update", count: 0 };
|
|
3457
3457
|
}
|
|
3458
3458
|
component = await select({
|
|
3459
3459
|
message: "Select component to update:",
|
|
3460
|
-
choices:
|
|
3460
|
+
choices: fragments.map((s) => ({
|
|
3461
3461
|
name: s.name,
|
|
3462
3462
|
value: s.name
|
|
3463
3463
|
}))
|
|
@@ -3607,7 +3607,7 @@ ${BRAND.name} Component Scaffold
|
|
|
3607
3607
|
dir = dir || "src/components";
|
|
3608
3608
|
const componentDir = resolve4(process.cwd(), dir, componentName);
|
|
3609
3609
|
const componentFile = join7(componentDir, `${componentName}.tsx`);
|
|
3610
|
-
const
|
|
3610
|
+
const fragmentFile = join7(componentDir, `${componentName}${BRAND.fileExtension}`);
|
|
3611
3611
|
const indexFile = join7(componentDir, "index.ts");
|
|
3612
3612
|
try {
|
|
3613
3613
|
await access2(componentDir);
|
|
@@ -3622,9 +3622,9 @@ ${BRAND.name} Component Scaffold
|
|
|
3622
3622
|
await writeFile4(componentFile, componentCode);
|
|
3623
3623
|
console.log(`${pc16.green("\u2713")} Created ${relative5(process.cwd(), componentFile)}`);
|
|
3624
3624
|
}
|
|
3625
|
-
const
|
|
3626
|
-
await writeFile4(
|
|
3627
|
-
console.log(`${pc16.green("\u2713")} Created ${relative5(process.cwd(),
|
|
3625
|
+
const fragmentCode = generateFragmentStub(componentName, category, template);
|
|
3626
|
+
await writeFile4(fragmentFile, fragmentCode);
|
|
3627
|
+
console.log(`${pc16.green("\u2713")} Created ${relative5(process.cwd(), fragmentFile)}`);
|
|
3628
3628
|
const indexCode = `export { ${componentName} } from './${componentName}.js';
|
|
3629
3629
|
`;
|
|
3630
3630
|
await writeFile4(indexFile, indexCode);
|
|
@@ -3644,7 +3644,7 @@ ${BRAND.name} Component Scaffold
|
|
|
3644
3644
|
return {
|
|
3645
3645
|
success: true,
|
|
3646
3646
|
componentPath: generateComponent ? componentFile : void 0,
|
|
3647
|
-
|
|
3647
|
+
fragmentPath: fragmentFile,
|
|
3648
3648
|
indexPath: indexFile
|
|
3649
3649
|
};
|
|
3650
3650
|
}
|
|
@@ -3673,7 +3673,7 @@ export function ${name}({ children, className }: ${name}Props) {
|
|
|
3673
3673
|
}
|
|
3674
3674
|
`;
|
|
3675
3675
|
}
|
|
3676
|
-
function
|
|
3676
|
+
function generateFragmentStub(name, category, template) {
|
|
3677
3677
|
const usageHints = {
|
|
3678
3678
|
action: {
|
|
3679
3679
|
when: ["User needs to trigger an action", "Form submission is required"],
|
|
@@ -3701,10 +3701,10 @@ function generateSegmentStub(name, category, template) {
|
|
|
3701
3701
|
};
|
|
3702
3702
|
const scenarioTags = scenarioTagHints[template] || scenarioTagHints.display;
|
|
3703
3703
|
return `import React from 'react';
|
|
3704
|
-
import {
|
|
3704
|
+
import { defineFragment } from '@fragments/core';
|
|
3705
3705
|
import { ${name} } from './index.js';
|
|
3706
3706
|
|
|
3707
|
-
export default
|
|
3707
|
+
export default defineFragment({
|
|
3708
3708
|
component: ${name},
|
|
3709
3709
|
|
|
3710
3710
|
meta: {
|
|
@@ -3837,40 +3837,40 @@ ${BRAND.name} Link Wizard
|
|
|
3837
3837
|
} else {
|
|
3838
3838
|
console.log();
|
|
3839
3839
|
}
|
|
3840
|
-
const
|
|
3841
|
-
if (
|
|
3842
|
-
console.log(pc17.yellow("No
|
|
3840
|
+
const fragmentFiles = await discoverFragmentFiles(config, configDir);
|
|
3841
|
+
if (fragmentFiles.length === 0) {
|
|
3842
|
+
console.log(pc17.yellow("No fragment files found in codebase."));
|
|
3843
3843
|
console.log(pc17.dim(`Looking for: ${config.include.join(", ")}`));
|
|
3844
3844
|
process.exit(0);
|
|
3845
3845
|
}
|
|
3846
|
-
console.log(pc17.dim(`Found ${
|
|
3846
|
+
console.log(pc17.dim(`Found ${fragmentFiles.length} fragment file(s)
|
|
3847
3847
|
`));
|
|
3848
|
-
const
|
|
3849
|
-
for (const file of
|
|
3848
|
+
const fragments = [];
|
|
3849
|
+
for (const file of fragmentFiles) {
|
|
3850
3850
|
try {
|
|
3851
3851
|
const content = await readFile4(file.absolutePath, "utf-8");
|
|
3852
3852
|
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
|
|
3853
3853
|
const hasFigma = /meta:\s*\{[^}]*figma:\s*['"]https?:/.test(content);
|
|
3854
|
-
const
|
|
3854
|
+
const fragmentVariants = extractVariants(content, nameMatch?.[1]);
|
|
3855
3855
|
if (nameMatch) {
|
|
3856
|
-
|
|
3856
|
+
fragments.push({
|
|
3857
3857
|
name: nameMatch[1],
|
|
3858
3858
|
filePath: file.absolutePath,
|
|
3859
3859
|
relativePath: file.relativePath,
|
|
3860
3860
|
hasFigma,
|
|
3861
|
-
variants:
|
|
3861
|
+
variants: fragmentVariants
|
|
3862
3862
|
});
|
|
3863
3863
|
}
|
|
3864
3864
|
} catch {
|
|
3865
3865
|
}
|
|
3866
3866
|
}
|
|
3867
3867
|
const matches = [];
|
|
3868
|
-
const
|
|
3869
|
-
for (const
|
|
3868
|
+
const unmatchedFragments = [];
|
|
3869
|
+
for (const fragment of fragments) {
|
|
3870
3870
|
let bestMatch = null;
|
|
3871
3871
|
let bestScore = 0;
|
|
3872
3872
|
for (const figmaComp of allFigmaComponents) {
|
|
3873
|
-
const score = calculateMatchScore(
|
|
3873
|
+
const score = calculateMatchScore(fragment.name, figmaComp.name);
|
|
3874
3874
|
if (score > bestScore) {
|
|
3875
3875
|
bestMatch = figmaComp;
|
|
3876
3876
|
bestScore = score;
|
|
@@ -3878,18 +3878,18 @@ ${BRAND.name} Link Wizard
|
|
|
3878
3878
|
}
|
|
3879
3879
|
}
|
|
3880
3880
|
if (bestMatch && bestScore >= 65) {
|
|
3881
|
-
const alreadyLinked =
|
|
3881
|
+
const alreadyLinked = fragment.hasFigma;
|
|
3882
3882
|
if (alreadyLinked && !auto) {
|
|
3883
|
-
console.log(pc17.dim(`\u23ED\uFE0F ${
|
|
3883
|
+
console.log(pc17.dim(`\u23ED\uFE0F ${fragment.name} (already linked)`));
|
|
3884
3884
|
}
|
|
3885
|
-
matches.push({
|
|
3885
|
+
matches.push({ fragment, figmaComponent: bestMatch, score: bestScore, alreadyLinked });
|
|
3886
3886
|
} else {
|
|
3887
|
-
|
|
3887
|
+
unmatchedFragments.push(fragment);
|
|
3888
3888
|
}
|
|
3889
3889
|
}
|
|
3890
|
-
if (
|
|
3891
|
-
console.log(pc17.dim("Unmatched
|
|
3892
|
-
for (const seg of
|
|
3890
|
+
if (unmatchedFragments.length > 0) {
|
|
3891
|
+
console.log(pc17.dim("Unmatched fragments:"));
|
|
3892
|
+
for (const seg of unmatchedFragments) {
|
|
3893
3893
|
console.log(` ${pc17.dim("\u2022")} ${seg.name}`);
|
|
3894
3894
|
}
|
|
3895
3895
|
console.log();
|
|
@@ -3898,7 +3898,7 @@ ${BRAND.name} Link Wizard
|
|
|
3898
3898
|
const alreadyLinkedMatches = matches.filter((m) => m.alreadyLinked);
|
|
3899
3899
|
if (matches.length === 0) {
|
|
3900
3900
|
console.log(pc17.yellow("\nNo automatic matches found."));
|
|
3901
|
-
console.log(pc17.dim("You can manually add figma URLs to your
|
|
3901
|
+
console.log(pc17.dim("You can manually add figma URLs to your fragment definitions."));
|
|
3902
3902
|
process.exit(0);
|
|
3903
3903
|
}
|
|
3904
3904
|
if (dryRun) {
|
|
@@ -3907,7 +3907,7 @@ ${BRAND.name} Link Wizard
|
|
|
3907
3907
|
for (const match of newMatches) {
|
|
3908
3908
|
const scoreColor = match.score === 100 ? pc17.green : pc17.yellow;
|
|
3909
3909
|
console.log(
|
|
3910
|
-
` ${pc17.green("\u2713")} ${pc17.bold(match.
|
|
3910
|
+
` ${pc17.green("\u2713")} ${pc17.bold(match.fragment.name)} \u2192 ${match.figmaComponent.name} ${scoreColor(`(${Math.round(match.score)}%)`)}`
|
|
3911
3911
|
);
|
|
3912
3912
|
}
|
|
3913
3913
|
}
|
|
@@ -3921,7 +3921,7 @@ ${BRAND.name} Link Wizard
|
|
|
3921
3921
|
for (const match of newMatches) {
|
|
3922
3922
|
const scoreColor = match.score === 100 ? pc17.green : pc17.yellow;
|
|
3923
3923
|
console.log(
|
|
3924
|
-
` ${pc17.green("\u2713")} ${pc17.bold(match.
|
|
3924
|
+
` ${pc17.green("\u2713")} ${pc17.bold(match.fragment.name)} \u2192 ${match.figmaComponent.name} ${scoreColor(`(${Math.round(match.score)}%)`)}`
|
|
3925
3925
|
);
|
|
3926
3926
|
}
|
|
3927
3927
|
} else {
|
|
@@ -3931,7 +3931,7 @@ ${BRAND.name} Link Wizard
|
|
|
3931
3931
|
const choices = newMatches.map((match) => {
|
|
3932
3932
|
const scoreColor = match.score === 100 ? pc17.green : pc17.yellow;
|
|
3933
3933
|
return {
|
|
3934
|
-
name: `${pc17.bold(match.
|
|
3934
|
+
name: `${pc17.bold(match.fragment.name)} \u2192 ${match.figmaComponent.name} ${scoreColor(`(${Math.round(match.score)}%)`)}`,
|
|
3935
3935
|
value: match,
|
|
3936
3936
|
checked: true
|
|
3937
3937
|
};
|
|
@@ -3953,7 +3953,7 @@ ${BRAND.name} Link Wizard
|
|
|
3953
3953
|
for (const match of selectedMatches) {
|
|
3954
3954
|
if (match.alreadyLinked) continue;
|
|
3955
3955
|
try {
|
|
3956
|
-
let content = await readFile4(match.
|
|
3956
|
+
let content = await readFile4(match.fragment.filePath, "utf-8");
|
|
3957
3957
|
const figmaUrlToInsert = figmaClient.buildNodeUrl(
|
|
3958
3958
|
match.figmaComponent.file_key,
|
|
3959
3959
|
match.figmaComponent.node_id,
|
|
@@ -3971,16 +3971,16 @@ ${BRAND.name} Link Wizard
|
|
|
3971
3971
|
figma: '${figmaUrlToInsert}',`
|
|
3972
3972
|
);
|
|
3973
3973
|
}
|
|
3974
|
-
await writeFile5(match.
|
|
3974
|
+
await writeFile5(match.fragment.filePath, content);
|
|
3975
3975
|
updated++;
|
|
3976
|
-
console.log(` ${pc17.green("\u2713")} Updated ${match.
|
|
3976
|
+
console.log(` ${pc17.green("\u2713")} Updated ${match.fragment.relativePath}`);
|
|
3977
3977
|
} catch (error) {
|
|
3978
|
-
console.log(` ${pc17.red("\u2717")} Failed to update ${match.
|
|
3978
|
+
console.log(` ${pc17.red("\u2717")} Failed to update ${match.fragment.relativePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3979
3979
|
}
|
|
3980
3980
|
}
|
|
3981
3981
|
if (updated > 0) {
|
|
3982
3982
|
console.log(pc17.green(`
|
|
3983
|
-
\u2713 Updated ${updated}
|
|
3983
|
+
\u2713 Updated ${updated} fragment file(s)
|
|
3984
3984
|
`));
|
|
3985
3985
|
}
|
|
3986
3986
|
let variantUpdates = 0;
|
|
@@ -4035,37 +4035,37 @@ function extractVariants(content, componentName) {
|
|
|
4035
4035
|
}
|
|
4036
4036
|
return variants;
|
|
4037
4037
|
}
|
|
4038
|
-
function calculateMatchScore(
|
|
4038
|
+
function calculateMatchScore(fragmentName, figmaName) {
|
|
4039
4039
|
const normalizeForMatch = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
4040
|
-
const
|
|
4040
|
+
const normalizedFragment = normalizeForMatch(fragmentName);
|
|
4041
4041
|
const normalizedFigma = normalizeForMatch(figmaName);
|
|
4042
|
-
if (
|
|
4042
|
+
if (normalizedFragment === normalizedFigma) {
|
|
4043
4043
|
return 100;
|
|
4044
4044
|
}
|
|
4045
|
-
if (normalizedFigma.startsWith(
|
|
4046
|
-
const coverage =
|
|
4045
|
+
if (normalizedFigma.startsWith(normalizedFragment)) {
|
|
4046
|
+
const coverage = normalizedFragment.length / normalizedFigma.length;
|
|
4047
4047
|
return Math.max(85, coverage * 100);
|
|
4048
4048
|
}
|
|
4049
|
-
if (
|
|
4050
|
-
const coverage = normalizedFigma.length /
|
|
4049
|
+
if (normalizedFragment.startsWith(normalizedFigma)) {
|
|
4050
|
+
const coverage = normalizedFigma.length / normalizedFragment.length;
|
|
4051
4051
|
return Math.max(80, coverage * 100);
|
|
4052
4052
|
}
|
|
4053
4053
|
const getWords = (s) => {
|
|
4054
4054
|
return s.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[^a-zA-Z0-9]+/g, " ").toLowerCase().split(/\s+/).filter((w) => w.length > 0);
|
|
4055
4055
|
};
|
|
4056
|
-
const
|
|
4056
|
+
const fragmentWords = getWords(fragmentName);
|
|
4057
4057
|
const figmaWords = getWords(figmaName);
|
|
4058
|
-
const
|
|
4058
|
+
const allFragmentWordsInFigma = fragmentWords.every(
|
|
4059
4059
|
(sw) => figmaWords.some((fw) => fw === sw || fw.startsWith(sw) || sw.startsWith(fw))
|
|
4060
4060
|
);
|
|
4061
|
-
if (
|
|
4062
|
-
const wordOverlap =
|
|
4061
|
+
if (allFragmentWordsInFigma && fragmentWords.length > 0) {
|
|
4062
|
+
const wordOverlap = fragmentWords.length / Math.max(fragmentWords.length, figmaWords.length);
|
|
4063
4063
|
return Math.max(75, wordOverlap * 95);
|
|
4064
4064
|
}
|
|
4065
|
-
if (normalizedFigma.includes(
|
|
4065
|
+
if (normalizedFigma.includes(normalizedFragment)) {
|
|
4066
4066
|
return 70;
|
|
4067
4067
|
}
|
|
4068
|
-
if (
|
|
4068
|
+
if (normalizedFragment.includes(normalizedFigma)) {
|
|
4069
4069
|
return 65;
|
|
4070
4070
|
}
|
|
4071
4071
|
return 0;
|
|
@@ -4089,24 +4089,24 @@ async function linkVariants(matches, figmaData, figmaClient, fileKey) {
|
|
|
4089
4089
|
if (!csWithVariants || csWithVariants.variants.length === 0) {
|
|
4090
4090
|
continue;
|
|
4091
4091
|
}
|
|
4092
|
-
const
|
|
4093
|
-
if (
|
|
4094
|
-
console.log(pc17.dim(` \u23ED\uFE0F ${match.
|
|
4092
|
+
const fragmentVariants = match.fragment.variants.filter((v) => !v.hasFigma);
|
|
4093
|
+
if (fragmentVariants.length === 0) {
|
|
4094
|
+
console.log(pc17.dim(` \u23ED\uFE0F ${match.fragment.name}: all variants already linked`));
|
|
4095
4095
|
continue;
|
|
4096
4096
|
}
|
|
4097
|
-
console.log(pc17.dim(` ${match.
|
|
4098
|
-
for (const
|
|
4097
|
+
console.log(pc17.dim(` ${match.fragment.name}: ${csWithVariants.variants.length} Figma variants`));
|
|
4098
|
+
for (const fragmentVariant of fragmentVariants) {
|
|
4099
4099
|
const variantMatches = [];
|
|
4100
4100
|
for (const fv of csWithVariants.variants) {
|
|
4101
|
-
const
|
|
4101
|
+
const normalizedFragment = normalizeForMatch(fragmentVariant.name);
|
|
4102
4102
|
for (const value of fv.values) {
|
|
4103
4103
|
const normalizedValue = normalizeForMatch(value);
|
|
4104
|
-
if (
|
|
4104
|
+
if (normalizedFragment === normalizedValue) {
|
|
4105
4105
|
variantMatches.push({ figmaVariant: fv, score: 100 });
|
|
4106
4106
|
break;
|
|
4107
|
-
} else if (normalizedValue.includes(
|
|
4107
|
+
} else if (normalizedValue.includes(normalizedFragment)) {
|
|
4108
4108
|
variantMatches.push({ figmaVariant: fv, score: 85 });
|
|
4109
|
-
} else if (
|
|
4109
|
+
} else if (normalizedFragment.includes(normalizedValue)) {
|
|
4110
4110
|
variantMatches.push({ figmaVariant: fv, score: 75 });
|
|
4111
4111
|
}
|
|
4112
4112
|
}
|
|
@@ -4120,9 +4120,9 @@ async function linkVariants(matches, figmaData, figmaClient, fileKey) {
|
|
|
4120
4120
|
figmaData.fileName
|
|
4121
4121
|
);
|
|
4122
4122
|
try {
|
|
4123
|
-
let content = await readFile4(match.
|
|
4123
|
+
let content = await readFile4(match.fragment.filePath, "utf-8");
|
|
4124
4124
|
const namePattern = new RegExp(
|
|
4125
|
-
`(name:\\s*['"]${escapeRegExp(
|
|
4125
|
+
`(name:\\s*['"]${escapeRegExp(fragmentVariant.name)}['"],?)`,
|
|
4126
4126
|
"g"
|
|
4127
4127
|
);
|
|
4128
4128
|
let replaced = false;
|
|
@@ -4132,14 +4132,14 @@ async function linkVariants(matches, figmaData, figmaClient, fileKey) {
|
|
|
4132
4132
|
return `${matchedStr}
|
|
4133
4133
|
figma: '${variantUrl}',`;
|
|
4134
4134
|
});
|
|
4135
|
-
await writeFile5(match.
|
|
4135
|
+
await writeFile5(match.fragment.filePath, content);
|
|
4136
4136
|
variantUpdates++;
|
|
4137
4137
|
console.log(
|
|
4138
|
-
` ${pc17.green("\u2713")} ${
|
|
4138
|
+
` ${pc17.green("\u2713")} ${fragmentVariant.name} \u2192 ${bestMatch.figmaVariant.name}`
|
|
4139
4139
|
);
|
|
4140
4140
|
} catch (error) {
|
|
4141
4141
|
console.log(
|
|
4142
|
-
` ${pc17.red("\u2717")} ${
|
|
4142
|
+
` ${pc17.red("\u2717")} ${fragmentVariant.name}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
4143
4143
|
);
|
|
4144
4144
|
}
|
|
4145
4145
|
} else if (variantMatches.length > 0) {
|
|
@@ -4152,7 +4152,7 @@ async function linkVariants(matches, figmaData, figmaClient, fileKey) {
|
|
|
4152
4152
|
];
|
|
4153
4153
|
try {
|
|
4154
4154
|
const selectedVariant = await select({
|
|
4155
|
-
message: ` Match for "${
|
|
4155
|
+
message: ` Match for "${fragmentVariant.name}":`,
|
|
4156
4156
|
choices
|
|
4157
4157
|
});
|
|
4158
4158
|
if (selectedVariant) {
|
|
@@ -4161,9 +4161,9 @@ async function linkVariants(matches, figmaData, figmaClient, fileKey) {
|
|
|
4161
4161
|
selectedVariant.node_id,
|
|
4162
4162
|
figmaData.fileName
|
|
4163
4163
|
);
|
|
4164
|
-
let content = await readFile4(match.
|
|
4164
|
+
let content = await readFile4(match.fragment.filePath, "utf-8");
|
|
4165
4165
|
const namePattern = new RegExp(
|
|
4166
|
-
`(name:\\s*['"]${escapeRegExp(
|
|
4166
|
+
`(name:\\s*['"]${escapeRegExp(fragmentVariant.name)}['"],?)`,
|
|
4167
4167
|
"g"
|
|
4168
4168
|
);
|
|
4169
4169
|
let replaced = false;
|
|
@@ -4173,19 +4173,19 @@ async function linkVariants(matches, figmaData, figmaClient, fileKey) {
|
|
|
4173
4173
|
return `${matchedStr}
|
|
4174
4174
|
figma: '${variantUrl}',`;
|
|
4175
4175
|
});
|
|
4176
|
-
await writeFile5(match.
|
|
4176
|
+
await writeFile5(match.fragment.filePath, content);
|
|
4177
4177
|
variantUpdates++;
|
|
4178
4178
|
console.log(
|
|
4179
|
-
` ${pc17.green("\u2713")} ${
|
|
4179
|
+
` ${pc17.green("\u2713")} ${fragmentVariant.name} \u2192 ${selectedVariant.name}`
|
|
4180
4180
|
);
|
|
4181
4181
|
} else {
|
|
4182
|
-
console.log(` ${pc17.dim("\u23ED\uFE0F")} ${
|
|
4182
|
+
console.log(` ${pc17.dim("\u23ED\uFE0F")} ${fragmentVariant.name} (skipped)`);
|
|
4183
4183
|
}
|
|
4184
4184
|
} catch {
|
|
4185
|
-
console.log(` ${pc17.dim("\u23ED\uFE0F")} ${
|
|
4185
|
+
console.log(` ${pc17.dim("\u23ED\uFE0F")} ${fragmentVariant.name} (cancelled)`);
|
|
4186
4186
|
}
|
|
4187
4187
|
} else {
|
|
4188
|
-
console.log(` ${pc17.yellow("?")} ${
|
|
4188
|
+
console.log(` ${pc17.yellow("?")} ${fragmentVariant.name}: no matching Figma variant`);
|
|
4189
4189
|
}
|
|
4190
4190
|
}
|
|
4191
4191
|
}
|
|
@@ -4246,7 +4246,7 @@ ${BRAND.name} Storybook Link
|
|
|
4246
4246
|
process.stdout.write(`\r ${pc18.dim(`[${i + 1}/${total}]`)} ${relativePath.slice(0, 60).padEnd(60)}`);
|
|
4247
4247
|
try {
|
|
4248
4248
|
const parsed = await parseStoryFile(storyFile);
|
|
4249
|
-
const result =
|
|
4249
|
+
const result = convertToFragment(parsed);
|
|
4250
4250
|
const outputFile = out ? join8(out, relativePath.replace(/\.stories\.(tsx?|jsx?)$/, BRAND.fileExtension)) : result.outputFile;
|
|
4251
4251
|
previews.push({
|
|
4252
4252
|
componentName: result.componentName,
|
|
@@ -4288,14 +4288,14 @@ ${parseErrors} file(s) could not be parsed (use --verbose for details)`));
|
|
|
4288
4288
|
}
|
|
4289
4289
|
if (dryRun) {
|
|
4290
4290
|
console.log(pc18.dim(`
|
|
4291
|
-
${previews.length}
|
|
4291
|
+
${previews.length} fragment file(s) would be created`));
|
|
4292
4292
|
console.log(pc18.yellow("\n[Dry run - no files were written]"));
|
|
4293
4293
|
return { success: true, generated: 0 };
|
|
4294
4294
|
}
|
|
4295
4295
|
let selectedPreviews = previews;
|
|
4296
4296
|
if (yes) {
|
|
4297
4297
|
console.log(pc18.dim(`
|
|
4298
|
-
${previews.length}
|
|
4298
|
+
${previews.length} fragment file(s) will be created`));
|
|
4299
4299
|
} else {
|
|
4300
4300
|
const { checkbox } = await import("@inquirer/prompts");
|
|
4301
4301
|
console.log(pc18.dim("\nUse \u2191/\u2193 to navigate, Space to toggle, Enter to confirm\n"));
|
|
@@ -4325,7 +4325,7 @@ ${previews.length} segment file(s) will be created`));
|
|
|
4325
4325
|
}
|
|
4326
4326
|
const genTotal = selectedPreviews.length;
|
|
4327
4327
|
console.log(pc18.dim(`
|
|
4328
|
-
Generating ${genTotal}
|
|
4328
|
+
Generating ${genTotal} fragment file(s)...
|
|
4329
4329
|
`));
|
|
4330
4330
|
let generated = 0;
|
|
4331
4331
|
let genErrors = 0;
|
|
@@ -4334,7 +4334,7 @@ Generating ${genTotal} segment file(s)...
|
|
|
4334
4334
|
const storyFile = join8(projectRoot, preview.sourceFile);
|
|
4335
4335
|
try {
|
|
4336
4336
|
const parsed = await parseStoryFile(storyFile);
|
|
4337
|
-
const result =
|
|
4337
|
+
const result = convertToFragment(parsed);
|
|
4338
4338
|
const outputFile = out ? join8(projectRoot, out, preview.sourceFile.replace(/\.stories\.(tsx?|jsx?)$/, BRAND.fileExtension)) : result.outputFile;
|
|
4339
4339
|
await mkdir6(dirname3(outputFile), { recursive: true });
|
|
4340
4340
|
await writeFile6(outputFile, result.code);
|
|
@@ -4346,7 +4346,7 @@ Generating ${genTotal} segment file(s)...
|
|
|
4346
4346
|
}
|
|
4347
4347
|
}
|
|
4348
4348
|
console.log(pc18.green(`
|
|
4349
|
-
\u2713 Generated ${generated}
|
|
4349
|
+
\u2713 Generated ${generated} fragment file(s)
|
|
4350
4350
|
`));
|
|
4351
4351
|
console.log(pc18.dim("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
4352
4352
|
console.log(pc18.bold("\nNext steps:"));
|
|
@@ -4456,8 +4456,8 @@ ${BRAND.name} AI Enhancement
|
|
|
4456
4456
|
if (isInteractive) {
|
|
4457
4457
|
console.log(pc19.dim("Phase 3: Loading fragment files..."));
|
|
4458
4458
|
}
|
|
4459
|
-
const
|
|
4460
|
-
if (
|
|
4459
|
+
const fragmentFiles = await findFragmentFiles(rootDir);
|
|
4460
|
+
if (fragmentFiles.length === 0) {
|
|
4461
4461
|
const msg = "No fragment files found";
|
|
4462
4462
|
if (format === "json") {
|
|
4463
4463
|
console.log(JSON.stringify({ success: false, error: msg }));
|
|
@@ -4467,27 +4467,27 @@ ${BRAND.name} AI Enhancement
|
|
|
4467
4467
|
return { success: false, enhanced: [], totalTokens: 0, estimatedCost: 0 };
|
|
4468
4468
|
}
|
|
4469
4469
|
if (isInteractive) {
|
|
4470
|
-
console.log(pc19.green(` Found ${
|
|
4470
|
+
console.log(pc19.green(` Found ${fragmentFiles.length} fragment files`));
|
|
4471
4471
|
}
|
|
4472
4472
|
let componentsToEnhance;
|
|
4473
4473
|
if (component && component !== "all") {
|
|
4474
4474
|
componentsToEnhance = [component];
|
|
4475
4475
|
} else {
|
|
4476
|
-
componentsToEnhance =
|
|
4476
|
+
componentsToEnhance = fragmentFiles.map((f) => extractComponentName(f));
|
|
4477
4477
|
}
|
|
4478
4478
|
if (isInteractive) {
|
|
4479
4479
|
console.log(pc19.dim("Phase 4: Extracting props from TypeScript interfaces..."));
|
|
4480
4480
|
}
|
|
4481
4481
|
const propsExtractions = /* @__PURE__ */ new Map();
|
|
4482
4482
|
for (const compName of componentsToEnhance) {
|
|
4483
|
-
const
|
|
4484
|
-
if (!
|
|
4485
|
-
const
|
|
4483
|
+
const fragmentFile = fragmentFiles.find((f) => extractComponentName(f) === compName);
|
|
4484
|
+
if (!fragmentFile) continue;
|
|
4485
|
+
const fragmentDir = fragmentFile.replace(/\.fragment\.(tsx?|jsx?)$/, "");
|
|
4486
4486
|
const possiblePaths = [
|
|
4487
|
-
`${
|
|
4488
|
-
`${
|
|
4489
|
-
`${
|
|
4490
|
-
`${
|
|
4487
|
+
`${fragmentDir}.tsx`,
|
|
4488
|
+
`${fragmentDir}.ts`,
|
|
4489
|
+
`${fragmentDir}/index.tsx`,
|
|
4490
|
+
`${fragmentDir}/index.ts`,
|
|
4491
4491
|
join9(rootDir, "src", "components", `${compName}.tsx`),
|
|
4492
4492
|
join9(rootDir, "src", "components", compName, `${compName}.tsx`),
|
|
4493
4493
|
join9(rootDir, "src", "components", compName, "index.tsx")
|
|
@@ -4555,9 +4555,9 @@ ${BRAND.name} AI Enhancement
|
|
|
4555
4555
|
for (const compName of componentsToEnhance) {
|
|
4556
4556
|
const analysis = usageAnalysis.components[compName];
|
|
4557
4557
|
const stories = storyFiles.get(compName);
|
|
4558
|
-
const
|
|
4558
|
+
const fragmentFile = fragmentFiles.find((f) => extractComponentName(f) === compName);
|
|
4559
4559
|
const propsExtraction = propsExtractions.get(compName);
|
|
4560
|
-
if (!
|
|
4560
|
+
if (!fragmentFile) continue;
|
|
4561
4561
|
const context2 = generateComponentContext(
|
|
4562
4562
|
compName,
|
|
4563
4563
|
analysis,
|
|
@@ -4565,7 +4565,7 @@ ${BRAND.name} AI Enhancement
|
|
|
4565
4565
|
stories,
|
|
4566
4566
|
propsExtraction
|
|
4567
4567
|
);
|
|
4568
|
-
contexts.push({ name: compName, context: context2,
|
|
4568
|
+
contexts.push({ name: compName, context: context2, fragmentFile });
|
|
4569
4569
|
}
|
|
4570
4570
|
if (isContextMode) {
|
|
4571
4571
|
return handleContextOnlyMode(contexts, format, isInteractive);
|
|
@@ -4578,7 +4578,7 @@ Phase 6: Generating AI enhancements for ${componentsToEnhance.length} component(
|
|
|
4578
4578
|
const enhanced = [];
|
|
4579
4579
|
let totalTokens = 0;
|
|
4580
4580
|
const aiClient = await createAIClient(provider, apiKey);
|
|
4581
|
-
for (const { name: compName, context: context2,
|
|
4581
|
+
for (const { name: compName, context: context2, fragmentFile } of contexts) {
|
|
4582
4582
|
if (!context2.usageAnalysis || context2.usageAnalysis.totalUsages < 2) {
|
|
4583
4583
|
enhanced.push({
|
|
4584
4584
|
componentName: compName,
|
|
@@ -4629,22 +4629,22 @@ Phase 6: Generating AI enhancements for ${componentsToEnhance.length} component(
|
|
|
4629
4629
|
const estimatedCost = calculateCost(provider, totalTokens);
|
|
4630
4630
|
if (!dryRun) {
|
|
4631
4631
|
if (isInteractive) {
|
|
4632
|
-
console.log(pc19.dim("\nPhase 7: Updating
|
|
4632
|
+
console.log(pc19.dim("\nPhase 7: Updating fragment files..."));
|
|
4633
4633
|
}
|
|
4634
4634
|
for (const result of enhanced) {
|
|
4635
4635
|
if (result.skipped || result.added.when.length === 0 && result.added.whenNot.length === 0) {
|
|
4636
4636
|
continue;
|
|
4637
4637
|
}
|
|
4638
|
-
const
|
|
4639
|
-
if (!
|
|
4638
|
+
const fragmentFile = fragmentFiles.find((f) => extractComponentName(f) === result.componentName);
|
|
4639
|
+
if (!fragmentFile) continue;
|
|
4640
4640
|
try {
|
|
4641
|
-
await
|
|
4641
|
+
await updateFragmentFile(fragmentFile, result.added);
|
|
4642
4642
|
if (isInteractive) {
|
|
4643
|
-
console.log(pc19.green(` Updated: ${relative7(rootDir,
|
|
4643
|
+
console.log(pc19.green(` Updated: ${relative7(rootDir, fragmentFile)}`));
|
|
4644
4644
|
}
|
|
4645
4645
|
} catch {
|
|
4646
4646
|
if (isInteractive) {
|
|
4647
|
-
console.log(pc19.red(` Failed to update: ${relative7(rootDir,
|
|
4647
|
+
console.log(pc19.red(` Failed to update: ${relative7(rootDir, fragmentFile)}`));
|
|
4648
4648
|
}
|
|
4649
4649
|
}
|
|
4650
4650
|
}
|
|
@@ -4727,7 +4727,7 @@ For each component, provide your response in JSON format:
|
|
|
4727
4727
|
console.log(pc19.dim("\u2500".repeat(60)));
|
|
4728
4728
|
console.log();
|
|
4729
4729
|
console.log(pc19.green("Tip: In Cursor, press Cmd+L to open chat and paste this prompt."));
|
|
4730
|
-
console.log(pc19.dim("After getting suggestions, manually update your
|
|
4730
|
+
console.log(pc19.dim("After getting suggestions, manually update your fragment files."));
|
|
4731
4731
|
console.log();
|
|
4732
4732
|
}
|
|
4733
4733
|
return {
|
|
@@ -4878,19 +4878,19 @@ function calculateCost(provider, tokens) {
|
|
|
4878
4878
|
};
|
|
4879
4879
|
return tokens / 1e6 * costsPer1M[provider];
|
|
4880
4880
|
}
|
|
4881
|
-
async function
|
|
4881
|
+
async function findFragmentFiles(dir) {
|
|
4882
4882
|
const fg4 = await import("fast-glob");
|
|
4883
|
-
return fg4.default(["**/*.
|
|
4883
|
+
return fg4.default(["**/*.fragment.tsx", "**/*.fragment.ts"], {
|
|
4884
4884
|
cwd: dir,
|
|
4885
4885
|
absolute: true,
|
|
4886
4886
|
ignore: ["**/node_modules/**", "**/dist/**"]
|
|
4887
4887
|
});
|
|
4888
4888
|
}
|
|
4889
4889
|
function extractComponentName(filePath) {
|
|
4890
|
-
const match = filePath.match(/([^/\\]+)\.
|
|
4890
|
+
const match = filePath.match(/([^/\\]+)\.fragment\.(tsx?|jsx?)$/);
|
|
4891
4891
|
return match ? match[1] : "";
|
|
4892
4892
|
}
|
|
4893
|
-
async function
|
|
4893
|
+
async function updateFragmentFile(filePath, suggestions) {
|
|
4894
4894
|
const content = await readFile5(filePath, "utf-8");
|
|
4895
4895
|
let updated = content;
|
|
4896
4896
|
if (suggestions.when.length > 0) {
|
|
@@ -4944,6 +4944,242 @@ ${whenNotItems}
|
|
|
4944
4944
|
}
|
|
4945
4945
|
}
|
|
4946
4946
|
|
|
4947
|
+
// src/commands/graph.ts
|
|
4948
|
+
import pc20 from "picocolors";
|
|
4949
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
4950
|
+
import { resolve as resolve6 } from "path";
|
|
4951
|
+
import {
|
|
4952
|
+
ComponentGraphEngine,
|
|
4953
|
+
deserializeGraph
|
|
4954
|
+
} from "@fragments-sdk/context/graph";
|
|
4955
|
+
async function graph(component, options) {
|
|
4956
|
+
const { config, configDir } = await loadConfig(options.config);
|
|
4957
|
+
const outputPath = resolve6(configDir, config.outFile ?? BRAND.outFile);
|
|
4958
|
+
let data;
|
|
4959
|
+
try {
|
|
4960
|
+
const content = await readFile6(outputPath, "utf-8");
|
|
4961
|
+
data = JSON.parse(content);
|
|
4962
|
+
} catch {
|
|
4963
|
+
console.error(
|
|
4964
|
+
pc20.red(`Error: Could not load ${BRAND.outFile}. Run \`${BRAND.cliCommand} build\` first.`)
|
|
4965
|
+
);
|
|
4966
|
+
process.exit(1);
|
|
4967
|
+
}
|
|
4968
|
+
if (!data.graph) {
|
|
4969
|
+
console.error(
|
|
4970
|
+
pc20.red(`Error: No graph data in ${BRAND.outFile}. Rebuild with the latest CLI.`)
|
|
4971
|
+
);
|
|
4972
|
+
process.exit(1);
|
|
4973
|
+
}
|
|
4974
|
+
const graph2 = deserializeGraph(data.graph);
|
|
4975
|
+
const blocks = data.blocks ? Object.fromEntries(
|
|
4976
|
+
Object.entries(data.blocks).map(([k, v]) => [k, { components: v.components }])
|
|
4977
|
+
) : void 0;
|
|
4978
|
+
const engine = new ComponentGraphEngine(graph2, blocks);
|
|
4979
|
+
const mode = options.mode ?? (component ? "dependencies" : "health");
|
|
4980
|
+
const format = options.format ?? "table";
|
|
4981
|
+
const edgeTypes = options.edgeTypes ? options.edgeTypes.split(",") : void 0;
|
|
4982
|
+
const needsComponent = ["dependencies", "dependents", "impact", "path", "composition", "alternatives"];
|
|
4983
|
+
if (needsComponent.includes(mode) && !component) {
|
|
4984
|
+
console.error(pc20.red(`Error: "${mode}" mode requires a component name.`));
|
|
4985
|
+
process.exit(1);
|
|
4986
|
+
}
|
|
4987
|
+
if (component && !engine.hasNode(component)) {
|
|
4988
|
+
console.error(pc20.red(`Error: Component "${component}" not found in graph.`));
|
|
4989
|
+
process.exit(1);
|
|
4990
|
+
}
|
|
4991
|
+
switch (mode) {
|
|
4992
|
+
case "health": {
|
|
4993
|
+
const health = engine.getHealth();
|
|
4994
|
+
if (format === "json") {
|
|
4995
|
+
console.log(JSON.stringify(health, null, 2));
|
|
4996
|
+
return;
|
|
4997
|
+
}
|
|
4998
|
+
console.log(pc20.bold("\nComponent Graph Health\n"));
|
|
4999
|
+
console.log(` ${pc20.cyan("Nodes:")} ${health.nodeCount}`);
|
|
5000
|
+
console.log(` ${pc20.cyan("Edges:")} ${health.edgeCount}`);
|
|
5001
|
+
console.log(` ${pc20.cyan("Avg degree:")} ${health.averageDegree}`);
|
|
5002
|
+
console.log(` ${pc20.cyan("Islands:")} ${health.connectedComponents.length}`);
|
|
5003
|
+
console.log(` ${pc20.cyan("Coverage:")} ${health.compositionCoverage}% in blocks`);
|
|
5004
|
+
console.log(` ${pc20.cyan("Orphans:")} ${health.orphans.length > 0 ? health.orphans.join(", ") : pc20.green("none")}`);
|
|
5005
|
+
if (health.hubs.length > 0) {
|
|
5006
|
+
console.log(`
|
|
5007
|
+
${pc20.bold("Top hubs:")}`);
|
|
5008
|
+
for (const hub of health.hubs.slice(0, 5)) {
|
|
5009
|
+
console.log(` ${pc20.yellow(hub.name)} \u2014 ${hub.degree} connections`);
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
5012
|
+
console.log();
|
|
5013
|
+
break;
|
|
5014
|
+
}
|
|
5015
|
+
case "dependencies": {
|
|
5016
|
+
const deps = engine.dependencies(component, edgeTypes);
|
|
5017
|
+
if (format === "json") {
|
|
5018
|
+
console.log(JSON.stringify({ component, dependencies: deps }, null, 2));
|
|
5019
|
+
return;
|
|
5020
|
+
}
|
|
5021
|
+
console.log(pc20.bold(`
|
|
5022
|
+
Dependencies of ${component}
|
|
5023
|
+
`));
|
|
5024
|
+
if (deps.length === 0) {
|
|
5025
|
+
console.log(" No outgoing dependencies.");
|
|
5026
|
+
} else {
|
|
5027
|
+
for (const dep of deps) {
|
|
5028
|
+
console.log(` ${pc20.yellow(dep.target)} ${pc20.dim(`(${dep.type})`)}${dep.note ? ` \u2014 ${dep.note}` : ""}`);
|
|
5029
|
+
}
|
|
5030
|
+
}
|
|
5031
|
+
console.log();
|
|
5032
|
+
break;
|
|
5033
|
+
}
|
|
5034
|
+
case "dependents": {
|
|
5035
|
+
const deps = engine.dependents(component, edgeTypes);
|
|
5036
|
+
if (format === "json") {
|
|
5037
|
+
console.log(JSON.stringify({ component, dependents: deps }, null, 2));
|
|
5038
|
+
return;
|
|
5039
|
+
}
|
|
5040
|
+
console.log(pc20.bold(`
|
|
5041
|
+
Dependents of ${component}
|
|
5042
|
+
`));
|
|
5043
|
+
if (deps.length === 0) {
|
|
5044
|
+
console.log(" No incoming dependents.");
|
|
5045
|
+
} else {
|
|
5046
|
+
for (const dep of deps) {
|
|
5047
|
+
console.log(` ${pc20.yellow(dep.source)} ${pc20.dim(`(${dep.type})`)}${dep.note ? ` \u2014 ${dep.note}` : ""}`);
|
|
5048
|
+
}
|
|
5049
|
+
}
|
|
5050
|
+
console.log();
|
|
5051
|
+
break;
|
|
5052
|
+
}
|
|
5053
|
+
case "impact": {
|
|
5054
|
+
const result = engine.impact(component, options.depth ?? 3);
|
|
5055
|
+
if (format === "json") {
|
|
5056
|
+
console.log(JSON.stringify(result, null, 2));
|
|
5057
|
+
return;
|
|
5058
|
+
}
|
|
5059
|
+
console.log(pc20.bold(`
|
|
5060
|
+
Impact analysis: ${component}
|
|
5061
|
+
`));
|
|
5062
|
+
console.log(` ${pc20.red(`${result.totalAffected}`)} affected components, ${pc20.red(`${result.affectedBlocks.length}`)} affected blocks
|
|
5063
|
+
`);
|
|
5064
|
+
if (result.affected.length > 0) {
|
|
5065
|
+
console.log(` ${pc20.bold("Affected components:")}`);
|
|
5066
|
+
for (const entry of result.affected) {
|
|
5067
|
+
const indent = " ".repeat(entry.depth + 1);
|
|
5068
|
+
console.log(`${indent}${pc20.yellow(entry.component)} ${pc20.dim(`(depth ${entry.depth}, via ${entry.edgeType})`)}`);
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
if (result.affectedBlocks.length > 0) {
|
|
5072
|
+
console.log(`
|
|
5073
|
+
${pc20.bold("Affected blocks:")} ${result.affectedBlocks.join(", ")}`);
|
|
5074
|
+
}
|
|
5075
|
+
console.log();
|
|
5076
|
+
break;
|
|
5077
|
+
}
|
|
5078
|
+
case "path": {
|
|
5079
|
+
if (!options.target) {
|
|
5080
|
+
console.error(pc20.red("Error: --target is required for path mode."));
|
|
5081
|
+
process.exit(1);
|
|
5082
|
+
}
|
|
5083
|
+
const result = engine.path(component, options.target);
|
|
5084
|
+
if (format === "json") {
|
|
5085
|
+
console.log(JSON.stringify(result, null, 2));
|
|
5086
|
+
return;
|
|
5087
|
+
}
|
|
5088
|
+
console.log(pc20.bold(`
|
|
5089
|
+
Path: ${component} \u2192 ${options.target}
|
|
5090
|
+
`));
|
|
5091
|
+
if (!result.found) {
|
|
5092
|
+
console.log(` ${pc20.red("No path found.")}`);
|
|
5093
|
+
} else {
|
|
5094
|
+
console.log(` ${result.path.map((n) => pc20.yellow(n)).join(pc20.dim(" \u2192 "))}`);
|
|
5095
|
+
if (result.edges.length > 0) {
|
|
5096
|
+
console.log(` ${pc20.dim(`(${result.edges.map((e) => e.type).join(" \u2192 ")})`)}`);
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
console.log();
|
|
5100
|
+
break;
|
|
5101
|
+
}
|
|
5102
|
+
case "composition": {
|
|
5103
|
+
const tree = engine.composition(component);
|
|
5104
|
+
if (format === "json") {
|
|
5105
|
+
console.log(JSON.stringify(tree, null, 2));
|
|
5106
|
+
return;
|
|
5107
|
+
}
|
|
5108
|
+
console.log(pc20.bold(`
|
|
5109
|
+
Composition: ${component}
|
|
5110
|
+
`));
|
|
5111
|
+
console.log(` ${pc20.cyan("Pattern:")} ${tree.compositionPattern ?? "unknown"}`);
|
|
5112
|
+
if (tree.parent) {
|
|
5113
|
+
console.log(` ${pc20.cyan("Parent:")} ${tree.parent}`);
|
|
5114
|
+
}
|
|
5115
|
+
if (tree.subComponents.length > 0) {
|
|
5116
|
+
console.log(` ${pc20.cyan("Sub-components:")}`);
|
|
5117
|
+
for (const sub of tree.subComponents) {
|
|
5118
|
+
const isRequired = tree.requiredChildren.includes(sub);
|
|
5119
|
+
console.log(` ${pc20.yellow(sub)}${isRequired ? pc20.red(" (required)") : ""}`);
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
5122
|
+
if (tree.siblings.length > 0) {
|
|
5123
|
+
console.log(` ${pc20.cyan("Siblings:")} ${tree.siblings.join(", ")}`);
|
|
5124
|
+
}
|
|
5125
|
+
if (tree.blocks.length > 0) {
|
|
5126
|
+
console.log(` ${pc20.cyan("In blocks:")} ${tree.blocks.join(", ")}`);
|
|
5127
|
+
}
|
|
5128
|
+
console.log();
|
|
5129
|
+
break;
|
|
5130
|
+
}
|
|
5131
|
+
case "alternatives": {
|
|
5132
|
+
const alts = engine.alternatives(component);
|
|
5133
|
+
if (format === "json") {
|
|
5134
|
+
console.log(JSON.stringify({ component, alternatives: alts }, null, 2));
|
|
5135
|
+
return;
|
|
5136
|
+
}
|
|
5137
|
+
console.log(pc20.bold(`
|
|
5138
|
+
Alternatives for ${component}
|
|
5139
|
+
`));
|
|
5140
|
+
if (alts.length === 0) {
|
|
5141
|
+
console.log(" No known alternatives.");
|
|
5142
|
+
} else {
|
|
5143
|
+
for (const alt of alts) {
|
|
5144
|
+
console.log(` ${pc20.yellow(alt.component)}${alt.note ? ` \u2014 ${alt.note}` : ""}`);
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
console.log();
|
|
5148
|
+
break;
|
|
5149
|
+
}
|
|
5150
|
+
case "islands": {
|
|
5151
|
+
const islands = engine.islands();
|
|
5152
|
+
if (format === "json") {
|
|
5153
|
+
console.log(JSON.stringify({ islands }, null, 2));
|
|
5154
|
+
return;
|
|
5155
|
+
}
|
|
5156
|
+
console.log(pc20.bold(`
|
|
5157
|
+
Connected Islands (${islands.length})
|
|
5158
|
+
`));
|
|
5159
|
+
for (let i = 0; i < islands.length; i++) {
|
|
5160
|
+
console.log(` ${pc20.cyan(`Island ${i + 1}`)} (${islands[i].length} components): ${islands[i].join(", ")}`);
|
|
5161
|
+
}
|
|
5162
|
+
console.log();
|
|
5163
|
+
break;
|
|
5164
|
+
}
|
|
5165
|
+
default:
|
|
5166
|
+
console.error(pc20.red(`Unknown mode: "${mode}". Valid: health, dependencies, dependents, impact, path, composition, alternatives, islands`));
|
|
5167
|
+
process.exit(1);
|
|
5168
|
+
}
|
|
5169
|
+
if (format === "dot") {
|
|
5170
|
+
const lines = ["digraph ComponentGraph {", " rankdir=LR;", " node [shape=box, style=rounded];"];
|
|
5171
|
+
for (const node of graph2.nodes) {
|
|
5172
|
+
lines.push(` "${node.name}" [label="${node.name}\\n(${node.category})"];`);
|
|
5173
|
+
}
|
|
5174
|
+
for (const edge of graph2.edges) {
|
|
5175
|
+
const style = edge.type === "alternative-to" ? "dashed" : "solid";
|
|
5176
|
+
lines.push(` "${edge.source}" -> "${edge.target}" [label="${edge.type}", style=${style}];`);
|
|
5177
|
+
}
|
|
5178
|
+
lines.push("}");
|
|
5179
|
+
console.log(lines.join("\n"));
|
|
5180
|
+
}
|
|
5181
|
+
}
|
|
5182
|
+
|
|
4947
5183
|
// src/bin.ts
|
|
4948
5184
|
var __dirname = dirname4(fileURLToPath(import.meta.url));
|
|
4949
5185
|
var pkg = JSON.parse(readFileSync(join10(__dirname, "../package.json"), "utf-8"));
|
|
@@ -4956,7 +5192,7 @@ program.command("validate").description("Validate fragment files").option("-c, -
|
|
|
4956
5192
|
process.exit(1);
|
|
4957
5193
|
}
|
|
4958
5194
|
} catch (error) {
|
|
4959
|
-
console.error(
|
|
5195
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
4960
5196
|
process.exit(1);
|
|
4961
5197
|
}
|
|
4962
5198
|
});
|
|
@@ -4976,7 +5212,7 @@ program.command("build").description(`Build compiled ${BRAND.outFile} and ${BRAN
|
|
|
4976
5212
|
process.exit(1);
|
|
4977
5213
|
}
|
|
4978
5214
|
} catch (error) {
|
|
4979
|
-
console.error(
|
|
5215
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
4980
5216
|
process.exit(1);
|
|
4981
5217
|
}
|
|
4982
5218
|
});
|
|
@@ -4995,7 +5231,7 @@ program.command("context").description("Generate AI-ready context for your desig
|
|
|
4995
5231
|
process.exit(1);
|
|
4996
5232
|
}
|
|
4997
5233
|
} catch (error) {
|
|
4998
|
-
console.error(
|
|
5234
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
4999
5235
|
process.exit(1);
|
|
5000
5236
|
}
|
|
5001
5237
|
});
|
|
@@ -5022,7 +5258,7 @@ program.command("ai").description("Generate context optimized for AI assistants
|
|
|
5022
5258
|
}
|
|
5023
5259
|
}
|
|
5024
5260
|
} catch (error) {
|
|
5025
|
-
console.error(
|
|
5261
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5026
5262
|
process.exit(1);
|
|
5027
5263
|
}
|
|
5028
5264
|
});
|
|
@@ -5030,7 +5266,7 @@ program.command("list").description("List all discovered fragment files").option
|
|
|
5030
5266
|
try {
|
|
5031
5267
|
await list(options);
|
|
5032
5268
|
} catch (error) {
|
|
5033
|
-
console.error(
|
|
5269
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5034
5270
|
process.exit(1);
|
|
5035
5271
|
}
|
|
5036
5272
|
});
|
|
@@ -5038,7 +5274,7 @@ program.command("reset").description("Reset to initial state (delete all generat
|
|
|
5038
5274
|
try {
|
|
5039
5275
|
await reset(options);
|
|
5040
5276
|
} catch (error) {
|
|
5041
|
-
console.error(
|
|
5277
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5042
5278
|
process.exit(1);
|
|
5043
5279
|
}
|
|
5044
5280
|
});
|
|
@@ -5052,7 +5288,7 @@ linkCommand.command("figma").argument("[figma-url]", "Figma file URL to link com
|
|
|
5052
5288
|
variants: options.variants
|
|
5053
5289
|
});
|
|
5054
5290
|
} catch (error) {
|
|
5055
|
-
console.error(
|
|
5291
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5056
5292
|
process.exit(1);
|
|
5057
5293
|
}
|
|
5058
5294
|
});
|
|
@@ -5067,7 +5303,7 @@ linkCommand.command("storybook").description("Bootstrap fragments from existing
|
|
|
5067
5303
|
exclude: options.exclude
|
|
5068
5304
|
});
|
|
5069
5305
|
} catch (error) {
|
|
5070
|
-
console.error(
|
|
5306
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5071
5307
|
process.exit(1);
|
|
5072
5308
|
}
|
|
5073
5309
|
});
|
|
@@ -5082,9 +5318,9 @@ program.command("dev").description("Start the development server with live compo
|
|
|
5082
5318
|
skipBuild: options.skipBuild
|
|
5083
5319
|
});
|
|
5084
5320
|
} catch (error) {
|
|
5085
|
-
console.error(
|
|
5321
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5086
5322
|
if (error instanceof Error && error.stack) {
|
|
5087
|
-
console.error(
|
|
5323
|
+
console.error(pc21.dim(error.stack));
|
|
5088
5324
|
}
|
|
5089
5325
|
process.exit(1);
|
|
5090
5326
|
}
|
|
@@ -5105,7 +5341,7 @@ program.command("screenshot").description("Capture screenshots of component vari
|
|
|
5105
5341
|
process.exit(1);
|
|
5106
5342
|
}
|
|
5107
5343
|
} catch (error) {
|
|
5108
|
-
console.error(
|
|
5344
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5109
5345
|
process.exit(1);
|
|
5110
5346
|
}
|
|
5111
5347
|
});
|
|
@@ -5124,7 +5360,7 @@ program.command("diff").argument("[component]", "Component name to diff (optiona
|
|
|
5124
5360
|
process.exit(1);
|
|
5125
5361
|
}
|
|
5126
5362
|
} catch (error) {
|
|
5127
|
-
console.error(
|
|
5363
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5128
5364
|
process.exit(1);
|
|
5129
5365
|
}
|
|
5130
5366
|
});
|
|
@@ -5143,8 +5379,8 @@ program.command("compare").argument("[component]", "Component name to compare").
|
|
|
5143
5379
|
process.exit(1);
|
|
5144
5380
|
}
|
|
5145
5381
|
} catch (error) {
|
|
5146
|
-
console.error(
|
|
5147
|
-
console.log(
|
|
5382
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5383
|
+
console.log(pc21.dim(`
|
|
5148
5384
|
Make sure the dev server is running: ${BRAND.cliCommand} dev`));
|
|
5149
5385
|
process.exit(1);
|
|
5150
5386
|
}
|
|
@@ -5163,7 +5399,7 @@ program.command("analyze").description("Analyze design system and generate repor
|
|
|
5163
5399
|
process.exit(1);
|
|
5164
5400
|
}
|
|
5165
5401
|
} catch (error) {
|
|
5166
|
-
console.error(
|
|
5402
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5167
5403
|
process.exit(1);
|
|
5168
5404
|
}
|
|
5169
5405
|
});
|
|
@@ -5182,7 +5418,7 @@ program.command("verify").argument("[component]", "Component name to verify (opt
|
|
|
5182
5418
|
if (options.ci) {
|
|
5183
5419
|
console.log(JSON.stringify({ error: error instanceof Error ? error.message : "Verification failed" }));
|
|
5184
5420
|
} else {
|
|
5185
|
-
console.error(
|
|
5421
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5186
5422
|
}
|
|
5187
5423
|
process.exit(1);
|
|
5188
5424
|
}
|
|
@@ -5199,7 +5435,7 @@ program.command("audit").description("Scan all fragments and show compliance met
|
|
|
5199
5435
|
if (options.json) {
|
|
5200
5436
|
console.log(JSON.stringify({ error: error instanceof Error ? error.message : "Audit failed" }));
|
|
5201
5437
|
} else {
|
|
5202
|
-
console.error(
|
|
5438
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5203
5439
|
}
|
|
5204
5440
|
process.exit(1);
|
|
5205
5441
|
}
|
|
@@ -5221,7 +5457,7 @@ program.command("a11y").description("Run accessibility checks on all component v
|
|
|
5221
5457
|
if (options.json) {
|
|
5222
5458
|
console.log(JSON.stringify({ error: error instanceof Error ? error.message : "A11y check failed" }));
|
|
5223
5459
|
} else {
|
|
5224
|
-
console.error(
|
|
5460
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5225
5461
|
}
|
|
5226
5462
|
process.exit(1);
|
|
5227
5463
|
}
|
|
@@ -5244,7 +5480,7 @@ program.command("enhance").description("AI-powered documentation generation from
|
|
|
5244
5480
|
if (options.format === "json") {
|
|
5245
5481
|
console.log(JSON.stringify({ success: false, error: error instanceof Error ? error.message : "Enhance failed" }));
|
|
5246
5482
|
} else {
|
|
5247
|
-
console.error(
|
|
5483
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5248
5484
|
}
|
|
5249
5485
|
process.exit(1);
|
|
5250
5486
|
}
|
|
@@ -5265,11 +5501,11 @@ program.command("scan").description(`Zero-config ${BRAND.outFile} generation fro
|
|
|
5265
5501
|
process.exit(1);
|
|
5266
5502
|
}
|
|
5267
5503
|
} catch (error) {
|
|
5268
|
-
console.error(
|
|
5504
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5269
5505
|
process.exit(1);
|
|
5270
5506
|
}
|
|
5271
5507
|
});
|
|
5272
|
-
program.command("storygen").description("Generate Storybook stories from fragment definitions").option("-c, --config <path>", "Path to config file").option("-o, --output <dir>", "Output directory", ".storybook/generated").option("--watch", "Watch for
|
|
5508
|
+
program.command("storygen").description("Generate Storybook stories from fragment definitions").option("-c, --config <path>", "Path to config file").option("-o, --output <dir>", "Output directory", ".storybook/generated").option("--watch", "Watch for fragment changes and regenerate").option("--format <format>", "Story format (csf3)", "csf3").action(async (options) => {
|
|
5273
5509
|
try {
|
|
5274
5510
|
await storygen({
|
|
5275
5511
|
config: options.config,
|
|
@@ -5278,7 +5514,7 @@ program.command("storygen").description("Generate Storybook stories from fragmen
|
|
|
5278
5514
|
format: options.format
|
|
5279
5515
|
});
|
|
5280
5516
|
} catch (error) {
|
|
5281
|
-
console.error(
|
|
5517
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5282
5518
|
process.exit(1);
|
|
5283
5519
|
}
|
|
5284
5520
|
});
|
|
@@ -5290,7 +5526,7 @@ program.command("metrics").argument("[component]", "Component name (optional, sh
|
|
|
5290
5526
|
json: options.json
|
|
5291
5527
|
});
|
|
5292
5528
|
} catch (error) {
|
|
5293
|
-
console.error(
|
|
5529
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5294
5530
|
process.exit(1);
|
|
5295
5531
|
}
|
|
5296
5532
|
});
|
|
@@ -5304,9 +5540,9 @@ program.command("baseline").description("Manage visual regression baselines").ar
|
|
|
5304
5540
|
port: options.port
|
|
5305
5541
|
});
|
|
5306
5542
|
} catch (error) {
|
|
5307
|
-
console.error(
|
|
5543
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5308
5544
|
if (action === "update") {
|
|
5309
|
-
console.log(
|
|
5545
|
+
console.log(pc21.dim(`
|
|
5310
5546
|
Make sure the dev server is running: ${BRAND.cliCommand} dev`));
|
|
5311
5547
|
}
|
|
5312
5548
|
process.exit(1);
|
|
@@ -5314,27 +5550,27 @@ Make sure the dev server is running: ${BRAND.cliCommand} dev`));
|
|
|
5314
5550
|
});
|
|
5315
5551
|
program.command("view").description(`Generate a static HTML viewer for ${BRAND.outFile}`).option("-i, --input <path>", `Path to ${BRAND.outFile}`, BRAND.outFile).option("-o, --output <path>", "Output HTML file path", BRAND.viewerHtmlFile).option("--open", "Open in browser after generation").action(async (options) => {
|
|
5316
5552
|
try {
|
|
5317
|
-
const { generateViewerFromJson } = await import("./static-viewer-
|
|
5553
|
+
const { generateViewerFromJson } = await import("./static-viewer-Q4F4QP5M.js");
|
|
5318
5554
|
const fs2 = await import("fs/promises");
|
|
5319
5555
|
const path = await import("path");
|
|
5320
5556
|
const inputPath = path.resolve(process.cwd(), options.input);
|
|
5321
5557
|
const outputPath = path.resolve(process.cwd(), options.output);
|
|
5322
|
-
console.log(
|
|
5558
|
+
console.log(pc21.cyan(`
|
|
5323
5559
|
${BRAND.name} Viewer Generator
|
|
5324
5560
|
`));
|
|
5325
5561
|
try {
|
|
5326
5562
|
await fs2.access(inputPath);
|
|
5327
5563
|
} catch {
|
|
5328
|
-
console.log(
|
|
5329
|
-
console.log(
|
|
5330
|
-
Run ${
|
|
5564
|
+
console.log(pc21.red(`Error: ${options.input} not found.`));
|
|
5565
|
+
console.log(pc21.dim(`
|
|
5566
|
+
Run ${pc21.cyan(`${BRAND.cliCommand} build`)} first to generate ${BRAND.outFile}
|
|
5331
5567
|
`));
|
|
5332
5568
|
process.exit(1);
|
|
5333
5569
|
}
|
|
5334
|
-
console.log(
|
|
5570
|
+
console.log(pc21.dim(`Reading: ${options.input}`));
|
|
5335
5571
|
const html = await generateViewerFromJson(inputPath);
|
|
5336
5572
|
await fs2.writeFile(outputPath, html);
|
|
5337
|
-
console.log(
|
|
5573
|
+
console.log(pc21.green(`
|
|
5338
5574
|
\u2713 Generated: ${options.output}
|
|
5339
5575
|
`));
|
|
5340
5576
|
if (options.open) {
|
|
@@ -5343,7 +5579,7 @@ Run ${pc20.cyan(`${BRAND.cliCommand} build`)} first to generate ${BRAND.outFile}
|
|
|
5343
5579
|
exec(`${openCmd} "${outputPath}"`);
|
|
5344
5580
|
}
|
|
5345
5581
|
} catch (error) {
|
|
5346
|
-
console.error(
|
|
5582
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5347
5583
|
process.exit(1);
|
|
5348
5584
|
}
|
|
5349
5585
|
});
|
|
@@ -5356,33 +5592,33 @@ program.command("add").argument("[name]", 'Component name (e.g., "Button", "Text
|
|
|
5356
5592
|
component: options.component
|
|
5357
5593
|
});
|
|
5358
5594
|
} catch (error) {
|
|
5359
|
-
console.error(
|
|
5595
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5360
5596
|
process.exit(1);
|
|
5361
5597
|
}
|
|
5362
5598
|
});
|
|
5363
5599
|
program.command("init").description("Initialize fragments in a project (interactive by default)").option("--force", "Overwrite existing config").option("-y, --yes", "Non-interactive mode - auto-detect and use defaults").action(async (options) => {
|
|
5364
5600
|
try {
|
|
5365
|
-
const { init } = await import("./init-
|
|
5601
|
+
const { init } = await import("./init-EIM5WNMP.js");
|
|
5366
5602
|
const result = await init({
|
|
5367
5603
|
projectRoot: process.cwd(),
|
|
5368
5604
|
force: options.force,
|
|
5369
5605
|
yes: options.yes
|
|
5370
5606
|
});
|
|
5371
5607
|
if (!result.success) {
|
|
5372
|
-
console.error(
|
|
5608
|
+
console.error(pc21.red("\nInit failed with errors:"));
|
|
5373
5609
|
for (const error of result.errors) {
|
|
5374
|
-
console.error(
|
|
5610
|
+
console.error(pc21.red(` - ${error}`));
|
|
5375
5611
|
}
|
|
5376
5612
|
process.exit(1);
|
|
5377
5613
|
}
|
|
5378
5614
|
} catch (error) {
|
|
5379
|
-
console.error(
|
|
5615
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5380
5616
|
process.exit(1);
|
|
5381
5617
|
}
|
|
5382
5618
|
});
|
|
5383
5619
|
program.command("tokens").description("Discover and list design tokens from CSS/SCSS files").option("-c, --config <path>", "Path to config file").option("--json", "Output as JSON").option("--categories", "Group tokens by category").option("--theme <theme>", "Filter by theme name").option("--category <category>", "Filter by category (color, spacing, typography, etc.)").option("--verbose", "Show all tokens (no truncation)").action(async (options) => {
|
|
5384
5620
|
try {
|
|
5385
|
-
const { tokens } = await import("./tokens-
|
|
5621
|
+
const { tokens } = await import("./tokens-P2B7ZAM3.js");
|
|
5386
5622
|
const result = await tokens({
|
|
5387
5623
|
config: options.config,
|
|
5388
5624
|
json: options.json,
|
|
@@ -5395,13 +5631,13 @@ program.command("tokens").description("Discover and list design tokens from CSS/
|
|
|
5395
5631
|
process.exit(1);
|
|
5396
5632
|
}
|
|
5397
5633
|
} catch (error) {
|
|
5398
|
-
console.error(
|
|
5634
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5399
5635
|
process.exit(1);
|
|
5400
5636
|
}
|
|
5401
5637
|
});
|
|
5402
5638
|
program.command("generate").description("Generate fragment files from component source code").argument("[component]", "Specific component name to generate (optional)").option("--force", "Overwrite existing fragment files").option("--pattern <glob>", "Pattern for component files", "src/components/**/*.tsx").action(async (component, options) => {
|
|
5403
5639
|
try {
|
|
5404
|
-
const { generate } = await import("./generate-
|
|
5640
|
+
const { generate } = await import("./generate-54GJAWUY.js");
|
|
5405
5641
|
const result = await generate({
|
|
5406
5642
|
projectRoot: process.cwd(),
|
|
5407
5643
|
component,
|
|
@@ -5409,18 +5645,26 @@ program.command("generate").description("Generate fragment files from component
|
|
|
5409
5645
|
componentPattern: options.pattern
|
|
5410
5646
|
});
|
|
5411
5647
|
if (!result.success) {
|
|
5412
|
-
console.error(
|
|
5648
|
+
console.error(pc21.red("\nGenerate completed with errors"));
|
|
5413
5649
|
process.exit(1);
|
|
5414
5650
|
}
|
|
5415
5651
|
} catch (error) {
|
|
5416
|
-
console.error(
|
|
5652
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5653
|
+
process.exit(1);
|
|
5654
|
+
}
|
|
5655
|
+
});
|
|
5656
|
+
program.command("graph").description("Query the component relationship graph").argument("[component]", "Component name (optional)").option("-c, --config <path>", "Path to config file").option("-m, --mode <mode>", "Query mode: health, dependencies, dependents, impact, path, composition, alternatives, islands").option("-t, --target <component>", "Target component for path mode").option("--edge-types <types>", "Comma-separated edge types to filter by").option("--depth <number>", "Max traversal depth for impact mode", parseInt).option("--format <format>", "Output format: table, json, dot", "table").action(async (component, options) => {
|
|
5657
|
+
try {
|
|
5658
|
+
await graph(component, options);
|
|
5659
|
+
} catch (error) {
|
|
5660
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5417
5661
|
process.exit(1);
|
|
5418
5662
|
}
|
|
5419
5663
|
});
|
|
5420
5664
|
program.command("test").description("Run interaction tests for fragments with play functions").option("-c, --config <path>", "Path to config file").option("--component <name>", "Filter by component name").option("--tags <tags>", "Filter by tags (comma-separated)").option("--grep <pattern>", "Filter by variant name pattern").option("--exclude <pattern>", "Exclude tests matching pattern").option("--parallel <count>", "Number of parallel browser contexts", parseInt, 4).option("--timeout <ms>", "Timeout per test in milliseconds", parseInt, 3e4).option("--retries <count>", "Number of retries for failed tests", parseInt, 0).option("--bail", "Stop on first failure").option("--browser <name>", "Browser to use (chromium, firefox, webkit)", "chromium").option("--headed", "Run in headed mode (show browser)").option("--a11y", "Run accessibility checks with axe-core").option("--visual", "Capture screenshots for visual regression").option("--update-snapshots", "Update visual snapshots").option("--watch", "Watch mode - re-run on file changes").option("--reporters <names>", "Reporters to use (console, junit, json)", "console").option("-o, --output <dir>", "Output directory for results", "./test-results").option("--server-url <url>", "URL of running dev server (skips starting server)").option("-p, --port <port>", "Port for dev server", parseInt, 6006).option("--ci", "CI mode - non-interactive, exit with code 1 on failure").option("--list", "List available tests without running them").action(async (options) => {
|
|
5421
5665
|
try {
|
|
5422
5666
|
const { config, configDir } = await loadConfig(options.config);
|
|
5423
|
-
const { runTestCommand, listTests } = await import("./test-
|
|
5667
|
+
const { runTestCommand, listTests } = await import("./test-6VN2DA3S.js");
|
|
5424
5668
|
if (options.list) {
|
|
5425
5669
|
await listTests(config, configDir, {
|
|
5426
5670
|
component: options.component,
|
|
@@ -5453,7 +5697,7 @@ program.command("test").description("Run interaction tests for fragments with pl
|
|
|
5453
5697
|
});
|
|
5454
5698
|
process.exit(exitCode);
|
|
5455
5699
|
} catch (error) {
|
|
5456
|
-
console.error(
|
|
5700
|
+
console.error(pc21.red("Error:"), error instanceof Error ? error.message : error);
|
|
5457
5701
|
process.exit(1);
|
|
5458
5702
|
}
|
|
5459
5703
|
});
|