slicejs-cli 2.0.11 → 2.0.13
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/client.js
CHANGED
|
@@ -13,6 +13,8 @@ import validations from "./commands/Validations.js";
|
|
|
13
13
|
|
|
14
14
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
|
|
16
18
|
const loadConfig = () => {
|
|
17
19
|
try {
|
|
18
20
|
const configPath = path.join(__dirname, "../../src/sliceConfig.json");
|
|
@@ -33,18 +35,17 @@ const sliceClient = program;
|
|
|
33
35
|
|
|
34
36
|
sliceClient.version("1.0.0").description("CLI for managing framework components");
|
|
35
37
|
|
|
38
|
+
// COMPONENT COMMAND GROUP
|
|
39
|
+
const componentCommand = sliceClient.command("component").description("Manage components");
|
|
36
40
|
|
|
37
|
-
//
|
|
41
|
+
//create init command
|
|
38
42
|
sliceClient
|
|
39
43
|
.command("init")
|
|
40
|
-
.description("Initialize
|
|
44
|
+
.description("Initialize a new SliceJS project")
|
|
41
45
|
.action(() => {
|
|
42
|
-
initializeProject(
|
|
46
|
+
initializeProject();
|
|
43
47
|
});
|
|
44
48
|
|
|
45
|
-
// COMPONENT COMMAND GROUP
|
|
46
|
-
const componentCommand = sliceClient.command("component").description("Manage components");
|
|
47
|
-
|
|
48
49
|
// CREATE COMPONENT
|
|
49
50
|
componentCommand
|
|
50
51
|
.command("create")
|
package/commands/Validations.js
CHANGED
|
@@ -53,6 +53,26 @@ class Validations {
|
|
|
53
53
|
return { isValid: false, category: null };
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
componentExists(componentName) {
|
|
58
|
+
try {
|
|
59
|
+
const componentFilePath = path.join(__dirname, '../../../src/Components/components.js');
|
|
60
|
+
|
|
61
|
+
if (!fs.existsSync(componentFilePath)) {
|
|
62
|
+
console.error('❌ El archivo components.js no existe en la ruta esperada.');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const fileContent = fs.readFileSync(componentFilePath, 'utf-8');
|
|
67
|
+
const components = eval(fileContent.replace('export default', '')); // Evalúa el contenido como objeto
|
|
68
|
+
|
|
69
|
+
return components.hasOwnProperty(componentName);
|
|
70
|
+
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error('❌ Error al verificar el componente:', error);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
56
76
|
}
|
|
57
77
|
|
|
58
78
|
const validations = new Validations();
|
|
File without changes
|
|
@@ -18,8 +18,14 @@ function createComponent(componentName, category, properties) {
|
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
if(Validations.componentExists(componentName)){
|
|
22
|
+
Print.error(`Component '${componentName}' already exists. Please use a different name.`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
let flagCategory = Validations.isValidCategory(category);
|
|
22
27
|
|
|
28
|
+
|
|
23
29
|
|
|
24
30
|
if (!flagCategory.isValid) {
|
|
25
31
|
Print.error('Invalid category. Please use one of the following categories: Service, Visual, Provider, Structural');
|
package/package.json
CHANGED
package/post.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import Print from './commands/Print.js';
|
|
5
|
+
import initializeProject from './commands/init/init.js';
|
|
4
6
|
|
|
5
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
8
|
const __dirname = path.dirname(__filename);
|
|
@@ -20,19 +22,23 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
|
|
|
20
22
|
|
|
21
23
|
// Agrega los comandos personalizados a los scripts del proyecto
|
|
22
24
|
projectPackageJson.scripts = projectPackageJson.scripts || {};
|
|
23
|
-
projectPackageJson.scripts['slice:init'] = 'node node_modules/slicejs-cli/client.js init';
|
|
24
25
|
projectPackageJson.scripts['slice:create'] = 'node node_modules/slicejs-cli/client.js component create';
|
|
25
26
|
projectPackageJson.scripts['slice:list'] = 'node node_modules/slicejs-cli/client.js component list';
|
|
26
27
|
projectPackageJson.scripts['slice:delete'] = 'node node_modules/slicejs-cli/client.js component delete';
|
|
28
|
+
projectPackageJson.scripts['slice:init'] = 'node node_modules/slicejs-cli/client.js init';
|
|
27
29
|
projectPackageJson.scripts['run'] = 'node api/index.js';
|
|
28
30
|
projectPackageJson.scripts['slice:start'] = 'node api/index.js';
|
|
29
31
|
projectPackageJson.scripts['development'] = 'node api/index.js';
|
|
30
32
|
|
|
31
33
|
// add type module
|
|
32
34
|
projectPackageJson.type = 'module';
|
|
35
|
+
projectPackageJson.engines = {
|
|
36
|
+
"node": "20.x"
|
|
37
|
+
};
|
|
33
38
|
|
|
34
39
|
// Escribe el nuevo contenido en el package.json del proyecto
|
|
35
|
-
|
|
40
|
+
fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2), 'utf8');
|
|
41
|
+
return Print.success("Run 'npm run slice:init' to initialize your project");
|
|
36
42
|
})
|
|
37
43
|
.then(() => {
|
|
38
44
|
console.log('SliceJS CLI commands added to package.json.');
|
|
@@ -46,20 +52,24 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
|
|
|
46
52
|
description: 'Project description',
|
|
47
53
|
main: 'api/index.js',
|
|
48
54
|
scripts: {
|
|
49
|
-
'slice:init': 'node node_modules/slicejs-cli/client.js init',
|
|
50
55
|
'slice:create': 'node node_modules/slicejs-cli/client.js component create',
|
|
51
56
|
'slice:list': 'node node_modules/slicejs-cli/client.js component list',
|
|
52
57
|
'slice:delete': 'node node_modules/slicejs-cli/client.js component delete',
|
|
53
58
|
"run": "node api/index.js",
|
|
54
|
-
"slice:start": "node api/index.js"
|
|
59
|
+
"slice:start": "node api/index.js",
|
|
60
|
+
"slice:start": "node node_modules/slicejs-cli/client.js init"
|
|
55
61
|
},
|
|
56
62
|
keywords: [],
|
|
57
63
|
author: '',
|
|
58
64
|
license: 'ISC',
|
|
59
|
-
type: 'module'
|
|
65
|
+
type: 'module',
|
|
66
|
+
engines: {
|
|
67
|
+
"node": "20.x"
|
|
68
|
+
}
|
|
60
69
|
};
|
|
61
70
|
// Guardamos el nuevo package.json
|
|
62
|
-
|
|
71
|
+
fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(defaultPackageJson, null, 2), 'utf8');
|
|
72
|
+
return Print.success("Run 'npm run slice:init' to initialize your project");
|
|
63
73
|
} else {
|
|
64
74
|
console.error('Error:', err);
|
|
65
75
|
}
|
|
@@ -69,4 +79,6 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
|
|
|
69
79
|
})
|
|
70
80
|
.catch(err => {
|
|
71
81
|
console.error('Error:', err);
|
|
72
|
-
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
|