slicejs-cli 4.3.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.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +260 -257
  3. package/client.js +927 -823
  4. package/commands/Print.js +163 -163
  5. package/commands/Validations.js +92 -92
  6. package/commands/build/build.js +97 -107
  7. package/commands/buildProduction/buildProduction.js +613 -613
  8. package/commands/bundle/bundle.js +251 -239
  9. package/commands/createComponent/VisualComponentTemplate.js +55 -55
  10. package/commands/createComponent/createComponent.js +128 -128
  11. package/commands/deleteComponent/deleteComponent.js +81 -81
  12. package/commands/docs/docs.js +365 -365
  13. package/commands/doctor/doctor.js +677 -563
  14. package/commands/getComponent/getComponent.js +842 -842
  15. package/commands/init/init.js +526 -475
  16. package/commands/lint/lint.js +75 -0
  17. package/commands/lint/types.js +85 -0
  18. package/commands/listComponents/listComponents.js +172 -172
  19. package/commands/seo/check.js +91 -0
  20. package/commands/seo/images.js +586 -0
  21. package/commands/seo/sitemap.js +106 -0
  22. package/commands/seo/support.js +130 -0
  23. package/commands/setup/lint.js +151 -0
  24. package/commands/skill/skill.js +236 -236
  25. package/commands/startServer/startServer.js +240 -240
  26. package/commands/startServer/watchServer.js +66 -66
  27. package/commands/typecheck/typecheck.js +83 -0
  28. package/commands/types/types.js +1378 -1097
  29. package/commands/utils/JsMinifier.js +230 -230
  30. package/commands/utils/LocalCliDelegation.js +78 -53
  31. package/commands/utils/PackageManager.js +148 -148
  32. package/commands/utils/PathHelper.js +87 -75
  33. package/commands/utils/ProjectValidation.js +274 -0
  34. package/commands/utils/SourceDiagnostics.js +201 -201
  35. package/commands/utils/VersionChecker.js +169 -169
  36. package/commands/utils/analyzeSource.js +77 -77
  37. package/commands/utils/bundling/BundleGenerator.js +3748 -3776
  38. package/commands/utils/bundling/DependencyAnalyzer.js +976 -976
  39. package/commands/utils/bundling/ExternalModuleBundler.js +298 -298
  40. package/commands/utils/componentAudit.js +74 -0
  41. package/commands/utils/compressAssets.js +103 -103
  42. package/commands/utils/cssScope.js +83 -0
  43. package/commands/utils/loadConfig.js +31 -31
  44. package/commands/utils/semver.js +66 -0
  45. package/commands/utils/sliceConfigSchema.js +72 -0
  46. package/commands/utils/sliceScripts.js +48 -48
  47. package/commands/utils/updateManager.js +471 -471
  48. package/eslint-config.js +128 -0
  49. package/package.json +19 -13
