storybook-addon-sdc 0.4.4 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +49 -42
  2. package/dist/preset.js +205 -142
  3. package/package.json +4 -1
package/README.md CHANGED
@@ -15,6 +15,7 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
15
15
  - [Setting Default Values](#setting-default-values)
16
16
  - [Creating Experimental Stories](#creating-experimental-stories)
17
17
  - [Regular Storybook](#regular-storybook)
18
+ - [Configuration Options](#configuration-options)
18
19
  - [Dependencies](#dependencies)
19
20
  - [Known Issues](#known-issues)
20
21
  - [UI Patterns](#ui-patterns)
@@ -35,11 +36,12 @@ You can view a [live example of the SDC Addon in Storybook](https://iberdinsky-s
35
36
 
36
37
  The SDC Storybook Addon simplifies the integration of Drupal Single Directory Components (SDC) into Storybook, offering several key features:
37
38
 
38
- - Vite Plugin Integration: Leverages the vite-plugin-twig-drupal plugin to seamlessly load and process Twig templates used in SDC components.
39
- - Dynamic Path Resolution: Utilizes namespaces to dynamically discover components within your project structure, eliminating the need for manual configuration.
40
- - Story Generation: Automatically creates stories based on the YAML configurations of your SDC components, streamlining the story creation process.
41
- - JSON Schema Support: Supports JSON Schema for props and slots, enabling the generation of mock data for missing values and ensuring data consistency.
42
- - Drupal Behavior Embedding: Allows you to directly embed Drupal behaviors like Drupal.attachBehaviors() into Storybook previews, ensuring components behave similarly to their Drupal counterparts.
39
+ - **Vite Plugin Integration**: Leverages the vite-plugin-twig-drupal plugin to seamlessly load and process Twig templates used in SDC components.
40
+ - **Dynamic Path Resolution**: Utilizes namespaces to dynamically discover components within your project structure, eliminating the need for manual configuration.
41
+ - **Story Generation**: Automatically creates stories based on the YAML configurations of your SDC components, streamlining the story creation process.
42
+ - **JSON Schema Support**: Supports JSON Schema for props and slots, enabling the generation of mock data for missing values and ensuring data consistency.
43
+ - **Drupal Behavior Embedding**: Allows you to directly embed Drupal behaviors like `Drupal.attachBehaviors()` into Storybook previews, ensuring components behave similarly to their Drupal counterparts.
44
+ - **Custom and External Schema Definitions**: Supports custom and external JSON schema definitions to validate components based on Drupal-specific configurations (e.g., UI Patterns, Experience Builder).
43
45
 
44
46
  ## Why Choose SDC Storybook Over Alternatives?
45
47
 
@@ -223,39 +225,6 @@ thirdPartySettings:
223
225
  content: 'Hello from third grid card!'
224
226
  ```
225
227
 
226
- ### Key Features
227
-
228
- This configuration provides three distinct options for creating stories:
229
-
230
- 1. **Render Using Basic Args**
231
- The first card in the `grid` example uses only its basic arguments (`Basic.args`). No additional configuration or props are required for this component.
232
-
233
- ```yaml
234
- - type: component
235
- component: 'umami:card'
236
- ```
237
-
238
- 2. **Reuse an Existing Story**
239
- The second card uses the `Preview` story defined earlier. This is particularly useful for reusing pre-configured props and slots without redefining them in each story.
240
-
241
- ```yaml
242
- - type: component
243
- component: 'umami:card'
244
- story: Preview
245
- ```
246
-
247
- 3. **Define Custom Slots**
248
- The third card defines a custom `content` slot. This allows you to override or enhance the default behavior of the component with specific content.
249
-
250
- ```yaml
251
- - type: component
252
- component: 'umami:card'
253
- props:
254
- html_tag: 'div'
255
- slots:
256
- content: 'Hello from third grid card!'
257
- ```
258
-
259
228
  ### How It Works in Practice
260
229
 
261
230
  The addon dynamically renders the components and stories as defined:
@@ -264,6 +233,8 @@ The addon dynamically renders the components and stories as defined:
264
233
  - **Existing Story:** The `Preview` story is loaded, ensuring consistency across the Storybook environment.
265
234
  - **Custom Slots and Props:** Overrides the default slots and props behavior with unique content for that instance.
266
235
 
236
+ [![Stories](https://i.gyazo.com/7212a3f44052ebde34b59a1555d96afe.png)](https://gyazo.com/7212a3f44052ebde34b59a1555d96afe)
237
+
267
238
  ### Why stories experimental?
268
239
 
269
240
  The [community will have to decide](https://docs.google.com/document/d/1wCQLXrK1lrV2gYlqmqD2pybTql6_H1dByWIKB5xQFcQ/edit?tab=t.0#heading=h.3949vjfiqczr) what format the YAML stories should be.
@@ -302,9 +273,9 @@ export const Basic = {}
302
273
 
303
274
  In addition to the standard configuration options, you can also specify customDefs and externalDefs to provide additional schema definitions. These options are optional and can be used to extend or override the default definitions.
304
275
 
305
- #### `customDefs`
276
+ ### `customDefs`
306
277
 
307
- The `customDefs` option allows you to define custom schema definitions directly within your configuration. This can be a link to an external file, a link to a local file, or an object with custom definitions.
278
+ The `customDefs` option allows you to define custom schema definitions directly within your configuration. This can be object with custom definitions.
308
279
 
309
280
  Example:
310
281
 
@@ -322,7 +293,7 @@ const options = {
322
293
  }
323
294
  ```
324
295
 
325
- #### `externalDefs`
296
+ ### `externalDefs`
326
297
 
327
298
  The `externalDefs` option allows you to specify an array of paths to external definition files. These paths can be URLs to CDN-hosted files or local file paths.
328
299
 
@@ -332,6 +303,7 @@ Example:
332
303
  const options = {
333
304
  sdcStorybookOptions: {
334
305
  externalDefs: [
306
+ 'https://cdn.jsdelivr.net/gh/iberdinsky-skilld/sdc-addon@v0.4.3/drupal-defs/uiPatternsSchema.yml',
335
307
  'https://example.com/path/to/definitions.yml',
336
308
  './local/path/to/definitions.yml',
337
309
  ],
@@ -341,10 +313,45 @@ const options = {
341
313
 
342
314
  When using externalDefs, the definitions will be fetched and registered automatically.
343
315
 
316
+ ### `validate`
317
+
318
+ The `validate` option enables schema validation for SDC components using the [JSON Schema](https://www.npmjs.com/package/jsonschema) validator. By default, the validator checks the component configurations against the global schema located at:
319
+
320
+ ```
321
+ $schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
322
+ ```
323
+
324
+ #### How It Works:
325
+
326
+ - **Global Schema Validation (Default):** The addon uses the default global schema for validation. This schema is provided by Drupal and ensures that SDC components conform to the expected structure with the correct data types and properties.
327
+
328
+ - **Custom Component Schema:** If a specific SDC component includes its own `$schema` field pointing to a custom schema, the validator will use that schema for validation instead of the global one. This allows for more flexibility and component-specific validation, especially when components have custom requirements.
329
+
330
+ - **Validation Warnings:** Validation errors or warnings are logged to the console, helping developers identify any issues with component configurations. **Note:** Validation will not break the rendering of the components. Even if a validation error occurs, the component will still appear in Storybook, and the warning will be logged for review.
331
+
332
+ To disable validation, set `validate: false`:
333
+
334
+ ```js
335
+ const config = {
336
+ stories: ['../components/**/*.component.yml'],
337
+ addons: [
338
+ {
339
+ name: 'storybook-addon-sdc',
340
+ options: {
341
+ sdcStorybookOptions: {
342
+ validate: false, // Disable schema validation
343
+ },
344
+ },
345
+ },
346
+ ],
347
+ }
348
+ ```
349
+
344
350
  ## Dependencies
345
351
 
346
352
  - [vite-plugin-twig-drupal](https://github.com/larowlan/vite-plugin-twig-drupal): Loads Twig with Drupal functions.
347
- - [json-schema-faker](https://github.com/json-schema-faker/json-schema-faker): Generates mock data for missing props and slots.
353
+ - [json-schema-faker](https://github.com/json-schema-faker/json-schema-faker): Generates mock data for missing props and
354
+ - [JSON Schema validator](https://www.npmjs.com/package/jsonschema)
348
355
 
349
356
  ## Known Issues
350
357
 
package/dist/preset.js CHANGED
@@ -2133,7 +2133,7 @@ var require_parse_cst = __commonJS({
2133
2133
  * @returns {?Node} - null if at a document boundary
2134
2134
  */
2135
2135
  };
2136
- function parse3(src) {
2136
+ function parse2(src) {
2137
2137
  const cr = [];
2138
2138
  if (src.indexOf("\r") !== -1) {
2139
2139
  src = src.replace(/\r\n?/g, (match, offset2) => {
@@ -2164,7 +2164,7 @@ var require_parse_cst = __commonJS({
2164
2164
  documents.toString = () => documents.join("...\n");
2165
2165
  return documents;
2166
2166
  }
2167
- exports.parse = parse3;
2167
+ exports.parse = parse2;
2168
2168
  }
2169
2169
  });
2170
2170
 
@@ -5444,7 +5444,7 @@ var require_dist = __commonJS({
5444
5444
  }
5445
5445
  return doc;
5446
5446
  }
5447
- function parse3(src, options) {
5447
+ function parse2(src, options) {
5448
5448
  const doc = parseDocument(src, options);
5449
5449
  doc.warnings.forEach((warning) => warnings.warn(warning));
5450
5450
  if (doc.errors.length > 0) throw doc.errors[0];
@@ -5459,7 +5459,7 @@ var require_dist = __commonJS({
5459
5459
  createNode,
5460
5460
  defaultOptions: Document$1.defaultOptions,
5461
5461
  Document,
5462
- parse: parse3,
5462
+ parse: parse2,
5463
5463
  parseAllDocuments,
5464
5464
  parseCST: parseCst.parse,
5465
5465
  parseDocument,
@@ -7365,140 +7365,9 @@ var componentMetadata_default = (id, content) => {
7365
7365
  };
7366
7366
  };
7367
7367
 
7368
- // src/vite-plugin-storybook-yaml-stories.ts
7369
- var readCDC = (filePath, defs) => {
7370
- return { $defs: defs, ...(0, import_yaml.parse)(readFileSync(filePath, "utf8")) };
7371
- };
7372
- var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(baseDir, entry.name));
7373
- var resolveComponentPath = (namespace, component) => {
7374
- const baseDir = resolve("./components");
7375
- const directories = [baseDir, ...getSubdirectories(baseDir)];
7376
- const possiblePaths = directories.map(
7377
- (dir) => join(dir, component, `${component}.component.yml`)
7378
- );
7379
- return possiblePaths.find(existsSync);
7380
- };
7381
- var generateImports = (directory) => readdirSync(directory).filter(
7382
- (asset) => [".css", ".js", ".mjs", ".twig"].includes(extname(asset))
7383
- ).map((asset) => {
7384
- const assetPath = `./${asset}`;
7385
- return extname(asset) === ".twig" ? `import COMPONENT from '${assetPath}';` : `import '${assetPath}';`;
7386
- }).join("\n");
7387
- var dynamicImports = (stories) => {
7388
- const imports = /* @__PURE__ */ new Set();
7389
- const findComponentArgs = (args) => {
7390
- Object.values(args).forEach((value) => {
7391
- if (Array.isArray(value)) {
7392
- value.forEach((item) => {
7393
- if (item.type === "component") {
7394
- const [namespace, componentName] = item.component.split(":");
7395
- const resolvedPath = resolveComponentPath(namespace, componentName);
7396
- const kebabCaseName = item.component.replace(/[-:]/g, "");
7397
- if (resolvedPath) {
7398
- imports.add(
7399
- `import * as ${kebabCaseName} from '${resolvedPath}';`
7400
- );
7401
- }
7402
- }
7403
- });
7404
- } else if (value && typeof value === "object") {
7405
- findComponentArgs(value);
7406
- }
7407
- });
7408
- };
7409
- Object.values(stories).forEach(
7410
- ({ slots = {}, props = {} }) => findComponentArgs({ ...slots, ...props })
7411
- );
7412
- return Array.from(imports).join("\n");
7413
- };
7414
- var vite_plugin_storybook_yaml_stories_default = ({
7415
- jsonSchemaFakerOptions = {},
7416
- globalDefs = {}
7417
- }) => ({
7418
- name: "vite-plugin-storybook-yaml-stories",
7419
- async load(id) {
7420
- if (!id.endsWith("component.yml")) return;
7421
- const content = readCDC(id, { ...globalDefs });
7422
- const imports = generateImports(dirname2(id));
7423
- const storiesImports = dynamicImports(
7424
- content.thirdPartySettings?.sdcStorybook?.stories || {}
7425
- );
7426
- const metadata = componentMetadata_default(id, content);
7427
- const argTypes = {
7428
- componentMetadata: { table: { disable: true } },
7429
- ...content.variants && {
7430
- variant: {
7431
- control: "select",
7432
- options: content.variants ? Object.keys(content.variants) : []
7433
- }
7434
- },
7435
- ...argTypesGenerator_default(content)
7436
- };
7437
- const args = {
7438
- componentMetadata: metadata,
7439
- ...content.variants && {
7440
- variant: Object.keys(content.variants)[0]
7441
- },
7442
- ...generateStorybookArgs(content, jsonSchemaFakerOptions)
7443
- };
7444
- const basicArgs = { ...args };
7445
- const stories = content.thirdPartySettings?.sdcStorybook?.stories ? storiesGenerator_default(content.thirdPartySettings.sdcStorybook.stories) : "";
7446
- return `
7447
- ${imports}
7448
- ${storiesImports}
7449
-
7450
- export default {
7451
- component: COMPONENT,
7452
- argTypes: ${JSON.stringify(argTypes, null, 2)},
7453
- args: ${JSON.stringify(args, null, 2)},
7454
- };
7455
-
7456
- export const Basic = {
7457
- args: ${JSON.stringify(basicArgs, null, 2)},
7458
- play: async ({ canvasElement }) => {
7459
- Drupal.attachBehaviors(canvasElement, window.drupalSettings);
7460
- },
7461
- };
7462
-
7463
- ${stories}
7464
- `;
7465
- }
7466
- });
7467
- var yamlStoriesIndexer = {
7468
- test: /component\.yml$/,
7469
- createIndex: async (fileName, { makeTitle }) => {
7470
- const content = readCDC(fileName);
7471
- const baseTitle = makeTitle(`SDC/${content.name}`);
7472
- const storiesIndex = [
7473
- {
7474
- type: "story",
7475
- importPath: fileName,
7476
- exportName: "Basic",
7477
- title: baseTitle
7478
- }
7479
- ];
7480
- const stories = content.thirdPartySettings?.sdcStorybook?.stories;
7481
- if (stories) {
7482
- Object.keys(stories).forEach((storyKey) => {
7483
- storiesIndex.push({
7484
- type: "story",
7485
- importPath: fileName,
7486
- exportName: storyKey,
7487
- title: baseTitle
7488
- });
7489
- });
7490
- }
7491
- return storiesIndex;
7492
- }
7493
- };
7494
-
7495
- // src/preset.ts
7496
- var import_yaml2 = __toESM(require_yaml(), 1);
7497
- import twig from "vite-plugin-twig-drupal";
7498
- import { mergeConfig } from "vite";
7499
- import { resolve as resolve2 } from "path";
7500
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
7501
- import glob from "glob";
7368
+ // src/validateJson.ts
7369
+ init_esm_shims();
7370
+ import { Validator } from "jsonschema";
7502
7371
 
7503
7372
  // node_modules/node-fetch/lib/index.mjs
7504
7373
  init_esm_shims();
@@ -8666,7 +8535,196 @@ fetch.isRedirect = function(code) {
8666
8535
  fetch.Promise = global.Promise;
8667
8536
  var lib_default = fetch;
8668
8537
 
8538
+ // src/logger.ts
8539
+ init_esm_shims();
8540
+ import pino from "pino";
8541
+ var logger = pino({
8542
+ transport: {
8543
+ target: "pino-pretty",
8544
+ options: {
8545
+ colorize: true
8546
+ }
8547
+ }
8548
+ });
8549
+
8550
+ // src/validateJson.ts
8551
+ var validator = new Validator();
8552
+ var schemaCache = /* @__PURE__ */ new Map();
8553
+ var fetchSchema = async (url) => {
8554
+ if (schemaCache.has(url)) {
8555
+ return schemaCache.get(url);
8556
+ }
8557
+ try {
8558
+ const response = await lib_default(url);
8559
+ if (!response.ok) {
8560
+ throw new Error(`Failed to fetch schema: ${response.statusText}`);
8561
+ }
8562
+ const schema = await response.json();
8563
+ schemaCache.set(url, schema);
8564
+ return schema;
8565
+ } catch (error) {
8566
+ logger.error("Error fetching schema:", error);
8567
+ throw new Error(`Could not fetch schema from ${url}`);
8568
+ }
8569
+ };
8570
+ var validateJson = async (data, schemaUrl) => {
8571
+ const rootSchema = await fetchSchema(schemaUrl);
8572
+ validator.addSchema(rootSchema, schemaUrl);
8573
+ const unresolvedRefs = validator.unresolvedRefs;
8574
+ while (unresolvedRefs.length > 0) {
8575
+ const refUrl = unresolvedRefs.shift();
8576
+ const schema = await fetchSchema(refUrl);
8577
+ validator.addSchema(schema, refUrl);
8578
+ }
8579
+ const validationResult = validator.validate(data, rootSchema);
8580
+ if (validationResult.errors.length > 0) {
8581
+ logger.warn(`
8582
+ ${data.name}.component.yml has validation errors:
8583
+ ${validationResult.errors.map((error) => error.stack).join("\n")}
8584
+ `);
8585
+ }
8586
+ };
8587
+
8588
+ // src/vite-plugin-storybook-yaml-stories.ts
8589
+ var readSDC = (filePath, defs, validate) => {
8590
+ const sdcSchema = {
8591
+ $defs: defs,
8592
+ ...(0, import_yaml.parse)(readFileSync(filePath, "utf8"))
8593
+ };
8594
+ if (typeof validate === "string" && validate.length > 0) {
8595
+ validateJson(sdcSchema, sdcSchema["$schema"] || validate);
8596
+ }
8597
+ return sdcSchema;
8598
+ };
8599
+ var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(baseDir, entry.name));
8600
+ var resolveComponentPath = (namespace, component) => {
8601
+ const baseDir = resolve("./components");
8602
+ const directories = [baseDir, ...getSubdirectories(baseDir)];
8603
+ const possiblePaths = directories.map(
8604
+ (dir) => join(dir, component, `${component}.component.yml`)
8605
+ );
8606
+ return possiblePaths.find(existsSync);
8607
+ };
8608
+ var generateImports = (directory) => readdirSync(directory).filter((file) => [".css", ".js", ".mjs", ".twig"].includes(extname(file))).map((file) => {
8609
+ const filePath = `./${file}`;
8610
+ return extname(file) === ".twig" ? `import COMPONENT from '${filePath}';` : `import '${filePath}';`;
8611
+ }).join("\n");
8612
+ var dynamicImports = (stories) => {
8613
+ const imports = /* @__PURE__ */ new Set();
8614
+ const extractComponentImports = (args) => {
8615
+ Object.values(args).forEach((value) => {
8616
+ if (Array.isArray(value)) {
8617
+ value.forEach((item) => {
8618
+ if (item.type === "component") {
8619
+ const [namespace, componentName] = item.component.split(":");
8620
+ const resolvedPath = resolveComponentPath(namespace, componentName);
8621
+ const kebabCaseName = item.component.replace(/[-:]/g, "");
8622
+ if (resolvedPath) {
8623
+ imports.add(
8624
+ `import * as ${kebabCaseName} from '${resolvedPath}';`
8625
+ );
8626
+ }
8627
+ }
8628
+ });
8629
+ } else if (value && typeof value === "object") {
8630
+ extractComponentImports(value);
8631
+ }
8632
+ });
8633
+ };
8634
+ Object.values(stories).forEach(
8635
+ ({ slots = {}, props = {} }) => extractComponentImports({ ...slots, ...props })
8636
+ );
8637
+ return Array.from(imports).join("\n");
8638
+ };
8639
+ var vite_plugin_storybook_yaml_stories_default = ({
8640
+ jsonSchemaFakerOptions = {},
8641
+ sdcStorybookOptions = {},
8642
+ globalDefs = {}
8643
+ }) => ({
8644
+ name: "vite-plugin-storybook-yaml-stories",
8645
+ async load(id) {
8646
+ if (!id.endsWith("component.yml")) return;
8647
+ const content = readSDC(id, globalDefs, sdcStorybookOptions.validate);
8648
+ const imports = generateImports(dirname2(id));
8649
+ const storiesImports = dynamicImports(
8650
+ content.thirdPartySettings?.sdcStorybook?.stories || {}
8651
+ );
8652
+ const metadata = componentMetadata_default(id, content);
8653
+ const argTypes = {
8654
+ componentMetadata: { table: { disable: true } },
8655
+ ...content.variants && {
8656
+ variant: {
8657
+ control: "select",
8658
+ options: Object.keys(content.variants)
8659
+ }
8660
+ },
8661
+ ...argTypesGenerator_default(content)
8662
+ };
8663
+ const args = {
8664
+ componentMetadata: metadata,
8665
+ ...content.variants && {
8666
+ variant: Object.keys(content.variants)[0]
8667
+ },
8668
+ ...generateStorybookArgs(content, jsonSchemaFakerOptions)
8669
+ };
8670
+ const basicArgs = { ...args };
8671
+ const stories = content.thirdPartySettings?.sdcStorybook?.stories ? storiesGenerator_default(content.thirdPartySettings.sdcStorybook.stories) : "";
8672
+ return `
8673
+ ${imports}
8674
+ ${storiesImports}
8675
+
8676
+ export default {
8677
+ component: COMPONENT,
8678
+ argTypes: ${JSON.stringify(argTypes, null, 2)},
8679
+ args: ${JSON.stringify(args, null, 2)},
8680
+ };
8681
+
8682
+ export const Basic = {
8683
+ args: ${JSON.stringify(basicArgs, null, 2)},
8684
+ play: async ({ canvasElement }) => {
8685
+ Drupal.attachBehaviors(canvasElement, window.drupalSettings);
8686
+ },
8687
+ };
8688
+
8689
+ ${stories}
8690
+ `;
8691
+ }
8692
+ });
8693
+ var yamlStoriesIndexer = {
8694
+ test: /component\.yml$/,
8695
+ createIndex: async (fileName, { makeTitle }) => {
8696
+ const content = readSDC(fileName);
8697
+ const baseTitle = makeTitle(`SDC/${content.name}`);
8698
+ const storiesIndex = [
8699
+ {
8700
+ type: "story",
8701
+ importPath: fileName,
8702
+ exportName: "Basic",
8703
+ title: baseTitle
8704
+ }
8705
+ ];
8706
+ const stories = content.thirdPartySettings?.sdcStorybook?.stories;
8707
+ if (stories) {
8708
+ Object.keys(stories).forEach((storyKey) => {
8709
+ storiesIndex.push({
8710
+ type: "story",
8711
+ importPath: fileName,
8712
+ exportName: storyKey,
8713
+ title: baseTitle
8714
+ });
8715
+ });
8716
+ }
8717
+ return storiesIndex;
8718
+ }
8719
+ };
8720
+
8669
8721
  // src/preset.ts
8722
+ var import_yaml2 = __toESM(require_yaml(), 1);
8723
+ import twig from "vite-plugin-twig-drupal";
8724
+ import { mergeConfig } from "vite";
8725
+ import { resolve as resolve2 } from "path";
8726
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
8727
+ import glob from "glob";
8670
8728
  async function loadExternalDef(defPath) {
8671
8729
  if (defPath.startsWith("http://") || defPath.startsWith("https://")) {
8672
8730
  const response = await lib_default(defPath);
@@ -8694,20 +8752,21 @@ var resolveComponentPath2 = (namespace, component) => {
8694
8752
  );
8695
8753
  return possiblePaths.find((path) => existsSync2(path));
8696
8754
  };
8697
- var defaultOptions = {};
8755
+ var defaultOptions = {
8756
+ validate: "https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json"
8757
+ };
8698
8758
  async function viteFinal(config, options) {
8699
8759
  options.sdcStorybookOptions = {
8700
8760
  ...defaultOptions,
8701
8761
  ...options.sdcStorybookOptions
8702
8762
  };
8703
- const { namespace, customDefs, externalDefs } = options.sdcStorybookOptions;
8763
+ const { namespace, customDefs, externalDefs, validate } = options.sdcStorybookOptions;
8704
8764
  const globalDefs = {};
8705
8765
  if (externalDefs) {
8706
8766
  await Promise.all(
8707
8767
  externalDefs.map(async (defPath) => {
8708
8768
  const def = await loadExternalDef(defPath);
8709
8769
  Object.entries(def).forEach(([component, schema]) => {
8710
- console.log(`Registering external definition: ${component}`);
8711
8770
  globalDefs[component] = schema;
8712
8771
  });
8713
8772
  })
@@ -8715,10 +8774,14 @@ async function viteFinal(config, options) {
8715
8774
  }
8716
8775
  if (customDefs) {
8717
8776
  Object.entries(customDefs).forEach(([component, schema]) => {
8718
- console.log(`Registering custom definition: ${component}`);
8719
8777
  globalDefs[component] = schema;
8720
8778
  });
8721
8779
  }
8780
+ if (globalDefs?.length) {
8781
+ logger.info(
8782
+ `Registering custom definitions: ${Object.keys(globalDefs).join(", ")}`
8783
+ );
8784
+ }
8722
8785
  return mergeConfig(config, {
8723
8786
  plugins: [
8724
8787
  twig(options.vitePluginTwigDrupalOptions),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.4.4",
3
+ "version": "0.5.2",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",
@@ -38,6 +38,9 @@
38
38
  "dependencies": {
39
39
  "glob": "^11.0.0",
40
40
  "json-schema-faker": "^0.5.8",
41
+ "jsonschema": "^1.4.1",
42
+ "pino": "^9.5.0",
43
+ "pino-pretty": "^13.0.0",
41
44
  "vite-plugin-twig-drupal": "^1.4.2"
42
45
  },
43
46
  "devDependencies": {