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,239 +1,251 @@
1
- // cli/commands/bundle/bundle.js
2
- import path from 'path';
3
- import fs from 'fs-extra';
4
- import DependencyAnalyzer from '../utils/bundling/DependencyAnalyzer.js';
5
- import BundleGenerator from '../utils/bundling/BundleGenerator.js';
6
- import Print from '..//Print.js';
7
- import { getProjectRoot, getSrcPath } from '../utils/PathHelper.js';
8
-
9
- /**
10
- * Main bundling command
11
- */
12
- export default async function bundle(options = {}) {
13
- const startTime = Date.now();
14
- const projectRoot = getProjectRoot(import.meta.url);
15
-
16
- try {
17
- Print.title('📦 Slice.js Bundle Generator');
18
- Print.newLine();
19
-
20
- // Validate that it's a Slice.js project
21
- await validateProject(projectRoot);
22
-
23
- // Create default bundle config if needed
24
- const bundleGenerator = new BundleGenerator(import.meta.url, null);
25
- await bundleGenerator.createDefaultBundleConfig();
26
-
27
- // Phase 1: Analysis
28
- Print.buildProgress('Analyzing project...');
29
- const analyzer = new DependencyAnalyzer(import.meta.url);
30
- const analysisData = await analyzer.analyze();
31
-
32
- // Show report if in verbose mode
33
- if (options.verbose || options.analyze) {
34
- Print.newLine();
35
- analyzer.generateReport(analysisData.metrics);
36
- Print.newLine();
37
- }
38
-
39
- // If only analysis is requested, finish here
40
- if (options.analyze) {
41
- Print.success('Analysis completed');
42
- return;
43
- }
44
-
45
- // Phase 2: Bundle generation
46
- Print.buildProgress('Generating bundles...');
47
- const generator = new BundleGenerator(import.meta.url, analysisData, {
48
- minify: !!options.minify,
49
- obfuscate: !!options.obfuscate,
50
- output: options.output || 'src',
51
- strictExternal: !!options.strictExternal,
52
- sourcemap: !!options.sourcemap,
53
- hashFilenames: !!options.hashFilenames
54
- });
55
- const result = await generator.generate();
56
-
57
- // Phase 3: Save configuration
58
- Print.buildProgress('Saving configuration...');
59
- await generator.saveBundleConfig(result.config);
60
-
61
- // Phase 4: Summary
62
- Print.newLine();
63
- printSummary(result, startTime);
64
-
65
- // Show next step
66
- Print.newLine();
67
- Print.info('💡 Next step:');
68
- console.log(' Update your Slice.js to use the generated bundles');
69
- console.log(' Bundles will load automatically in production\n');
70
-
71
- } catch (error) {
72
- Print.error('Error generating bundles:', error.message);
73
- console.error('\n📍 Complete stack trace:');
74
- console.error(error.stack);
75
-
76
- if (error.code) {
77
- console.error('\n📍 Error code:', error.code);
78
- }
79
-
80
- throw error;
81
- }
82
- }
83
-
84
- /**
85
- * Validates that the project has the correct structure
86
- */
87
- async function validateProject(projectRoot) {
88
- const requiredPaths = [
89
- getSrcPath(import.meta.url, 'Components', 'components.js'),
90
- getSrcPath(import.meta.url, 'routes.js')
91
- ];
92
-
93
- for (const fullPath of requiredPaths) {
94
- if (!await fs.pathExists(fullPath)) {
95
- const relativePath = path.relative(projectRoot, fullPath);
96
- throw new Error(`Required file not found: ${relativePath}`);
97
- }
98
- }
99
- }
100
-
101
- /**
102
- * Prints summary of generated bundles
103
- */
104
- function printSummary(result, startTime) {
105
- const { bundles, config, files } = result;
106
- const duration = ((Date.now() - startTime) / 1000).toFixed(2);
107
-
108
- Print.success(`Bundles generated in ${duration}s\n`);
109
-
110
- // Critical bundle
111
- if (bundles.critical.components.length > 0) {
112
- Print.info('📦 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}\n`);
116
- }
117
-
118
- // Route bundles
119
- const routeCount = Object.keys(bundles.routes).length;
120
- if (routeCount > 0) {
121
- Print.info(`📦 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();
132
- }
133
-
134
- // Global statistics
135
- Print.info('📊 Statistics:');
136
- console.log(` Strategy: ${config.strategy}`);
137
- console.log(` Total components: ${config.stats.totalComponents}`);
138
- console.log(` Shared components: ${config.stats.sharedComponents}`);
139
- console.log(` Generated files: ${files.length}`);
140
-
141
- // Calculate estimated improvement
142
- const beforeRequests = config.stats.totalComponents;
143
- const afterRequests = files.length;
144
- const improvement = Math.round((1 - afterRequests / beforeRequests) * 100);
145
-
146
- console.log(` Request reduction: ${improvement}% (${beforeRequests} → ${afterRequests})`);
147
- }
148
-
149
- /**
150
- * Subcommand: Clean bundles
151
- */
152
- export async function cleanBundles() {
153
- const srcPath = getSrcPath(import.meta.url);
154
-
155
- try {
156
- Print.title('🧹 Cleaning bundles...');
157
-
158
- const files = await fs.readdir(srcPath);
159
- const bundleFiles = files.filter(f => f.startsWith('slice-bundle.'));
160
-
161
- if (bundleFiles.length === 0) {
162
- Print.warning('No bundles found to clean');
163
- return;
164
- }
165
-
166
- for (const file of bundleFiles) {
167
- await fs.remove(path.join(srcPath, file));
168
- console.log(` ✓ Deleted: ${file}`);
169
- }
170
-
171
- // Remove config
172
- const configPath = getSrcPath(import.meta.url, 'bundle.config.json');
173
- if (await fs.pathExists(configPath)) {
174
- await fs.remove(configPath);
175
- console.log(` ✓ Deleted: bundle.config.json`);
176
- }
177
-
178
- Print.newLine();
179
- Print.success(`${bundleFiles.length} files deleted`);
180
-
181
- } catch (error) {
182
- Print.error('Error cleaning bundles:', error.message);
183
- console.error(error.stack);
184
- throw error;
185
- }
186
- }
187
-
188
- /**
189
- * Subcommand: Bundle information
190
- */
191
- export async function bundleInfo() {
192
- const configPath = getSrcPath(import.meta.url, 'bundle.config.json');
193
-
194
- try {
195
- if (!await fs.pathExists(configPath)) {
196
- Print.warning('Bundle configuration not found');
197
- Print.info('Run "slice bundle" to generate bundles');
198
- return;
199
- }
200
-
201
- const config = await fs.readJson(configPath);
202
-
203
- Print.title('📦 Bundle Information');
204
- Print.newLine();
205
-
206
- Print.info('Configuration:');
207
- console.log(` Version: ${config.version}`);
208
- console.log(` Strategy: ${config.strategy}`);
209
- console.log(` Generated: ${new Date(config.generated).toLocaleString()}`);
210
- Print.newLine();
211
-
212
- Print.info('Statistics:');
213
- console.log(` Total components: ${config.stats.totalComponents}`);
214
- console.log(` Total routes: ${config.stats.totalRoutes}`);
215
- console.log(` Shared components: ${config.stats.sharedComponents} (${config.stats.sharedPercentage}%)`);
216
- console.log(` Total size: ${(config.stats.totalSize / 1024).toFixed(1)} KB`);
217
- Print.newLine();
218
-
219
- Print.info('Bundles:');
220
-
221
- // Critical
222
- if (config.bundles.critical) {
223
- console.log(` Critical: ${config.bundles.critical.components.length} components, ${(config.bundles.critical.size / 1024).toFixed(1)} KB`);
224
- }
225
-
226
- // Routes
227
- const routeCount = Object.keys(config.bundles.routes).length;
228
- console.log(` Routes: ${routeCount} bundles`);
229
-
230
- for (const [key, bundle] of Object.entries(config.bundles.routes)) {
231
- console.log(` ${key}: ${bundle.components.length} components, ${(bundle.size / 1024).toFixed(1)} KB`);
232
- }
233
-
234
- } catch (error) {
235
- Print.error('Error reading information:', error.message);
236
- console.error(error.stack);
237
- throw error;
238
- }
239
- }
1
+ // cli/commands/bundle/bundle.js
2
+ import path from 'path';
3
+ import fs from 'fs-extra';
4
+ import DependencyAnalyzer from '../utils/bundling/DependencyAnalyzer.js';
5
+ import BundleGenerator from '../utils/bundling/BundleGenerator.js';
6
+ import Print from '..//Print.js';
7
+ import { getProjectRoot, getSrcPath, getDistPath } from '../utils/PathHelper.js';
8
+
9
+ /**
10
+ * Main bundling command
11
+ */
12
+ export default async function bundle(options = {}) {
13
+ const startTime = Date.now();
14
+ const projectRoot = getProjectRoot(import.meta.url);
15
+
16
+ try {
17
+ Print.title('📦 Slice.js Bundle Generator');
18
+ Print.newLine();
19
+
20
+ // Validate that it's a Slice.js project
21
+ await validateProject(projectRoot);
22
+
23
+ // Phase 1: Analysis
24
+ Print.buildProgress('Analyzing project...');
25
+ const analyzer = new DependencyAnalyzer(import.meta.url);
26
+ const analysisData = await analyzer.analyze();
27
+
28
+ // Show report if in verbose mode
29
+ if (options.verbose || options.analyze) {
30
+ Print.newLine();
31
+ analyzer.generateReport(analysisData.metrics);
32
+ Print.newLine();
33
+ }
34
+
35
+ // If only analysis is requested, finish here
36
+ if (options.analyze) {
37
+ Print.success('Analysis completed');
38
+ return;
39
+ }
40
+
41
+ // Phase 2: Bundle generation
42
+ Print.buildProgress('Generating bundles...');
43
+ const generator = new BundleGenerator(import.meta.url, analysisData, {
44
+ minify: !!options.minify,
45
+ obfuscate: !!options.obfuscate,
46
+ output: options.output || 'dist',
47
+ strictExternal: !!options.strictExternal,
48
+ sourcemap: !!options.sourcemap,
49
+ hashFilenames: !!options.hashFilenames
50
+ });
51
+ const result = await generator.generate();
52
+
53
+ // Phase 3: Save configuration
54
+ Print.buildProgress('Saving configuration...');
55
+ await generator.saveBundleConfig(result.config);
56
+
57
+ // Phase 4: Summary
58
+ 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');
66
+
67
+ } catch (error) {
68
+ Print.error('Error generating bundles:', error.message);
69
+ console.error('\n📍 Complete stack trace:');
70
+ console.error(error.stack);
71
+
72
+ if (error.code) {
73
+ console.error('\n📍 Error code:', error.code);
74
+ }
75
+
76
+ throw error;
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Validates that the project has the correct structure
82
+ */
83
+ async function validateProject(projectRoot) {
84
+ const requiredPaths = [
85
+ getSrcPath(import.meta.url, 'Components', 'components.js'),
86
+ getSrcPath(import.meta.url, 'routes.js')
87
+ ];
88
+
89
+ for (const fullPath of requiredPaths) {
90
+ if (!await fs.pathExists(fullPath)) {
91
+ const relativePath = path.relative(projectRoot, fullPath);
92
+ throw new Error(`Required file not found: ${relativePath}`);
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Prints summary of generated bundles
99
+ */
100
+ function printSummary(result, startTime) {
101
+ const { bundles, config, files } = result;
102
+ const duration = ((Date.now() - startTime) / 1000).toFixed(2);
103
+
104
+ Print.success(`Bundles generated in ${duration}s\n`);
105
+
106
+ // Critical bundle
107
+ if (bundles.critical.components.length > 0) {
108
+ Print.info('📦 Critical Bundle:');
109
+ console.log(` Components: ${bundles.critical.components.length}`);
110
+ console.log(` Size: ${(bundles.critical.size / 1024).toFixed(1)} KB`);
111
+ console.log(` File: ${bundles.critical.file}\n`);
112
+ }
113
+
114
+ // Route bundles
115
+ const routeCount = Object.keys(bundles.routes).length;
116
+ if (routeCount > 0) {
117
+ Print.info(`📦 Route Bundles (${routeCount}):`);
118
+
119
+ for (const [key, bundle] of Object.entries(bundles.routes)) {
120
+ console.log(` ${key}:`);
121
+ const routeDisplay = Array.isArray(bundle.path) ? `${bundle.path.length} routes` : (bundle.path || key);
122
+ console.log(` Route: ${routeDisplay}`);
123
+ console.log(` Components: ${bundle.components.length}`);
124
+ console.log(` Size: ${(bundle.size / 1024).toFixed(1)} KB`);
125
+ console.log(` File: ${bundle.file}`);
126
+ }
127
+ Print.newLine();
128
+ }
129
+
130
+ // Global statistics
131
+ Print.info('📊 Statistics:');
132
+ console.log(` Strategy: ${config.strategy}`);
133
+ console.log(` Total components: ${config.stats.totalComponents}`);
134
+ console.log(` Shared components: ${config.stats.sharedComponents}`);
135
+ console.log(` Generated files: ${files.length}`);
136
+
137
+ // Calculate estimated improvement
138
+ const beforeRequests = config.stats.totalComponents;
139
+ const afterRequests = files.length;
140
+ const improvement = Math.round((1 - afterRequests / beforeRequests) * 100);
141
+
142
+ console.log(` Request reduction: ${improvement}% (${beforeRequests} → ${afterRequests})`);
143
+ }
144
+
145
+ /**
146
+ * Subcommand: Clean bundles
147
+ */
148
+ export async function cleanBundles() {
149
+ const bundlesPath = getDistPath(import.meta.url, 'bundles');
150
+ const legacyPath = getSrcPath(import.meta.url, 'bundles');
151
+
152
+ try {
153
+ Print.title('🧹 Cleaning bundles...');
154
+
155
+ // Checked before any early return: a project that upgraded and never rebuilt
156
+ // only has the old folder, and that is the case the hint exists for.
157
+ if (await fs.pathExists(legacyPath)) {
158
+ Print.info('Found a legacy src/bundles folder. Bundles live in dist/bundles now; remove it when convenient.');
159
+ }
160
+
161
+ if (!await fs.pathExists(bundlesPath)) {
162
+ Print.warning('No bundles found to clean');
163
+ return;
164
+ }
165
+
166
+ const files = await fs.readdir(bundlesPath);
167
+ // Includes the .br/.gz siblings `slice build --compress` writes; leaving them
168
+ // behind keeps the server answering /bundles/bundle.config.json from a stale
169
+ // precompressed copy.
170
+ const generated = files.filter(
171
+ (file) => file.startsWith('slice-bundle.') || file.startsWith('bundle.config.')
172
+ );
173
+
174
+ if (generated.length === 0) {
175
+ Print.warning('No bundles found to clean');
176
+ return;
177
+ }
178
+
179
+ for (const file of generated) {
180
+ await fs.remove(path.join(bundlesPath, file));
181
+ console.log(` ✓ Deleted: bundles/${file}`);
182
+ }
183
+
184
+ // Only remove the folder when this command emptied it: dist/bundles may hold
185
+ // something else the project put there.
186
+ if ((await fs.readdir(bundlesPath)).length === 0) {
187
+ await fs.remove(bundlesPath);
188
+ }
189
+
190
+ Print.newLine();
191
+ Print.success(`${generated.length} files deleted`);
192
+
193
+ } catch (error) {
194
+ Print.error('Error cleaning bundles:', error.message);
195
+ console.error(error.stack);
196
+ throw error;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Subcommand: Bundle information
202
+ */
203
+ export async function bundleInfo() {
204
+ const configPath = getDistPath(import.meta.url, 'bundles', 'bundle.config.json');
205
+
206
+ try {
207
+ if (!await fs.pathExists(configPath)) {
208
+ Print.warning('Bundle configuration not found');
209
+ Print.info('Run "slice build" to generate bundles');
210
+ return;
211
+ }
212
+
213
+ const config = await fs.readJson(configPath);
214
+
215
+ Print.title('📦 Bundle Information');
216
+ Print.newLine();
217
+
218
+ Print.info('Configuration:');
219
+ console.log(` Version: ${config.version}`);
220
+ console.log(` Strategy: ${config.strategy}`);
221
+ console.log(` Generated: ${new Date(config.generated).toLocaleString()}`);
222
+ Print.newLine();
223
+
224
+ Print.info('Statistics:');
225
+ console.log(` Total components: ${config.stats.totalComponents}`);
226
+ console.log(` Total routes: ${config.stats.totalRoutes}`);
227
+ console.log(` Shared components: ${config.stats.sharedComponents} (${config.stats.sharedPercentage}%)`);
228
+ console.log(` Total size: ${(config.stats.totalSize / 1024).toFixed(1)} KB`);
229
+ Print.newLine();
230
+
231
+ Print.info('Bundles:');
232
+
233
+ // Critical
234
+ if (config.bundles.critical) {
235
+ console.log(` Critical: ${config.bundles.critical.components.length} components, ${(config.bundles.critical.size / 1024).toFixed(1)} KB`);
236
+ }
237
+
238
+ // Routes
239
+ const routeCount = Object.keys(config.bundles.routes).length;
240
+ console.log(` Routes: ${routeCount} bundles`);
241
+
242
+ for (const [key, bundle] of Object.entries(config.bundles.routes)) {
243
+ console.log(` ${key}: ${bundle.components.length} components, ${(bundle.size / 1024).toFixed(1)} KB`);
244
+ }
245
+
246
+ } catch (error) {
247
+ Print.error('Error reading information:', error.message);
248
+ console.error(error.stack);
249
+ throw error;
250
+ }
251
+ }
@@ -1,55 +1,55 @@
1
- export default class componentTemplates{
2
-
3
- static visual(componentName){
4
- return `export default class ${componentName} extends HTMLElement {
5
-
6
- static props = {
7
- // Define your component props here
8
- // Example:
9
- /*
10
- "value": {
11
- type: 'string',
12
- default: 'Button',
13
- required: false
14
- },
15
- */
16
- }
17
-
18
- constructor(props) {
19
- super();
20
- slice.attachTemplate(this);
21
- slice.controller.setComponentProps(this, props);
22
- }
23
-
24
- init() {
25
- // Component initialization logic (can be async)
26
- }
27
-
28
- update() {
29
- // Component update logic (can be async)
30
- }
31
-
32
- // Add your custom methods here
33
- }
34
-
35
- customElements.define("slice-${componentName.toLowerCase()}", ${componentName});
36
- `;
37
- }
38
-
39
- static service(componentName) {
40
- return `export default class ${componentName} {
41
- constructor(props) {
42
- // Initialize service with props
43
- this.props = props || {};
44
- }
45
-
46
- init() {
47
- // Service initialization logic (can be async)
48
- }
49
-
50
- // Add your service methods here
51
- }
52
- `;
53
- }
54
- }
55
-
1
+ export default class componentTemplates{
2
+
3
+ static visual(componentName){
4
+ return `export default class ${componentName} extends HTMLElement {
5
+
6
+ static props = {
7
+ // Define your component props here
8
+ // Example:
9
+ /*
10
+ "value": {
11
+ type: 'string',
12
+ default: 'Button',
13
+ required: false
14
+ },
15
+ */
16
+ }
17
+
18
+ constructor(props) {
19
+ super();
20
+ slice.attachTemplate(this);
21
+ slice.controller.setComponentProps(this, props);
22
+ }
23
+
24
+ init() {
25
+ // Component initialization logic (can be async)
26
+ }
27
+
28
+ update() {
29
+ // Component update logic (can be async)
30
+ }
31
+
32
+ // Add your custom methods here
33
+ }
34
+
35
+ customElements.define("slice-${componentName.toLowerCase()}", ${componentName});
36
+ `;
37
+ }
38
+
39
+ static service(componentName) {
40
+ return `export default class ${componentName} {
41
+ constructor(props) {
42
+ // Initialize service with props
43
+ this.props = props || {};
44
+ }
45
+
46
+ init() {
47
+ // Service initialization logic (can be async)
48
+ }
49
+
50
+ // Add your service methods here
51
+ }
52
+ `;
53
+ }
54
+ }
55
+