slicejs-cli 4.4.0 โ 4.6.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/client.js +192 -82
- package/commands/Print.js +158 -164
- package/commands/build/build.js +27 -1
- package/commands/buildProduction/buildProduction.js +42 -71
- package/commands/bundle/bundle.js +65 -60
- package/commands/docs/agents.js +260 -0
- package/commands/docs/events.js +365 -0
- package/commands/docs/index.js +123 -0
- package/commands/doctor/doctor.js +99 -12
- package/commands/export/checkExport.js +163 -0
- package/commands/export/clientRedirects.js +72 -0
- package/commands/export/copyDist.js +180 -0
- package/commands/export/export.js +236 -0
- package/commands/export/files.js +33 -0
- package/commands/export/hosts/cloudflare.js +48 -0
- package/commands/export/hosts/github.js +31 -0
- package/commands/export/hosts/index.js +69 -0
- package/commands/export/hosts/netlify.js +42 -0
- package/commands/export/hosts/nginx.js +73 -0
- package/commands/export/hosts/none.js +23 -0
- package/commands/export/hosts/s3.js +24 -0
- package/commands/export/hosts/shared.js +62 -0
- package/commands/export/hosts/vercel.js +69 -0
- package/commands/export/outDir.js +91 -0
- package/commands/export/prerender.js +121 -0
- package/commands/getComponent/getComponent.js +44 -40
- package/commands/init/init.js +32 -22
- package/commands/lint/lint.js +2 -2
- package/commands/lint/types.js +1 -1
- package/commands/listComponents/listComponents.js +205 -172
- package/commands/seo/check.js +7 -4
- package/commands/seo/images.js +77 -22
- package/commands/seo/sitemap.js +6 -3
- package/commands/seo/support.js +62 -0
- package/commands/setup/lint.js +1 -1
- package/commands/skill/skill.js +2 -2
- package/commands/startServer/startServer.js +60 -21
- package/commands/startServer/watchServer.js +3 -3
- package/commands/translator/check.js +32 -0
- package/commands/translator/init.js +125 -0
- package/commands/translator/scan.js +444 -0
- package/commands/typecheck/typecheck.js +2 -2
- package/commands/types/types.js +22 -3
- package/commands/utils/VersionChecker.js +14 -14
- package/commands/utils/bundling/BundleGenerator.js +45 -27
- package/commands/utils/bundling/DependencyAnalyzer.js +1007 -976
- package/commands/utils/componentCatalog.js +120 -0
- package/commands/utils/publicEnv.js +74 -0
- package/commands/utils/sliceConfigSchema.js +34 -0
- package/commands/utils/updateManager.js +12 -12
- package/package.json +22 -23
|
@@ -10,6 +10,7 @@ import { minifyJs, sourceFileOptions, componentsRegistryOptions } from '../utils
|
|
|
10
10
|
import { describeSyntaxError } from '../utils/SourceDiagnostics.js';
|
|
11
11
|
import { getSrcPath, getDistPath, getConfigPath, getProjectRoot } from '../utils/PathHelper.js';
|
|
12
12
|
import { resolvePackageManager, runScriptCommand } from '../utils/PackageManager.js';
|
|
13
|
+
import { writeSliceEnv } from '../utils/publicEnv.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Loads configuration from sliceConfig.json
|
|
@@ -59,8 +60,6 @@ async function checkBuildDependencies() {
|
|
|
59
60
|
* Verifies that critical Slice.js files exist
|
|
60
61
|
*/
|
|
61
62
|
async function verifySliceFiles(srcDir) {
|
|
62
|
-
Print.info('Verifying Slice.js critical files...');
|
|
63
|
-
|
|
64
63
|
const criticalFiles = [
|
|
65
64
|
'sliceConfig.json',
|
|
66
65
|
'Components/components.js',
|
|
@@ -73,16 +72,12 @@ async function verifySliceFiles(srcDir) {
|
|
|
73
72
|
throw new Error(`Critical Slice.js file missing: ${file}`);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
Print.success('All critical Slice.js files verified');
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
/**
|
|
81
78
|
* Verifies build integrity for Slice.js
|
|
82
79
|
*/
|
|
83
80
|
async function verifyBuildIntegrity(distDir) {
|
|
84
|
-
Print.info('Verifying build integrity for Slice.js...');
|
|
85
|
-
|
|
86
81
|
const criticalBuiltFiles = [
|
|
87
82
|
'sliceConfig.json',
|
|
88
83
|
'Components/components.js',
|
|
@@ -102,20 +97,18 @@ async function verifyBuildIntegrity(distDir) {
|
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
|
-
|
|
106
|
-
Print.success('Build integrity verified - all Slice.js components preserved');
|
|
107
100
|
}
|
|
108
101
|
|
|
109
102
|
/**
|
|
110
103
|
* Copies sliceConfig.json to the dist directory
|
|
111
104
|
*/
|
|
112
|
-
async function copySliceConfig() {
|
|
105
|
+
async function copySliceConfig(options = {}) {
|
|
113
106
|
const srcConfig = getConfigPath(import.meta.url);
|
|
114
107
|
const distConfig = getDistPath(import.meta.url, 'sliceConfig.json');
|
|
115
108
|
|
|
116
109
|
if (await fs.pathExists(srcConfig)) {
|
|
117
110
|
await fs.copy(srcConfig, distConfig);
|
|
118
|
-
Print.info('sliceConfig.json copied to dist');
|
|
111
|
+
if (options.verbose) Print.info('sliceConfig.json copied to dist');
|
|
119
112
|
}
|
|
120
113
|
}
|
|
121
114
|
|
|
@@ -142,7 +135,7 @@ async function copyFrameworkRuntime() {
|
|
|
142
135
|
await fs.copy(frameworkEntry, distSlice);
|
|
143
136
|
|
|
144
137
|
const stat = await fs.stat(distSlice);
|
|
145
|
-
Print.
|
|
138
|
+
Print.success(`Framework runtime copied (${(stat.size / 1024).toFixed(1)} KB)`);
|
|
146
139
|
} catch (error) {
|
|
147
140
|
Print.warning(`Could not bundle framework runtime into dist: ${error.message}`);
|
|
148
141
|
Print.warning('Production servers that serve /Slice/Slice.js from dist may 404 until this is resolved.');
|
|
@@ -227,45 +220,45 @@ async function processFile(srcFilePath, distFilePath, options) {
|
|
|
227
220
|
await fs.copy(srcFilePath, distFilePath);
|
|
228
221
|
const stat = await fs.stat(srcFilePath);
|
|
229
222
|
const sizeKB = (stat.size / 1024).toFixed(1);
|
|
230
|
-
Print.info(
|
|
223
|
+
if (options?.verbose) Print.info(`Copied ${fileName} (${sizeKB} KB)`);
|
|
231
224
|
} else {
|
|
232
|
-
await processComponentsFile(srcFilePath, distFilePath);
|
|
225
|
+
await processComponentsFile(srcFilePath, distFilePath, options);
|
|
233
226
|
}
|
|
234
227
|
} else if (ext === '.js') {
|
|
235
228
|
if (options?.minify === false) {
|
|
236
229
|
await fs.copy(srcFilePath, distFilePath);
|
|
237
230
|
const stat = await fs.stat(srcFilePath);
|
|
238
231
|
const sizeKB = (stat.size / 1024).toFixed(1);
|
|
239
|
-
Print.info(
|
|
232
|
+
if (options?.verbose) Print.info(`Copied ${fileName} (${sizeKB} KB)`);
|
|
240
233
|
} else {
|
|
241
|
-
await minifyJavaScript(srcFilePath, distFilePath);
|
|
234
|
+
await minifyJavaScript(srcFilePath, distFilePath, options);
|
|
242
235
|
}
|
|
243
236
|
} else if (ext === '.css') {
|
|
244
237
|
if (options?.minify === false) {
|
|
245
238
|
await fs.copy(srcFilePath, distFilePath);
|
|
246
239
|
const stat = await fs.stat(srcFilePath);
|
|
247
240
|
const sizeKB = (stat.size / 1024).toFixed(1);
|
|
248
|
-
Print.info(
|
|
241
|
+
if (options?.verbose) Print.info(`Copied ${fileName} (${sizeKB} KB)`);
|
|
249
242
|
} else {
|
|
250
|
-
await minifyCSS(srcFilePath, distFilePath);
|
|
243
|
+
await minifyCSS(srcFilePath, distFilePath, options);
|
|
251
244
|
}
|
|
252
245
|
} else if (ext === '.html') {
|
|
253
246
|
if (options?.minify === false) {
|
|
254
247
|
await fs.copy(srcFilePath, distFilePath);
|
|
255
248
|
const stat = await fs.stat(srcFilePath);
|
|
256
249
|
const sizeKB = (stat.size / 1024).toFixed(1);
|
|
257
|
-
Print.info(
|
|
250
|
+
if (options?.verbose) Print.info(`Copied ${fileName} (${sizeKB} KB)`);
|
|
258
251
|
} else {
|
|
259
|
-
await minifyHTML(srcFilePath, distFilePath);
|
|
252
|
+
await minifyHTML(srcFilePath, distFilePath, options);
|
|
260
253
|
}
|
|
261
254
|
} else if (fileName === 'sliceConfig.json') {
|
|
262
255
|
await fs.copy(srcFilePath, distFilePath);
|
|
263
|
-
Print.info(
|
|
256
|
+
if (options?.verbose) Print.info(`Preserved ${fileName} (configuration file)`);
|
|
264
257
|
} else {
|
|
265
258
|
await fs.copy(srcFilePath, distFilePath);
|
|
266
259
|
const stat = await fs.stat(srcFilePath);
|
|
267
260
|
const sizeKB = (stat.size / 1024).toFixed(1);
|
|
268
|
-
Print.info(
|
|
261
|
+
if (options?.verbose) Print.info(`Copied ${fileName} (${sizeKB} KB)`);
|
|
269
262
|
}
|
|
270
263
|
} catch (error) {
|
|
271
264
|
// Copying the source through keeps the build usable, but the file ships
|
|
@@ -278,12 +271,14 @@ async function processFile(srcFilePath, distFilePath, options) {
|
|
|
278
271
|
});
|
|
279
272
|
await fs.copy(srcFilePath, distFilePath);
|
|
280
273
|
}
|
|
274
|
+
|
|
275
|
+
if (options) options.fileCount = (options.fileCount || 0) + 1;
|
|
281
276
|
}
|
|
282
277
|
|
|
283
278
|
/**
|
|
284
279
|
* Processes the components.js file in a special way
|
|
285
280
|
*/
|
|
286
|
-
async function processComponentsFile(srcPath, distPath) {
|
|
281
|
+
async function processComponentsFile(srcPath, distPath, options = {}) {
|
|
287
282
|
const content = await fs.readFile(srcPath, 'utf8');
|
|
288
283
|
const originalSize = Buffer.byteLength(content, 'utf8');
|
|
289
284
|
|
|
@@ -294,13 +289,13 @@ async function processComponentsFile(srcPath, distPath) {
|
|
|
294
289
|
const minifiedSize = Buffer.byteLength(result.code, 'utf8');
|
|
295
290
|
const savings = Math.round(((originalSize - minifiedSize) / originalSize) * 100);
|
|
296
291
|
|
|
297
|
-
Print.minificationResult(`${path.basename(srcPath)} (preserved structure)`, originalSize, minifiedSize, savings);
|
|
292
|
+
if (options.verbose) Print.minificationResult(`${path.basename(srcPath)} (preserved structure)`, originalSize, minifiedSize, savings);
|
|
298
293
|
}
|
|
299
294
|
|
|
300
295
|
/**
|
|
301
296
|
* Minifies JavaScript files preserving Slice.js architecture
|
|
302
297
|
*/
|
|
303
|
-
async function minifyJavaScript(srcPath, distPath) {
|
|
298
|
+
async function minifyJavaScript(srcPath, distPath, options = {}) {
|
|
304
299
|
const content = await fs.readFile(srcPath, 'utf8');
|
|
305
300
|
const originalSize = Buffer.byteLength(content, 'utf8');
|
|
306
301
|
|
|
@@ -323,13 +318,13 @@ async function minifyJavaScript(srcPath, distPath) {
|
|
|
323
318
|
const minifiedSize = Buffer.byteLength(result.code, 'utf8');
|
|
324
319
|
const savings = Math.round(((originalSize - minifiedSize) / originalSize) * 100);
|
|
325
320
|
|
|
326
|
-
Print.minificationResult(path.basename(srcPath), originalSize, minifiedSize, savings);
|
|
321
|
+
if (options.verbose) Print.minificationResult(path.basename(srcPath), originalSize, minifiedSize, savings);
|
|
327
322
|
}
|
|
328
323
|
|
|
329
324
|
/**
|
|
330
325
|
* Minifies CSS files
|
|
331
326
|
*/
|
|
332
|
-
async function minifyCSS(srcPath, distPath) {
|
|
327
|
+
async function minifyCSS(srcPath, distPath, options = {}) {
|
|
333
328
|
const content = await fs.readFile(srcPath, 'utf8');
|
|
334
329
|
const originalSize = Buffer.byteLength(content, 'utf8');
|
|
335
330
|
|
|
@@ -349,13 +344,13 @@ async function minifyCSS(srcPath, distPath) {
|
|
|
349
344
|
const minifiedSize = Buffer.byteLength(result.styles, 'utf8');
|
|
350
345
|
const savings = Math.round(((originalSize - minifiedSize) / originalSize) * 100);
|
|
351
346
|
|
|
352
|
-
Print.minificationResult(path.basename(srcPath), originalSize, minifiedSize, savings);
|
|
347
|
+
if (options.verbose) Print.minificationResult(path.basename(srcPath), originalSize, minifiedSize, savings);
|
|
353
348
|
}
|
|
354
349
|
|
|
355
350
|
/**
|
|
356
351
|
* Minifies HTML files
|
|
357
352
|
*/
|
|
358
|
-
async function minifyHTML(srcPath, distPath) {
|
|
353
|
+
async function minifyHTML(srcPath, distPath, options = {}) {
|
|
359
354
|
const content = await fs.readFile(srcPath, 'utf8');
|
|
360
355
|
const originalSize = Buffer.byteLength(content, 'utf8');
|
|
361
356
|
|
|
@@ -382,30 +377,13 @@ async function minifyHTML(srcPath, distPath) {
|
|
|
382
377
|
const minifiedSize = Buffer.byteLength(minified, 'utf8');
|
|
383
378
|
const savings = Math.round(((originalSize - minifiedSize) / originalSize) * 100);
|
|
384
379
|
|
|
385
|
-
Print.minificationResult(path.basename(srcPath), originalSize, minifiedSize, savings);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Creates an optimized bundle of the main file
|
|
390
|
-
*/
|
|
391
|
-
async function createOptimizedBundle() {
|
|
392
|
-
Print.buildProgress('Creating optimized bundle...');
|
|
393
|
-
|
|
394
|
-
const mainJSPath = getDistPath(import.meta.url, 'App', 'index.js');
|
|
395
|
-
|
|
396
|
-
if (await fs.pathExists(mainJSPath)) {
|
|
397
|
-
Print.success('Main bundle optimized');
|
|
398
|
-
} else {
|
|
399
|
-
Print.warning('No main JavaScript file found for bundling');
|
|
400
|
-
}
|
|
380
|
+
if (options.verbose) Print.minificationResult(path.basename(srcPath), originalSize, minifiedSize, savings);
|
|
401
381
|
}
|
|
402
382
|
|
|
403
383
|
/**
|
|
404
384
|
* Generates build statistics
|
|
405
385
|
*/
|
|
406
386
|
async function generateBuildStats(srcDir, distDir) {
|
|
407
|
-
Print.buildProgress('Generating build statistics...');
|
|
408
|
-
|
|
409
387
|
const getDirectorySize = async (dirPath) => {
|
|
410
388
|
let totalSize = 0;
|
|
411
389
|
const items = await fs.readdir(dirPath);
|
|
@@ -430,10 +408,10 @@ async function generateBuildStats(srcDir, distDir) {
|
|
|
430
408
|
const savings = Math.round(((srcSize - distSize) / srcSize) * 100);
|
|
431
409
|
|
|
432
410
|
Print.newLine();
|
|
433
|
-
Print.
|
|
434
|
-
console.log(`
|
|
435
|
-
console.log(`
|
|
436
|
-
console.log(`
|
|
411
|
+
Print.subtitle('Build size');
|
|
412
|
+
console.log(` Source: ${(srcSize / 1024).toFixed(1)} KB`);
|
|
413
|
+
console.log(` Built: ${(distSize / 1024).toFixed(1)} KB`);
|
|
414
|
+
console.log(` Saved: ${savings}% smaller`);
|
|
437
415
|
|
|
438
416
|
} catch (error) {
|
|
439
417
|
Print.warning('Could not generate build statistics');
|
|
@@ -462,46 +440,49 @@ async function analyzeBuild() {
|
|
|
462
440
|
* MAIN BUILD FUNCTION
|
|
463
441
|
*/
|
|
464
442
|
export default async function buildProduction(options = {}) {
|
|
465
|
-
const startTime = Date.now();
|
|
466
|
-
const packageManager = resolvePackageManager(getProjectRoot(import.meta.url)).name;
|
|
467
443
|
resetDegradations();
|
|
468
444
|
|
|
469
445
|
try {
|
|
470
|
-
Print.title('
|
|
446
|
+
Print.title('Building for production');
|
|
471
447
|
Print.newLine();
|
|
472
448
|
|
|
473
449
|
const srcDir = getSrcPath(import.meta.url);
|
|
474
450
|
const distDir = getDistPath(import.meta.url);
|
|
451
|
+
const processOptions = { ...options, fileCount: 0 };
|
|
475
452
|
|
|
476
453
|
if (!await fs.pathExists(srcDir)) {
|
|
477
454
|
throw new Error('Source directory not found. Run "slice init" first.');
|
|
478
455
|
}
|
|
479
456
|
|
|
480
457
|
await verifySliceFiles(srcDir);
|
|
458
|
+
Print.success('Project files verified');
|
|
481
459
|
|
|
482
460
|
// Clean dist directory
|
|
483
461
|
if (await fs.pathExists(distDir)) {
|
|
484
462
|
if (!options.skipClean) {
|
|
485
|
-
Print.info('Cleaning previous build...');
|
|
486
463
|
await fs.remove(distDir);
|
|
487
|
-
Print.success('
|
|
464
|
+
Print.success('Cleaned dist/');
|
|
488
465
|
}
|
|
489
466
|
}
|
|
490
467
|
|
|
491
468
|
await fs.ensureDir(distDir);
|
|
492
|
-
await copySliceConfig();
|
|
469
|
+
await copySliceConfig(processOptions);
|
|
493
470
|
|
|
494
471
|
// Process files
|
|
495
|
-
Print.info('
|
|
496
|
-
await processDirectory(srcDir, distDir, srcDir,
|
|
497
|
-
Print.success(
|
|
472
|
+
Print.info('Optimizing source files...');
|
|
473
|
+
await processDirectory(srcDir, distDir, srcDir, processOptions);
|
|
474
|
+
Print.success(`Optimized ${processOptions.fileCount} files`);
|
|
498
475
|
|
|
499
476
|
// Make dist self-contained: the framework runtime the app imports at
|
|
500
477
|
// /Slice/Slice.js must live under dist so it ships with serverless deploys.
|
|
501
478
|
await copyFrameworkRuntime();
|
|
502
479
|
|
|
503
480
|
await verifyBuildIntegrity(distDir);
|
|
504
|
-
|
|
481
|
+
Print.success('Build integrity verified');
|
|
482
|
+
|
|
483
|
+
const envKeys = await writeSliceEnv(distDir, getProjectRoot(import.meta.url));
|
|
484
|
+
Print.success(`Public env generated (${envKeys} key(s))`);
|
|
485
|
+
|
|
505
486
|
await generateBuildStats(srcDir, distDir);
|
|
506
487
|
|
|
507
488
|
const fullyOptimized = reportDegradations();
|
|
@@ -510,16 +491,6 @@ export default async function buildProduction(options = {}) {
|
|
|
510
491
|
return false;
|
|
511
492
|
}
|
|
512
493
|
|
|
513
|
-
const buildTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
514
|
-
|
|
515
|
-
Print.newLine();
|
|
516
|
-
Print.success(`โจ Slice.js production build completed in ${buildTime}s`);
|
|
517
|
-
Print.info('Your optimized project is ready in the /dist directory');
|
|
518
|
-
Print.newLine();
|
|
519
|
-
Print.info('Next steps:');
|
|
520
|
-
console.log(` โข Use "${runScriptCommand(packageManager, 'start')}" to test the production build`);
|
|
521
|
-
console.log(' โข All Slice.js components and architecture preserved');
|
|
522
|
-
|
|
523
494
|
return true;
|
|
524
495
|
|
|
525
496
|
} catch (error) {
|
|
@@ -604,7 +575,7 @@ export async function buildCommand(options = {}) {
|
|
|
604
575
|
|
|
605
576
|
if (success && options.preview) {
|
|
606
577
|
Print.newLine();
|
|
607
|
-
Print.
|
|
578
|
+
Print.success('Build completed');
|
|
608
579
|
Print.info(`Starting preview server on port ${options.port || defaultPort}...`);
|
|
609
580
|
await serveProductionBuild(options.port || defaultPort);
|
|
610
581
|
}
|
|
@@ -14,16 +14,20 @@ export default async function bundle(options = {}) {
|
|
|
14
14
|
const projectRoot = getProjectRoot(import.meta.url);
|
|
15
15
|
|
|
16
16
|
try {
|
|
17
|
-
Print.title('๐ฆ Slice.js Bundle Generator');
|
|
18
|
-
Print.newLine();
|
|
19
|
-
|
|
20
17
|
// Validate that it's a Slice.js project
|
|
21
18
|
await validateProject(projectRoot);
|
|
22
19
|
|
|
20
|
+
if (options.analyze) {
|
|
21
|
+
Print.title('Build analysis');
|
|
22
|
+
Print.newLine();
|
|
23
|
+
} else {
|
|
24
|
+
Print.buildProgress('Generating bundles...');
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
// Phase 1: Analysis
|
|
24
|
-
Print.buildProgress('Analyzing project...');
|
|
25
28
|
const analyzer = new DependencyAnalyzer(import.meta.url);
|
|
26
29
|
const analysisData = await analyzer.analyze();
|
|
30
|
+
analyzer.reportDynamicBuildWarnings();
|
|
27
31
|
|
|
28
32
|
// Show report if in verbose mode
|
|
29
33
|
if (options.verbose || options.analyze) {
|
|
@@ -39,38 +43,30 @@ export default async function bundle(options = {}) {
|
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
// Phase 2: Bundle generation
|
|
42
|
-
Print.buildProgress('Generating bundles...');
|
|
43
46
|
const generator = new BundleGenerator(import.meta.url, analysisData, {
|
|
44
47
|
minify: !!options.minify,
|
|
45
48
|
obfuscate: !!options.obfuscate,
|
|
46
49
|
output: options.output || 'dist',
|
|
47
50
|
strictExternal: !!options.strictExternal,
|
|
48
51
|
sourcemap: !!options.sourcemap,
|
|
49
|
-
hashFilenames: !!options.hashFilenames
|
|
52
|
+
hashFilenames: !!options.hashFilenames,
|
|
53
|
+
verbose: !!options.verbose
|
|
50
54
|
});
|
|
51
55
|
const result = await generator.generate();
|
|
52
56
|
|
|
53
57
|
// Phase 3: Save configuration
|
|
54
|
-
Print.buildProgress('Saving configuration...');
|
|
55
58
|
await generator.saveBundleConfig(result.config);
|
|
56
59
|
|
|
57
60
|
// Phase 4: Summary
|
|
58
61
|
Print.newLine();
|
|
59
|
-
printSummary(result, startTime);
|
|
60
|
-
|
|
61
|
-
// Show next step
|
|
62
|
-
Print.newLine();
|
|
63
|
-
Print.info('๐ก Next step:');
|
|
64
|
-
console.log(' Update your Slice.js to use the generated bundles');
|
|
65
|
-
console.log(' Bundles will load automatically in production\n');
|
|
62
|
+
printSummary(result, startTime, options);
|
|
66
63
|
|
|
67
64
|
} catch (error) {
|
|
68
|
-
Print.error(
|
|
69
|
-
|
|
70
|
-
console.error(error.stack);
|
|
65
|
+
Print.error(`Error generating bundles: ${error.message}`);
|
|
66
|
+
Print.stack(error);
|
|
71
67
|
|
|
72
68
|
if (error.code) {
|
|
73
|
-
|
|
69
|
+
Print.verbose(`Error code: ${error.code}`);
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
throw error;
|
|
@@ -97,49 +93,58 @@ async function validateProject(projectRoot) {
|
|
|
97
93
|
/**
|
|
98
94
|
* Prints summary of generated bundles
|
|
99
95
|
*/
|
|
100
|
-
function printSummary(result, startTime) {
|
|
96
|
+
function printSummary(result, startTime, options = {}) {
|
|
101
97
|
const { bundles, config, files } = result;
|
|
102
98
|
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
99
|
+
const beforeRequests = config.stats.totalComponents;
|
|
100
|
+
const afterRequests = files.length;
|
|
101
|
+
const improvement = beforeRequests > 0
|
|
102
|
+
? Math.round((1 - afterRequests / beforeRequests) * 100)
|
|
103
|
+
: 0;
|
|
104
|
+
const routeCount = Object.keys(bundles.routes).length;
|
|
103
105
|
|
|
104
|
-
Print.success(`Bundles generated in ${duration}s
|
|
106
|
+
Print.success(`Bundles generated in ${duration}s`);
|
|
107
|
+
Print.newLine();
|
|
105
108
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
109
|
+
if (options.verbose) {
|
|
110
|
+
// Critical bundle
|
|
111
|
+
if (bundles.critical.components.length > 0) {
|
|
112
|
+
Print.subtitle('Critical bundle');
|
|
113
|
+
console.log(` Components: ${bundles.critical.components.length}`);
|
|
114
|
+
console.log(` Size: ${(bundles.critical.size / 1024).toFixed(1)} KB`);
|
|
115
|
+
console.log(` File: ${bundles.critical.file}`);
|
|
116
|
+
Print.newLine();
|
|
117
|
+
}
|
|
113
118
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
// Route bundles
|
|
120
|
+
if (routeCount > 0) {
|
|
121
|
+
Print.subtitle(`Route bundles (${routeCount})`);
|
|
122
|
+
|
|
123
|
+
for (const [key, bundle] of Object.entries(bundles.routes)) {
|
|
124
|
+
console.log(` ${key}`);
|
|
125
|
+
const routeDisplay = Array.isArray(bundle.path) ? `${bundle.path.length} routes` : (bundle.path || key);
|
|
126
|
+
console.log(` Route: ${routeDisplay}`);
|
|
127
|
+
console.log(` Components: ${bundle.components.length}`);
|
|
128
|
+
console.log(` Size: ${(bundle.size / 1024).toFixed(1)} KB`);
|
|
129
|
+
console.log(` File: ${bundle.file}`);
|
|
130
|
+
}
|
|
131
|
+
Print.newLine();
|
|
126
132
|
}
|
|
127
|
-
Print.newLine();
|
|
128
133
|
}
|
|
129
134
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log(`
|
|
134
|
-
console.log(`
|
|
135
|
-
console.log(`
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
console.log(`
|
|
135
|
+
// One summary for both modes. The per-route detail above is opt-in because a
|
|
136
|
+
// large app has dozens of bundles and the list drowns the build result.
|
|
137
|
+
Print.subtitle('Bundles');
|
|
138
|
+
console.log(` Strategy: ${config.strategy}`);
|
|
139
|
+
console.log(` Components: ${config.stats.totalComponents}`);
|
|
140
|
+
console.log(` Bundles: ${files.length}`);
|
|
141
|
+
if (bundles.critical.components.length > 0) {
|
|
142
|
+
console.log(` Critical: ${bundles.critical.components.length} components, ${(bundles.critical.size / 1024).toFixed(1)} KB`);
|
|
143
|
+
}
|
|
144
|
+
if (routeCount > 0) {
|
|
145
|
+
console.log(` Routes: ${routeCount}`);
|
|
146
|
+
}
|
|
147
|
+
console.log(` Requests: ${beforeRequests} โ ${afterRequests} (${improvement}% fewer)`);
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/**
|
|
@@ -150,7 +155,7 @@ export async function cleanBundles() {
|
|
|
150
155
|
const legacyPath = getSrcPath(import.meta.url, 'bundles');
|
|
151
156
|
|
|
152
157
|
try {
|
|
153
|
-
Print.title('
|
|
158
|
+
Print.title('Cleaning bundles');
|
|
154
159
|
|
|
155
160
|
// Checked before any early return: a project that upgraded and never rebuilt
|
|
156
161
|
// only has the old folder, and that is the case the hint exists for.
|
|
@@ -178,7 +183,7 @@ export async function cleanBundles() {
|
|
|
178
183
|
|
|
179
184
|
for (const file of generated) {
|
|
180
185
|
await fs.remove(path.join(bundlesPath, file));
|
|
181
|
-
console.log(`
|
|
186
|
+
console.log(` Deleted: bundles/${file}`);
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
// Only remove the folder when this command emptied it: dist/bundles may hold
|
|
@@ -191,8 +196,8 @@ export async function cleanBundles() {
|
|
|
191
196
|
Print.success(`${generated.length} files deleted`);
|
|
192
197
|
|
|
193
198
|
} catch (error) {
|
|
194
|
-
Print.error(
|
|
195
|
-
|
|
199
|
+
Print.error(`Error cleaning bundles: ${error.message}`);
|
|
200
|
+
Print.stack(error);
|
|
196
201
|
throw error;
|
|
197
202
|
}
|
|
198
203
|
}
|
|
@@ -212,7 +217,7 @@ export async function bundleInfo() {
|
|
|
212
217
|
|
|
213
218
|
const config = await fs.readJson(configPath);
|
|
214
219
|
|
|
215
|
-
Print.title('
|
|
220
|
+
Print.title('Bundle information');
|
|
216
221
|
Print.newLine();
|
|
217
222
|
|
|
218
223
|
Print.info('Configuration:');
|
|
@@ -244,8 +249,8 @@ export async function bundleInfo() {
|
|
|
244
249
|
}
|
|
245
250
|
|
|
246
251
|
} catch (error) {
|
|
247
|
-
Print.error(
|
|
248
|
-
|
|
252
|
+
Print.error(`Error reading bundle information: ${error.message}`);
|
|
253
|
+
Print.stack(error);
|
|
249
254
|
throw error;
|
|
250
255
|
}
|
|
251
256
|
}
|