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,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
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Phase
|
|
58
|
-
Print.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
Print.newLine();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
console.
|
|
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
|
-
console.log(`
|
|
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
|
-
|
|
161
|
-
if (
|
|
162
|
-
Print.warning('No bundles found to clean');
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
console.log(`
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
+
|