slicejs-cli 3.6.3 → 3.6.4
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 +226 -226
- package/client.js +744 -744
- package/commands/Print.js +163 -163
- package/commands/Validations.js +92 -92
- package/commands/build/build.js +40 -40
- package/commands/buildProduction/buildProduction.js +577 -579
- package/commands/bundle/bundle.js +234 -234
- package/commands/createComponent/VisualComponentTemplate.js +55 -55
- package/commands/createComponent/createComponent.js +128 -128
- package/commands/deleteComponent/deleteComponent.js +81 -81
- package/commands/doctor/doctor.js +440 -440
- package/commands/getComponent/getComponent.js +701 -701
- package/commands/init/init.js +467 -467
- package/commands/listComponents/listComponents.js +172 -172
- package/commands/startServer/startServer.js +261 -261
- package/commands/startServer/watchServer.js +66 -66
- package/commands/types/types.js +580 -580
- package/commands/utils/LocalCliDelegation.js +53 -53
- package/commands/utils/PackageManager.js +148 -148
- package/commands/utils/PathHelper.js +75 -75
- package/commands/utils/VersionChecker.js +169 -169
- package/commands/utils/bundling/BundleGenerator.js +2525 -2525
- package/commands/utils/bundling/DependencyAnalyzer.js +925 -925
- package/commands/utils/loadConfig.js +31 -31
- package/commands/utils/sliceScripts.js +23 -23
- package/commands/utils/updateManager.js +471 -471
- package/package.json +73 -73
- package/post.js +60 -60
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import Table from 'cli-table3';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import Print from '../Print.js';
|
|
6
|
-
import { getSrcPath, getComponentsJsPath, getConfigPath } from '../utils/PathHelper.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Loads configuration from sliceConfig.json
|
|
10
|
-
* @returns {object} - Configuration object
|
|
11
|
-
*/
|
|
12
|
-
const loadConfig = () => {
|
|
13
|
-
try {
|
|
14
|
-
const configPath = getConfigPath(import.meta.url);
|
|
15
|
-
if (!fs.existsSync(configPath)) {
|
|
16
|
-
Print.error('sliceConfig.json not found');
|
|
17
|
-
Print.info('Run "slice init" to initialize your project');
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
21
|
-
return JSON.parse(rawData);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
Print.error(`Failed to load configuration: ${error.message}`);
|
|
24
|
-
Print.info('Check that sliceConfig.json is valid JSON');
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Lists files in a given folder, filtering only .js files
|
|
31
|
-
* @param {string} folderPath - Path of the folder to read
|
|
32
|
-
* @returns {string[]} - List of found files
|
|
33
|
-
*/
|
|
34
|
-
const listComponents = (folderPath) => {
|
|
35
|
-
try {
|
|
36
|
-
if (!fs.existsSync(folderPath)) {
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
const result = fs.readdirSync(folderPath);
|
|
40
|
-
return result;
|
|
41
|
-
} catch (error) {
|
|
42
|
-
Print.error(`Failed to read directory ${folderPath}: ${error.message}`);
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Counts files in a component directory
|
|
49
|
-
*/
|
|
50
|
-
const countComponentFiles = (componentPath) => {
|
|
51
|
-
try {
|
|
52
|
-
if (!fs.existsSync(componentPath)) return 0;
|
|
53
|
-
const files = fs.readdirSync(componentPath);
|
|
54
|
-
return files.filter(f => fs.statSync(path.join(componentPath, f)).isFile()).length;
|
|
55
|
-
} catch {
|
|
56
|
-
return 0;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Gets components dynamically from sliceConfig.json
|
|
62
|
-
* @returns {object} - Component mapping with their category
|
|
63
|
-
*/
|
|
64
|
-
const getComponents = () => {
|
|
65
|
-
const config = loadConfig();
|
|
66
|
-
if (!config) return {};
|
|
67
|
-
|
|
68
|
-
const folderSuffix = 'src'; // Always use 'src' for development
|
|
69
|
-
const componentPaths = config.paths?.components || {};
|
|
70
|
-
let allComponents = new Map();
|
|
71
|
-
|
|
72
|
-
Object.entries(componentPaths).forEach(([category, { path: folderPath }]) => {
|
|
73
|
-
const cleanFolderPath = folderPath ? folderPath.replace(/^[/\\]+/, '') : '';
|
|
74
|
-
const fullPath = getSrcPath(import.meta.url, cleanFolderPath);
|
|
75
|
-
const files = listComponents(fullPath);
|
|
76
|
-
|
|
77
|
-
files.forEach(file => {
|
|
78
|
-
const componentPath = path.join(fullPath, file);
|
|
79
|
-
if (fs.statSync(componentPath).isDirectory()) {
|
|
80
|
-
const fileCount = countComponentFiles(componentPath);
|
|
81
|
-
allComponents.set(file, { category, files: fileCount });
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return Object.fromEntries(allComponents);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
function listComponentsReal() {
|
|
90
|
-
try {
|
|
91
|
-
// Get components dynamically
|
|
92
|
-
const components = getComponents();
|
|
93
|
-
|
|
94
|
-
if (Object.keys(components).length === 0) {
|
|
95
|
-
Print.warning('No components found in your project');
|
|
96
|
-
Print.info('Create your first component with "slice component create"');
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Create table with cli-table3
|
|
101
|
-
const table = new Table({
|
|
102
|
-
head: [
|
|
103
|
-
chalk.cyan.bold('Component'),
|
|
104
|
-
chalk.cyan.bold('Category'),
|
|
105
|
-
chalk.cyan.bold('Files')
|
|
106
|
-
],
|
|
107
|
-
colWidths: [30, 20, 10],
|
|
108
|
-
style: {
|
|
109
|
-
head: [],
|
|
110
|
-
border: ['gray']
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Group by category for better visualization
|
|
115
|
-
const byCategory = {};
|
|
116
|
-
Object.entries(components).forEach(([name, data]) => {
|
|
117
|
-
if (!byCategory[data.category]) {
|
|
118
|
-
byCategory[data.category] = [];
|
|
119
|
-
}
|
|
120
|
-
byCategory[data.category].push({ name, files: data.files });
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// Add rows to the table
|
|
124
|
-
Object.entries(byCategory).forEach(([category, comps]) => {
|
|
125
|
-
comps.forEach((comp, index) => {
|
|
126
|
-
if (index === 0) {
|
|
127
|
-
// First row of the category
|
|
128
|
-
table.push([
|
|
129
|
-
chalk.bold(comp.name),
|
|
130
|
-
chalk.yellow(category),
|
|
131
|
-
comp.files.toString()
|
|
132
|
-
]);
|
|
133
|
-
} else {
|
|
134
|
-
// Rest of components in the category
|
|
135
|
-
table.push([
|
|
136
|
-
chalk.bold(comp.name),
|
|
137
|
-
chalk.gray('″'), // Ditto mark
|
|
138
|
-
comp.files.toString()
|
|
139
|
-
]);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
Print.newLine();
|
|
145
|
-
Print.title('📦 Local Components');
|
|
146
|
-
Print.newLine();
|
|
147
|
-
console.log(table.toString());
|
|
148
|
-
Print.newLine();
|
|
149
|
-
Print.info(`Total: ${Object.keys(components).length} component${Object.keys(components).length !== 1 ? 's' : ''} found`);
|
|
150
|
-
|
|
151
|
-
// Path where components.js will be generated
|
|
152
|
-
const outputPath = getComponentsJsPath(import.meta.url);
|
|
153
|
-
|
|
154
|
-
// Ensure the directory exists
|
|
155
|
-
const outputDir = path.dirname(outputPath);
|
|
156
|
-
if (!fs.existsSync(outputDir)) {
|
|
157
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Generate components.js file with detected components
|
|
161
|
-
const componentsForExport = Object.fromEntries(
|
|
162
|
-
Object.entries(components).map(([name, data]) => [name, data.category])
|
|
163
|
-
);
|
|
164
|
-
fs.writeFileSync(outputPath, `const components = ${JSON.stringify(componentsForExport, null, 2)};\n\nexport default components;\n`);
|
|
165
|
-
|
|
166
|
-
} catch (error) {
|
|
167
|
-
Print.error(`Failed to list components: ${error.message}`);
|
|
168
|
-
Print.info('Make sure your project structure is correct');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export default listComponentsReal;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import Print from '../Print.js';
|
|
6
|
+
import { getSrcPath, getComponentsJsPath, getConfigPath } from '../utils/PathHelper.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Loads configuration from sliceConfig.json
|
|
10
|
+
* @returns {object} - Configuration object
|
|
11
|
+
*/
|
|
12
|
+
const loadConfig = () => {
|
|
13
|
+
try {
|
|
14
|
+
const configPath = getConfigPath(import.meta.url);
|
|
15
|
+
if (!fs.existsSync(configPath)) {
|
|
16
|
+
Print.error('sliceConfig.json not found');
|
|
17
|
+
Print.info('Run "slice init" to initialize your project');
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
21
|
+
return JSON.parse(rawData);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
Print.error(`Failed to load configuration: ${error.message}`);
|
|
24
|
+
Print.info('Check that sliceConfig.json is valid JSON');
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Lists files in a given folder, filtering only .js files
|
|
31
|
+
* @param {string} folderPath - Path of the folder to read
|
|
32
|
+
* @returns {string[]} - List of found files
|
|
33
|
+
*/
|
|
34
|
+
const listComponents = (folderPath) => {
|
|
35
|
+
try {
|
|
36
|
+
if (!fs.existsSync(folderPath)) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const result = fs.readdirSync(folderPath);
|
|
40
|
+
return result;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
Print.error(`Failed to read directory ${folderPath}: ${error.message}`);
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Counts files in a component directory
|
|
49
|
+
*/
|
|
50
|
+
const countComponentFiles = (componentPath) => {
|
|
51
|
+
try {
|
|
52
|
+
if (!fs.existsSync(componentPath)) return 0;
|
|
53
|
+
const files = fs.readdirSync(componentPath);
|
|
54
|
+
return files.filter(f => fs.statSync(path.join(componentPath, f)).isFile()).length;
|
|
55
|
+
} catch {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets components dynamically from sliceConfig.json
|
|
62
|
+
* @returns {object} - Component mapping with their category
|
|
63
|
+
*/
|
|
64
|
+
const getComponents = () => {
|
|
65
|
+
const config = loadConfig();
|
|
66
|
+
if (!config) return {};
|
|
67
|
+
|
|
68
|
+
const folderSuffix = 'src'; // Always use 'src' for development
|
|
69
|
+
const componentPaths = config.paths?.components || {};
|
|
70
|
+
let allComponents = new Map();
|
|
71
|
+
|
|
72
|
+
Object.entries(componentPaths).forEach(([category, { path: folderPath }]) => {
|
|
73
|
+
const cleanFolderPath = folderPath ? folderPath.replace(/^[/\\]+/, '') : '';
|
|
74
|
+
const fullPath = getSrcPath(import.meta.url, cleanFolderPath);
|
|
75
|
+
const files = listComponents(fullPath);
|
|
76
|
+
|
|
77
|
+
files.forEach(file => {
|
|
78
|
+
const componentPath = path.join(fullPath, file);
|
|
79
|
+
if (fs.statSync(componentPath).isDirectory()) {
|
|
80
|
+
const fileCount = countComponentFiles(componentPath);
|
|
81
|
+
allComponents.set(file, { category, files: fileCount });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return Object.fromEntries(allComponents);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
function listComponentsReal() {
|
|
90
|
+
try {
|
|
91
|
+
// Get components dynamically
|
|
92
|
+
const components = getComponents();
|
|
93
|
+
|
|
94
|
+
if (Object.keys(components).length === 0) {
|
|
95
|
+
Print.warning('No components found in your project');
|
|
96
|
+
Print.info('Create your first component with "slice component create"');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Create table with cli-table3
|
|
101
|
+
const table = new Table({
|
|
102
|
+
head: [
|
|
103
|
+
chalk.cyan.bold('Component'),
|
|
104
|
+
chalk.cyan.bold('Category'),
|
|
105
|
+
chalk.cyan.bold('Files')
|
|
106
|
+
],
|
|
107
|
+
colWidths: [30, 20, 10],
|
|
108
|
+
style: {
|
|
109
|
+
head: [],
|
|
110
|
+
border: ['gray']
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Group by category for better visualization
|
|
115
|
+
const byCategory = {};
|
|
116
|
+
Object.entries(components).forEach(([name, data]) => {
|
|
117
|
+
if (!byCategory[data.category]) {
|
|
118
|
+
byCategory[data.category] = [];
|
|
119
|
+
}
|
|
120
|
+
byCategory[data.category].push({ name, files: data.files });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Add rows to the table
|
|
124
|
+
Object.entries(byCategory).forEach(([category, comps]) => {
|
|
125
|
+
comps.forEach((comp, index) => {
|
|
126
|
+
if (index === 0) {
|
|
127
|
+
// First row of the category
|
|
128
|
+
table.push([
|
|
129
|
+
chalk.bold(comp.name),
|
|
130
|
+
chalk.yellow(category),
|
|
131
|
+
comp.files.toString()
|
|
132
|
+
]);
|
|
133
|
+
} else {
|
|
134
|
+
// Rest of components in the category
|
|
135
|
+
table.push([
|
|
136
|
+
chalk.bold(comp.name),
|
|
137
|
+
chalk.gray('″'), // Ditto mark
|
|
138
|
+
comp.files.toString()
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
Print.newLine();
|
|
145
|
+
Print.title('📦 Local Components');
|
|
146
|
+
Print.newLine();
|
|
147
|
+
console.log(table.toString());
|
|
148
|
+
Print.newLine();
|
|
149
|
+
Print.info(`Total: ${Object.keys(components).length} component${Object.keys(components).length !== 1 ? 's' : ''} found`);
|
|
150
|
+
|
|
151
|
+
// Path where components.js will be generated
|
|
152
|
+
const outputPath = getComponentsJsPath(import.meta.url);
|
|
153
|
+
|
|
154
|
+
// Ensure the directory exists
|
|
155
|
+
const outputDir = path.dirname(outputPath);
|
|
156
|
+
if (!fs.existsSync(outputDir)) {
|
|
157
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Generate components.js file with detected components
|
|
161
|
+
const componentsForExport = Object.fromEntries(
|
|
162
|
+
Object.entries(components).map(([name, data]) => [name, data.category])
|
|
163
|
+
);
|
|
164
|
+
fs.writeFileSync(outputPath, `const components = ${JSON.stringify(componentsForExport, null, 2)};\n\nexport default components;\n`);
|
|
165
|
+
|
|
166
|
+
} catch (error) {
|
|
167
|
+
Print.error(`Failed to list components: ${error.message}`);
|
|
168
|
+
Print.info('Make sure your project structure is correct');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export default listComponentsReal;
|