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,128 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
import componentTemplates from './VisualComponentTemplate.js';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import Validations from '../Validations.js';
|
|
6
|
-
import Print from '../Print.js';
|
|
7
|
-
import { getSrcPath } from '../utils/PathHelper.js';
|
|
8
|
-
|
|
9
|
-
function createComponent(componentName, category) {
|
|
10
|
-
// Validation: Component name is required
|
|
11
|
-
if (!componentName) {
|
|
12
|
-
Print.error('Component name is required');
|
|
13
|
-
Print.commandExample("Create a component", "slice component create");
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Validation: Valid component name
|
|
18
|
-
if (!Validations.isValidComponentName(componentName)) {
|
|
19
|
-
Print.error(`Invalid component name: '${componentName}'`);
|
|
20
|
-
Print.info('Component name must start with a letter and contain only alphanumeric characters');
|
|
21
|
-
Print.commandExample("Valid names", "Button, UserCard, NavBar");
|
|
22
|
-
Print.commandExample("Invalid names", "1Button, user-card, Nav_Bar");
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Components follow a PascalCase convention: normalize the initial to
|
|
27
|
-
// uppercase so the folder name, registry entry and existence checks agree.
|
|
28
|
-
componentName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
29
|
-
|
|
30
|
-
// Validation: Component already exists
|
|
31
|
-
if(Validations.componentExists(componentName)){
|
|
32
|
-
Print.error(`Component '${componentName}' already exists in your project`);
|
|
33
|
-
Print.info('Please use a different name or delete the existing component first');
|
|
34
|
-
Print.commandExample("Delete component", "slice component delete");
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Validation: Valid category
|
|
39
|
-
let flagCategory = Validations.isValidCategory(category);
|
|
40
|
-
|
|
41
|
-
if (!flagCategory.isValid) {
|
|
42
|
-
Print.error(`Invalid category: '${category}'`);
|
|
43
|
-
const availableCategories = Object.keys(Validations.getCategories()).join(', ');
|
|
44
|
-
Print.info(`Available categories: ${availableCategories}`);
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
category = flagCategory.category;
|
|
48
|
-
|
|
49
|
-
// Create class name and file name (componentName is already PascalCase).
|
|
50
|
-
const className = componentName;
|
|
51
|
-
const fileName = `${className}.js`;
|
|
52
|
-
let template;
|
|
53
|
-
|
|
54
|
-
const type = Validations.getCategoryType(category);
|
|
55
|
-
|
|
56
|
-
// Generate template based on type
|
|
57
|
-
if(type === 'Visual'){
|
|
58
|
-
template = componentTemplates.visual(className);
|
|
59
|
-
} else if(type === 'Service'){
|
|
60
|
-
template = componentTemplates.service(className);
|
|
61
|
-
} else {
|
|
62
|
-
Print.error(`Unsupported component type: '${type}'`);
|
|
63
|
-
Print.info('Only Visual and Service components are currently supported');
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const categoryPath = Validations.getCategoryPath(category);
|
|
68
|
-
const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
|
|
69
|
-
const componentDir = getSrcPath(import.meta.url, categoryPathClean, className);
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
// Create component directory
|
|
73
|
-
fs.ensureDirSync(componentDir);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
Print.error(`Failed to create component directory: '${componentDir}'`);
|
|
76
|
-
Print.info(`Error details: ${error.message}`);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Determine the file path
|
|
81
|
-
let componentPath = path.join(componentDir, fileName);
|
|
82
|
-
|
|
83
|
-
// Verify if the file already exists (double check)
|
|
84
|
-
if (fs.existsSync(componentPath)) {
|
|
85
|
-
Print.error(`Component file already exists at: '${componentPath}'`);
|
|
86
|
-
Print.info('This component may have been created outside the CLI');
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
// Write component code to file
|
|
92
|
-
fs.writeFileSync(componentPath, template);
|
|
93
|
-
|
|
94
|
-
// If Visual, create additional files (CSS and HTML)
|
|
95
|
-
if(type === 'Visual'){
|
|
96
|
-
const cssPath = path.join(componentDir, `${className}.css`);
|
|
97
|
-
const htmlPath = path.join(componentDir, `${className}.html`);
|
|
98
|
-
|
|
99
|
-
fs.writeFileSync(cssPath, '/* Styles for ' + componentName + ' component */\n');
|
|
100
|
-
fs.writeFileSync(htmlPath, `<div class="${componentName.toLowerCase()}">\n ${componentName}\n</div>`);
|
|
101
|
-
|
|
102
|
-
Print.info(`Created files: ${fileName}, ${className}.css, ${className}.html`);
|
|
103
|
-
} else {
|
|
104
|
-
Print.info(`Created file: ${fileName}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return true;
|
|
108
|
-
} catch (error) {
|
|
109
|
-
Print.error(`Failed to create component files`);
|
|
110
|
-
Print.info(`Error details: ${error.message}`);
|
|
111
|
-
|
|
112
|
-
// Try to clean up partially created files
|
|
113
|
-
try {
|
|
114
|
-
if (fs.existsSync(componentDir)) {
|
|
115
|
-
fs.removeSync(componentDir);
|
|
116
|
-
Print.info('Cleaned up partial files');
|
|
117
|
-
}
|
|
118
|
-
} catch (cleanupError) {
|
|
119
|
-
Print.warning('Could not clean up partial files. You may need to delete them manually');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
export default createComponent;
|
|
128
|
-
|
|
1
|
+
|
|
2
|
+
import componentTemplates from './VisualComponentTemplate.js';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import Validations from '../Validations.js';
|
|
6
|
+
import Print from '../Print.js';
|
|
7
|
+
import { getSrcPath } from '../utils/PathHelper.js';
|
|
8
|
+
|
|
9
|
+
function createComponent(componentName, category) {
|
|
10
|
+
// Validation: Component name is required
|
|
11
|
+
if (!componentName) {
|
|
12
|
+
Print.error('Component name is required');
|
|
13
|
+
Print.commandExample("Create a component", "slice component create");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Validation: Valid component name
|
|
18
|
+
if (!Validations.isValidComponentName(componentName)) {
|
|
19
|
+
Print.error(`Invalid component name: '${componentName}'`);
|
|
20
|
+
Print.info('Component name must start with a letter and contain only alphanumeric characters');
|
|
21
|
+
Print.commandExample("Valid names", "Button, UserCard, NavBar");
|
|
22
|
+
Print.commandExample("Invalid names", "1Button, user-card, Nav_Bar");
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Components follow a PascalCase convention: normalize the initial to
|
|
27
|
+
// uppercase so the folder name, registry entry and existence checks agree.
|
|
28
|
+
componentName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
29
|
+
|
|
30
|
+
// Validation: Component already exists
|
|
31
|
+
if(Validations.componentExists(componentName)){
|
|
32
|
+
Print.error(`Component '${componentName}' already exists in your project`);
|
|
33
|
+
Print.info('Please use a different name or delete the existing component first');
|
|
34
|
+
Print.commandExample("Delete component", "slice component delete");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Validation: Valid category
|
|
39
|
+
let flagCategory = Validations.isValidCategory(category);
|
|
40
|
+
|
|
41
|
+
if (!flagCategory.isValid) {
|
|
42
|
+
Print.error(`Invalid category: '${category}'`);
|
|
43
|
+
const availableCategories = Object.keys(Validations.getCategories()).join(', ');
|
|
44
|
+
Print.info(`Available categories: ${availableCategories}`);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
category = flagCategory.category;
|
|
48
|
+
|
|
49
|
+
// Create class name and file name (componentName is already PascalCase).
|
|
50
|
+
const className = componentName;
|
|
51
|
+
const fileName = `${className}.js`;
|
|
52
|
+
let template;
|
|
53
|
+
|
|
54
|
+
const type = Validations.getCategoryType(category);
|
|
55
|
+
|
|
56
|
+
// Generate template based on type
|
|
57
|
+
if(type === 'Visual'){
|
|
58
|
+
template = componentTemplates.visual(className);
|
|
59
|
+
} else if(type === 'Service'){
|
|
60
|
+
template = componentTemplates.service(className);
|
|
61
|
+
} else {
|
|
62
|
+
Print.error(`Unsupported component type: '${type}'`);
|
|
63
|
+
Print.info('Only Visual and Service components are currently supported');
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const categoryPath = Validations.getCategoryPath(category);
|
|
68
|
+
const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
|
|
69
|
+
const componentDir = getSrcPath(import.meta.url, categoryPathClean, className);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
// Create component directory
|
|
73
|
+
fs.ensureDirSync(componentDir);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
Print.error(`Failed to create component directory: '${componentDir}'`);
|
|
76
|
+
Print.info(`Error details: ${error.message}`);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Determine the file path
|
|
81
|
+
let componentPath = path.join(componentDir, fileName);
|
|
82
|
+
|
|
83
|
+
// Verify if the file already exists (double check)
|
|
84
|
+
if (fs.existsSync(componentPath)) {
|
|
85
|
+
Print.error(`Component file already exists at: '${componentPath}'`);
|
|
86
|
+
Print.info('This component may have been created outside the CLI');
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
// Write component code to file
|
|
92
|
+
fs.writeFileSync(componentPath, template);
|
|
93
|
+
|
|
94
|
+
// If Visual, create additional files (CSS and HTML)
|
|
95
|
+
if(type === 'Visual'){
|
|
96
|
+
const cssPath = path.join(componentDir, `${className}.css`);
|
|
97
|
+
const htmlPath = path.join(componentDir, `${className}.html`);
|
|
98
|
+
|
|
99
|
+
fs.writeFileSync(cssPath, '/* Styles for ' + componentName + ' component */\n');
|
|
100
|
+
fs.writeFileSync(htmlPath, `<div class="${componentName.toLowerCase()}">\n ${componentName}\n</div>`);
|
|
101
|
+
|
|
102
|
+
Print.info(`Created files: ${fileName}, ${className}.css, ${className}.html`);
|
|
103
|
+
} else {
|
|
104
|
+
Print.info(`Created file: ${fileName}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return true;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
Print.error(`Failed to create component files`);
|
|
110
|
+
Print.info(`Error details: ${error.message}`);
|
|
111
|
+
|
|
112
|
+
// Try to clean up partially created files
|
|
113
|
+
try {
|
|
114
|
+
if (fs.existsSync(componentDir)) {
|
|
115
|
+
fs.removeSync(componentDir);
|
|
116
|
+
Print.info('Cleaned up partial files');
|
|
117
|
+
}
|
|
118
|
+
} catch (cleanupError) {
|
|
119
|
+
Print.warning('Could not clean up partial files. You may need to delete them manually');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
export default createComponent;
|
|
128
|
+
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import Validations from '../Validations.js';
|
|
4
|
-
import Print from '../Print.js';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
import { getSrcPath } from '../utils/PathHelper.js';
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
function deleteComponent(componentName, category) {
|
|
10
|
-
// Validation: Component name is required
|
|
11
|
-
if (!componentName) {
|
|
12
|
-
Print.error('Component name is required to delete');
|
|
13
|
-
Print.commandExample("Delete a component", "slice component delete");
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Validation: Valid component name
|
|
18
|
-
if (!Validations.isValidComponentName(componentName)) {
|
|
19
|
-
Print.error(`Invalid component name: '${componentName}'`);
|
|
20
|
-
Print.info('Component name must start with a letter and contain only alphanumeric characters');
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Components follow a PascalCase convention: normalize the initial so the
|
|
25
|
-
// lookup matches the folder name created by `slice component create`.
|
|
26
|
-
componentName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
27
|
-
|
|
28
|
-
// Validation: Valid category
|
|
29
|
-
let flagCategory = Validations.isValidCategory(category);
|
|
30
|
-
|
|
31
|
-
if (!flagCategory.isValid) {
|
|
32
|
-
Print.error(`Invalid category: '${category}'`);
|
|
33
|
-
const availableCategories = Object.keys(Validations.getCategories()).join(', ');
|
|
34
|
-
Print.info(`Available categories: ${availableCategories}`);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
category = flagCategory.category;
|
|
38
|
-
|
|
39
|
-
const categoryPath = Validations.getCategoryPath(category);
|
|
40
|
-
const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
|
|
41
|
-
const componentDir = getSrcPath(import.meta.url, categoryPathClean, componentName);
|
|
42
|
-
|
|
43
|
-
// Check if component directory exists
|
|
44
|
-
if (!fs.existsSync(componentDir)) {
|
|
45
|
-
Print.error(`Component '${componentName}' does not exist in category '${category}'`);
|
|
46
|
-
Print.info('Make sure you selected the correct category');
|
|
47
|
-
Print.commandExample("List components", "slice component list");
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Verify it's a directory
|
|
52
|
-
try {
|
|
53
|
-
const stats = fs.statSync(componentDir);
|
|
54
|
-
if (!stats.isDirectory()) {
|
|
55
|
-
Print.error(`'${componentName}' is not a valid component directory`);
|
|
56
|
-
Print.info('Components must be stored in directories');
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
Print.error(`Failed to access component directory: '${componentDir}'`);
|
|
61
|
-
Print.info(`Error details: ${error.message}`);
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Try to delete the component directory and its contents
|
|
66
|
-
try {
|
|
67
|
-
const files = fs.readdirSync(componentDir);
|
|
68
|
-
Print.info(`Deleting ${files.length} file(s) from component directory...`);
|
|
69
|
-
|
|
70
|
-
fs.removeSync(componentDir);
|
|
71
|
-
return true;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
Print.error(`Failed to delete component '${componentName}'`);
|
|
74
|
-
Print.info(`Error details: ${error.message}`);
|
|
75
|
-
Print.warning('You may need to delete the component files manually');
|
|
76
|
-
Print.info(`Component location: ${componentDir}`);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export default deleteComponent;
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import Validations from '../Validations.js';
|
|
4
|
+
import Print from '../Print.js';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { getSrcPath } from '../utils/PathHelper.js';
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
function deleteComponent(componentName, category) {
|
|
10
|
+
// Validation: Component name is required
|
|
11
|
+
if (!componentName) {
|
|
12
|
+
Print.error('Component name is required to delete');
|
|
13
|
+
Print.commandExample("Delete a component", "slice component delete");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Validation: Valid component name
|
|
18
|
+
if (!Validations.isValidComponentName(componentName)) {
|
|
19
|
+
Print.error(`Invalid component name: '${componentName}'`);
|
|
20
|
+
Print.info('Component name must start with a letter and contain only alphanumeric characters');
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Components follow a PascalCase convention: normalize the initial so the
|
|
25
|
+
// lookup matches the folder name created by `slice component create`.
|
|
26
|
+
componentName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
27
|
+
|
|
28
|
+
// Validation: Valid category
|
|
29
|
+
let flagCategory = Validations.isValidCategory(category);
|
|
30
|
+
|
|
31
|
+
if (!flagCategory.isValid) {
|
|
32
|
+
Print.error(`Invalid category: '${category}'`);
|
|
33
|
+
const availableCategories = Object.keys(Validations.getCategories()).join(', ');
|
|
34
|
+
Print.info(`Available categories: ${availableCategories}`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
category = flagCategory.category;
|
|
38
|
+
|
|
39
|
+
const categoryPath = Validations.getCategoryPath(category);
|
|
40
|
+
const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
|
|
41
|
+
const componentDir = getSrcPath(import.meta.url, categoryPathClean, componentName);
|
|
42
|
+
|
|
43
|
+
// Check if component directory exists
|
|
44
|
+
if (!fs.existsSync(componentDir)) {
|
|
45
|
+
Print.error(`Component '${componentName}' does not exist in category '${category}'`);
|
|
46
|
+
Print.info('Make sure you selected the correct category');
|
|
47
|
+
Print.commandExample("List components", "slice component list");
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Verify it's a directory
|
|
52
|
+
try {
|
|
53
|
+
const stats = fs.statSync(componentDir);
|
|
54
|
+
if (!stats.isDirectory()) {
|
|
55
|
+
Print.error(`'${componentName}' is not a valid component directory`);
|
|
56
|
+
Print.info('Components must be stored in directories');
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
Print.error(`Failed to access component directory: '${componentDir}'`);
|
|
61
|
+
Print.info(`Error details: ${error.message}`);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Try to delete the component directory and its contents
|
|
66
|
+
try {
|
|
67
|
+
const files = fs.readdirSync(componentDir);
|
|
68
|
+
Print.info(`Deleting ${files.length} file(s) from component directory...`);
|
|
69
|
+
|
|
70
|
+
fs.removeSync(componentDir);
|
|
71
|
+
return true;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
Print.error(`Failed to delete component '${componentName}'`);
|
|
74
|
+
Print.info(`Error details: ${error.message}`);
|
|
75
|
+
Print.warning('You may need to delete the component files manually');
|
|
76
|
+
Print.info(`Component location: ${componentDir}`);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default deleteComponent;
|