slicejs-cli 2.8.6 → 2.9.1
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/README.md +347 -315
- package/client.js +526 -539
- package/commands/Print.js +167 -167
- package/commands/Validations.js +103 -103
- package/commands/build/build.js +40 -0
- package/commands/buildProduction/buildProduction.js +45 -10
- package/commands/bundle/bundle.js +235 -231
- package/commands/createComponent/VisualComponentTemplate.js +55 -55
- package/commands/createComponent/createComponent.js +126 -126
- package/commands/deleteComponent/deleteComponent.js +77 -77
- package/commands/doctor/doctor.js +369 -369
- package/commands/getComponent/getComponent.js +747 -747
- package/commands/init/init.js +261 -261
- package/commands/listComponents/listComponents.js +175 -175
- package/commands/startServer/startServer.js +260 -270
- package/commands/startServer/watchServer.js +79 -79
- package/commands/utils/PathHelper.js +68 -68
- package/commands/utils/VersionChecker.js +167 -167
- package/commands/utils/bundling/BundleGenerator.js +1331 -783
- package/commands/utils/bundling/DependencyAnalyzer.js +859 -679
- package/commands/utils/updateManager.js +437 -384
- package/package.json +46 -46
- package/post.js +25 -25
- package/refactor.md +271 -271
- package/tests/bundle-generator.test.js +38 -0
- package/tests/dependency-analyzer.test.js +24 -0
package/client.js
CHANGED
|
@@ -1,539 +1,526 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import inquirer from "inquirer";
|
|
4
|
-
import initializeProject from "./commands/init/init.js";
|
|
5
|
-
import createComponent from "./commands/createComponent/createComponent.js";
|
|
6
|
-
import listComponents from "./commands/listComponents/listComponents.js";
|
|
7
|
-
import deleteComponent from "./commands/deleteComponent/deleteComponent.js";
|
|
8
|
-
import getComponent, { listComponents as listRemoteComponents, syncComponents } from "./commands/getComponent/getComponent.js";
|
|
9
|
-
import startServer from "./commands/startServer/startServer.js";
|
|
10
|
-
import runDiagnostics from "./commands/doctor/doctor.js";
|
|
11
|
-
import versionChecker from "./commands/utils/VersionChecker.js";
|
|
12
|
-
import updateManager from "./commands/utils/updateManager.js";
|
|
13
|
-
import fs from "fs";
|
|
14
|
-
import path from "path";
|
|
15
|
-
import { fileURLToPath } from "url";
|
|
16
|
-
import { getConfigPath, getProjectRoot } from "./commands/utils/PathHelper.js";
|
|
17
|
-
import { exec } from "child_process";
|
|
18
|
-
import { promisify } from "util";
|
|
19
|
-
import validations from "./commands/Validations.js";
|
|
20
|
-
import Print from "./commands/Print.js";
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
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
|
-
const
|
|
109
|
-
const
|
|
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
|
-
.option("-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
.
|
|
165
|
-
.
|
|
166
|
-
.option("-
|
|
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
|
-
|
|
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
|
-
// Paso
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (
|
|
308
|
-
Print.
|
|
309
|
-
return;
|
|
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
|
-
.description("
|
|
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
|
-
.action(async () => {
|
|
424
|
-
await runWithVersionCheck(async () => {
|
|
425
|
-
await
|
|
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
|
-
slice
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
slice
|
|
498
|
-
slice
|
|
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
|
-
// Error handling for unknown commands
|
|
528
|
-
program.on('command:*', () => {
|
|
529
|
-
Print.error('Invalid command. See available commands above');
|
|
530
|
-
Print.info("Use 'slice --help' for help");
|
|
531
|
-
process.exit(1);
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
// HELP Command
|
|
535
|
-
const helpCommand = sliceClient.command("help").description("Display help information for Slice.js CLI").action(() => {
|
|
536
|
-
sliceClient.outputHelp();
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
program.parse();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import initializeProject from "./commands/init/init.js";
|
|
5
|
+
import createComponent from "./commands/createComponent/createComponent.js";
|
|
6
|
+
import listComponents from "./commands/listComponents/listComponents.js";
|
|
7
|
+
import deleteComponent from "./commands/deleteComponent/deleteComponent.js";
|
|
8
|
+
import getComponent, { listComponents as listRemoteComponents, syncComponents } from "./commands/getComponent/getComponent.js";
|
|
9
|
+
import startServer from "./commands/startServer/startServer.js";
|
|
10
|
+
import runDiagnostics from "./commands/doctor/doctor.js";
|
|
11
|
+
import versionChecker from "./commands/utils/VersionChecker.js";
|
|
12
|
+
import updateManager from "./commands/utils/updateManager.js";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
import { getConfigPath, getProjectRoot } from "./commands/utils/PathHelper.js";
|
|
17
|
+
import { exec } from "child_process";
|
|
18
|
+
import { promisify } from "util";
|
|
19
|
+
import validations from "./commands/Validations.js";
|
|
20
|
+
import Print from "./commands/Print.js";
|
|
21
|
+
import build from './commands/build/build.js';
|
|
22
|
+
import { cleanBundles, bundleInfo } from './commands/bundle/bundle.js';
|
|
23
|
+
|
|
24
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
|
|
26
|
+
const loadConfig = () => {
|
|
27
|
+
try {
|
|
28
|
+
const configPath = getConfigPath(import.meta.url);
|
|
29
|
+
const rawData = fs.readFileSync(configPath, "utf-8");
|
|
30
|
+
return JSON.parse(rawData);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const getCategories = () => {
|
|
37
|
+
const config = loadConfig();
|
|
38
|
+
return config && config.paths?.components ? Object.keys(config.paths.components) : [];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Function to run version check for all commands
|
|
42
|
+
async function runWithVersionCheck(commandFunction, ...args) {
|
|
43
|
+
try {
|
|
44
|
+
const execAsync = promisify(exec);
|
|
45
|
+
await (async () => {
|
|
46
|
+
try {
|
|
47
|
+
const info = await updateManager.detectCliInstall();
|
|
48
|
+
if (info && info.type === 'global') {
|
|
49
|
+
const projectRoot = getProjectRoot(import.meta.url);
|
|
50
|
+
const pkgPath = path.join(projectRoot, 'package.json');
|
|
51
|
+
let hasPkg = fs.existsSync(pkgPath);
|
|
52
|
+
if (!hasPkg) {
|
|
53
|
+
const { confirmInit } = await inquirer.prompt([
|
|
54
|
+
{
|
|
55
|
+
type: 'confirm',
|
|
56
|
+
name: 'confirmInit',
|
|
57
|
+
message: 'No package.json found. Initialize npm in this project now?',
|
|
58
|
+
default: true
|
|
59
|
+
}
|
|
60
|
+
]);
|
|
61
|
+
if (confirmInit) {
|
|
62
|
+
await execAsync('npm init -y', { cwd: projectRoot });
|
|
63
|
+
hasPkg = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (hasPkg) {
|
|
67
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
68
|
+
const hasFramework = pkg.dependencies?.['slicejs-web-framework'];
|
|
69
|
+
if (!hasFramework) {
|
|
70
|
+
const { confirm } = await inquirer.prompt([
|
|
71
|
+
{
|
|
72
|
+
type: 'confirm',
|
|
73
|
+
name: 'confirm',
|
|
74
|
+
message: 'slicejs-web-framework is not installed in this project. Install it now?',
|
|
75
|
+
default: true
|
|
76
|
+
}
|
|
77
|
+
]);
|
|
78
|
+
if (confirm) {
|
|
79
|
+
await updateManager.updatePackage('slicejs-web-framework');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} catch {}
|
|
85
|
+
})();
|
|
86
|
+
|
|
87
|
+
const updateInfo = await updateManager.checkForUpdates();
|
|
88
|
+
if (updateInfo && updateInfo.hasUpdates) {
|
|
89
|
+
await updateManager.checkAndPromptUpdates({});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const result = await commandFunction(...args);
|
|
93
|
+
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
versionChecker.checkForUpdates(false);
|
|
96
|
+
}, 100);
|
|
97
|
+
|
|
98
|
+
return result;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
Print.error(`Command execution: ${error.message}`);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const sliceClient = program;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const pkgPath = path.join(__dirname, "./package.json");
|
|
109
|
+
const pkgRaw = fs.readFileSync(pkgPath, "utf-8");
|
|
110
|
+
const pkg = JSON.parse(pkgRaw);
|
|
111
|
+
sliceClient.version(pkg.version).description("CLI for managing Slice.js framework components");
|
|
112
|
+
} catch {
|
|
113
|
+
sliceClient.version("0.0.0").description("CLI for managing Slice.js framework components");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// INIT COMMAND
|
|
117
|
+
sliceClient
|
|
118
|
+
.command("init")
|
|
119
|
+
.description("Initialize a new Slice.js project")
|
|
120
|
+
.action(async () => {
|
|
121
|
+
await runWithVersionCheck(() => {
|
|
122
|
+
initializeProject();
|
|
123
|
+
return Promise.resolve();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// VERSION COMMAND
|
|
128
|
+
sliceClient
|
|
129
|
+
.command("version")
|
|
130
|
+
.alias("v")
|
|
131
|
+
.description("Show version information and check for updates")
|
|
132
|
+
.action(async () => {
|
|
133
|
+
await versionChecker.showVersionInfo();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// BUILD COMMAND
|
|
137
|
+
const buildCommand = sliceClient.command("build")
|
|
138
|
+
.description("Build Slice.js project for production")
|
|
139
|
+
.action(async (options) => {
|
|
140
|
+
await runWithVersionCheck(async () => {
|
|
141
|
+
await build(options);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
buildCommand
|
|
146
|
+
.command("clean")
|
|
147
|
+
.description("Remove all generated bundles")
|
|
148
|
+
.action(async () => {
|
|
149
|
+
await cleanBundles();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
buildCommand
|
|
153
|
+
.command("info")
|
|
154
|
+
.description("Show information about generated bundles")
|
|
155
|
+
.action(async () => {
|
|
156
|
+
await bundleInfo();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
buildCommand
|
|
160
|
+
.option("-a, --analyze", "Analyze project dependencies without bundling")
|
|
161
|
+
.option("-v, --verbose", "Show detailed output")
|
|
162
|
+
.option("--no-minify", "Disable minification (enabled by default)")
|
|
163
|
+
.option("--no-obfuscate", "Disable obfuscation (enabled by default, no prop mangling)")
|
|
164
|
+
.option("--preview", "Start preview server after build")
|
|
165
|
+
.option("--serve", "Start preview server without building")
|
|
166
|
+
.option("--skip-clean", "Skip cleaning dist before build");
|
|
167
|
+
|
|
168
|
+
// DEV COMMAND (DEVELOPMENT)
|
|
169
|
+
sliceClient
|
|
170
|
+
.command("dev")
|
|
171
|
+
.description("Start development server")
|
|
172
|
+
.option("-p, --port <port>", "Port for development server", 3000)
|
|
173
|
+
.option("-w, --watch", "Enable watch mode for file changes")
|
|
174
|
+
.action(async (options) => {
|
|
175
|
+
await runWithVersionCheck(async () => {
|
|
176
|
+
await startServer({
|
|
177
|
+
mode: 'development',
|
|
178
|
+
port: parseInt(options.port),
|
|
179
|
+
watch: options.watch,
|
|
180
|
+
bundled: false
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// START COMMAND - PRODUCTION MODE
|
|
186
|
+
sliceClient
|
|
187
|
+
.command("start")
|
|
188
|
+
.description("Start production server")
|
|
189
|
+
.option("-p, --port <port>", "Port for server", 3000)
|
|
190
|
+
.option("-w, --watch", "Enable watch mode for file changes")
|
|
191
|
+
.action(async (options) => {
|
|
192
|
+
await runWithVersionCheck(async () => {
|
|
193
|
+
await startServer({
|
|
194
|
+
mode: 'production',
|
|
195
|
+
port: parseInt(options.port),
|
|
196
|
+
watch: options.watch,
|
|
197
|
+
bundled: false
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// COMPONENT COMMAND GROUP - For local component management
|
|
203
|
+
const componentCommand = sliceClient.command("component").alias("comp").description("Manage local project components");
|
|
204
|
+
|
|
205
|
+
// CREATE LOCAL COMPONENT
|
|
206
|
+
componentCommand
|
|
207
|
+
.command("create")
|
|
208
|
+
.alias("new")
|
|
209
|
+
.description("Create a new component in your local project")
|
|
210
|
+
.action(async () => {
|
|
211
|
+
await runWithVersionCheck(async () => {
|
|
212
|
+
const categories = getCategories();
|
|
213
|
+
if (categories.length === 0) {
|
|
214
|
+
Print.error("No categories found in your project configuration");
|
|
215
|
+
Print.info("Run 'slice init' to initialize your project first");
|
|
216
|
+
Print.commandExample("Initialize project", "slice init");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const answers = await inquirer.prompt([
|
|
221
|
+
{
|
|
222
|
+
type: "input",
|
|
223
|
+
name: "componentName",
|
|
224
|
+
message: "Enter the component name:",
|
|
225
|
+
validate: (input) => {
|
|
226
|
+
if (!input) return "Component name cannot be empty";
|
|
227
|
+
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(input)) {
|
|
228
|
+
return "Component name must start with a letter and contain only alphanumeric characters";
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: "list",
|
|
235
|
+
name: "category",
|
|
236
|
+
message: "Select the component category:",
|
|
237
|
+
choices: categories,
|
|
238
|
+
}
|
|
239
|
+
]);
|
|
240
|
+
|
|
241
|
+
const result = createComponent(answers.componentName, answers.category);
|
|
242
|
+
if (result) {
|
|
243
|
+
Print.success(`Component '${answers.componentName}' created successfully in category '${answers.category}'`);
|
|
244
|
+
Print.info("Listing updated components:");
|
|
245
|
+
listComponents();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// LIST LOCAL COMPONENTS
|
|
251
|
+
componentCommand
|
|
252
|
+
.command("list")
|
|
253
|
+
.alias("ls")
|
|
254
|
+
.description("List all components in your local project")
|
|
255
|
+
.action(async () => {
|
|
256
|
+
await runWithVersionCheck(() => {
|
|
257
|
+
listComponents();
|
|
258
|
+
return Promise.resolve();
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// DELETE LOCAL COMPONENT
|
|
263
|
+
componentCommand
|
|
264
|
+
.command("delete")
|
|
265
|
+
.alias("remove")
|
|
266
|
+
.description("Delete a component from your local project")
|
|
267
|
+
.action(async () => {
|
|
268
|
+
await runWithVersionCheck(async () => {
|
|
269
|
+
const categories = getCategories();
|
|
270
|
+
if (categories.length === 0) {
|
|
271
|
+
Print.error("No categories available. Check your configuration");
|
|
272
|
+
Print.info("Run 'slice init' to initialize your project");
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
// Paso 1: Seleccionar categoría
|
|
278
|
+
const categoryAnswer = await inquirer.prompt([
|
|
279
|
+
{
|
|
280
|
+
type: "list",
|
|
281
|
+
name: "category",
|
|
282
|
+
message: "Select the component category:",
|
|
283
|
+
choices: categories,
|
|
284
|
+
}
|
|
285
|
+
]);
|
|
286
|
+
|
|
287
|
+
// Paso 2: Listar componentes de esa categoría
|
|
288
|
+
const config = loadConfig();
|
|
289
|
+
if (!config) {
|
|
290
|
+
Print.error("Could not load configuration");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const categoryPath = config.paths.components[categoryAnswer.category].path;
|
|
295
|
+
const fullPath = path.join(__dirname, "../../src", categoryPath);
|
|
296
|
+
|
|
297
|
+
if (!fs.existsSync(fullPath)) {
|
|
298
|
+
Print.error(`Category path does not exist: ${categoryPath}`);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const components = fs.readdirSync(fullPath).filter(item => {
|
|
303
|
+
const itemPath = path.join(fullPath, item);
|
|
304
|
+
return fs.statSync(itemPath).isDirectory();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
if (components.length === 0) {
|
|
308
|
+
Print.info(`No components found in category '${categoryAnswer.category}'`);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Paso 3: Seleccionar componente a eliminar
|
|
313
|
+
const componentAnswer = await inquirer.prompt([
|
|
314
|
+
{
|
|
315
|
+
type: "list",
|
|
316
|
+
name: "componentName",
|
|
317
|
+
message: "Select the component to delete:",
|
|
318
|
+
choices: components,
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
type: "confirm",
|
|
322
|
+
name: "confirm",
|
|
323
|
+
message: (answers) => `Are you sure you want to delete '${answers.componentName}'?`,
|
|
324
|
+
default: false,
|
|
325
|
+
}
|
|
326
|
+
]);
|
|
327
|
+
|
|
328
|
+
if (!componentAnswer.confirm) {
|
|
329
|
+
Print.info("Delete operation cancelled");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Paso 4: Eliminar el componente
|
|
334
|
+
if (deleteComponent(componentAnswer.componentName, categoryAnswer.category)) {
|
|
335
|
+
Print.success(`Component ${componentAnswer.componentName} deleted successfully`);
|
|
336
|
+
Print.info("Listing updated components:");
|
|
337
|
+
listComponents();
|
|
338
|
+
}
|
|
339
|
+
} catch (error) {
|
|
340
|
+
Print.error(`Deleting component: ${error.message}`);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// REGISTRY COMMAND GROUP - For component registry operations
|
|
346
|
+
const registryCommand = sliceClient.command("registry").alias("reg").description("Manage components from official Slice.js repository");
|
|
347
|
+
|
|
348
|
+
// GET COMPONENTS FROM REGISTRY
|
|
349
|
+
registryCommand
|
|
350
|
+
.command("get [components...]")
|
|
351
|
+
.description("Download and install components from official repository")
|
|
352
|
+
.option("-f, --force", "Force overwrite existing components")
|
|
353
|
+
.option("-s, --service", "Install Service components instead of Visual")
|
|
354
|
+
.action(async (components, options) => {
|
|
355
|
+
await runWithVersionCheck(async () => {
|
|
356
|
+
await getComponent(components, {
|
|
357
|
+
force: options.force,
|
|
358
|
+
service: options.service
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// LIST REGISTRY COMPONENTS
|
|
364
|
+
registryCommand
|
|
365
|
+
.command("list")
|
|
366
|
+
.alias("ls")
|
|
367
|
+
.description("List all available components in the official repository")
|
|
368
|
+
.action(async () => {
|
|
369
|
+
await runWithVersionCheck(async () => {
|
|
370
|
+
await listRemoteComponents();
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// SYNC COMPONENTS FROM REGISTRY
|
|
375
|
+
registryCommand
|
|
376
|
+
.command("sync")
|
|
377
|
+
.description("Update all local components to latest versions from repository")
|
|
378
|
+
.option("-f, --force", "Force update without confirmation")
|
|
379
|
+
.action(async (options) => {
|
|
380
|
+
await runWithVersionCheck(async () => {
|
|
381
|
+
await syncComponents({
|
|
382
|
+
force: options.force
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// SHORTCUTS - Top-level convenient commands
|
|
388
|
+
sliceClient
|
|
389
|
+
.command("get [components...]")
|
|
390
|
+
.description("Quick install components from registry")
|
|
391
|
+
.option("-f, --force", "Force overwrite existing components")
|
|
392
|
+
.option("-s, --service", "Install Service components instead of Visual")
|
|
393
|
+
.action(async (components, options) => {
|
|
394
|
+
await runWithVersionCheck(async () => {
|
|
395
|
+
if (!components || components.length === 0) {
|
|
396
|
+
Print.info("Use 'slice registry list' to see available components");
|
|
397
|
+
Print.commandExample("Get multiple components", "slice get Button Card Input");
|
|
398
|
+
Print.commandExample("Get service component", "slice get FetchManager --service");
|
|
399
|
+
Print.commandExample("Browse components", "slice browse");
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
await getComponent(components, {
|
|
404
|
+
force: options.force,
|
|
405
|
+
service: options.service
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
sliceClient
|
|
411
|
+
.command("browse")
|
|
412
|
+
.description("Quick browse available components")
|
|
413
|
+
.action(async () => {
|
|
414
|
+
await runWithVersionCheck(async () => {
|
|
415
|
+
await listRemoteComponents();
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
sliceClient
|
|
420
|
+
.command("sync")
|
|
421
|
+
.description("Quick sync local components to latest versions")
|
|
422
|
+
.option("-f, --force", "Force update without confirmation")
|
|
423
|
+
.action(async (options) => {
|
|
424
|
+
await runWithVersionCheck(async () => {
|
|
425
|
+
await syncComponents({
|
|
426
|
+
force: options.force
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// LIST COMMAND - Quick shortcut for listing local components
|
|
432
|
+
sliceClient
|
|
433
|
+
.command("list")
|
|
434
|
+
.description("Quick list all local components (alias for component list)")
|
|
435
|
+
.action(async () => {
|
|
436
|
+
await runWithVersionCheck(() => {
|
|
437
|
+
listComponents();
|
|
438
|
+
return Promise.resolve();
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
// UPDATE COMMAND
|
|
443
|
+
sliceClient
|
|
444
|
+
.command("update")
|
|
445
|
+
.alias("upgrade")
|
|
446
|
+
.description("Update CLI and framework to latest versions")
|
|
447
|
+
.option("-y, --yes", "Skip confirmation and update all packages automatically")
|
|
448
|
+
.option("--cli", "Update only the Slice.js CLI")
|
|
449
|
+
.option("-f, --framework", "Update only the Slice.js Framework")
|
|
450
|
+
.action(async (options) => {
|
|
451
|
+
await updateManager.checkAndPromptUpdates(options);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// DOCTOR COMMAND - Diagnose project issues
|
|
455
|
+
sliceClient
|
|
456
|
+
.command("doctor")
|
|
457
|
+
.alias("diagnose")
|
|
458
|
+
.description("Run diagnostics to check project health")
|
|
459
|
+
.action(async () => {
|
|
460
|
+
await runWithVersionCheck(async () => {
|
|
461
|
+
await runDiagnostics();
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// Enhanced help
|
|
466
|
+
sliceClient
|
|
467
|
+
.option("--no-version-check", "Skip version check for this command")
|
|
468
|
+
.configureHelp({
|
|
469
|
+
sortSubcommands: true,
|
|
470
|
+
subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage()
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
// Custom help - SIMPLIFICADO para development only
|
|
475
|
+
sliceClient.addHelpText('after', `
|
|
476
|
+
Common Usage Examples:
|
|
477
|
+
slice init - Initialize new Slice.js project
|
|
478
|
+
slice dev - Start development server
|
|
479
|
+
slice build - Build production output (bundles + dist)
|
|
480
|
+
slice start - Start production server
|
|
481
|
+
slice get Button Card Input - Install Visual components from registry
|
|
482
|
+
slice get FetchManager -s - Install Service component from registry
|
|
483
|
+
slice browse - Browse all available components
|
|
484
|
+
slice sync - Update local components to latest versions
|
|
485
|
+
slice component create - Create new local component
|
|
486
|
+
slice list - List all local components
|
|
487
|
+
slice doctor - Run project diagnostics
|
|
488
|
+
|
|
489
|
+
Command Categories:
|
|
490
|
+
• init, dev, start - Project lifecycle (development only)
|
|
491
|
+
• get, browse, sync, list - Quick shortcuts
|
|
492
|
+
• component <cmd> - Local component management
|
|
493
|
+
• registry <cmd> - Official repository operations
|
|
494
|
+
• version, update, doctor - Maintenance commands
|
|
495
|
+
|
|
496
|
+
Development Workflow:
|
|
497
|
+
• slice init - Initialize project
|
|
498
|
+
• slice dev - Start development server (serves from /src)
|
|
499
|
+
• slice build - Build production output to /dist (includes bundles)
|
|
500
|
+
• slice start - Serve production build from /dist
|
|
501
|
+
|
|
502
|
+
More info: https://slice-js-docs.vercel.app/
|
|
503
|
+
`);
|
|
504
|
+
|
|
505
|
+
// Default action with better messaging
|
|
506
|
+
if (!process.argv.slice(2).length) {
|
|
507
|
+
Print.newLine();
|
|
508
|
+
Print.info("Start with: slice init");
|
|
509
|
+
Print.commandExample("Development", "slice dev");
|
|
510
|
+
Print.commandExample("View available components", "slice browse");
|
|
511
|
+
Print.info("Use 'slice --help' for full help");
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// Error handling for unknown commands
|
|
515
|
+
program.on('command:*', () => {
|
|
516
|
+
Print.error('Invalid command. See available commands above');
|
|
517
|
+
Print.info("Use 'slice --help' for help");
|
|
518
|
+
process.exit(1);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// HELP Command
|
|
522
|
+
const helpCommand = sliceClient.command("help").description("Display help information for Slice.js CLI").action(() => {
|
|
523
|
+
sliceClient.outputHelp();
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
program.parse();
|