@schalkneethling/miyagi-core 4.4.2 → 4.4.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.
Files changed (115) hide show
  1. package/README.md +7 -2
  2. package/api/app.js +16 -16
  3. package/api/index.js +263 -262
  4. package/bin/miyagi.js +1 -1
  5. package/dist/css/iframe.css +6 -30
  6. package/frontend/assets/css/iframe/accordion-tabs.css +39 -39
  7. package/frontend/assets/css/iframe/jsontree.js.css +149 -149
  8. package/frontend/assets/css/iframe/prism.css +45 -45
  9. package/frontend/assets/css/iframe/styleguide/colors.css +27 -27
  10. package/frontend/assets/css/iframe/styleguide/fonts.css +23 -23
  11. package/frontend/assets/css/iframe/styleguide/index.css +58 -58
  12. package/frontend/assets/css/iframe/styleguide/spacings.css +10 -10
  13. package/frontend/assets/css/iframe.css +191 -191
  14. package/frontend/assets/css/main/menu/config-switcher.css +21 -21
  15. package/frontend/assets/css/main/menu/config-switchers.css +34 -34
  16. package/frontend/assets/css/main/menu/goto.css +16 -16
  17. package/frontend/assets/css/main/menu/nav.css +49 -49
  18. package/frontend/assets/css/main/menu/search.css +34 -34
  19. package/frontend/assets/css/main/menu/title.css +18 -18
  20. package/frontend/assets/css/main/menu.css +89 -89
  21. package/frontend/assets/css/main/reset.css +47 -47
  22. package/frontend/assets/css/main.css +41 -41
  23. package/frontend/assets/css/shared.css +16 -16
  24. package/frontend/assets/css/tokens.css +108 -107
  25. package/frontend/assets/js/_accordion-tabs.js +392 -392
  26. package/frontend/assets/js/_goto.js +59 -59
  27. package/frontend/assets/js/_iframe-links.js +14 -14
  28. package/frontend/assets/js/_is-triggered.js +3 -3
  29. package/frontend/assets/js/_main.js +369 -369
  30. package/frontend/assets/js/_mock-data.js +8 -8
  31. package/frontend/assets/js/_prism.js +1082 -1081
  32. package/frontend/assets/js/_search.js +186 -186
  33. package/frontend/assets/js/_socket.js +44 -44
  34. package/frontend/assets/js/config-switcher/development-mode.js +38 -38
  35. package/frontend/assets/js/config-switcher/index.js +55 -55
  36. package/frontend/assets/js/config-switcher/text-direction.js +22 -22
  37. package/frontend/assets/js/config-switcher/theme.js +68 -68
  38. package/frontend/assets/js/iframe.build.js +25 -25
  39. package/frontend/assets/js/iframe.js +38 -38
  40. package/frontend/assets/js/jsontree.js +979 -976
  41. package/frontend/assets/js/main.build.js +29 -29
  42. package/frontend/assets/js/main.js +31 -31
  43. package/frontend/assets/js/styleguide/color-converter.js +652 -652
  44. package/frontend/assets/js/styleguide/index.js +100 -100
  45. package/lib/build/index.js +1014 -1020
  46. package/lib/cli/app.js +16 -16
  47. package/lib/cli/component.js +50 -50
  48. package/lib/cli/doctor.js +130 -121
  49. package/lib/cli/drupal-assets.js +163 -157
  50. package/lib/cli/lint.js +196 -196
  51. package/lib/cli/run.js +150 -146
  52. package/lib/config.js +86 -86
  53. package/lib/constants/lint-log-levels.js +6 -6
  54. package/lib/drupal/load-assets-config.js +59 -60
  55. package/lib/drupal/resolve-library-assets.js +132 -141
  56. package/lib/errors.js +20 -20
  57. package/lib/generator/component.js +124 -124
  58. package/lib/generator/mocks.js +156 -156
  59. package/lib/helpers.js +68 -68
  60. package/lib/i18n/en.js +93 -93
  61. package/lib/i18n/index.js +8 -8
  62. package/lib/index.js +13 -13
  63. package/lib/init/args.js +153 -153
  64. package/lib/init/config.js +452 -438
  65. package/lib/init/engines.js +41 -41
  66. package/lib/init/index.js +83 -83
  67. package/lib/init/rendering.js +3 -3
  68. package/lib/init/static.js +90 -90
  69. package/lib/init/twing/cache.js +27 -27
  70. package/lib/init/twing/functions.js +37 -37
  71. package/lib/init/views.js +5 -5
  72. package/lib/logger.js +72 -72
  73. package/lib/mocks/get.js +88 -88
  74. package/lib/mocks/index.js +2 -2
  75. package/lib/mocks/resolve/ref.js +447 -447
  76. package/lib/mocks/resolve/tpl.js +218 -218
  77. package/lib/mocks/resolve.js +154 -154
  78. package/lib/render/helpers/resolve-assets.js +29 -39
  79. package/lib/render/helpers.js +27 -27
  80. package/lib/render/index.js +18 -18
  81. package/lib/render/views/iframe/component.docs.js +50 -50
  82. package/lib/render/views/iframe/component.js +249 -248
  83. package/lib/render/views/iframe/design-tokens/colors.js +38 -38
  84. package/lib/render/views/iframe/design-tokens/index.js +3 -3
  85. package/lib/render/views/iframe/design-tokens/sizes.js +35 -35
  86. package/lib/render/views/iframe/design-tokens/typography.js +37 -37
  87. package/lib/render/views/iframe/docs.js +42 -42
  88. package/lib/render/views/iframe/index.js +28 -28
  89. package/lib/render/views/iframe/variation.js +89 -89
  90. package/lib/render/views/iframe/variation.standalone.js +69 -68
  91. package/lib/render/views/main/component.docs.js +38 -38
  92. package/lib/render/views/main/component.js +55 -55
  93. package/lib/render/views/main/design-tokens.js +38 -38
  94. package/lib/render/views/main/docs.js +33 -33
  95. package/lib/render/views/main/index.js +33 -33
  96. package/lib/state/components.js +99 -99
  97. package/lib/state/css.js +33 -33
  98. package/lib/state/docs.js +72 -72
  99. package/lib/state/file-contents.js +154 -154
  100. package/lib/state/helpers.js +53 -53
  101. package/lib/state/index.js +39 -39
  102. package/lib/state/menu/index.js +202 -202
  103. package/lib/state/menu/structure.js +84 -84
  104. package/lib/state/partials.js +12 -12
  105. package/lib/state/source-tree.js +51 -51
  106. package/lib/styleguide/color-names.js +148 -148
  107. package/lib/styleguide/colors.js +113 -113
  108. package/lib/styleguide/helpers.js +33 -33
  109. package/lib/styleguide/index.js +4 -4
  110. package/lib/styleguide/media-queries.js +18 -18
  111. package/lib/styleguide/spacings.js +22 -22
  112. package/lib/styleguide/typography.js +46 -46
  113. package/lib/validator/mocks.js +110 -83
  114. package/lib/validator/schemas.js +236 -227
  115. package/package.json +118 -117
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
3
3
  import deepMerge from "deepmerge";
