slicejs-cli 4.2.0 → 4.4.0
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/LICENSE +21 -21
- package/README.md +260 -257
- package/client.js +927 -780
- package/commands/Print.js +163 -163
- package/commands/Validations.js +92 -92
- package/commands/build/build.js +97 -107
- package/commands/buildProduction/buildProduction.js +613 -613
- package/commands/bundle/bundle.js +251 -239
- package/commands/createComponent/VisualComponentTemplate.js +55 -55
- package/commands/createComponent/createComponent.js +128 -128
- package/commands/deleteComponent/deleteComponent.js +81 -81
- package/commands/docs/docs.js +365 -0
- package/commands/doctor/doctor.js +677 -563
- package/commands/getComponent/getComponent.js +842 -842
- package/commands/init/init.js +526 -475
- package/commands/lint/lint.js +75 -0
- package/commands/lint/types.js +85 -0
- package/commands/listComponents/listComponents.js +172 -172
- package/commands/seo/check.js +91 -0
- package/commands/seo/images.js +586 -0
- package/commands/seo/sitemap.js +106 -0
- package/commands/seo/support.js +130 -0
- package/commands/setup/lint.js +151 -0
- package/commands/skill/skill.js +236 -236
- package/commands/startServer/startServer.js +240 -240
- package/commands/startServer/watchServer.js +66 -66
- package/commands/typecheck/typecheck.js +83 -0
- package/commands/types/types.js +1378 -1097
- package/commands/utils/JsMinifier.js +230 -230
- package/commands/utils/LocalCliDelegation.js +78 -53
- package/commands/utils/PackageManager.js +148 -148
- package/commands/utils/PathHelper.js +87 -75
- package/commands/utils/ProjectValidation.js +274 -0
- package/commands/utils/SourceDiagnostics.js +201 -201
- package/commands/utils/VersionChecker.js +169 -169
- package/commands/utils/analyzeSource.js +77 -77
- package/commands/utils/bundling/BundleGenerator.js +3748 -3776
- package/commands/utils/bundling/DependencyAnalyzer.js +976 -976
- package/commands/utils/bundling/ExternalModuleBundler.js +298 -298
- package/commands/utils/componentAudit.js +74 -0
- package/commands/utils/compressAssets.js +103 -103
- package/commands/utils/cssScope.js +83 -0
- package/commands/utils/loadConfig.js +31 -31
- package/commands/utils/semver.js +66 -0
- package/commands/utils/sliceConfigSchema.js +72 -0
- package/commands/utils/sliceScripts.js +48 -48
- package/commands/utils/updateManager.js +471 -471
- package/eslint-config.js +128 -0
- package/package.json +19 -13
|
@@ -1,563 +1,677 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { createServer } from 'net';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import Table from 'cli-table3';
|
|
6
|
-
import Print from '../Print.js';
|
|
7
|
-
import { getProjectRoot, getSrcPath, getApiPath, getConfigPath, getPath, getComponentsJsPath } from '../utils/PathHelper.js';
|
|
8
|
-
import { resolvePackageManager, installCommand } from '../utils/PackageManager.js';
|
|
9
|
-
import updateManager from '../utils/updateManager.js';
|
|
10
|
-
import { parseComponentsRegistry
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
pass:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
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
|
-
try {
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
*
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
{
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
if (
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { createServer } from 'net';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import Table from 'cli-table3';
|
|
6
|
+
import Print from '../Print.js';
|
|
7
|
+
import { getProjectRoot, getSrcPath, getApiPath, getConfigPath, getPath, getComponentsJsPath } from '../utils/PathHelper.js';
|
|
8
|
+
import { resolvePackageManager, installCommand } from '../utils/PackageManager.js';
|
|
9
|
+
import updateManager from '../utils/updateManager.js';
|
|
10
|
+
import { parseComponentsRegistry } from '../types/types.js';
|
|
11
|
+
import { validateConfigRules, validateProject, validateServerEntry, classifyValidation, describeIssue } from '../utils/ProjectValidation.js';
|
|
12
|
+
import { loadConfigSchema, validateAgainstSchema } from '../utils/sliceConfigSchema.js';
|
|
13
|
+
import { rangeMismatch } from '../utils/semver.js';
|
|
14
|
+
import { parse as parseModule } from '@babel/parser';
|
|
15
|
+
import traverse from '@babel/traverse';
|
|
16
|
+
import ExternalModuleBundler from '../utils/bundling/ExternalModuleBundler.js';
|
|
17
|
+
import { loadFrameworkSeo, loadManifest } from '../seo/support.js';
|
|
18
|
+
import { loadRoutes } from '../seo/check.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* SEO: is it configured, and is it safe to deploy?
|
|
22
|
+
*
|
|
23
|
+
* Warns rather than fails for an unconfigured project (SEO is opt-in), and
|
|
24
|
+
* fails only for input the user has to fix. The rules are the framework's
|
|
25
|
+
* validator, the same one `slice seo check` uses, so the two cannot disagree.
|
|
26
|
+
*/
|
|
27
|
+
async function checkSeoConfiguration() {
|
|
28
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
29
|
+
|
|
30
|
+
if (!fs.existsSync(path.join(projectRoot, 'api', 'index.js'))) {
|
|
31
|
+
return { pass: true, message: 'Not a server app (no api/index.js)' };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let loaded;
|
|
35
|
+
try {
|
|
36
|
+
loaded = loadManifest(projectRoot);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
message: `seo.json is not valid JSON: ${error.message}`,
|
|
40
|
+
suggestion: 'Fix the file: the server fails at startup on the same error'
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { manifest } = loaded;
|
|
45
|
+
if (!manifest) {
|
|
46
|
+
return {
|
|
47
|
+
warn: true,
|
|
48
|
+
message: 'Not configured: every route shares one <head> and unknown paths answer 200',
|
|
49
|
+
suggestion: 'Add seo.json and pass it to createSliceServer({ seo: { manifest: "seo.json" } })'
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let framework;
|
|
54
|
+
try {
|
|
55
|
+
framework = await loadFrameworkSeo(projectRoot);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return { warn: true, message: `seo.json exists, but the installed framework has no SEO module: ${error.message}` };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const routes = await loadRoutes(projectRoot).catch(() => []);
|
|
61
|
+
const { errors, warnings } = framework.validateSeoManifest(manifest, {
|
|
62
|
+
routes,
|
|
63
|
+
publicDir: path.join(projectRoot, 'src', 'public')
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// The sitemap is a committed artifact, so a stale one is a deploy problem.
|
|
67
|
+
if (manifest.sitemap !== false) {
|
|
68
|
+
const sitemapFile = path.join(projectRoot, 'src', 'public', 'sitemap.xml');
|
|
69
|
+
const origin = framework.normalizeOrigin(manifest.origin);
|
|
70
|
+
if (!fs.existsSync(sitemapFile)) {
|
|
71
|
+
warnings.push('sitemap.xml is missing: run `slice seo sitemap`');
|
|
72
|
+
} else if (origin && fs.readFileSync(sitemapFile, 'utf8') !== framework.buildSitemap({ manifest, origin })) {
|
|
73
|
+
warnings.push('sitemap.xml is out of date: run `slice seo sitemap`');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const routeCount = Object.keys(manifest.routes || {}).length;
|
|
78
|
+
|
|
79
|
+
if (errors.length) {
|
|
80
|
+
return {
|
|
81
|
+
message: `${errors.length} problem(s) in seo.json: ${errors[0]}`,
|
|
82
|
+
suggestion: errors.length > 1 ? `${errors[1]} (run \`slice seo check\` for the full list)` : 'Run `slice seo check`'
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (warnings.length) {
|
|
87
|
+
return {
|
|
88
|
+
warn: true,
|
|
89
|
+
message: `origin ${manifest.origin}, ${routeCount} routes — ${warnings.length} warning(s): ${warnings[0]}`,
|
|
90
|
+
suggestion: warnings.length > 1 ? `${warnings[1]} (run \`slice seo check\` for the full list)` : undefined
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
pass: true,
|
|
96
|
+
message: `origin ${manifest.origin}, ${routeCount} routes, sitemap ${manifest.sitemap === false ? 'off' : 'ok'}`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Checks the Node.js version
|
|
102
|
+
*/
|
|
103
|
+
async function checkNodeVersion() {
|
|
104
|
+
const currentVersion = process.version;
|
|
105
|
+
const majorVersion = parseInt(currentVersion.slice(1).split('.')[0]);
|
|
106
|
+
const required = 20;
|
|
107
|
+
|
|
108
|
+
if (majorVersion >= required) {
|
|
109
|
+
return {
|
|
110
|
+
pass: true,
|
|
111
|
+
message: `Node.js version: ${currentVersion} (required: >= v${required})`
|
|
112
|
+
};
|
|
113
|
+
} else {
|
|
114
|
+
return {
|
|
115
|
+
pass: false,
|
|
116
|
+
message: `Node.js version: ${currentVersion} (required: >= v${required})`,
|
|
117
|
+
suggestion: `Update Node.js to v${required} or higher`
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Checks the directory structure
|
|
124
|
+
*/
|
|
125
|
+
async function checkDirectoryStructure() {
|
|
126
|
+
const srcPath = getSrcPath(import.meta.url);
|
|
127
|
+
const apiPath = getApiPath(import.meta.url);
|
|
128
|
+
|
|
129
|
+
const srcExists = await fs.pathExists(srcPath);
|
|
130
|
+
const apiExists = await fs.pathExists(apiPath);
|
|
131
|
+
|
|
132
|
+
if (srcExists && apiExists) {
|
|
133
|
+
return {
|
|
134
|
+
pass: true,
|
|
135
|
+
message: 'Project structure (src/ and api/) exists'
|
|
136
|
+
};
|
|
137
|
+
} else {
|
|
138
|
+
const missing = [];
|
|
139
|
+
if (!srcExists) missing.push('src/');
|
|
140
|
+
if (!apiExists) missing.push('api/');
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
pass: false,
|
|
144
|
+
message: `Missing directories: ${missing.join(', ')}`,
|
|
145
|
+
suggestion: 'Run "slice init" to initialize your project'
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Checks sliceConfig.json
|
|
152
|
+
*/
|
|
153
|
+
async function checkConfig() {
|
|
154
|
+
const configPath = getConfigPath(import.meta.url);
|
|
155
|
+
|
|
156
|
+
if (!await fs.pathExists(configPath)) {
|
|
157
|
+
return {
|
|
158
|
+
pass: false,
|
|
159
|
+
message: 'sliceConfig.json not found',
|
|
160
|
+
suggestion: 'Run "slice init" to create configuration'
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
const config = await fs.readJson(configPath);
|
|
166
|
+
|
|
167
|
+
if (!config.paths || !config.paths.components) {
|
|
168
|
+
return {
|
|
169
|
+
pass: false,
|
|
170
|
+
message: 'sliceConfig.json is invalid (missing paths.components)',
|
|
171
|
+
suggestion: 'Check your configuration file'
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// The framework publishes a JSON Schema for this file and nothing read
|
|
176
|
+
// it. Type errors are silent killers: `"port": "3001"` makes listen()
|
|
177
|
+
// open a pipe, `"enabled": "false"` is truthy.
|
|
178
|
+
const schema = await loadConfigSchema(getProjectRoot(import.meta.url));
|
|
179
|
+
if (schema) {
|
|
180
|
+
const schemaIssues = validateAgainstSchema(config, schema);
|
|
181
|
+
if (schemaIssues.length > 0) {
|
|
182
|
+
return {
|
|
183
|
+
pass: false,
|
|
184
|
+
message: `sliceConfig.json does not match the published schema: ${schemaIssues[0].path} ${schemaIssues[0].message}`,
|
|
185
|
+
suggestion: schemaIssues
|
|
186
|
+
.slice(0, 5)
|
|
187
|
+
.map((issue) => `${issue.path} ${issue.message}`)
|
|
188
|
+
.join('\n') + (schemaIssues.length > 5 ? `\n… ${schemaIssues.length - 5} more` : '')
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Same rules `slice build` applies before bundling. A config that passes
|
|
194
|
+
// here but blocks the build is worse than no check at all.
|
|
195
|
+
const ruleProblems = validateConfigRules(config);
|
|
196
|
+
if (ruleProblems.length > 0) {
|
|
197
|
+
return {
|
|
198
|
+
pass: false,
|
|
199
|
+
message: `sliceConfig.json would build a broken bundle: ${ruleProblems[0].path}`,
|
|
200
|
+
suggestion: ruleProblems.map((problem) => `${problem.path} ${problem.message}`).join('\n')
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
pass: true,
|
|
206
|
+
message: 'sliceConfig.json is valid'
|
|
207
|
+
};
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return {
|
|
210
|
+
pass: false,
|
|
211
|
+
message: `sliceConfig.json is invalid JSON: ${error.message}`,
|
|
212
|
+
suggestion: 'Fix JSON syntax errors in sliceConfig.json'
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Checks port availability
|
|
219
|
+
*/
|
|
220
|
+
async function checkPort() {
|
|
221
|
+
const configPath = getConfigPath(import.meta.url);
|
|
222
|
+
let port = 3000;
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
if (await fs.pathExists(configPath)) {
|
|
226
|
+
const config = await fs.readJson(configPath);
|
|
227
|
+
port = config.server?.port || 3000;
|
|
228
|
+
}
|
|
229
|
+
} catch { /* config missing or unreadable — use default port */ }
|
|
230
|
+
|
|
231
|
+
return new Promise((resolve) => {
|
|
232
|
+
const server = createServer();
|
|
233
|
+
|
|
234
|
+
server.once('error', (err) => {
|
|
235
|
+
if (err.code === 'EADDRINUSE') {
|
|
236
|
+
resolve({
|
|
237
|
+
warn: true,
|
|
238
|
+
message: `Port ${port} is already in use`,
|
|
239
|
+
suggestion: `Stop the process using port ${port} or use: slice dev -p <other-port>`
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
resolve({
|
|
243
|
+
pass: true,
|
|
244
|
+
message: `Port ${port} is available`
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
server.once('listening', () => {
|
|
250
|
+
server.close();
|
|
251
|
+
resolve({
|
|
252
|
+
pass: true,
|
|
253
|
+
message: `Port ${port} is available`
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
server.listen(port);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Checks the package manager setup: mixed lockfiles, packageManager field
|
|
263
|
+
* consistency, and a project-local CLI install (required for local delegation).
|
|
264
|
+
* Exported for tests.
|
|
265
|
+
*/
|
|
266
|
+
export async function checkPackageManagerSetup(projectRoot = getProjectRoot(import.meta.url)) {
|
|
267
|
+
const issues = [];
|
|
268
|
+
const suggestions = [];
|
|
269
|
+
|
|
270
|
+
const LOCKFILE_PM = {
|
|
271
|
+
'package-lock.json': 'npm',
|
|
272
|
+
'pnpm-lock.yaml': 'pnpm'
|
|
273
|
+
};
|
|
274
|
+
const lockfiles = [];
|
|
275
|
+
for (const lockfile of Object.keys(LOCKFILE_PM)) {
|
|
276
|
+
if (await fs.pathExists(path.join(projectRoot, lockfile))) {
|
|
277
|
+
lockfiles.push(lockfile);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
let pkg = null;
|
|
282
|
+
const pkgPath = path.join(projectRoot, 'package.json');
|
|
283
|
+
if (await fs.pathExists(pkgPath)) {
|
|
284
|
+
try { pkg = await fs.readJson(pkgPath); } catch { /* reported by Dependencies check */ }
|
|
285
|
+
}
|
|
286
|
+
const pmField = typeof pkg?.packageManager === 'string' ? pkg.packageManager.split('@')[0] : null;
|
|
287
|
+
const pm = resolvePackageManager(projectRoot).name;
|
|
288
|
+
|
|
289
|
+
if (lockfiles.length > 1) {
|
|
290
|
+
issues.push(`Mixed lockfiles found: ${lockfiles.join(', ')}`);
|
|
291
|
+
const keep = pmField || pm;
|
|
292
|
+
const keepLockfile = Object.entries(LOCKFILE_PM).find(([, name]) => name === keep)?.[0];
|
|
293
|
+
suggestions.push(`Keep only ${keepLockfile ?? 'the lockfile of your package manager'} and delete the rest`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (pkg && !pmField) {
|
|
297
|
+
issues.push('No "packageManager" field in package.json');
|
|
298
|
+
suggestions.push(`Pin it (e.g. "packageManager": "${pm}@<version>") so every tool resolves the same package manager`);
|
|
299
|
+
} else if (pmField && lockfiles.length === 1 && LOCKFILE_PM[lockfiles[0]] !== pmField) {
|
|
300
|
+
issues.push(`packageManager is "${pmField}" but the lockfile is ${lockfiles[0]}`);
|
|
301
|
+
suggestions.push(`Reinstall with ${pmField} (or update the packageManager field) so they agree`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const localCliPath = path.join(projectRoot, 'node_modules', 'slicejs-cli', 'package.json');
|
|
305
|
+
if (pkg && !(await fs.pathExists(localCliPath))) {
|
|
306
|
+
issues.push('slicejs-cli is not installed locally');
|
|
307
|
+
suggestions.push(`Run "${installCommand(pm, 'slicejs-cli', { dev: true })}" so the launcher delegates to a version pinned per project`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (issues.length === 0) {
|
|
311
|
+
return {
|
|
312
|
+
pass: true,
|
|
313
|
+
message: `Package manager setup is consistent (${pmField || pm})`
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
warn: true,
|
|
318
|
+
message: issues.join(' | '),
|
|
319
|
+
suggestion: suggestions.join(' | ')
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Checks dependencies in package.json
|
|
325
|
+
*/
|
|
326
|
+
async function checkDependencies() {
|
|
327
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
328
|
+
const packagePath = getPath(import.meta.url, 'package.json');
|
|
329
|
+
|
|
330
|
+
if (!await fs.pathExists(packagePath)) {
|
|
331
|
+
return {
|
|
332
|
+
warn: true,
|
|
333
|
+
message: 'package.json not found',
|
|
334
|
+
suggestion: 'Run "npm init" to create package.json'
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
const pkg = await fs.readJson(packagePath);
|
|
340
|
+
const hasFrameworkDep = pkg.dependencies?.['slicejs-web-framework'] || pkg.devDependencies?.['slicejs-web-framework'];
|
|
341
|
+
const frameworkNodePath = getPath(import.meta.url, 'node_modules', 'slicejs-web-framework', 'package.json');
|
|
342
|
+
const hasFrameworkNode = await fs.pathExists(frameworkNodePath);
|
|
343
|
+
const hasFramework = !!(hasFrameworkDep || hasFrameworkNode);
|
|
344
|
+
|
|
345
|
+
if (hasFramework) {
|
|
346
|
+
// A declared range that does not accept the installed version is a
|
|
347
|
+
// reproducibility bug: the next clean install gets a different
|
|
348
|
+
// runtime. The CLI's own requirement matters more — a published CLI
|
|
349
|
+
// declaring ^3.5.0 while the app runs 4.x shipped a broken install.
|
|
350
|
+
const mismatches = [];
|
|
351
|
+
const installed = await fs.readJson(frameworkNodePath).catch(() => null);
|
|
352
|
+
|
|
353
|
+
if (installed?.version) {
|
|
354
|
+
const appRange = pkg.dependencies?.['slicejs-web-framework'] || pkg.devDependencies?.['slicejs-web-framework'];
|
|
355
|
+
const appMismatch = appRange ? rangeMismatch(appRange, installed.version) : null;
|
|
356
|
+
if (appMismatch) {
|
|
357
|
+
mismatches.push(`package.json declares ${appMismatch}, but ${installed.version} is installed`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const cliPkgPath = getPath(import.meta.url, 'node_modules', 'slicejs-cli', 'package.json');
|
|
361
|
+
const cliPkg = await fs.pathExists(cliPkgPath) ? await fs.readJson(cliPkgPath).catch(() => null) : null;
|
|
362
|
+
const cliRange = cliPkg?.dependencies?.['slicejs-web-framework'];
|
|
363
|
+
const cliMismatch = cliRange ? rangeMismatch(cliRange, installed.version) : null;
|
|
364
|
+
if (cliMismatch) {
|
|
365
|
+
mismatches.push(`slicejs-cli@${cliPkg.version} requires slicejs-web-framework@${cliRange}, but ${installed.version} is installed`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (mismatches.length > 0) {
|
|
370
|
+
return {
|
|
371
|
+
warn: true,
|
|
372
|
+
message: `Version mismatch: ${mismatches[0]}`,
|
|
373
|
+
suggestion: mismatches.length > 1
|
|
374
|
+
? mismatches.slice(1).join('\n')
|
|
375
|
+
: 'Align the declared range with the installed version, or reinstall from the lockfile.'
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
pass: true,
|
|
381
|
+
message: 'Required framework dependency is installed'
|
|
382
|
+
};
|
|
383
|
+
} else {
|
|
384
|
+
const missing = ['slicejs-web-framework'];
|
|
385
|
+
|
|
386
|
+
return {
|
|
387
|
+
warn: true,
|
|
388
|
+
message: `Missing dependencies: ${missing.join(', ')}`,
|
|
389
|
+
suggestion: missing.includes('slicejs-web-framework')
|
|
390
|
+
? `Run "${installCommand(resolvePackageManager(getProjectRoot(import.meta.url)).name, 'slicejs-web-framework@latest')}" in your project`
|
|
391
|
+
: `Run "${installCommand(resolvePackageManager(getProjectRoot(import.meta.url)).name, 'slicejs-cli@latest', { dev: true })}" in your project`,
|
|
392
|
+
missing
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
} catch (error) {
|
|
396
|
+
return {
|
|
397
|
+
pass: false,
|
|
398
|
+
message: `package.json is invalid: ${error.message}`,
|
|
399
|
+
suggestion: 'Fix JSON syntax errors in package.json'
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Components and routes: one verdict for everything the build validates statically.
|
|
406
|
+
*
|
|
407
|
+
* The same pass `slice build` runs, classified by the same helper. It used to be
|
|
408
|
+
* two rows that disagreed with each other and with the build: "Components"
|
|
409
|
+
* scanned folders, "Component Props" read only prop definitions and dropped the
|
|
410
|
+
* source errors the build blocks on, and routes were never checked at all.
|
|
411
|
+
*/
|
|
412
|
+
async function checkComponents() {
|
|
413
|
+
const registryPath = getComponentsJsPath(import.meta.url);
|
|
414
|
+
|
|
415
|
+
if (!await fs.pathExists(registryPath)) {
|
|
416
|
+
return { pass: true, message: 'No components registered (components.js not found)' };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
try {
|
|
420
|
+
const validation = await validateProject({ projectRoot: getProjectRoot(import.meta.url) });
|
|
421
|
+
const { blocking, advisory } = classifyValidation(validation);
|
|
422
|
+
const summary = `${validation.registeredCount} components, ${validation.routeCount} routes`;
|
|
423
|
+
|
|
424
|
+
if (blocking.length > 0) {
|
|
425
|
+
const componentCount = new Set(blocking.map((issue) => issue.component)).size;
|
|
426
|
+
return {
|
|
427
|
+
message: `${blocking.length} issue(s) in ${componentCount} file(s) block "slice build"`,
|
|
428
|
+
suggestion: blocking
|
|
429
|
+
.slice(0, 5)
|
|
430
|
+
.map(describeIssue)
|
|
431
|
+
.join('\n') + (blocking.length > 5 ? `\n… ${blocking.length - 5} more (run "slice build" for the full list)` : ''),
|
|
432
|
+
issues: blocking
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (advisory.length > 0) {
|
|
437
|
+
return {
|
|
438
|
+
warn: true,
|
|
439
|
+
message: `${summary}, ${advisory.length} warning(s) — none block the build`,
|
|
440
|
+
suggestion: advisory
|
|
441
|
+
.slice(0, 3)
|
|
442
|
+
.map(describeIssue)
|
|
443
|
+
.join('\n') + (advisory.length > 3 ? `\n… ${advisory.length - 3} more` : ''),
|
|
444
|
+
issues: advisory
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
pass: true,
|
|
450
|
+
message: `${summary}, ${validation.checkedCount} with static props: all valid`
|
|
451
|
+
};
|
|
452
|
+
} catch (error) {
|
|
453
|
+
return { warn: true, message: `Cannot check components: ${error.message}` };
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The deployment entrypoint. `slice build` bundles `src/` and never runs `api/`,
|
|
459
|
+
* so a syntax error there reached production as a 500.
|
|
460
|
+
*/
|
|
461
|
+
async function checkServerEntry() {
|
|
462
|
+
const { serverErrors, hasServer } = await validateServerEntry({ projectRoot: getProjectRoot(import.meta.url) });
|
|
463
|
+
|
|
464
|
+
if (!hasServer) return { pass: true, message: 'No api/index.js (static app)' };
|
|
465
|
+
if (serverErrors.length === 0) return { pass: true, message: 'api/index.js parses' };
|
|
466
|
+
|
|
467
|
+
return {
|
|
468
|
+
message: `api/index.js does not parse: ${serverErrors[0].message.split('\n')[0]}`,
|
|
469
|
+
suggestion: 'Fix the syntax error: the deploy fails on the same file.'
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** Package root of a bare specifier: 'lodash/fp' -> 'lodash', '@s/p/x' -> '@s/p'. */
|
|
474
|
+
function packageRootOf(spec) {
|
|
475
|
+
const parts = spec.split('/');
|
|
476
|
+
return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Collects bare (node_modules) import specifiers from a module's source. */
|
|
480
|
+
function extractBareImports(source) {
|
|
481
|
+
const found = new Set();
|
|
482
|
+
const add = (spec) => {
|
|
483
|
+
if (typeof spec === 'string' && ExternalModuleBundler.isBareSpecifier(spec)) found.add(spec);
|
|
484
|
+
};
|
|
485
|
+
try {
|
|
486
|
+
const ast = parseModule(source, { sourceType: 'module', plugins: ['jsx'] });
|
|
487
|
+
traverse.default(ast, {
|
|
488
|
+
ImportDeclaration(p) { add(p.node.source?.value); },
|
|
489
|
+
ExportNamedDeclaration(p) { if (p.node.source) add(p.node.source.value); },
|
|
490
|
+
ExportAllDeclaration(p) { add(p.node.source?.value); },
|
|
491
|
+
CallExpression(p) {
|
|
492
|
+
if (p.node.callee?.type === 'Import' && p.node.arguments?.[0]?.type === 'StringLiteral') {
|
|
493
|
+
add(p.node.arguments[0].value);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
} catch { /* unparseable → skip */ }
|
|
498
|
+
return found;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Verifies that every node_modules package imported by a component is actually
|
|
503
|
+
* installed. Bare imports are resolved from node_modules at build/dev time, so a
|
|
504
|
+
* missing package would fail there — this surfaces it early.
|
|
505
|
+
*/
|
|
506
|
+
async function checkExternalDependencies() {
|
|
507
|
+
const registryPath = getComponentsJsPath(import.meta.url);
|
|
508
|
+
const configPath = getConfigPath(import.meta.url);
|
|
509
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
510
|
+
|
|
511
|
+
if (!await fs.pathExists(registryPath)) {
|
|
512
|
+
return { pass: true, message: 'No components to check' };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
try {
|
|
516
|
+
const content = await fs.readFile(registryPath, 'utf-8');
|
|
517
|
+
const entries = Object.entries(parseComponentsRegistry(content, registryPath));
|
|
518
|
+
|
|
519
|
+
const categoryPathCache = new Map();
|
|
520
|
+
if (await fs.pathExists(configPath)) {
|
|
521
|
+
try {
|
|
522
|
+
const config = await fs.readJson(configPath);
|
|
523
|
+
for (const [cat, catMeta] of Object.entries(config.paths?.components || {})) {
|
|
524
|
+
categoryPathCache.set(cat, catMeta.path?.replace(/^[/\\]+/, '') || '');
|
|
525
|
+
}
|
|
526
|
+
} catch { /* config issues reported elsewhere */ }
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const usedBy = new Map(); // packageRoot -> Set(component names)
|
|
530
|
+
for (const [compName, meta] of entries) {
|
|
531
|
+
const category = typeof meta === 'string' ? meta : (meta.category || '');
|
|
532
|
+
const relPath = categoryPathCache.get(category);
|
|
533
|
+
if (!relPath) continue;
|
|
534
|
+
const jsPath = getSrcPath(import.meta.url, relPath, compName, `${compName}.js`);
|
|
535
|
+
if (!await fs.pathExists(jsPath)) continue;
|
|
536
|
+
|
|
537
|
+
const source = await fs.readFile(jsPath, 'utf-8');
|
|
538
|
+
for (const spec of extractBareImports(source)) {
|
|
539
|
+
const root = packageRootOf(spec);
|
|
540
|
+
if (!usedBy.has(root)) usedBy.set(root, new Set());
|
|
541
|
+
usedBy.get(root).add(compName);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (usedBy.size === 0) {
|
|
546
|
+
return { pass: true, message: 'No external (node_modules) imports' };
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const missing = [];
|
|
550
|
+
for (const root of usedBy.keys()) {
|
|
551
|
+
const pkgJson = path.join(projectRoot, 'node_modules', root, 'package.json');
|
|
552
|
+
if (!await fs.pathExists(pkgJson)) missing.push(root);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (missing.length === 0) {
|
|
556
|
+
return { pass: true, message: `${usedBy.size} external package(s) imported, all installed` };
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return {
|
|
560
|
+
warn: true,
|
|
561
|
+
message: `${missing.length} imported package(s) not in node_modules: ${missing.sort().join(', ')}`,
|
|
562
|
+
details: missing.sort().map((m) => `Install "${m}" — used by: ${Array.from(usedBy.get(m)).sort().join(', ')}`)
|
|
563
|
+
};
|
|
564
|
+
} catch (error) {
|
|
565
|
+
return { warn: true, message: `Cannot check external dependencies: ${error.message}` };
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Main diagnostic command
|
|
571
|
+
*/
|
|
572
|
+
export {
|
|
573
|
+
checkNodeVersion,
|
|
574
|
+
checkDirectoryStructure,
|
|
575
|
+
checkConfig,
|
|
576
|
+
checkSeoConfiguration,
|
|
577
|
+
checkPort,
|
|
578
|
+
checkDependencies,
|
|
579
|
+
checkComponents,
|
|
580
|
+
checkServerEntry,
|
|
581
|
+
checkExternalDependencies
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
export default async function runDiagnostics() {
|
|
585
|
+
Print.newLine();
|
|
586
|
+
Print.title('🔍 Running Slice.js Diagnostics...');
|
|
587
|
+
Print.newLine();
|
|
588
|
+
|
|
589
|
+
const checks = [
|
|
590
|
+
{ name: 'Node.js Version', fn: checkNodeVersion },
|
|
591
|
+
{ name: 'Project Structure', fn: checkDirectoryStructure },
|
|
592
|
+
{ name: 'Configuration', fn: checkConfig },
|
|
593
|
+
{ name: 'SEO', fn: checkSeoConfiguration },
|
|
594
|
+
{ name: 'Port Availability', fn: checkPort },
|
|
595
|
+
{ name: 'Package Manager', fn: checkPackageManagerSetup },
|
|
596
|
+
{ name: 'Dependencies', fn: checkDependencies },
|
|
597
|
+
{ name: 'Components & Routes', fn: checkComponents },
|
|
598
|
+
{ name: 'Server entry', fn: checkServerEntry },
|
|
599
|
+
{ name: 'External Dependencies', fn: checkExternalDependencies }
|
|
600
|
+
];
|
|
601
|
+
|
|
602
|
+
const results = [];
|
|
603
|
+
|
|
604
|
+
for (const check of checks) {
|
|
605
|
+
const result = await check.fn();
|
|
606
|
+
results.push({ ...result, name: check.name });
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Crear tabla de resultados
|
|
610
|
+
const table = new Table({
|
|
611
|
+
head: [chalk.cyan.bold('Check'), chalk.cyan.bold('Status'), chalk.cyan.bold('Details')],
|
|
612
|
+
colWidths: [25, 10, 55],
|
|
613
|
+
style: {
|
|
614
|
+
head: [],
|
|
615
|
+
border: ['gray']
|
|
616
|
+
},
|
|
617
|
+
wordWrap: true
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
results.forEach(result => {
|
|
621
|
+
let status;
|
|
622
|
+
if (result.pass) {
|
|
623
|
+
status = chalk.green('✅ PASS');
|
|
624
|
+
} else if (result.warn) {
|
|
625
|
+
status = chalk.yellow('⚠️ WARN');
|
|
626
|
+
} else {
|
|
627
|
+
status = chalk.red('❌ FAIL');
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const details = result.suggestion
|
|
631
|
+
? `${result.message}\n${chalk.gray('→ ' + result.suggestion)}`
|
|
632
|
+
: result.message;
|
|
633
|
+
|
|
634
|
+
table.push([result.name, status, details]);
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
console.log(table.toString());
|
|
638
|
+
|
|
639
|
+
// Resumen
|
|
640
|
+
const issues = results.filter(r => !r.pass && !r.warn).length;
|
|
641
|
+
const warnings = results.filter(r => r.warn).length;
|
|
642
|
+
const passed = results.filter(r => r.pass).length;
|
|
643
|
+
|
|
644
|
+
Print.newLine();
|
|
645
|
+
Print.separator();
|
|
646
|
+
|
|
647
|
+
const depsResult = results.find(r => r.name === 'Dependencies');
|
|
648
|
+
if (depsResult && depsResult.warn && Array.isArray(depsResult.missing) && depsResult.missing.length > 0) {
|
|
649
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
650
|
+
const pm = resolvePackageManager(projectRoot).name;
|
|
651
|
+
for (const pkg of depsResult.missing) {
|
|
652
|
+
Print.info(`Missing: ${pkg}. Install with: ${installCommand(pm, `${pkg}@latest`)}`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (issues === 0 && warnings === 0) {
|
|
657
|
+
Print.success('All checks passed! 🎉');
|
|
658
|
+
Print.info('Your Slice.js project is correctly configured');
|
|
659
|
+
} else {
|
|
660
|
+
console.log(chalk.bold('📊 Summary:'));
|
|
661
|
+
console.log(chalk.green(` ✅ Passed: ${passed}`));
|
|
662
|
+
if (warnings > 0) console.log(chalk.yellow(` ⚠️ Warnings: ${warnings}`));
|
|
663
|
+
if (issues > 0) console.log(chalk.red(` ❌ Issues: ${issues}`));
|
|
664
|
+
|
|
665
|
+
Print.newLine();
|
|
666
|
+
|
|
667
|
+
if (issues > 0) {
|
|
668
|
+
Print.warning('Fix the issues above: they block "slice build" and would ship a broken project');
|
|
669
|
+
// A diagnostic command that always exits 0 cannot gate a pipeline.
|
|
670
|
+
process.exitCode = 1;
|
|
671
|
+
} else {
|
|
672
|
+
Print.info('Warnings are non-critical but should be addressed');
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
Print.separator();
|
|
677
|
+
}
|