@@ -1,107 +1,97 @@
1
- import bundle from '../bundle/bundle.js';
2
- import buildProduction, { serveProductionBuild } from '../buildProduction/buildProduction.js';
3
- import { loadConfigSync } from '../utils/loadConfig.js';
4
- import { validateComponentProps } from '../types/types.js';
5
- import { getProjectRoot, getDistPath } from '../utils/PathHelper.js';
6
- import { precompressDirectory } from '../utils/compressAssets.js';
7
- import Print from '../Print.js';
8
-
9
- export default async function build(options = {}) {
10
- const minify = options.minify !== false;
11
- const obfuscate = options.obfuscate !== false;
12
-
13
- if (options.analyze) {
14
- return bundle({ analyze: true, verbose: options.verbose });
15
- }
16
-
17
- if (options.serve) {
18
- await serveProductionBuild(options.port);
19
- return true;
20
- }
21
-
22
- // Hard-fail before producing a bundle: ContextManager reactivity (setState →
23
- // watch/bind) is delivered through EventManager, and EventManager is only
24
- // bundled when events.enabled is true. context on + events off would ship a
25
- // bundle where every context watcher is silently dead — catch it here so the
26
- // broken bundle never gets built.
27
- const config = loadConfigSync(import.meta.url);
28
- if (config?.context?.enabled && !config?.events?.enabled) {
29
- Print.error('sliceConfig: context.enabled requires events.enabled.');
30
- Print.info('ContextManager reactivity (setState → watch/bind) runs through EventManager, which is only bundled when events.enabled is true. Set "events": { "enabled": true } in sliceConfig.json.');
31
- process.exit(1);
32
- }
33
-
34
- // Validate component static props before building (same checks as `slice
35
- // doctor`). Definition errors fail the build so a broken component contract
36
- // never ships; style issues warn but don't block. Skip with --no-validate.
37
- if (options.validate !== false) {
38
- const { errors, warnings, sourceErrors, sourceWarnings } = await validateComponentProps({ projectRoot: getProjectRoot(import.meta.url) });
39
-
40
- // Source-level problems first: they cover every registered component,
41
- // including ones no route reaches — which the bundler never sees at all.
42
- if (sourceErrors.length > 0) {
43
- Print.error(`Build blocked: ${sourceErrors.length} component source error(s) found.`);
44
- for (const e of sourceErrors) {
45
- Print.newLine();
46
- Print.info(` ${e.component}: ${e.message}`);
47
- }
48
- Print.newLine();
49
- Print.info('Fix the components above. These files cannot be bundled or loaded as they are.');
50
- process.exit(1);
51
- }
52
-
53
- for (const w of sourceWarnings) {
54
- Print.warning(`${w.component}: ${w.message}`);
55
- }
56
-
57
- for (const w of warnings) {
58
- Print.warning(`Props: ${w.component}.${w.prop} — ${w.message}`);
59
- }
60
-
61
- if (errors.length > 0) {
62
- Print.error(`Build blocked: ${errors.length} component prop error(s) found.`);
63
- for (const e of errors) {
64
- Print.info(` ${e.component}.${e.prop} — ${e.message}`);
65
- }
66
- Print.info('Fix the component prop definitions above, or run "slice build --no-validate" to bypass (not recommended).');
67
- process.exit(1);
68
- }
69
- }
70
-
71
- const success = await buildProduction({
72
- ...options,
73
- minify,
74
- obfuscate
75
- });
76
- if (!success) {
77
- return false;
78
- }
79
-
80
- Print.info('Generating bundles for production build...');
81
- await bundle({
82
- verbose: options.verbose,
83
- minify,
84
- obfuscate,
85
- output: 'dist',
86
- strictExternal: options.strictExternal,
87
- sourcemap: options.sourcemap,
88
- hashFilenames: options.hashFilenames
89
- });
90
-
91
- if (options.compress) {
92
- Print.info('Precompressing assets (gzip + brotli)...');
93
- const stats = await precompressDirectory(getDistPath(import.meta.url));
94
- if (stats.files > 0) {
95
- const pct = (n) => `${Math.round((1 - n / stats.originalBytes) * 100)}%`;
96
- Print.info(`Precompressed ${stats.files} file(s): ${(stats.originalBytes / 1024).toFixed(0)} KB → gzip ${(stats.gzipBytes / 1024).toFixed(0)} KB (${pct(stats.gzipBytes)}), brotli ${(stats.brotliBytes / 1024).toFixed(0)} KB (${pct(stats.brotliBytes)})`);
97
- } else {
98
- Print.info('No compressible assets found to precompress.');
99
- }
100
- }
101
-
102
- if (options.preview) {
103
- await serveProductionBuild(options.port);
104
- }
105
-
106
- return true;
107
- }
1
+ import bundle from '../bundle/bundle.js';
2
+ import buildProduction, { serveProductionBuild } from '../buildProduction/buildProduction.js';
3
+ import { validateProject, validateServerEntry, classifyValidation, describeIssue } from '../utils/ProjectValidation.js';
4
+ import { getProjectRoot, getDistPath } from '../utils/PathHelper.js';
5
+ import { precompressDirectory } from '../utils/compressAssets.js';
6
+ import Print from '../Print.js';
7
+
8
+ export default async function build(options = {}) {
9
+ const minify = options.minify !== false;
10
+ const obfuscate = options.obfuscate !== false;
11
+
12
+ if (options.analyze) {
13
+ return bundle({ analyze: true, verbose: options.verbose });
14
+ }
15
+
16
+ if (options.serve) {
17
+ await serveProductionBuild(options.port);
18
+ return true;
19
+ }
20
+
21
+ // One static pass: config rules, components and routes. `slice doctor`
22
+ // reports exactly this result, so a green doctor means the build's pre-flight
23
+ // passes. `--no-validate` skips the component findings; config and routes
24
+ // always run, because both produce a broken deployment rather than a style
25
+ // issue.
26
+ const validation = await validateProject({
27
+ projectRoot: getProjectRoot(import.meta.url),
28
+ skipComponents: options.validate === false,
29
+ // CSS scoping is a doctor advisory: it never blocks, and on an existing app
30
+ // it can be dozens of lines that do not belong in a build log.
31
+ includeCss: false
32
+ });
33
+ // The server entry is not part of the bundle, but a deploy with a broken
34
+ // api/index.js is a broken deploy: it joins the same blocking list.
35
+ const server = await validateServerEntry({ projectRoot: getProjectRoot(import.meta.url) });
36
+ const { blocking, advisory } = classifyValidation({ ...validation, ...server });
37
+
38
+ if (validation.configErrors.length > 0) {
39
+ for (const problem of validation.configErrors) {
40
+ Print.error(`sliceConfig: ${problem.path} ${problem.message}`);
41
+ }
42
+ Print.info('Fix sliceConfig.json and run the build again.');
43
+ process.exit(1);
44
+ }
45
+
46
+ if (blocking.length > 0) {
47
+ Print.error(`Build blocked: ${blocking.length} issue(s) found.`);
48
+ for (const issue of blocking) {
49
+ Print.info(` ${describeIssue(issue)}`);
50
+ }
51
+ Print.newLine();
52
+ Print.info('Fix the entries above. Component files that do not parse, have no default export or import a missing file cannot be bundled; routes.js is served as-is, so a broken import stops the app from navigating.');
53
+ Print.info('Bypass the component checks with "slice build --no-validate" (not recommended).');
54
+ process.exit(1);
55
+ }
56
+
57
+ for (const issue of advisory) {
58
+ Print.warning(describeIssue(issue));
59
+ }
60
+
61
+ const success = await buildProduction({
62
+ ...options,
63
+ minify,
64
+ obfuscate
65
+ });
66
+ if (!success) {
67
+ return false;
68
+ }
69
+
70
+ Print.info('Generating bundles for production build...');
71
+ await bundle({
72
+ verbose: options.verbose,
73
+ minify,
74
+ obfuscate,
75
+ output: 'dist',
76
+ strictExternal: options.strictExternal,
77
+ sourcemap: options.sourcemap,
78
+ hashFilenames: options.hashFilenames
79
+ });
80
+
81
+ if (options.compress) {
82
+ Print.info('Precompressing assets (gzip + brotli)...');
83
+ const stats = await precompressDirectory(getDistPath(import.meta.url));
84
+ if (stats.files > 0) {
85
+ const pct = (n) => `${Math.round((1 - n / stats.originalBytes) * 100)}%`;
86
+ Print.info(`Precompressed ${stats.files} file(s): ${(stats.originalBytes / 1024).toFixed(0)} KB → gzip ${(stats.gzipBytes / 1024).toFixed(0)} KB (${pct(stats.gzipBytes)}), brotli ${(stats.brotliBytes / 1024).toFixed(0)} KB (${pct(stats.brotliBytes)})`);
87
+ } else {
88
+ Print.info('No compressible assets found to precompress.');
89
+ }
90
+ }
91
+
92
+ if (options.preview) {
93
+ await serveProductionBuild(options.port);
94
+ }
95
+
96
+ return true;
97
+ }