storybook-addon-sdc 0.7.5 → 0.7.7
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 +28 -6
- package/package.json +1 -1
package/dist/preset.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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 { basename, dirname as dirname2, extname } from "path";
|
|
4
|
+
import { join as join2, basename, dirname as dirname2, extname } from "path";
|
|
5
|
+
import { globSync } from "glob";
|
|
5
6
|
|
|
6
7
|
// src/argsGenerator.ts
|
|
7
8
|
import { JSONSchemaFaker } from "json-schema-faker";
|
|
@@ -180,7 +181,7 @@ var readSDC = (filePath, defs, validate) => {
|
|
|
180
181
|
}
|
|
181
182
|
return sdcSchema;
|
|
182
183
|
};
|
|
183
|
-
var generateImports = (directory) => readdirSync2(directory).filter((file) => [".css", ".js", ".mjs", ".twig"].includes(extname(file))).map((file) => {
|
|
184
|
+
var generateImports = (directory) => readdirSync2(directory).filter((file) => [".css", ".js", ".mjs", ".twig", ".yml"].includes(extname(file))).map((file) => {
|
|
184
185
|
const filePath = `./${file}`;
|
|
185
186
|
return extname(file) === ".twig" ? `import COMPONENT from '${filePath}';` : `import '${filePath}';`;
|
|
186
187
|
}).join("\n");
|
|
@@ -239,12 +240,19 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
239
240
|
}) => ({
|
|
240
241
|
name: "vite-plugin-storybook-yaml-stories",
|
|
241
242
|
async load(id) {
|
|
243
|
+
if (id.endsWith("story.yml")) {
|
|
244
|
+
return "";
|
|
245
|
+
}
|
|
242
246
|
if (!id.endsWith("component.yml")) return;
|
|
243
247
|
try {
|
|
244
248
|
const content = readSDC(id, globalDefs, sdcStorybookOptions.validate);
|
|
245
249
|
const imports = generateImports(dirname2(id));
|
|
250
|
+
const previewsStories = {
|
|
251
|
+
...content.thirdPartySettings?.sdcStorybook?.stories || {},
|
|
252
|
+
...loadStoryFilesSync(id)
|
|
253
|
+
};
|
|
246
254
|
const storiesImports = dynamicImports(
|
|
247
|
-
|
|
255
|
+
previewsStories
|
|
248
256
|
);
|
|
249
257
|
const metadata = componentMetadata_default(id, content);
|
|
250
258
|
const argTypes = {
|
|
@@ -272,7 +280,7 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
272
280
|
...generateStorybookArgs(content, jsonSchemaFakerOptions)
|
|
273
281
|
};
|
|
274
282
|
const basicArgs = { ...args };
|
|
275
|
-
const stories =
|
|
283
|
+
const stories = previewsStories ? storiesGenerator_default(previewsStories) : "";
|
|
276
284
|
return `
|
|
277
285
|
${imports}
|
|
278
286
|
${storiesImports}
|
|
@@ -305,19 +313,33 @@ var yamlStoriesIndexer = {
|
|
|
305
313
|
const content = readSDC(fileName);
|
|
306
314
|
const baseTitle = makeTitle(`SDC/${content.name}`);
|
|
307
315
|
const stories = content.thirdPartySettings?.sdcStorybook?.stories;
|
|
308
|
-
|
|
316
|
+
const storiesContent = loadStoryFilesSync(fileName);
|
|
317
|
+
const mergedStories = { ...stories, ...storiesContent };
|
|
318
|
+
return createStoryIndex(fileName, baseTitle, mergedStories);
|
|
309
319
|
} catch (error) {
|
|
310
320
|
console.error(`Error creating index for YAML file: ${fileName}`, error);
|
|
311
321
|
throw error;
|
|
312
322
|
}
|
|
313
323
|
}
|
|
314
324
|
};
|
|
325
|
+
var loadStoryFilesSync = (fileName) => {
|
|
326
|
+
const folderPath = dirname2(fileName);
|
|
327
|
+
const storyFiles = globSync(join2(folderPath, "*.story.yml"));
|
|
328
|
+
return storyFiles.reduce((acc, file) => {
|
|
329
|
+
const content = readFileSync(file, "utf8");
|
|
330
|
+
const key = basename(file).split(".")[1];
|
|
331
|
+
return {
|
|
332
|
+
...acc,
|
|
333
|
+
[key]: parseYaml(content)
|
|
334
|
+
};
|
|
335
|
+
}, {});
|
|
336
|
+
};
|
|
315
337
|
|
|
316
338
|
// src/preset.ts
|
|
317
339
|
import twig from "vite-plugin-twig-drupal";
|
|
318
340
|
import { mergeConfig } from "vite";
|
|
319
341
|
import { resolve as resolve2 } from "path";
|
|
320
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "
|
|
342
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
321
343
|
import { parse } from "yaml";
|
|
322
344
|
import { sync } from "glob";
|
|
323
345
|
import fetch2 from "node-fetch";
|