4
4
  import log from "../logger.js";
5
5
  import { t } from "../i18n/index.js";
6
+ import { loadGlobalSchemas } from "./schemas.js";
6
7
 
7
8
  /**
8
9
  * Module for validating mock data against JSON schema
@@ -14,97 +15,123 @@ import { t } from "../i18n/index.js";
14
15
  * @returns {null|object[]} null if there is no schema or an array with booleans defining the validity of the entries in the data array
15
16
  */
16
17
  export default function validateMockData(
17
- component,
18
- dataArray,
19
- noCli,
20
- validSchemas = [],
18
+ component,
19
+ dataArray,
20
+ noCli,
21
+ validSchemas = [],
21
22
  ) {
22
- const componentSchema =
23
- global.state.fileContents[component.paths.schema.full];
23
+ const componentSchema =
24
+ global.state.fileContents[component.paths.schema.full];
24
25
 
25
- if (componentSchema) {
26
- const validity = [];
27
- let validate;
28
- let jsonSchemaValidator;
26
+ if (componentSchema) {
27
+ const validity = [];
28
+ let validate;
29
+ let jsonSchemaValidator;
29
30
 
30
- try {
31
- jsonSchemaValidator = new global.config.schema.ajv(
32
- deepMerge(
33
- {
34
- allErrors: true,
35
- },
36
- global.config.schema.options || {},
37
- ),
38
- );
31
+ try {
32
+ jsonSchemaValidator = new global.config.schema.ajv(
33
+ deepMerge(
34
+ {
35
+ allErrors: true,
36
+ },
37
+ global.config.schema.options || {},
38
+ ),
39
+ );
39
40
 
40
- validSchemas.forEach((entry) => {
41
- // Preload only other validated schemas for cross-component $ref resolution.
42
- // The current component schema is compiled below and must not be added twice.
43
- if (entry?.schemaFile !== component.paths.schema.full && entry?.schema) {
44
- jsonSchemaValidator.addSchema(entry.schema);
45
- }
46
- });
41
+ validSchemas.forEach((entry) => {
42
+ // Preload only other validated schemas for cross-component $ref resolution.
43
+ // The current component schema is compiled below and must not be added twice.
44
+ if (
45
+ entry?.schemaFile !== component.paths.schema.full &&
46
+ entry?.schema
47
+ ) {
48
+ jsonSchemaValidator.addSchema(entry.schema);
49
+ }
50
+ });
47
51
 
48
- validate = jsonSchemaValidator.compile(componentSchema);
49
- } catch (e) {
50
- const message = e.toString();
51
- if (!noCli) {
52
- log("error", `${component.paths.dir.short}:\n${message}`, e);
53
- }
54
- return [
55
- {
56
- type: "schema",
57
- data: [{ message }],
58
- },
59
- ];
60
- }
52
+ // Register global schema definitions when they were not already included in
53
+ // validSchemas (e.g. when called directly from the dev server render path).
54
+ const preloadedSchemaFiles = new Set(
55
+ validSchemas.map((entry) => entry?.schemaFile),
56
+ );
57
+ for (const [
58
+ index,
59
+ { schema, globalSchemaFile },
60
+ ] of loadGlobalSchemas().entries()) {
61
+ if (preloadedSchemaFiles.has(globalSchemaFile)) {
62
+ continue;
63
+ }
61
64
 
62
- if (validate && dataArray) {
63
- dataArray.forEach((entry) => {
64
- const valid = validate(entry?.resolved ?? {});
65
- if (!valid && !noCli) {
66
- validate.errors.forEach((error) => {
67
- log(
68
- "error",
69
- `${component.paths.dir.short} # ${entry.name}\n${jsYaml.dump(error)}`,
70
- );
71
- });
72
- }
65
+ if (!schema.$id) {
66
+ schema.$id = `miyagi-global:${index}`;
67
+ }
73
68
 
74
- if (!valid) {
75
- validity.push({
76
- variant: entry.name,
77
- data: validate.errors,
78
- });
79
- }
80
- });
81
- }
69
+ try {
70
+ jsonSchemaValidator.addSchema(schema);
71
+ } catch {
72
+ // Silently skip duplicates — the same $id registered by the lint
73
+ // path would otherwise cause AJV to throw here.
74
+ }
75
+ }
82
76
 
83
- return validity.map((item) => ({
84
- type: "mocks",
85
- ...item,
86
- }));
87
- }
77
+ validate = jsonSchemaValidator.compile(componentSchema);
78
+ } catch (e) {
79
+ const message = e.toString();
80
+ if (!noCli) {
81
+ log("error", `${component.paths.dir.short}:\n${message}`, e);
82
+ }
83
+ return [
84
+ {
85
+ type: "schema",
86
+ data: [{ message }],
87
+ },
88
+ ];
89
+ }
88
90
 
89
- if (!global.config.isBuild && !noCli) {
90
- const parseError = global.state.fileReadErrors?.[component.paths.schema.full];
91
- const schemaExistsOnDisk = existsSync(component.paths.schema.full);
92
- const warningMessage = parseError
93
- ? t("validator.mocks.schemaParseFailed")
94
- .replace("{{schemaFile}}", component.paths.schema.short)
95
- .replace("{{format}}", "JSON or YAML")
96
- : schemaExistsOnDisk
97
- ? t("validator.mocks.schemaParseFailed")
98
- .replace("{{schemaFile}}", component.paths.schema.short)
99
- .replace("{{format}}", "JSON or YAML")
100
- : t("validator.mocks.schemaMissing")
101
- .replace("{{component}}", component.paths.dir.short)
102
- .replace("{{schemaFile}}", component.paths.schema.short);
103
- log(
104
- "warn",
105
- warningMessage,
106
- );
107
- }
91
+ if (validate && dataArray) {
92
+ dataArray.forEach((entry) => {
93
+ const valid = validate(entry?.resolved ?? {});
94
+ if (!valid && !noCli) {
95
+ validate.errors.forEach((error) => {
96
+ log(
97
+ "error",
98
+ `${component.paths.dir.short} # ${entry.name}\n${jsYaml.dump(error)}`,
99
+ );
100
+ });
101
+ }
108
102
 
109
- return null;
103
+ if (!valid) {
104
+ validity.push({
105
+ variant: entry.name,
106
+ data: validate.errors,
107
+ });
108
+ }
109
+ });
110
+ }
111
+
112
+ return validity.map((item) => ({
113
+ type: "mocks",
114
+ ...item,
115
+ }));
116
+ }
117
+
118
+ if (!global.config.isBuild && !noCli) {
119
+ const parseError =
120
+ global.state.fileReadErrors?.[component.paths.schema.full];
121
+ const schemaExistsOnDisk = existsSync(component.paths.schema.full);
122
+ const warningMessage = parseError
123
+ ? t("validator.mocks.schemaParseFailed")
124
+ .replace("{{schemaFile}}", component.paths.schema.short)
125
+ .replace("{{format}}", "JSON or YAML")
126
+ : schemaExistsOnDisk
127
+ ? t("validator.mocks.schemaParseFailed")
128
+ .replace("{{schemaFile}}", component.paths.schema.short)
129
+ .replace("{{format}}", "JSON or YAML")
130
+ : t("validator.mocks.schemaMissing")
131
+ .replace("{{component}}", component.paths.dir.short)
132
+ .replace("{{schemaFile}}", component.paths.schema.short);
133
+ log("warn", warningMessage);
134
+ }
135
+
136
+ return null;
110
137
  }