@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
@@ -7,9 +7,9 @@ import log from "../logger.js";
7
7
  import { EXIT_CODES } from "../errors.js";
8
8
  import { loadAssetsConfig } from "../drupal/load-assets-config.js";
9
9
  import {
10
- parseLibrariesYaml,
11
- resolveComponentAssets,
12
- mapLibraryToComponent,
10
+ parseLibrariesYaml,
11
+ resolveComponentAssets,
12
+ mapLibraryToComponent,
13
13
  } from "../drupal/resolve-library-assets.js";
14
14
 
15
15
  /**
@@ -22,112 +22,118 @@ import {
22
22
  * @returns {Promise<object>}
23
23
  */
24
24
  export default async function drupalAssets(args) {
25
- let config;
26
- try {
27
- config = await loadAssetsConfig(args);
28
- } catch (err) {
29
- const message = /** @type {Error} */ (err).message;
30
- log("error", message);
31
- return {
32
- success: false,
33
- code: EXIT_CODES.CONFIG_ERROR,
34
- shouldExit: true,
35
- message,
36
- };
37
- }
38
-
39
- if (!config.libraries) {
40
- const message =
41
- "No libraries file specified. Use --libraries or configure it in .miyagi-assets.js.";
42
- log("error", message);
43
- return {
44
- success: false,
45
- code: EXIT_CODES.CLI_USAGE_ERROR,
46
- shouldExit: true,
47
- message,
48
- };
49
- }
50
-
51
- let yamlContent;
52
- try {
53
- yamlContent = await readFile(config.libraries, "utf8");
54
- } catch {
55
- const message = `Could not read libraries file: ${config.libraries}`;
56
- log("error", message);
57
- return {
58
- success: false,
59
- code: EXIT_CODES.CONFIG_ERROR,
60
- shouldExit: true,
61
- message,
62
- };
63
- }
64
-
65
- const librariesMap = parseLibrariesYaml(yamlContent);
66
- const targetLibraries = config.components || Object.keys(librariesMap);
67
- const componentsFolder = global.config?.components?.folder || "src";
68
-
69
- let updatedCount = 0;
70
-
71
- for (const libraryName of targetLibraries) {
72
- if (!librariesMap[libraryName]) {
73
- log("warn", `Library "${libraryName}" not found in ${config.libraries} — skipping.`);
74
- continue;
75
- }
76
-
77
- const componentPath = mapLibraryToComponent(
78
- libraryName,
79
- config.mapping,
80
- componentsFolder,
81
- config.autoDiscoveryPrefixes ?? undefined,
82
- );
83
-
84
- if (!componentPath) {
85
- log("warn", `Could not map library "${libraryName}" to a component folder — skipping.`);
86
- continue;
87
- }
88
-
89
- const assets = resolveComponentAssets(
90
- libraryName,
91
- librariesMap,
92
- config.ignorePrefixes,
93
- );
94
-
95
- if (config.dryRun) {
96
- log("info", `[dry-run] ${libraryName} → ${componentPath}`);
97
- console.log(JSON.stringify({ $assets: assets }, null, "\t"));
98
- continue;
99
- }
100
-
101
- const updated = await updateMockFile(
102
- path.join(componentsFolder, componentPath),
103
- assets,
104
- );
105
-
106
- if (updated) {
107
- updatedCount++;
108
- log("info", `Updated $assets in ${componentPath}`);
109
- }
110
- }
111
-
112
- if (!config.dryRun) {
113
- const message = `Done. Updated ${updatedCount} component(s).`;
114
- log("success", message);
115
- return {
116
- success: true,
117
- code: EXIT_CODES.SUCCESS,
118
- shouldExit: true,
119
- message,
120
- updatedCount,
121
- };
122
- }
123
-
124
- return {
125
- success: true,
126
- code: EXIT_CODES.SUCCESS,
127
- shouldExit: true,
128
- message: "Dry run completed.",
129
- updatedCount,
130
- };
25
+ let config;
26
+ try {
27
+ config = await loadAssetsConfig(args);
28
+ } catch (err) {
29
+ const message = /** @type {Error} */ (err).message;
30
+ log("error", message);
31
+ return {
32
+ success: false,
33
+ code: EXIT_CODES.CONFIG_ERROR,
34
+ shouldExit: true,
35
+ message,
36
+ };
37
+ }
38
+
39
+ if (!config.libraries) {
40
+ const message =
41
+ "No libraries file specified. Use --libraries or configure it in .miyagi-assets.js.";
42
+ log("error", message);
43
+ return {
44
+ success: false,
45
+ code: EXIT_CODES.CLI_USAGE_ERROR,
46
+ shouldExit: true,
47
+ message,
48
+ };
49
+ }
50
+
51
+ let yamlContent;
52
+ try {
53
+ yamlContent = await readFile(config.libraries, "utf8");
54
+ } catch {
55
+ const message = `Could not read libraries file: ${config.libraries}`;
56
+ log("error", message);
57
+ return {
58
+ success: false,
59
+ code: EXIT_CODES.CONFIG_ERROR,
60
+ shouldExit: true,
61
+ message,
62
+ };
63
+ }
64
+
65
+ const librariesMap = parseLibrariesYaml(yamlContent);
66
+ const targetLibraries = config.components || Object.keys(librariesMap);
67
+ const componentsFolder = global.config?.components?.folder || "src";
68
+
69
+ let updatedCount = 0;
70
+
71
+ for (const libraryName of targetLibraries) {
72
+ if (!librariesMap[libraryName]) {
73
+ log(
74
+ "warn",
75
+ `Library "${libraryName}" not found in ${config.libraries} — skipping.`,
76
+ );
77
+ continue;
78
+ }
79
+
80
+ const componentPath = mapLibraryToComponent(
81
+ libraryName,
82
+ config.mapping,
83
+ componentsFolder,
84
+ config.autoDiscoveryPrefixes ?? undefined,
85
+ );
86
+
87
+ if (!componentPath) {
88
+ log(
89
+ "warn",
90
+ `Could not map library "${libraryName}" to a component folder — skipping.`,
91
+ );
92
+ continue;
93
+ }
94
+
95
+ const assets = resolveComponentAssets(
96
+ libraryName,
97
+ librariesMap,
98
+ config.ignorePrefixes,
99
+ );
100
+
101
+ if (config.dryRun) {
102
+ log("info", `[dry-run] ${libraryName} → ${componentPath}`);
103
+ console.log(JSON.stringify({ $assets: assets }, null, "\t"));
104
+ continue;
105
+ }
106
+
107
+ const updated = await updateMockFile(
108
+ path.join(componentsFolder, componentPath),
109
+ assets,
110
+ );
111
+
112
+ if (updated) {
113
+ updatedCount++;
114
+ log("info", `Updated $assets in ${componentPath}`);
115
+ }
116
+ }
117
+
118
+ if (!config.dryRun) {
119
+ const message = `Done. Updated ${updatedCount} component(s).`;
120
+ log("success", message);
121
+ return {
122
+ success: true,
123
+ code: EXIT_CODES.SUCCESS,
124
+ shouldExit: true,
125
+ message,
126
+ updatedCount,
127
+ };
128
+ }
129
+
130
+ return {
131
+ success: true,
132
+ code: EXIT_CODES.SUCCESS,
133
+ shouldExit: true,
134
+ message: "Dry run completed.",
135
+ updatedCount,
136
+ };
131
137
  }
