@schalkneethling/miyagi-core 4.4.0 → 4.4.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.
- package/lib/default-config.js +170 -169
- package/lib/init/router.js +205 -205
- package/lib/init/watcher.js +704 -671
- package/lib/validator/schemas.js +58 -0
- package/package.json +1 -1
package/lib/init/router.js
CHANGED
|
@@ -14,17 +14,17 @@ import log from "../logger.js";
|
|
|
14
14
|
* @returns {object} the mock data of the given component
|
|
15
15
|
*/
|
|
16
16
|
function getDataForComponent(component) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const { fileContents } = global.state;
|
|
18
|
+
const { name, extension } = global.config.files.mocks;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const defaultPath = path.join(
|
|
21
|
+
component.paths.dir.full,
|
|
22
|
+
`${name}.${extension[0]}`,
|
|
23
|
+
);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const jsPath = path.join(component.paths.dir.full, `${name}.${extension[1]}`);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
return fileContents[defaultPath] || fileContents[jsPath];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -33,7 +33,7 @@ function getDataForComponent(component) {
|
|
|
33
33
|
* @returns {boolean} is true of the requested variation is in the given mock data
|
|
34
34
|
*/
|
|
35
35
|
function checkIfDataIncludesVariation(data, variation) {
|
|
36
|
-
|
|
36
|
+
return data?.$variants?.find((variant) => variant.$name === variation);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -42,209 +42,209 @@ function checkIfDataIncludesVariation(data, variation) {
|
|
|
42
42
|
* @returns {boolean} is true if the requested variation exists in the mock data of the given component
|
|
43
43
|
*/
|
|
44
44
|
function checkIfRequestedVariationIsValid(component, variation) {
|
|
45
|
-
|
|
45
|
+
const data = getDataForComponent(component);
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
if (
|
|
48
|
+
data &&
|
|
49
|
+
(variation === data.$name || variation === config.defaultVariationName) &&
|
|
50
|
+
!data.$hidden
|
|
51
|
+
) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
if (!data && variation === config.defaultVariationName) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
return checkIfDataIncludesVariation(data, variation);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* @returns {void}
|
|
64
64
|
*/
|
|
65
65
|
export default function Router() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
66
|
+
global.app.get("/design-tokens/colors", async (req, res) => {
|
|
67
|
+
return render.renderMainDesignTokens({
|
|
68
|
+
res,
|
|
69
|
+
cookies: req.cookies,
|
|
70
|
+
type: "colors",
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
global.app.get("/iframe/design-tokens/colors", async (req, res) => {
|
|
75
|
+
return render.iframe.designTokens.colors({ res, cookies: req.cookies });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
global.app.get("/design-tokens/sizes", async (req, res) => {
|
|
79
|
+
return render.renderMainDesignTokens({
|
|
80
|
+
res,
|
|
81
|
+
cookies: req.cookies,
|
|
82
|
+
type: "sizes",
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
global.app.get("/iframe/design-tokens/sizes", async (req, res) => {
|
|
87
|
+
return render.iframe.designTokens.sizes({ res, cookies: req.cookies });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
global.app.get("/design-tokens/typography", async (req, res) => {
|
|
91
|
+
return render.renderMainDesignTokens({
|
|
92
|
+
res,
|
|
93
|
+
cookies: req.cookies,
|
|
94
|
+
type: "typography",
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
global.app.get("/iframe/design-tokens/typography", async (req, res) => {
|
|
99
|
+
return render.iframe.designTokens.typography({
|
|
100
|
+
res,
|
|
101
|
+
cookies: req.cookies,
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
global.app.get("/show", async (req, res) => {
|
|
106
|
+
const { file, variation } = req.query;
|
|
107
|
+
|
|
108
|
+
if (!file) {
|
|
109
|
+
return res.redirect(302, "/");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (file === "all") {
|
|
113
|
+
return await render.renderMainIndex({ res, cookies: req.cookies });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const routesEntry = global.state.routes.find(
|
|
117
|
+
(route) => route.paths.dir.short === file,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (!routesEntry) {
|
|
121
|
+
return res.redirect(302, "/");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
switch (routesEntry.type) {
|
|
125
|
+
case "components": {
|
|
126
|
+
if (!routesEntry.paths.tpl) {
|
|
127
|
+
return await render.renderMainComponentDocs({
|
|
128
|
+
res,
|
|
129
|
+
component: routesEntry,
|
|
130
|
+
cookies: req.cookies,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return await render.renderMainComponent(
|
|
135
|
+
checkIfRequestedVariationIsValid(routesEntry, variation)
|
|
136
|
+
? {
|
|
137
|
+
res,
|
|
138
|
+
component: routesEntry,
|
|
139
|
+
cookies: req.cookies,
|
|
140
|
+
variation,
|
|
141
|
+
}
|
|
142
|
+
: {
|
|
143
|
+
res,
|
|
144
|
+
component: routesEntry,
|
|
145
|
+
cookies: req.cookies,
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case "docs": {
|
|
151
|
+
return await render.renderMainDocs({
|
|
152
|
+
res,
|
|
153
|
+
doc: routesEntry,
|
|
154
|
+
cookies: req.cookies,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
default:
|
|
159
|
+
return res.redirect(302, "/");
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
global.app.get("/component", async (req, res) => {
|
|
164
|
+
const { file, variation, embedded } = req.query;
|
|
165
|
+
|
|
166
|
+
if (!file) {
|
|
167
|
+
return res.redirect(302, global.config.indexPath.default);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (file === "all") {
|
|
171
|
+
return await render.renderIframeIndex({ res, cookies: req.cookies });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const routesEntry = global.state.routes.find(
|
|
175
|
+
(route) => route.paths.dir.short === file,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
if (!routesEntry) {
|
|
179
|
+
return res.redirect(302, global.config.indexPath.default);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
switch (routesEntry.type) {
|
|
183
|
+
case "components": {
|
|
184
|
+
if (!routesEntry.paths.tpl) {
|
|
185
|
+
return await render.renderIframeComponentDocs({
|
|
186
|
+
res,
|
|
187
|
+
component: routesEntry,
|
|
188
|
+
cookies: req.cookies,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
!variation ||
|
|
194
|
+
!checkIfRequestedVariationIsValid(routesEntry, variation)
|
|
195
|
+
) {
|
|
196
|
+
return await render.renderIframeComponent({
|
|
197
|
+
res,
|
|
198
|
+
component: routesEntry,
|
|
199
|
+
cookies: req.cookies,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const data = await getVariationData(routesEntry, decodeURI(variation));
|
|
204
|
+
|
|
205
|
+
if (embedded) {
|
|
206
|
+
return await render.renderIframeVariation({
|
|
207
|
+
res,
|
|
208
|
+
component: routesEntry,
|
|
209
|
+
variation,
|
|
210
|
+
cookies: req.cookies,
|
|
211
|
+
data,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (data?.messages?.length) {
|
|
216
|
+
for (const { type, text, verbose } of data.messages) {
|
|
217
|
+
log(type, text, verbose);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return await render.renderIframeVariationStandalone({
|
|
222
|
+
res,
|
|
223
|
+
component: routesEntry,
|
|
224
|
+
componentData: data?.resolved ?? {},
|
|
225
|
+
componentDeclaredAssets: data?.$assets || null,
|
|
226
|
+
cookies: req.cookies,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
case "docs": {
|
|
231
|
+
return await render.renderIframeDocs({
|
|
232
|
+
res,
|
|
233
|
+
doc: routesEntry,
|
|
234
|
+
cookies: req.cookies,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
default:
|
|
239
|
+
res.redirect(302, global.config.indexPath.default);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
global.app.get("/", async (req, res) => {
|
|
244
|
+
await render.renderMainIndex({ res, cookies: req.cookies });
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
global.app.all("*splat", async (req, res) => {
|
|
248
|
+
res.sendStatus(404);
|
|
249
|
+
});
|
|
250
250
|
}
|