@fragments-sdk/cli 0.7.1 → 0.7.3
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/LICENSE +77 -14
- package/dist/bin.js +22 -18
- package/dist/bin.js.map +1 -1
- package/dist/chunk-D34Q6A7S.js +266 -0
- package/dist/chunk-D34Q6A7S.js.map +1 -0
- package/dist/chunk-EKLMXTWU.js +80 -0
- package/dist/chunk-EKLMXTWU.js.map +1 -0
- package/dist/{chunk-GHYYFAQN.js → chunk-P33AKQJW.js} +1 -76
- package/dist/chunk-P33AKQJW.js.map +1 -0
- package/dist/{chunk-U6VTHBNI.js → chunk-QPY4DUFB.js} +177 -46
- package/dist/chunk-QPY4DUFB.js.map +1 -0
- package/dist/{chunk-32VIEOQY.js → chunk-R2YH7NLN.js} +9 -7
- package/dist/{chunk-32VIEOQY.js.map → chunk-R2YH7NLN.js.map} +1 -1
- package/dist/{chunk-5ITIP3ES.js → chunk-R6IZZSE7.js} +44 -278
- package/dist/chunk-R6IZZSE7.js.map +1 -0
- package/dist/{chunk-DQHWLAUV.js → chunk-TOIE7VXF.js} +2 -2
- package/dist/{chunk-GCZMFLDI.js → chunk-UXLGIGSX.js} +60 -3
- package/dist/chunk-UXLGIGSX.js.map +1 -0
- package/dist/{chunk-GKX2HPZ6.js → chunk-YMPGYEWK.js} +9 -3
- package/dist/chunk-YMPGYEWK.js.map +1 -0
- package/dist/chunk-Z7EY4VHE.js +50 -0
- package/dist/{core-SFHPYR5H.js → core-3NMNCLFW.js} +8 -5
- package/dist/discovery-AKGA6CJD.js +28 -0
- package/dist/{generate-54GJAWUY.js → generate-JAUEHKK7.js} +7 -4
- package/dist/{generate-54GJAWUY.js.map → generate-JAUEHKK7.js.map} +1 -1
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/{init-EIM5WNMP.js → init-DZQOT54X.js} +6 -4
- package/dist/{init-EIM5WNMP.js.map → init-DZQOT54X.js.map} +1 -1
- package/dist/mcp-bin.js +5 -3
- package/dist/mcp-bin.js.map +1 -1
- package/dist/sass.node-4XJK6YBF.js +130708 -0
- package/dist/sass.node-4XJK6YBF.js.map +1 -0
- package/dist/scan-OJRCVKK2.js +15 -0
- package/dist/{service-ED2LNCTU.js → service-CFFBHW4X.js} +6 -4
- package/dist/service-CFFBHW4X.js.map +1 -0
- package/dist/{static-viewer-Q4F4QP5M.js → static-viewer-VA2JXSCX.js} +6 -4
- package/dist/static-viewer-VA2JXSCX.js.map +1 -0
- package/dist/{test-6VN2DA3S.js → test-O7DZNKDC.js} +8 -4
- package/dist/{test-6VN2DA3S.js.map → test-O7DZNKDC.js.map} +1 -1
- package/dist/{tokens-P2B7ZAM3.js → tokens-N7THFD6J.js} +10 -7
- package/dist/{tokens-P2B7ZAM3.js.map → tokens-N7THFD6J.js.map} +1 -1
- package/dist/{viewer-GM7IQPPB.js → viewer-QTR7QJMM.js} +390 -25
- package/dist/viewer-QTR7QJMM.js.map +1 -0
- package/package.json +13 -2
- package/src/build.ts +60 -6
- package/src/commands/graph.ts +2 -2
- package/src/core/__tests__/token-resolver.test.ts +82 -0
- package/src/core/loader.ts +0 -3
- package/src/core/parser.ts +41 -1
- package/src/core/token-parser.ts +111 -1
- package/src/core/token-resolver.ts +155 -0
- package/src/service/__tests__/patch-generator.test.ts +2 -2
- package/src/service/patch-generator.ts +8 -1
- package/src/viewer/render-utils.ts +141 -0
- package/src/viewer/vite-plugin.ts +381 -23
- package/dist/chunk-5ITIP3ES.js.map +0 -1
- package/dist/chunk-GCZMFLDI.js.map +0 -1
- package/dist/chunk-GHYYFAQN.js.map +0 -1
- package/dist/chunk-GKX2HPZ6.js.map +0 -1
- package/dist/chunk-U6VTHBNI.js.map +0 -1
- package/dist/scan-KQBKUS64.js +0 -12
- package/dist/viewer-GM7IQPPB.js.map +0 -1
- /package/dist/{chunk-DQHWLAUV.js.map → chunk-TOIE7VXF.js.map} +0 -0
- /package/dist/{core-SFHPYR5H.js.map → chunk-Z7EY4VHE.js.map} +0 -0
- /package/dist/{scan-KQBKUS64.js.map → core-3NMNCLFW.js.map} +0 -0
- /package/dist/{service-ED2LNCTU.js.map → discovery-AKGA6CJD.js.map} +0 -0
- /package/dist/{static-viewer-Q4F4QP5M.js.map → scan-OJRCVKK2.js.map} +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
BRAND,
|
|
4
3
|
fragmentsConfigSchema
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-P33AKQJW.js";
|
|
5
|
+
import {
|
|
6
|
+
BRAND
|
|
7
|
+
} from "./chunk-EKLMXTWU.js";
|
|
6
8
|
|
|
7
9
|
// src/core/config.ts
|
|
8
10
|
import { existsSync } from "fs";
|
|
@@ -65,253 +67,6 @@ ${errors}`);
|
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
// src/core/discovery.ts
|
|
69
|
-
import { resolve as resolve2, dirname as dirname2 } from "path";
|
|
70
|
-
import { readFile } from "fs/promises";
|
|
71
|
-
import { existsSync as existsSync2 } from "fs";
|
|
72
|
-
import fg from "fast-glob";
|
|
73
|
-
async function discoverBlockFiles(configDir, exclude) {
|
|
74
|
-
const patterns = [
|
|
75
|
-
`**/*${BRAND.blockFileExtension}`,
|
|
76
|
-
`**/*${BRAND.recipeFileExtension}`
|
|
77
|
-
];
|
|
78
|
-
const files = await fg(patterns, {
|
|
79
|
-
cwd: configDir,
|
|
80
|
-
ignore: exclude ?? ["**/node_modules/**", "**/dist/**"],
|
|
81
|
-
absolute: false
|
|
82
|
-
});
|
|
83
|
-
return files.map((relativePath) => ({
|
|
84
|
-
relativePath,
|
|
85
|
-
absolutePath: resolve2(configDir, relativePath)
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
async function discoverFragmentFiles(config, configDir) {
|
|
89
|
-
const files = await fg(config.include, {
|
|
90
|
-
cwd: configDir,
|
|
91
|
-
ignore: config.exclude ?? [],
|
|
92
|
-
absolute: false
|
|
93
|
-
});
|
|
94
|
-
return files.map((relativePath) => ({
|
|
95
|
-
relativePath,
|
|
96
|
-
absolutePath: resolve2(configDir, relativePath)
|
|
97
|
-
}));
|
|
98
|
-
}
|
|
99
|
-
async function discoverComponentFiles(config, configDir) {
|
|
100
|
-
if (!config.components || config.components.length === 0) {
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
const files = await fg(config.components, {
|
|
104
|
-
cwd: configDir,
|
|
105
|
-
ignore: [
|
|
106
|
-
...config.exclude ?? [],
|
|
107
|
-
// Exclude fragment files themselves
|
|
108
|
-
...config.include,
|
|
109
|
-
// Exclude test files
|
|
110
|
-
"**/*.test.*",
|
|
111
|
-
"**/*.spec.*",
|
|
112
|
-
"**/__tests__/**"
|
|
113
|
-
],
|
|
114
|
-
absolute: false
|
|
115
|
-
});
|
|
116
|
-
return files.map((relativePath) => ({
|
|
117
|
-
relativePath,
|
|
118
|
-
absolutePath: resolve2(configDir, relativePath)
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
function extractComponentName(filePath) {
|
|
122
|
-
const parts = filePath.replace(/\\/g, "/").split("/");
|
|
123
|
-
const fileName = parts[parts.length - 1];
|
|
124
|
-
if (fileName === "index.tsx" || fileName === "index.ts") {
|
|
125
|
-
return parts[parts.length - 2] ?? "Unknown";
|
|
126
|
-
}
|
|
127
|
-
return fileName.replace(/\.(tsx?|jsx?)$/, "");
|
|
128
|
-
}
|
|
129
|
-
var DEFAULT_COMPONENT_PATTERNS = [
|
|
130
|
-
"src/components/**/*.tsx",
|
|
131
|
-
"src/components/**/index.tsx",
|
|
132
|
-
"components/**/*.tsx",
|
|
133
|
-
"lib/components/**/*.tsx",
|
|
134
|
-
"packages/*/src/components/**/*.tsx"
|
|
135
|
-
];
|
|
136
|
-
var DEFAULT_EXCLUDE_PATTERNS = [
|
|
137
|
-
"**/*.test.*",
|
|
138
|
-
"**/*.spec.*",
|
|
139
|
-
"**/*.stories.*",
|
|
140
|
-
"**/*.story.*",
|
|
141
|
-
"**/__tests__/**",
|
|
142
|
-
"**/__mocks__/**",
|
|
143
|
-
"**/node_modules/**",
|
|
144
|
-
"**/dist/**"
|
|
145
|
-
];
|
|
146
|
-
async function discoverComponentsFromSource(configDir, patterns, exclude) {
|
|
147
|
-
const searchPatterns = patterns && patterns.length > 0 ? patterns : DEFAULT_COMPONENT_PATTERNS;
|
|
148
|
-
const excludePatterns = [
|
|
149
|
-
...DEFAULT_EXCLUDE_PATTERNS,
|
|
150
|
-
...exclude ?? []
|
|
151
|
-
];
|
|
152
|
-
const files = await fg(searchPatterns, {
|
|
153
|
-
cwd: configDir,
|
|
154
|
-
ignore: excludePatterns,
|
|
155
|
-
absolute: false
|
|
156
|
-
});
|
|
157
|
-
const componentFiles = files.filter((file) => {
|
|
158
|
-
const name = extractComponentName(file);
|
|
159
|
-
return /^[A-Z]/.test(name);
|
|
160
|
-
});
|
|
161
|
-
const storyPatterns = [
|
|
162
|
-
"**/*.stories.tsx",
|
|
163
|
-
"**/*.stories.ts",
|
|
164
|
-
"**/*.story.tsx",
|
|
165
|
-
"**/*.story.ts"
|
|
166
|
-
];
|
|
167
|
-
const storyFiles = await fg(storyPatterns, {
|
|
168
|
-
cwd: configDir,
|
|
169
|
-
ignore: ["**/node_modules/**", "**/dist/**"],
|
|
170
|
-
absolute: false
|
|
171
|
-
});
|
|
172
|
-
const storyMap = /* @__PURE__ */ new Map();
|
|
173
|
-
for (const storyFile of storyFiles) {
|
|
174
|
-
const name = extractComponentName(storyFile.replace(/\.stories?\.(tsx?|jsx?)$/, ".tsx"));
|
|
175
|
-
storyMap.set(name, storyFile);
|
|
176
|
-
}
|
|
177
|
-
const components = [];
|
|
178
|
-
for (const file of componentFiles) {
|
|
179
|
-
const name = extractComponentName(file);
|
|
180
|
-
const absolutePath = resolve2(configDir, file);
|
|
181
|
-
const storyFile = storyMap.get(name);
|
|
182
|
-
components.push({
|
|
183
|
-
name,
|
|
184
|
-
sourcePath: absolutePath,
|
|
185
|
-
relativePath: file,
|
|
186
|
-
storyPath: storyFile ? resolve2(configDir, storyFile) : void 0
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
components.sort((a, b) => a.name.localeCompare(b.name));
|
|
190
|
-
return components;
|
|
191
|
-
}
|
|
192
|
-
async function discoverComponentsFromBarrel(barrelPath, configDir) {
|
|
193
|
-
const absoluteBarrelPath = resolve2(configDir, barrelPath);
|
|
194
|
-
if (!existsSync2(absoluteBarrelPath)) {
|
|
195
|
-
return [];
|
|
196
|
-
}
|
|
197
|
-
const content = await readFile(absoluteBarrelPath, "utf-8");
|
|
198
|
-
const components = [];
|
|
199
|
-
const exportRegex = /export\s+(?:\*|{([^}]+)})\s+from\s+['"]([^'"]+)['"]/g;
|
|
200
|
-
let match;
|
|
201
|
-
while ((match = exportRegex.exec(content)) !== null) {
|
|
202
|
-
const exportedNames = match[1];
|
|
203
|
-
const importPath = match[2];
|
|
204
|
-
const barrelDir = dirname2(absoluteBarrelPath);
|
|
205
|
-
let resolvedPath = resolve2(barrelDir, importPath);
|
|
206
|
-
if (!resolvedPath.endsWith(".tsx") && !resolvedPath.endsWith(".ts")) {
|
|
207
|
-
if (existsSync2(`${resolvedPath}.tsx`)) {
|
|
208
|
-
resolvedPath = `${resolvedPath}.tsx`;
|
|
209
|
-
} else if (existsSync2(`${resolvedPath}.ts`)) {
|
|
210
|
-
resolvedPath = `${resolvedPath}.ts`;
|
|
211
|
-
} else if (existsSync2(`${resolvedPath}/index.tsx`)) {
|
|
212
|
-
resolvedPath = `${resolvedPath}/index.tsx`;
|
|
213
|
-
} else if (existsSync2(`${resolvedPath}/index.ts`)) {
|
|
214
|
-
resolvedPath = `${resolvedPath}/index.ts`;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (!existsSync2(resolvedPath)) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (exportedNames) {
|
|
221
|
-
const names = exportedNames.split(",").map((n) => n.trim().split(/\s+as\s+/)[0].trim());
|
|
222
|
-
for (const name of names) {
|
|
223
|
-
if (/^[A-Z]/.test(name)) {
|
|
224
|
-
const relativePath = resolvedPath.replace(configDir + "/", "");
|
|
225
|
-
components.push({
|
|
226
|
-
name,
|
|
227
|
-
sourcePath: resolvedPath,
|
|
228
|
-
relativePath
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
const name = extractComponentName(importPath);
|
|
234
|
-
if (/^[A-Z]/.test(name)) {
|
|
235
|
-
const relativePath = resolvedPath.replace(configDir + "/", "");
|
|
236
|
-
components.push({
|
|
237
|
-
name,
|
|
238
|
-
sourcePath: resolvedPath,
|
|
239
|
-
relativePath
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return components;
|
|
245
|
-
}
|
|
246
|
-
var DEFAULT_TOKEN_PATTERNS = [
|
|
247
|
-
"src/**/tokens/**/_variables.scss",
|
|
248
|
-
"src/**/tokens/**/variables.scss",
|
|
249
|
-
"src/**/styles/**/variables.scss",
|
|
250
|
-
"src/**/styles/**/tokens.scss",
|
|
251
|
-
"src/**/styles/**/variables.css",
|
|
252
|
-
"src/**/theme/**/_variables.scss",
|
|
253
|
-
"src/**/theme/**/tokens.css"
|
|
254
|
-
];
|
|
255
|
-
async function discoverTokenFiles(configDir, patterns, exclude) {
|
|
256
|
-
const searchPatterns = patterns && patterns.length > 0 ? patterns : DEFAULT_TOKEN_PATTERNS;
|
|
257
|
-
const files = await fg(searchPatterns, {
|
|
258
|
-
cwd: configDir,
|
|
259
|
-
ignore: exclude ?? ["**/node_modules/**", "**/dist/**"],
|
|
260
|
-
absolute: false
|
|
261
|
-
});
|
|
262
|
-
return files.map((relativePath) => ({
|
|
263
|
-
relativePath,
|
|
264
|
-
absolutePath: resolve2(configDir, relativePath)
|
|
265
|
-
}));
|
|
266
|
-
}
|
|
267
|
-
async function discoverInstalledFragments(projectRoot) {
|
|
268
|
-
const pkgJsonPath = resolve2(projectRoot, "package.json");
|
|
269
|
-
if (!existsSync2(pkgJsonPath)) return [];
|
|
270
|
-
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf-8"));
|
|
271
|
-
const allDeps = { ...pkgJson.dependencies, ...pkgJson.devDependencies };
|
|
272
|
-
const results = [];
|
|
273
|
-
for (const depName of Object.keys(allDeps)) {
|
|
274
|
-
const depDir = resolve2(projectRoot, "node_modules", depName);
|
|
275
|
-
const depPkgPath = resolve2(depDir, "package.json");
|
|
276
|
-
if (!existsSync2(depPkgPath)) continue;
|
|
277
|
-
const depPkg = JSON.parse(await readFile(depPkgPath, "utf-8"));
|
|
278
|
-
if (!depPkg.fragments) continue;
|
|
279
|
-
const files = await fg(
|
|
280
|
-
[`src/**/*${BRAND.fileExtension}`, "src/**/*.stories.tsx"],
|
|
281
|
-
{ cwd: depDir, ignore: ["**/node_modules/**"], absolute: false }
|
|
282
|
-
);
|
|
283
|
-
for (const rel of files) {
|
|
284
|
-
results.push({
|
|
285
|
-
relativePath: `${depName}/${rel}`,
|
|
286
|
-
absolutePath: resolve2(depDir, rel)
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return results;
|
|
291
|
-
}
|
|
292
|
-
async function discoverAllComponents(configDir, options = {}) {
|
|
293
|
-
const componentsMap = /* @__PURE__ */ new Map();
|
|
294
|
-
const sourceComponents = await discoverComponentsFromSource(
|
|
295
|
-
configDir,
|
|
296
|
-
options.patterns,
|
|
297
|
-
options.exclude
|
|
298
|
-
);
|
|
299
|
-
for (const comp of sourceComponents) {
|
|
300
|
-
componentsMap.set(comp.name, comp);
|
|
301
|
-
}
|
|
302
|
-
if (options.barrelFiles && options.barrelFiles.length > 0) {
|
|
303
|
-
for (const barrelFile of options.barrelFiles) {
|
|
304
|
-
const barrelComponents = await discoverComponentsFromBarrel(barrelFile, configDir);
|
|
305
|
-
for (const comp of barrelComponents) {
|
|
306
|
-
if (!componentsMap.has(comp.name)) {
|
|
307
|
-
componentsMap.set(comp.name, comp);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return Array.from(componentsMap.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
70
|
// src/core/generators/typescript-extractor.ts
|
|
316
71
|
import ts from "typescript";
|
|
317
72
|
import { readFileSync } from "fs";
|
|
@@ -562,8 +317,8 @@ function getJSDocDefault(node) {
|
|
|
562
317
|
|
|
563
318
|
// src/core/generators/registry.ts
|
|
564
319
|
import { readFileSync as readFileSync2 } from "fs";
|
|
565
|
-
import { relative, dirname as
|
|
566
|
-
import
|
|
320
|
+
import { relative, dirname as dirname2, basename, join } from "path";
|
|
321
|
+
import fg from "fast-glob";
|
|
567
322
|
async function generateRegistry(options) {
|
|
568
323
|
const {
|
|
569
324
|
projectRoot,
|
|
@@ -581,18 +336,18 @@ async function generateRegistry(options) {
|
|
|
581
336
|
} = registryOptions;
|
|
582
337
|
const errors = [];
|
|
583
338
|
const warnings = [];
|
|
584
|
-
const storyFiles = await
|
|
339
|
+
const storyFiles = await fg(storyPatterns, {
|
|
585
340
|
cwd: projectRoot,
|
|
586
341
|
ignore: ["**/node_modules/**"],
|
|
587
342
|
absolute: true
|
|
588
343
|
});
|
|
589
344
|
const storyMap = /* @__PURE__ */ new Map();
|
|
590
345
|
for (const storyPath of storyFiles) {
|
|
591
|
-
const storyDir =
|
|
592
|
-
const storyBase =
|
|
346
|
+
const storyDir = dirname2(storyPath);
|
|
347
|
+
const storyBase = basename(storyPath).replace(/\.stories\.(tsx?|jsx?)$/, "");
|
|
593
348
|
storyMap.set(`${storyDir}/${storyBase}`, storyPath);
|
|
594
349
|
}
|
|
595
|
-
const componentFiles = await
|
|
350
|
+
const componentFiles = await fg(componentPatterns, {
|
|
596
351
|
cwd: projectRoot,
|
|
597
352
|
ignore: [
|
|
598
353
|
"**/node_modules/**",
|
|
@@ -608,13 +363,13 @@ async function generateRegistry(options) {
|
|
|
608
363
|
BRAND.componentsDir,
|
|
609
364
|
`*${BRAND.fileExtension}`
|
|
610
365
|
);
|
|
611
|
-
const fragmentFiles = await
|
|
366
|
+
const fragmentFiles = await fg(fragmentPattern, {
|
|
612
367
|
cwd: projectRoot,
|
|
613
368
|
absolute: true
|
|
614
369
|
});
|
|
615
370
|
const fragmentMap = /* @__PURE__ */ new Map();
|
|
616
371
|
for (const fragmentPath of fragmentFiles) {
|
|
617
|
-
const fragmentName =
|
|
372
|
+
const fragmentName = basename(fragmentPath).replace(BRAND.fileExtension, "");
|
|
618
373
|
try {
|
|
619
374
|
const content = readFileSync2(fragmentPath, "utf-8");
|
|
620
375
|
const fragment = JSON.parse(content);
|
|
@@ -643,8 +398,8 @@ async function generateRegistry(options) {
|
|
|
643
398
|
if (publicOnly && !extracted.exports.includes(componentName)) {
|
|
644
399
|
continue;
|
|
645
400
|
}
|
|
646
|
-
const componentDir =
|
|
647
|
-
const baseNameWithoutExt =
|
|
401
|
+
const componentDir = dirname2(filePath);
|
|
402
|
+
const baseNameWithoutExt = basename(filePath).replace(/\.(tsx?|jsx?)$/, "");
|
|
648
403
|
const storyPath = storyMap.get(`${componentDir}/${baseNameWithoutExt}`);
|
|
649
404
|
if (requireStory && !storyPath) {
|
|
650
405
|
continue;
|
|
@@ -1025,16 +780,13 @@ function estimateTokens(text) {
|
|
|
1025
780
|
|
|
1026
781
|
// src/core/loader.ts
|
|
1027
782
|
import { unlink } from "fs/promises";
|
|
1028
|
-
import { dirname as
|
|
783
|
+
import { dirname as dirname3, basename as basename2, join as join2 } from "path";
|
|
1029
784
|
import { pathToFileURL } from "url";
|
|
1030
785
|
import { build } from "esbuild";
|
|
1031
786
|
var DEFINE_FRAGMENT_SHIM = `
|
|
1032
787
|
export function defineFragment(def) {
|
|
1033
788
|
return def;
|
|
1034
789
|
}
|
|
1035
|
-
export function defineFragment(def) {
|
|
1036
|
-
return def;
|
|
1037
|
-
}
|
|
1038
790
|
export function defineBlock(def) {
|
|
1039
791
|
return def;
|
|
1040
792
|
}
|
|
@@ -1069,8 +821,8 @@ async function loadFragmentFile(absolutePath) {
|
|
|
1069
821
|
const module = await import(fileUrl);
|
|
1070
822
|
return module.default ?? null;
|
|
1071
823
|
}
|
|
1072
|
-
const sourceDir =
|
|
1073
|
-
const baseName =
|
|
824
|
+
const sourceDir = dirname3(absolutePath);
|
|
825
|
+
const baseName = basename2(absolutePath, `.${ext}`);
|
|
1074
826
|
const tempFile = join2(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.cjs`);
|
|
1075
827
|
try {
|
|
1076
828
|
await build({
|
|
@@ -1176,6 +928,7 @@ function parseFragmentFile(fileContent, filePath) {
|
|
|
1176
928
|
const variants = extractVariants(arg, sourceFile, warnings);
|
|
1177
929
|
const relations = extractRelations(arg, warnings);
|
|
1178
930
|
const ai = extractAIMetadata(arg, warnings);
|
|
931
|
+
const contract = extractContractMetadata(arg);
|
|
1179
932
|
return {
|
|
1180
933
|
componentImport,
|
|
1181
934
|
componentName,
|
|
@@ -1185,6 +938,7 @@ function parseFragmentFile(fileContent, filePath) {
|
|
|
1185
938
|
variants,
|
|
1186
939
|
relations,
|
|
1187
940
|
ai,
|
|
941
|
+
contract,
|
|
1188
942
|
warnings
|
|
1189
943
|
};
|
|
1190
944
|
}
|
|
@@ -1437,6 +1191,25 @@ function extractAIMetadata(arg, warnings) {
|
|
|
1437
1191
|
}
|
|
1438
1192
|
return void 0;
|
|
1439
1193
|
}
|
|
1194
|
+
function extractContractMetadata(arg) {
|
|
1195
|
+
const contractProp = findProperty(arg, "contract");
|
|
1196
|
+
if (!contractProp || !ts2.isObjectLiteralExpression(contractProp)) {
|
|
1197
|
+
return void 0;
|
|
1198
|
+
}
|
|
1199
|
+
const contract = {};
|
|
1200
|
+
const propsSummary = extractStringArray(contractProp, "propsSummary");
|
|
1201
|
+
if (propsSummary.length > 0) {
|
|
1202
|
+
contract.propsSummary = propsSummary;
|
|
1203
|
+
}
|
|
1204
|
+
const a11yRules = extractStringArray(contractProp, "a11yRules");
|
|
1205
|
+
if (a11yRules.length > 0) {
|
|
1206
|
+
contract.a11yRules = a11yRules;
|
|
1207
|
+
}
|
|
1208
|
+
if (Object.keys(contract).length > 0) {
|
|
1209
|
+
return contract;
|
|
1210
|
+
}
|
|
1211
|
+
return void 0;
|
|
1212
|
+
}
|
|
1440
1213
|
function extractStringProperty(obj, name) {
|
|
1441
1214
|
const prop = findProperty(obj, name);
|
|
1442
1215
|
if (prop && ts2.isStringLiteral(prop)) {
|
|
@@ -1502,8 +1275,8 @@ function extractLiteralValue(expr) {
|
|
|
1502
1275
|
}
|
|
1503
1276
|
|
|
1504
1277
|
// src/core/previewLoader.ts
|
|
1505
|
-
import { existsSync as
|
|
1506
|
-
import { join as join3, resolve as
|
|
1278
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1279
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
1507
1280
|
var PREVIEW_FILES = [
|
|
1508
1281
|
"preview.tsx",
|
|
1509
1282
|
"preview.ts",
|
|
@@ -1513,7 +1286,7 @@ var PREVIEW_FILES = [
|
|
|
1513
1286
|
function findPreviewConfigPath(storybookDir) {
|
|
1514
1287
|
for (const fileName of PREVIEW_FILES) {
|
|
1515
1288
|
const filePath = join3(storybookDir, fileName);
|
|
1516
|
-
if (
|
|
1289
|
+
if (existsSync3(filePath)) {
|
|
1517
1290
|
return filePath;
|
|
1518
1291
|
}
|
|
1519
1292
|
}
|
|
@@ -1525,7 +1298,7 @@ function findStorybookDir(projectRoot) {
|
|
|
1525
1298
|
join3(projectRoot, "storybook")
|
|
1526
1299
|
];
|
|
1527
1300
|
for (const dir of possiblePaths) {
|
|
1528
|
-
if (
|
|
1301
|
+
if (existsSync3(dir)) {
|
|
1529
1302
|
return dir;
|
|
1530
1303
|
}
|
|
1531
1304
|
}
|
|
@@ -1575,18 +1348,11 @@ export default {
|
|
|
1575
1348
|
// src/core/importAnalyzer.ts
|
|
1576
1349
|
import ts3 from "typescript";
|
|
1577
1350
|
import { readFileSync as readFileSync3 } from "fs";
|
|
1578
|
-
import { dirname as
|
|
1351
|
+
import { dirname as dirname4, basename as basename3 } from "path";
|
|
1579
1352
|
|
|
1580
1353
|
export {
|
|
1581
1354
|
findConfigFile,
|
|
1582
1355
|
loadConfig,
|
|
1583
|
-
discoverBlockFiles,
|
|
1584
|
-
discoverFragmentFiles,
|
|
1585
|
-
discoverComponentFiles,
|
|
1586
|
-
extractComponentName,
|
|
1587
|
-
discoverTokenFiles,
|
|
1588
|
-
discoverInstalledFragments,
|
|
1589
|
-
discoverAllComponents,
|
|
1590
1356
|
loadFragmentFile,
|
|
1591
1357
|
parseFragmentFile,
|
|
1592
1358
|
findPreviewConfigPath,
|
|
@@ -1596,4 +1362,4 @@ export {
|
|
|
1596
1362
|
generateRegistry,
|
|
1597
1363
|
generateContextMd
|
|
1598
1364
|
};
|
|
1599
|
-
//# sourceMappingURL=chunk-
|
|
1365
|
+
//# sourceMappingURL=chunk-R6IZZSE7.js.map
|