132
138
 
133
139
  /**
@@ -137,44 +143,44 @@ export default async function drupalAssets(args) {
137
143
  * @returns {Promise<boolean>} true if file was updated
138
144
  */
139
145
  async function updateMockFile(componentDir, assets) {
140
- const mocksConfig = global.config?.files?.mocks || {
141
- name: "mocks",
142
- extension: ["yaml", "yml", "json", "js"],
143
- };
144
- const extensions = Array.isArray(mocksConfig.extension)
145
- ? mocksConfig.extension
146
- : [mocksConfig.extension];
147
-
148
- for (const ext of extensions) {
149
- const filePath = path.join(componentDir, `${mocksConfig.name}.${ext}`);
150
-
151
- let content;
152
- try {
153
- content = await readFile(filePath, "utf8");
154
- } catch {
155
- continue;
156
- }
157
-
158
- if (["yaml", "yml"].includes(ext)) {
159
- /** @type {Record<string, unknown>} */
160
- const data = /** @type {Record<string, unknown>} */ (
161
- yaml.load(content) || {}
162
- );
163
- data.$assets = cleanAssets(assets);
164
- await writeFile(filePath, yaml.dump(data, { indent: 2 }));
165
- return true;
166
- }
167
-
168
- if (ext === "json") {
169
- /** @type {Record<string, unknown>} */
170
- const data = JSON.parse(content);
171
- data.$assets = cleanAssets(assets);
172
- await writeFile(filePath, JSON.stringify(data, null, 2) + "\n");
173
- return true;
174
- }
175
- }
176
-
177
- return false;
146
+ const mocksConfig = global.config?.files?.mocks || {
147
+ name: "mocks",
148
+ extension: ["yaml", "yml", "json", "js"],
149
+ };
150
+ const extensions = Array.isArray(mocksConfig.extension)
151
+ ? mocksConfig.extension
152
+ : [mocksConfig.extension];
153
+
154
+ for (const ext of extensions) {
155
+ const filePath = path.join(componentDir, `${mocksConfig.name}.${ext}`);
156
+
157
+ let content;
158
+ try {
159
+ content = await readFile(filePath, "utf8");
160
+ } catch {
161
+ continue;
162
+ }
163
+
164
+ if (["yaml", "yml"].includes(ext)) {
165
+ /** @type {Record<string, unknown>} */
166
+ const data = /** @type {Record<string, unknown>} */ (
167
+ yaml.load(content) || {}
168
+ );
169
+ data.$assets = cleanAssets(assets);
170
+ await writeFile(filePath, yaml.dump(data, { indent: 2 }));
171
+ return true;
172
+ }
173
+
174
+ if (ext === "json") {
175
+ /** @type {Record<string, unknown>} */
176
+ const data = JSON.parse(content);
177
+ data.$assets = cleanAssets(assets);
178
+ await writeFile(filePath, JSON.stringify(data, null, 2) + "\n");
179
+ return true;
180
+ }
181
+ }
182
+
183
+ return false;
178
184
  }
179
185
 
180
186
  /**
@@ -183,14 +189,14 @@ async function updateMockFile(componentDir, assets) {
183
189
  * @returns {Partial<ComponentAssets>}
184
190
  */
185
191
  function cleanAssets(assets) {
186
- /** @type {Partial<ComponentAssets>} */
187
- const result = {};
188
- if (assets.css?.length > 0) {
189
- result.css = assets.css;
190
- }
191
-
192
- if (assets.js?.length > 0) {
193
- result.js = assets.js;
194
- }
195
- return result;
192
+ /** @type {Partial<ComponentAssets>} */
193
+ const result = {};
194
+ if (assets.css?.length > 0) {
195
+ result.css = assets.css;
196
+ }
197
+
198
+ if (assets.js?.length > 0) {
199
+ result.js = assets.js;
200
+ }
201
+ return result;
196
202
  }