@schalkneethling/miyagi-core 4.4.2 → 4.4.4

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 +120 -117
@@ -11,133 +11,133 @@ import { mergeRootDataWithVariationData } from "../resolve.js";
11
11
  * @returns {Promise<object|Array|string|boolean>} the resolved value from the mock data object
12
12
  */
13
13
  export const resolveRefs = async function (entry, component) {
14
- const messages = [];
15
-
16
- if (entry) {
17
- if (
18
- typeof entry === "string" ||
19
- typeof entry === "number" ||
20
- typeof entry === "boolean" ||
21
- entry instanceof Map ||
22
- entry === null
23
- ) {
24
- return {
25
- messages,
26
- data: entry,
27
- };
28
- }
29
-
30
- if (entry instanceof Array) {
31
- const o = [];
32
-
33
- for (const ent of entry) {
34
- let newComponent = component;
35
-
36
- if (ent.$ref) {
37
- if (!ent.$ref.startsWith("#/$defs/")) {
38
- if (ent.$ref.startsWith("/")) {
39
- ent.$ref = ent.$ref.replace("/", "");
40
- }
41
- const path = ent.$ref.split("#")[0];
42
- const { resolved, message } = resolveNamespace(path);
43
-
44
- if (resolved) {
45
- newComponent = global.state.routes.find(
46
- (route) => route.paths.dir.short === resolved,
47
- );
48
- } else {
49
- messages.push(message);
50
- }
51
- }
52
- }
53
-
54
- const json = await resolve(ent, newComponent);
55
- const result = await resolveRefs(json.data, newComponent);
56
-
57
- o.push(result.data);
58
-
59
- for (const msg of [...json.messages, ...result.messages]) {
60
- if (msg) {
61
- messages.push(msg);
62
- }
63
- }
64
- }
65
-
66
- return {
67
- messages,
68
- data: o,
69
- };
70
- }
71
-
72
- let o = entry;
73
-
74
- for (const [key, value] of Object.entries({ ...entry })) {
75
- if (key === "$ref") {
76
- let newComponent;
77
-
78
- if (value.startsWith("#/$defs/")) {
79
- newComponent = component;
80
- } else {
81
- let path = value.split("#")[0];
82
-
83
- if (path.startsWith("/")) {
84
- path = path.replace("/", "");
85
- }
86
-
87
- const { resolved, message } = resolveNamespace(path);
88
-
89
- if (resolved) {
90
- newComponent = global.state.routes.find(
91
- (route) => route.paths.dir.short === resolved,
92
- );
93
- } else {
94
- messages.push(message);
95
- }
96
- }
97
-
98
- let { message, data: resolvedValue } =
99
- await getRootOrVariantDataOfReference(value, newComponent);
100
-
101
- if (message) {
102
- messages.push(message);
103
- }
104
-
105
- const json = await resolve(resolvedValue, newComponent);
106
- const result = await resolveRefs(json.data, newComponent);
107
-
108
- for (const msg of [...json.messages, ...result.messages]) {
109
- if (msg) {
110
- messages.push(msg);
111
- }
112
- }
113
-
114
- o = { ...o, ...result.data };
115
-
116
- delete o.$ref;
117
- } else {
118
- const json = await resolve(value, component);
119
- const result = await resolveRefs(json.data, component);
120
-
121
- o[key] = result.data;
122
-
123
- for (const msg of [...json.messages, ...result.messages]) {
124
- if (msg) {
125
- messages.push(msg);
126
- }
127
- }
128
- }
129
- }
130
-
131
- return {
132
- messages,
133
- data: o,
134
- };
135
- }
136
-
137
- return {
138
- messages,
139
- data: entry,
140
- };
14
+ const messages = [];
15
+
16
+ if (entry) {
17
+ if (
18
+ typeof entry === "string" ||
19
+ typeof entry === "number" ||
20
+ typeof entry === "boolean" ||
21
+ entry instanceof Map ||
22
+ entry === null
23
+ ) {
24
+ return {
25
+ messages,
26
+ data: entry,
27
+ };
28
+ }
29
+
30
+ if (entry instanceof Array) {
31
+ const o = [];
32
+
33
+ for (const ent of entry) {
34
+ let newComponent = component;
35
+
36
+ if (ent.$ref) {
37
+ if (!ent.$ref.startsWith("#/$defs/")) {
38
+ if (ent.$ref.startsWith("/")) {
39
+ ent.$ref = ent.$ref.replace("/", "");
40
+ }
41
+ const path = ent.$ref.split("#")[0];
42
+ const { resolved, message } = resolveNamespace(path);
43
+
44
+ if (resolved) {
45
+ newComponent = global.state.routes.find(
46
+ (route) => route.paths.dir.short === resolved,
47
+ );
48
+ } else {
49
+ messages.push(message);
50
+ }
51
+ }
52
+ }
53
+
54
+ const json = await resolve(ent, newComponent);
55
+ const result = await resolveRefs(json.data, newComponent);
56
+
57
+ o.push(result.data);
58
+
59
+ for (const msg of [...json.messages, ...result.messages]) {
60
+ if (msg) {
61
+ messages.push(msg);
62
+ }
63
+ }
64
+ }
65
+
66
+ return {
67
+ messages,
68
+ data: o,
69
+ };
70
+ }
71
+
72
+ let o = entry;
73
+
74
+ for (const [key, value] of Object.entries({ ...entry })) {
75
+ if (key === "$ref") {
76
+ let newComponent;
77
+
78
+ if (value.startsWith("#/$defs/")) {
79
+ newComponent = component;
80
+ } else {
81
+ let path = value.split("#")[0];
82
+
83
+ if (path.startsWith("/")) {
84
+ path = path.replace("/", "");
85
+ }
86
+
87
+ const { resolved, message } = resolveNamespace(path);
88
+
89
+ if (resolved) {
90
+ newComponent = global.state.routes.find(
91
+ (route) => route.paths.dir.short === resolved,
92
+ );
93
+ } else {
94
+ messages.push(message);
95
+ }
96
+ }
97
+
98
+ let { message, data: resolvedValue } =
99
+ await getRootOrVariantDataOfReference(value, newComponent);
100
+
101
+ if (message) {
102
+ messages.push(message);
103
+ }
104
+
105
+ const json = await resolve(resolvedValue, newComponent);
106
+ const result = await resolveRefs(json.data, newComponent);
107
+
108
+ for (const msg of [...json.messages, ...result.messages]) {
109
+ if (msg) {
110
+ messages.push(msg);
111
+ }
112
+ }
113
+
114
+ o = { ...o, ...result.data };
115
+
116
+ delete o.$ref;
117
+ } else {
118
+ const json = await resolve(value, component);
119
+ const result = await resolveRefs(json.data, component);
120
+
121
+ o[key] = result.data;
122
+
123
+ for (const msg of [...json.messages, ...result.messages]) {
124
+ if (msg) {
125
+ messages.push(msg);
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+ return {
132
+ messages,
133
+ data: o,
134
+ };
135
+ }
136
+
137
+ return {
138
+ messages,
139
+ data: entry,
140
+ };
141
141
  };
142
142
 
143
143
  /**
@@ -146,98 +146,98 @@ export const resolveRefs = async function (entry, component) {
146
146
  * @returns {Promise<object|Array|string|boolean>} the resolved value from the mock data object
147
147
  */
148
148
  async function resolve(entry, component) {
149
- const messages = [];
150
-
151
- if (entry !== null) {
152
- if (Array.isArray(entry)) {
153
- return {
154
- messages,
155
- data: entry,
156
- };
157
- }
158
-
159
- if (
160
- typeof entry === "string" ||
161
- typeof entry === "number" ||
162
- typeof entry === "boolean" ||
163
- entry instanceof Map ||
164
- entry === null
165
- ) {
166
- return {
167
- messages,
168
- data: entry,
169
- };
170
- }
171
-
172
- if (entry === undefined) {
173
- return {
174
- messages: [
175
- ...messages,
176
- {
177
- type: "warn",
178
- text: t("referencedMockFileNotFound"),
179
- },
180
- ],
181
- data: entry,
182
- };
183
- }
184
-
185
- if (entry.$ref) {
186
- const customData = helpers.cloneDeep(entry);
187
- delete customData.$ref;
188
-
189
- let newComponent;
190
-
191
- if (entry.$ref.startsWith("#/$defs/")) {
192
- newComponent = component;
193
- } else {
194
- let path = entry.$ref.split("#")[0];
195
-
196
- if (path.startsWith("/")) {
197
- path = path.replace("/", "");
198
- }
199
-
200
- const { resolved, message } = resolveNamespace(path);
201
-
202
- if (resolved) {
203
- newComponent = global.state.routes.find(
204
- (route) => route.paths.dir.short === resolved,
205
- );
206
-
207
- if (!newComponent) {
208
- messages.push({
209
- type: "warn",
210
- text: `${resolved} not found`,
211
- });
212
- }
213
- } else {
214
- messages.push(message);
215
- }
216
- }
217
-
218
- if (newComponent) {
219
- const { message, data } = await getRootOrVariantDataOfReference(
220
- entry.$ref,
221
- newComponent,
222
- );
223
-
224
- return {
225
- messages: [...messages, message],
226
- data: deepMerge(data, customData),
227
- };
228
- } else {
229
- return {
230
- messages,
231
- data: customData,
232
- };
233
- }
234
- }
235
- }
236
-
237
- return {
238
- messages,
239
- data: entry,
240
- };
149
+ const messages = [];
150
+
151
+ if (entry !== null) {
152
+ if (Array.isArray(entry)) {
153
+ return {
154
+ messages,
155
+ data: entry,
156
+ };
157
+ }
158
+
159
+ if (
160
+ typeof entry === "string" ||
161
+ typeof entry === "number" ||
162
+ typeof entry === "boolean" ||
163
+ entry instanceof Map ||
164
+ entry === null
165
+ ) {
166
+ return {
167
+ messages,
168
+ data: entry,
169
+ };
170
+ }
171
+
172
+ if (entry === undefined) {
173
+ return {
174
+ messages: [
175
+ ...messages,
176
+ {
177
+ type: "warn",
178
+ text: t("referencedMockFileNotFound"),
179
+ },
180
+ ],
181
+ data: entry,
182
+ };
183
+ }
184
+
185
+ if (entry.$ref) {
186
+ const customData = helpers.cloneDeep(entry);
187
+ delete customData.$ref;
188
+
189
+ let newComponent;
190
+
191
+ if (entry.$ref.startsWith("#/$defs/")) {
192
+ newComponent = component;
193
+ } else {
194
+ let path = entry.$ref.split("#")[0];
195
+
196
+ if (path.startsWith("/")) {
197
+ path = path.replace("/", "");
198
+ }
199
+
200
+ const { resolved, message } = resolveNamespace(path);
201
+
202
+ if (resolved) {
203
+ newComponent = global.state.routes.find(
204
+ (route) => route.paths.dir.short === resolved,
205
+ );
206
+
207
+ if (!newComponent) {
208
+ messages.push({
209
+ type: "warn",
210
+ text: `${resolved} not found`,
211
+ });
212
+ }
213
+ } else {
214
+ messages.push(message);
215
+ }
216
+ }
217
+
218
+ if (newComponent) {
219
+ const { message, data } = await getRootOrVariantDataOfReference(
220
+ entry.$ref,
221
+ newComponent,
222
+ );
223
+
224
+ return {
225
+ messages: [...messages, message],
226
+ data: deepMerge(data, customData),
227
+ };
228
+ } else {
229
+ return {
230
+ messages,
231
+ data: customData,
232
+ };
233
+ }
234
+ }
235
+ }
236
+
237
+ return {
238
+ messages,
239
+ data: entry,
240
+ };
241
241
  }
242
242
 
243
243
  /**
@@ -246,203 +246,203 @@ async function resolve(entry, component) {
246
246
  * @returns {Promise<object>} the resolved data object
247
247
  */
248
248
  async function getRootOrVariantDataOfReference(ref, component) {
249
- const { mocks } = global.config.files;
250
-
251
- let [shortVal, variation] = ref.split("#");
252
- let jsonFromData;
253
- let mocksBaseName;
254
- let fullPath;
255
-
256
- if (ref.startsWith("#/$defs/")) {
257
- const componentJson = helpers.cloneDeep(
258
- global.state.fileContents[
259
- component.paths.mocks.full(global.config.files.mocks.extension[0])
260
- ] ||
261
- global.state.fileContents[
262
- component.paths.mocks.full(global.config.files.mocks.extension[1])
263
- ],
264
- );
265
-
266
- mocksBaseName = ref;
267
-
268
- const defRef = ref.replace("#/$defs/", "");
269
- if ("$defs" in componentJson && defRef in componentJson.$defs) {
270
- return {
271
- data: componentJson.$defs[defRef],
272
- };
273
- }
274
-
275
- return {
276
- message: {
277
- type: "warn",
278
- text: t("fileNotFoundLinkIncorrect")
279
- .replace("{{filePath}}", mocksBaseName)
280
- .replace(
281
- "{{component}}",
282
- component.paths.mocks.short(
283
- global.config.files.mocks.extension[0],
284
- ) ||
285
- component.paths.mocks.short(
286
- global.config.files.mocks.extension[1],
287
- ),
288
- ),
289
- },
290
- data: {},
291
- };
292
- }
293
-
294
- if (ref.startsWith(`${global.config.files.mocks.name}/#/$defs/`)) {
295
- const defaultFile = helpers.getFullPathFromShortPath(
296
- `${global.config.files.mocks.name}.${global.config.files.mocks.extension[0]}`,
297
- );
298
- const jsFile = helpers.getFullPathFromShortPath(
299
- `${global.config.files.mocks.name}.${global.config.files.mocks.extension[1]}`,
300
- );
301
- const globalData = {
302
- ...(global.state.fileContents[defaultFile] ||
303
- global.state.fileContents[jsFile]),
304
- };
305
-
306
- const defRef = ref.replace(
307
- `${global.config.files.mocks.name}/#/$defs/`,
308
- "",
309
- );
310
-
311
- if (defRef in globalData.$defs) {
312
- return {
313
- data: globalData.$defs[defRef],
314
- };
315
- }
316
-
317
- return {
318
- message: {
319
- type: "warn",
320
- text: t("fileNotFoundLinkIncorrect")
321
- .replace("{{filePath}}", ref)
322
- .replace(
323
- "{{component}}",
324
- component.paths.mocks.short(
325
- global.config.files.mocks.extension[0],
326
- ) ||
327
- component.paths.mocks.short(
328
- global.config.files.mocks.extension[1],
329
- ),
330
- ),
331
- },
332
- data: {},
333
- };
334
- }
335
-
336
- if (shortVal.startsWith("@")) {
337
- const namespace = shortVal.split("/")[0];
338
- const resolvedNamespace = global.config.namespaces[namespace];
339
-
340
- if (!resolvedNamespace) {
341
- return {
342
- message: {
343
- type: "warn",
344
- text: `Could not resolve namespace ${namespace}`,
345
- },
346
- data: null,
347
- };
348
- }
349
-
350
- shortVal = path.relative(namespace, shortVal);
351
- mocksBaseName = path.join(shortVal, mocks.name);
352
- fullPath = path.join(
353
- process.cwd(),
354
- resolvedNamespace,
355
- shortVal,
356
- mocks.name,
357
- );
358
- } else {
359
- mocksBaseName = path.join(shortVal, mocks.name);
360
- fullPath = helpers.getFullPathFromShortPath(mocksBaseName);
361
- }
362
-
363
- jsonFromData =
364
- global.state.fileContents[`${fullPath}.${mocks.extension[0]}`] ||
365
- global.state.fileContents[`${fullPath}.${mocks.extension[1]}`];
366
-
367
- if (jsonFromData) {
368
- if (variation?.startsWith("/$defs/") && "$defs" in jsonFromData) {
369
- const defRef = variation.replace("/$defs/", "");
370
-
371
- if (defRef in jsonFromData.$defs) {
372
- return {
373
- data: jsonFromData.$defs[defRef],
374
- };
375
- }
376
-
377
- return {
378
- message: {
379
- type: "warn",
380
- text: t("fileNotFoundLinkIncorrect")
381
- .replace("{{filePath}}", ref)
382
- .replace(
383
- "{{component}}",
384
- component.paths.mocks.short(
385
- global.config.files.mocks.extension[0],
386
- ) ||
387
- component.paths.mocks.short(
388
- global.config.files.mocks.extension[1],
389
- ),
390
- ),
391
- },
392
- data: {},
393
- };
394
- }
395
-
396
- const embeddedJson = jsonFromData;
397
- const rootJson = helpers.removeInternalKeys(embeddedJson);
398
- let variantJson = {};
399
- let message;
400
-
401
- if (variation && embeddedJson.$variants && embeddedJson.$variants.length) {
402
- const variant = embeddedJson.$variants.find((vari) => {
403
- if (vari.$name) {
404
- return (
405
- helpers.normalizeString(vari.$name) ===
406
- helpers.normalizeString(variation)
407
- );
408
- }
409
- return false;
410
- });
411
-
412
- if (variant) {
413
- variantJson = helpers.removeInternalKeys(variant);
414
- } else {
415
- message = {
416
- type: "warn",
417
- text: t("variationNotFound")
418
- .replace("{{variation}}", variation)
419
- .replace("{{fileName}}", mocksBaseName),
420
- };
421
- }
422
- }
423
-
424
- return {
425
- message,
426
- data: mergeRootDataWithVariationData(
427
- helpers.cloneDeep(rootJson),
428
- variantJson,
429
- ),
430
- };
431
- }
432
-
433
- return {
434
- message: {
435
- type: "warn",
436
- text: t("fileNotFoundLinkIncorrect")
437
- .replace("{{filePath}}", mocksBaseName)
438
- .replace(
439
- "{{component}}",
440
- component.paths.mocks.short(global.config.files.mocks.extension[0]) ||
441
- component.paths.mocks.short(global.config.files.mocks.extension[1]),
442
- ),
443
- },
444
- data: {},
445
- };
249
+ const { mocks } = global.config.files;
250
+
251
+ let [shortVal, variation] = ref.split("#");
252
+ let jsonFromData;
253
+ let mocksBaseName;
254
+ let fullPath;
255
+
256
+ if (ref.startsWith("#/$defs/")) {
257
+ const componentJson = helpers.cloneDeep(
258
+ global.state.fileContents[
259
+ component.paths.mocks.full(global.config.files.mocks.extension[0])
260
+ ] ||
261
+ global.state.fileContents[
262
+ component.paths.mocks.full(global.config.files.mocks.extension[1])
263
+ ],
264
+ );
265
+
266
+ mocksBaseName = ref;
267
+
268
+ const defRef = ref.replace("#/$defs/", "");
269
+ if ("$defs" in componentJson && defRef in componentJson.$defs) {
270
+ return {
271
+ data: componentJson.$defs[defRef],
272
+ };
273
+ }
274
+
275
+ return {
276
+ message: {
277
+ type: "warn",
278
+ text: t("fileNotFoundLinkIncorrect")
279
+ .replace("{{filePath}}", mocksBaseName)
280
+ .replace(
281
+ "{{component}}",
282
+ component.paths.mocks.short(
283
+ global.config.files.mocks.extension[0],
284
+ ) ||
285
+ component.paths.mocks.short(
286
+ global.config.files.mocks.extension[1],
287
+ ),
288
+ ),
289
+ },
290
+ data: {},
291
+ };
292
+ }
293
+
294
+ if (ref.startsWith(`${global.config.files.mocks.name}/#/$defs/`)) {
295
+ const defaultFile = helpers.getFullPathFromShortPath(
296
+ `${global.config.files.mocks.name}.${global.config.files.mocks.extension[0]}`,
297
+ );
298
+ const jsFile = helpers.getFullPathFromShortPath(
299
+ `${global.config.files.mocks.name}.${global.config.files.mocks.extension[1]}`,
300
+ );
301
+ const globalData = {
302
+ ...(global.state.fileContents[defaultFile] ||
303
+ global.state.fileContents[jsFile]),
304
+ };
305
+
306
+ const defRef = ref.replace(
307
+ `${global.config.files.mocks.name}/#/$defs/`,
308
+ "",
309
+ );
310
+
311
+ if (defRef in globalData.$defs) {
312
+ return {
313
+ data: globalData.$defs[defRef],
314
+ };
315
+ }
316
+
317
+ return {
318
+ message: {
319
+ type: "warn",
320
+ text: t("fileNotFoundLinkIncorrect")
321
+ .replace("{{filePath}}", ref)
322
+ .replace(
323
+ "{{component}}",
324
+ component.paths.mocks.short(
325
+ global.config.files.mocks.extension[0],
326
+ ) ||
327
+ component.paths.mocks.short(
328
+ global.config.files.mocks.extension[1],
329
+ ),
330
+ ),
331
+ },
332
+ data: {},
333
+ };
334
+ }
335
+
336
+ if (shortVal.startsWith("@")) {
337
+ const namespace = shortVal.split("/")[0];
338
+ const resolvedNamespace = global.config.namespaces[namespace];
339
+
340
+ if (!resolvedNamespace) {
341
+ return {
342
+ message: {
343
+ type: "warn",
344
+ text: `Could not resolve namespace ${namespace}`,
345
+ },
346
+ data: null,
347
+ };
348
+ }
349
+
350
+ shortVal = path.relative(namespace, shortVal);
351
+ mocksBaseName = path.join(shortVal, mocks.name);
352
+ fullPath = path.join(
353
+ process.cwd(),
354
+ resolvedNamespace,
355
+ shortVal,
356
+ mocks.name,
357
+ );
358
+ } else {
359
+ mocksBaseName = path.join(shortVal, mocks.name);
360
+ fullPath = helpers.getFullPathFromShortPath(mocksBaseName);
361
+ }
362
+
363
+ jsonFromData =
364
+ global.state.fileContents[`${fullPath}.${mocks.extension[0]}`] ||
365
+ global.state.fileContents[`${fullPath}.${mocks.extension[1]}`];
366
+
367
+ if (jsonFromData) {
368
+ if (variation?.startsWith("/$defs/") && "$defs" in jsonFromData) {
369
+ const defRef = variation.replace("/$defs/", "");
370
+
371
+ if (defRef in jsonFromData.$defs) {
372
+ return {
373
+ data: jsonFromData.$defs[defRef],
374
+ };
375
+ }
376
+
377
+ return {
378
+ message: {
379
+ type: "warn",
380
+ text: t("fileNotFoundLinkIncorrect")
381
+ .replace("{{filePath}}", ref)
382
+ .replace(
383
+ "{{component}}",
384
+ component.paths.mocks.short(
385
+ global.config.files.mocks.extension[0],
386
+ ) ||
387
+ component.paths.mocks.short(
388
+ global.config.files.mocks.extension[1],
389
+ ),
390
+ ),
391
+ },
392
+ data: {},
393
+ };
394
+ }
395
+
396
+ const embeddedJson = jsonFromData;
397
+ const rootJson = helpers.removeInternalKeys(embeddedJson);
398
+ let variantJson = {};
399
+ let message;
400
+
401
+ if (variation && embeddedJson.$variants && embeddedJson.$variants.length) {
402
+ const variant = embeddedJson.$variants.find((vari) => {
403
+ if (vari.$name) {
404
+ return (
405
+ helpers.normalizeString(vari.$name) ===
406
+ helpers.normalizeString(variation)
407
+ );
408
+ }
409
+ return false;
410
+ });
411
+
412
+ if (variant) {
413
+ variantJson = helpers.removeInternalKeys(variant);
414
+ } else {
415
+ message = {
416
+ type: "warn",
417
+ text: t("variationNotFound")
418
+ .replace("{{variation}}", variation)
419
+ .replace("{{fileName}}", mocksBaseName),
420
+ };
421
+ }
422
+ }
423
+
424
+ return {
425
+ message,
426
+ data: mergeRootDataWithVariationData(
427
+ helpers.cloneDeep(rootJson),
428
+ variantJson,
429
+ ),
430
+ };
431
+ }
432
+
433
+ return {
434
+ message: {
435
+ type: "warn",
436
+ text: t("fileNotFoundLinkIncorrect")
437
+ .replace("{{filePath}}", mocksBaseName)
438
+ .replace(
439
+ "{{component}}",
440
+ component.paths.mocks.short(global.config.files.mocks.extension[0]) ||
441
+ component.paths.mocks.short(global.config.files.mocks.extension[1]),
442
+ ),
443
+ },
444
+ data: {},
445
+ };
446
446
  }
447
447
 
448
448
  /**
@@ -450,35 +450,35 @@ async function getRootOrVariantDataOfReference(ref, component) {
450
450
  * @returns {object}
451
451
  */
452
452
  function resolveNamespace(namespacedPath) {
453
- if (
454
- !Object.keys(global.config.namespaces).some((namespace) =>
455
- namespacedPath.startsWith(namespace),
456
- )
457
- ) {
458
- return {
459
- resolved: namespacedPath,
460
- };
461
- }
462
-
463
- const namespace = namespacedPath.split("/")[0];
464
- const resolvedNamespace = global.config.namespaces[namespace];
465
-
466
- if (!resolvedNamespace) {
467
- return {
468
- message: {
469
- type: "warn",
470
- text: `Could not resolve namespace ${namespace}`,
471
- },
472
- resolved: null,
473
- };
474
- }
475
-
476
- return {
477
- resolved: namespacedPath.replace(
478
- namespace,
479
- helpers.getShortPathFromFullPath(
480
- path.join(process.cwd(), resolvedNamespace),
481
- ),
482
- ),
483
- };
453
+ if (
454
+ !Object.keys(global.config.namespaces).some((namespace) =>
455
+ namespacedPath.startsWith(namespace),
456
+ )
457
+ ) {
458
+ return {
459
+ resolved: namespacedPath,
460
+ };
461
+ }
462
+
463
+ const namespace = namespacedPath.split("/")[0];
464
+ const resolvedNamespace = global.config.namespaces[namespace];
465
+
466
+ if (!resolvedNamespace) {
467
+ return {
468
+ message: {
469
+ type: "warn",
470
+ text: `Could not resolve namespace ${namespace}`,
471
+ },
472
+ resolved: null,
473
+ };
474
+ }
475
+
476
+ return {
477
+ resolved: namespacedPath.replace(
478
+ namespace,
479
+ helpers.getShortPathFromFullPath(
480
+ path.join(process.cwd(), resolvedNamespace),
481
+ ),
482
+ ),
483
+ };
484
484
  }