storybook-addon-sdc 0.12.3 → 0.13.2
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/preset.js +27 -13
- package/package.json +1 -1
package/dist/preset.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/vite-plugin-storybook-yaml-stories.ts
|
|
2
2
|
import { readdirSync as readdirSync2, readFileSync } from "fs";
|
|
3
3
|
import { parse as parseYaml } from "yaml";
|
|
4
|
-
import { join as join2, basename as basename2, dirname as
|
|
4
|
+
import { join as join2, basename as basename2, dirname as dirname3, extname } from "path";
|
|
5
5
|
import { globSync } from "glob";
|
|
6
6
|
|
|
7
7
|
// src/logger.ts
|
|
@@ -63,6 +63,7 @@ var argTypesGenerator_default = (content) => {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
// src/utils.ts
|
|
66
|
+
import { dirname, sep } from "path";
|
|
66
67
|
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
67
68
|
var convertToKebabCase = (str) => str.replace(/[-:]/g, "");
|
|
68
69
|
var toAttributes = (attrs) => {
|
|
@@ -74,6 +75,16 @@ var toAttributes = (attrs) => {
|
|
|
74
75
|
return `${key}="${value}"`;
|
|
75
76
|
}).join(" ");
|
|
76
77
|
};
|
|
78
|
+
var deriveGroupFromPath = (fileName) => {
|
|
79
|
+
const dir = dirname(fileName);
|
|
80
|
+
const parts = dir.split(sep).filter(Boolean);
|
|
81
|
+
const lower = parts.map((p) => p.toLowerCase());
|
|
82
|
+
const index = lower.lastIndexOf("components");
|
|
83
|
+
if (index !== -1 && parts[index + 2]) {
|
|
84
|
+
return parts[index + 1];
|
|
85
|
+
}
|
|
86
|
+
return "SDC";
|
|
87
|
+
};
|
|
77
88
|
|
|
78
89
|
// src/storyNodeRender.ts
|
|
79
90
|
var generateArgs2 = (args, isSlot = false) => Object.entries(args).map(([key, value]) => `${key}: ${formatArgValue(value, isSlot)},`).join("\n");
|
|
@@ -164,15 +175,15 @@ var generateVariants = (variants) => {
|
|
|
164
175
|
};
|
|
165
176
|
|
|
166
177
|
// src/componentMetadata.ts
|
|
167
|
-
import { dirname, relative } from "path";
|
|
178
|
+
import { dirname as dirname2, relative } from "path";
|
|
168
179
|
import { cwd } from "process";
|
|
169
180
|
var componentMetadata_default = (id, content) => {
|
|
170
181
|
return {
|
|
171
|
-
path: relative(cwd(),
|
|
182
|
+
path: relative(cwd(), dirname2(id)),
|
|
172
183
|
machineName: id,
|
|
173
184
|
status: content.status || "stable",
|
|
174
185
|
name: content.name,
|
|
175
|
-
group: content.group
|
|
186
|
+
group: content.group
|
|
176
187
|
};
|
|
177
188
|
};
|
|
178
189
|
|
|
@@ -218,13 +229,13 @@ ${validationResult.errors.map((error) => error.stack).join("\n")}
|
|
|
218
229
|
|
|
219
230
|
// src/namespaces.ts
|
|
220
231
|
import { readdirSync, existsSync } from "fs";
|
|
221
|
-
import { basename, join, resolve, sep, relative as relative2 } from "path";
|
|
232
|
+
import { basename, join, resolve, sep as sep2, relative as relative2 } from "path";
|
|
222
233
|
import { cwd as cwd2 } from "process";
|
|
223
234
|
import { normalizePath } from "vite";
|
|
224
235
|
var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(baseDir, entry.name));
|
|
225
236
|
var getProjectName = (p) => {
|
|
226
237
|
const fullPath = resolve(p);
|
|
227
|
-
const parts = fullPath.split(
|
|
238
|
+
const parts = fullPath.split(sep2);
|
|
228
239
|
const i = parts.lastIndexOf("components");
|
|
229
240
|
if (i < 1) {
|
|
230
241
|
throw new Error(`Could not find 'components' folder in path: ${fullPath}`);
|
|
@@ -318,15 +329,15 @@ var Namespaces = class {
|
|
|
318
329
|
const componentsDir = join(rootPath, "components");
|
|
319
330
|
if (existsSync(componentsDir)) {
|
|
320
331
|
const isExact = fsPath === componentsDir;
|
|
321
|
-
const isChild = fsPath.startsWith(componentsDir +
|
|
332
|
+
const isChild = fsPath.startsWith(componentsDir + sep2);
|
|
322
333
|
if (!isExact && !isChild) {
|
|
323
334
|
throw new Error(
|
|
324
335
|
`Could not find 'components' folder in path: ${fsPath}, namespace: ${ns} (${Object.values(this.namespaces).join(", ")})`
|
|
325
336
|
);
|
|
326
337
|
}
|
|
327
338
|
let rel = relative2(componentsDir, fsPath);
|
|
328
|
-
if (
|
|
329
|
-
rel = rel.split(
|
|
339
|
+
if (sep2 !== "/") {
|
|
340
|
+
rel = rel.split(sep2).join("/");
|
|
330
341
|
}
|
|
331
342
|
if (makeComponentIdFormat) {
|
|
332
343
|
return `${ns}:${rel}`;
|
|
@@ -431,7 +442,7 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
431
442
|
if (!id.endsWith("component.yml")) return;
|
|
432
443
|
try {
|
|
433
444
|
const content = readSDC(id, globalDefs, sdcStorybookOptions.validate);
|
|
434
|
-
const imports = generateImports(
|
|
445
|
+
const imports = generateImports(dirname3(id), namespaces);
|
|
435
446
|
const previewsStories = {
|
|
436
447
|
...content.thirdPartySettings?.sdcStorybook?.stories || {},
|
|
437
448
|
...loadStoryFilesSync(id)
|
|
@@ -454,7 +465,7 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
454
465
|
defaultAttributes: [
|
|
455
466
|
[
|
|
456
467
|
"data-component-id",
|
|
457
|
-
`${namespaces.pathToNamespace(
|
|
468
|
+
`${namespaces.pathToNamespace(dirname3(id), true)}`
|
|
458
469
|
]
|
|
459
470
|
],
|
|
460
471
|
componentMetadata: metadata,
|
|
@@ -503,7 +514,10 @@ var yamlStoriesIndexer = {
|
|
|
503
514
|
createIndex: async (fileName, { makeTitle }) => {
|
|
504
515
|
try {
|
|
505
516
|
const content = readSDC(fileName);
|
|
506
|
-
const
|
|
517
|
+
const group = content.group || deriveGroupFromPath(fileName);
|
|
518
|
+
const baseTitle = makeTitle(
|
|
519
|
+
`${getProjectName(fileName)}/${capitalize(group)}/${content.name}`
|
|
520
|
+
);
|
|
507
521
|
const stories = content.thirdPartySettings?.sdcStorybook?.stories;
|
|
508
522
|
const disableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory ?? false;
|
|
509
523
|
const storiesContent = loadStoryFilesSync(fileName);
|
|
@@ -521,7 +535,7 @@ var yamlStoriesIndexer = {
|
|
|
521
535
|
}
|
|
522
536
|
};
|
|
523
537
|
var loadStoryFilesSync = (fileName) => {
|
|
524
|
-
const folderPath =
|
|
538
|
+
const folderPath = dirname3(fileName);
|
|
525
539
|
const storyFiles = globSync(join2(folderPath, "*.story.yml"));
|
|
526
540
|
return storyFiles.reduce(
|
|
527
541
|
(acc, file) => {
|