slicejs-cli 2.8.5 → 2.9.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.
@@ -1,126 +1,126 @@
1
-
2
- import componentTemplates from './VisualComponentTemplate.js';
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
- import Validations from '../Validations.js';
7
- import Print from '../Print.js';
8
- import { getSrcPath } from '../utils/PathHelper.js';
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
-
11
- function createComponent(componentName, category) {
12
- // Validación: Nombre de componente requerido
13
- if (!componentName) {
14
- Print.error('Component name is required');
15
- Print.commandExample("Create a component", "slice component create");
16
- return false;
17
- }
18
-
19
- // Validación: Nombre de componente válido
20
- if (!Validations.isValidComponentName(componentName)) {
21
- Print.error(`Invalid component name: '${componentName}'`);
22
- Print.info('Component name must start with a letter and contain only alphanumeric characters');
23
- Print.commandExample("Valid names", "Button, UserCard, NavBar");
24
- Print.commandExample("Invalid names", "1Button, user-card, Nav_Bar");
25
- return false;
26
- }
27
-
28
- // Validación: Componente ya existe
29
- if(Validations.componentExists(componentName)){
30
- Print.error(`Component '${componentName}' already exists in your project`);
31
- Print.info('Please use a different name or delete the existing component first');
32
- Print.commandExample("Delete component", "slice component delete");
33
- return false;
34
- }
35
-
36
- // Validación: Categoría válida
37
- let flagCategory = Validations.isValidCategory(category);
38
-
39
- if (!flagCategory.isValid) {
40
- Print.error(`Invalid category: '${category}'`);
41
- const availableCategories = Object.keys(Validations.getCategories()).join(', ');
42
- Print.info(`Available categories: ${availableCategories}`);
43
- return false;
44
- }
45
- category = flagCategory.category;
46
-
47
- // Crear el nombre de la clase y del archivo
48
- const className = componentName.charAt(0).toUpperCase() + componentName.slice(1);
49
- const fileName = `${className}.js`;
50
- let template;
51
-
52
- const type = Validations.getCategoryType(category);
53
-
54
- // Generar template según el tipo
55
- if(type === 'Visual'){
56
- template = componentTemplates.visual(className);
57
- } else if(type === 'Service'){
58
- template = componentTemplates.service(className);
59
- } else {
60
- Print.error(`Unsupported component type: '${type}'`);
61
- Print.info('Only Visual and Service components are currently supported');
62
- return false;
63
- }
64
-
65
- const categoryPath = Validations.getCategoryPath(category);
66
- const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
67
- const componentDir = getSrcPath(import.meta.url, categoryPathClean, className);
68
-
69
- try {
70
- // Crear directorio del componente
71
- fs.ensureDirSync(componentDir);
72
- } catch (error) {
73
- Print.error(`Failed to create component directory: '${componentDir}'`);
74
- Print.info(`Error details: ${error.message}`);
75
- return false;
76
- }
77
-
78
- // Determinar la ruta del archivo
79
- let componentPath = path.join(componentDir, fileName);
80
-
81
- // Verificar si el archivo ya existe (doble verificación)
82
- if (fs.existsSync(componentPath)) {
83
- Print.error(`Component file already exists at: '${componentPath}'`);
84
- Print.info('This component may have been created outside the CLI');
85
- return false;
86
- }
87
-
88
- try {
89
- // Escribir el código del componente en el archivo
90
- fs.writeFileSync(componentPath, template);
91
-
92
- // Si es Visual, crear archivos adicionales (CSS y HTML)
93
- if(type === 'Visual'){
94
- const cssPath = `${componentDir}/${className}.css`;
95
- const htmlPath = `${componentDir}/${className}.html`;
96
-
97
- fs.writeFileSync(cssPath, '/* Styles for ' + componentName + ' component */\n');
98
- fs.writeFileSync(htmlPath, `<div class="${componentName.toLowerCase()}">\n ${componentName}\n</div>`);
99
-
100
- Print.info(`Created files: ${fileName}, ${className}.css, ${className}.html`);
101
- } else {
102
- Print.info(`Created file: ${fileName}`);
103
- }
104
-
105
- return true;
106
- } catch (error) {
107
- Print.error(`Failed to create component files`);
108
- Print.info(`Error details: ${error.message}`);
109
-
110
- // Intentar limpiar archivos parcialmente creados
111
- try {
112
- if (fs.existsSync(componentDir)) {
113
- fs.removeSync(componentDir);
114
- Print.info('Cleaned up partial files');
115
- }
116
- } catch (cleanupError) {
117
- Print.warning('Could not clean up partial files. You may need to delete them manually');
118
- }
119
-
120
- return false;
121
- }
122
- }
123
-
124
-
125
- export default createComponent;
126
-
1
+
2
+ import componentTemplates from './VisualComponentTemplate.js';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+ import Validations from '../Validations.js';
7
+ import Print from '../Print.js';
8
+ import { getSrcPath } from '../utils/PathHelper.js';
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+
11
+ function createComponent(componentName, category) {
12
+ // Validación: Nombre de componente requerido
13
+ if (!componentName) {
14
+ Print.error('Component name is required');
15
+ Print.commandExample("Create a component", "slice component create");
16
+ return false;
17
+ }
18
+
19
+ // Validación: Nombre de componente válido
20
+ if (!Validations.isValidComponentName(componentName)) {
21
+ Print.error(`Invalid component name: '${componentName}'`);
22
+ Print.info('Component name must start with a letter and contain only alphanumeric characters');
23
+ Print.commandExample("Valid names", "Button, UserCard, NavBar");
24
+ Print.commandExample("Invalid names", "1Button, user-card, Nav_Bar");
25
+ return false;
26
+ }
27
+
28
+ // Validación: Componente ya existe
29
+ if(Validations.componentExists(componentName)){
30
+ Print.error(`Component '${componentName}' already exists in your project`);
31
+ Print.info('Please use a different name or delete the existing component first');
32
+ Print.commandExample("Delete component", "slice component delete");
33
+ return false;
34
+ }
35
+
36
+ // Validación: Categoría válida
37
+ let flagCategory = Validations.isValidCategory(category);
38
+
39
+ if (!flagCategory.isValid) {
40
+ Print.error(`Invalid category: '${category}'`);
41
+ const availableCategories = Object.keys(Validations.getCategories()).join(', ');
42
+ Print.info(`Available categories: ${availableCategories}`);
43
+ return false;
44
+ }
45
+ category = flagCategory.category;
46
+
47
+ // Crear el nombre de la clase y del archivo
48
+ const className = componentName.charAt(0).toUpperCase() + componentName.slice(1);
49
+ const fileName = `${className}.js`;
50
+ let template;
51
+
52
+ const type = Validations.getCategoryType(category);
53
+
54
+ // Generar template según el tipo
55
+ if(type === 'Visual'){
56
+ template = componentTemplates.visual(className);
57
+ } else if(type === 'Service'){
58
+ template = componentTemplates.service(className);
59
+ } else {
60
+ Print.error(`Unsupported component type: '${type}'`);
61
+ Print.info('Only Visual and Service components are currently supported');
62
+ return false;
63
+ }
64
+
65
+ const categoryPath = Validations.getCategoryPath(category);
66
+ const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
67
+ const componentDir = getSrcPath(import.meta.url, categoryPathClean, className);
68
+
69
+ try {
70
+ // Crear directorio del componente
71
+ fs.ensureDirSync(componentDir);
72
+ } catch (error) {
73
+ Print.error(`Failed to create component directory: '${componentDir}'`);
74
+ Print.info(`Error details: ${error.message}`);
75
+ return false;
76
+ }
77
+
78
+ // Determinar la ruta del archivo
79
+ let componentPath = path.join(componentDir, fileName);
80
+
81
+ // Verificar si el archivo ya existe (doble verificación)
82
+ if (fs.existsSync(componentPath)) {
83
+ Print.error(`Component file already exists at: '${componentPath}'`);
84
+ Print.info('This component may have been created outside the CLI');
85
+ return false;
86
+ }
87
+
88
+ try {
89
+ // Escribir el código del componente en el archivo
90
+ fs.writeFileSync(componentPath, template);
91
+
92
+ // Si es Visual, crear archivos adicionales (CSS y HTML)
93
+ if(type === 'Visual'){
94
+ const cssPath = `${componentDir}/${className}.css`;
95
+ const htmlPath = `${componentDir}/${className}.html`;
96
+
97
+ fs.writeFileSync(cssPath, '/* Styles for ' + componentName + ' component */\n');
98
+ fs.writeFileSync(htmlPath, `<div class="${componentName.toLowerCase()}">\n ${componentName}\n</div>`);
99
+
100
+ Print.info(`Created files: ${fileName}, ${className}.css, ${className}.html`);
101
+ } else {
102
+ Print.info(`Created file: ${fileName}`);
103
+ }
104
+
105
+ return true;
106
+ } catch (error) {
107
+ Print.error(`Failed to create component files`);
108
+ Print.info(`Error details: ${error.message}`);
109
+
110
+ // Intentar limpiar archivos parcialmente creados
111
+ try {
112
+ if (fs.existsSync(componentDir)) {
113
+ fs.removeSync(componentDir);
114
+ Print.info('Cleaned up partial files');
115
+ }
116
+ } catch (cleanupError) {
117
+ Print.warning('Could not clean up partial files. You may need to delete them manually');
118
+ }
119
+
120
+ return false;
121
+ }
122
+ }
123
+
124
+
125
+ export default createComponent;
126
+
@@ -1,77 +1,77 @@
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
- // Validación: Nombre de componente requerido
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
- // Validación: Nombre de componente válido
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
- // Validación: Categoría válida
25
- let flagCategory = Validations.isValidCategory(category);
26
-
27
- if (!flagCategory.isValid) {
28
- Print.error(`Invalid category: '${category}'`);
29
- const availableCategories = Object.keys(Validations.getCategories()).join(', ');
30
- Print.info(`Available categories: ${availableCategories}`);
31
- return false;
32
- }
33
- category = flagCategory.category;
34
-
35
- const categoryPath = Validations.getCategoryPath(category);
36
- const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
37
- const componentDir = getSrcPath(import.meta.url, categoryPathClean, componentName);
38
-
39
- // Verificar si el directorio del componente existe
40
- if (!fs.existsSync(componentDir)) {
41
- Print.error(`Component '${componentName}' does not exist in category '${category}'`);
42
- Print.info('Make sure you selected the correct category');
43
- Print.commandExample("List components", "slice component list");
44
- return false;
45
- }
46
-
47
- // Verificar si es un directorio
48
- try {
49
- const stats = fs.statSync(componentDir);
50
- if (!stats.isDirectory()) {
51
- Print.error(`'${componentName}' is not a valid component directory`);
52
- Print.info('Components must be stored in directories');
53
- return false;
54
- }
55
- } catch (error) {
56
- Print.error(`Failed to access component directory: '${componentDir}'`);
57
- Print.info(`Error details: ${error.message}`);
58
- return false;
59
- }
60
-
61
- // Intentar eliminar el directorio del componente y su contenido
62
- try {
63
- const files = fs.readdirSync(componentDir);
64
- Print.info(`Deleting ${files.length} file(s) from component directory...`);
65
-
66
- fs.removeSync(componentDir);
67
- return true;
68
- } catch (error) {
69
- Print.error(`Failed to delete component '${componentName}'`);
70
- Print.info(`Error details: ${error.message}`);
71
- Print.warning('You may need to delete the component files manually');
72
- Print.info(`Component location: ${componentDir}`);
73
- return false;
74
- }
75
- }
76
-
77
- 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
+ // Validación: Nombre de componente requerido
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
+ // Validación: Nombre de componente válido
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
+ // Validación: Categoría válida
25
+ let flagCategory = Validations.isValidCategory(category);
26
+
27
+ if (!flagCategory.isValid) {
28
+ Print.error(`Invalid category: '${category}'`);
29
+ const availableCategories = Object.keys(Validations.getCategories()).join(', ');
30
+ Print.info(`Available categories: ${availableCategories}`);
31
+ return false;
32
+ }
33
+ category = flagCategory.category;
34
+
35
+ const categoryPath = Validations.getCategoryPath(category);
36
+ const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
37
+ const componentDir = getSrcPath(import.meta.url, categoryPathClean, componentName);
38
+
39
+ // Verificar si el directorio del componente existe
40
+ if (!fs.existsSync(componentDir)) {
41
+ Print.error(`Component '${componentName}' does not exist in category '${category}'`);
42
+ Print.info('Make sure you selected the correct category');
43
+ Print.commandExample("List components", "slice component list");
44
+ return false;
45
+ }
46
+
47
+ // Verificar si es un directorio
48
+ try {
49
+ const stats = fs.statSync(componentDir);
50
+ if (!stats.isDirectory()) {
51
+ Print.error(`'${componentName}' is not a valid component directory`);
52
+ Print.info('Components must be stored in directories');
53
+ return false;
54
+ }
55
+ } catch (error) {
56
+ Print.error(`Failed to access component directory: '${componentDir}'`);
57
+ Print.info(`Error details: ${error.message}`);
58
+ return false;
59
+ }
60
+
61
+ // Intentar eliminar el directorio del componente y su contenido
62
+ try {
63
+ const files = fs.readdirSync(componentDir);
64
+ Print.info(`Deleting ${files.length} file(s) from component directory...`);
65
+
66
+ fs.removeSync(componentDir);
67
+ return true;
68
+ } catch (error) {
69
+ Print.error(`Failed to delete component '${componentName}'`);
70
+ Print.info(`Error details: ${error.message}`);
71
+ Print.warning('You may need to delete the component files manually');
72
+ Print.info(`Component location: ${componentDir}`);
73
+ return false;
74
+ }
75
+ }
76
+
77
+ export default deleteComponent;