slicejs-cli 2.0.10 → 2.0.12

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
@@ -33,15 +33,6 @@ const sliceClient = program;
33
33
 
34
34
  sliceClient.version("1.0.0").description("CLI for managing framework components");
35
35
 
36
-
37
- // INIT COMMAND
38
- sliceClient
39
- .command("init")
40
- .description("Initialize the project")
41
- .action(() => {
42
- initializeProject("basic");
43
- });
44
-
45
36
  // COMPONENT COMMAND GROUP
46
37
  const componentCommand = sliceClient.command("component").description("Manage components");
47
38
 
@@ -75,8 +66,7 @@ componentCommand
75
66
  {
76
67
  type: "input",
77
68
  name: "properties",
78
- message: "Enter the properties (comma separated):",
79
- validate: (input) => (input ? true : "Properties cannot be empty"),
69
+ message: "Enter the properties (comma separated):"
80
70
  },
81
71
  ]);
82
72
  answers.properties = properties.properties.split(",").map((prop) => prop.trim());
@@ -53,6 +53,25 @@ 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
+ } catch (error) {
71
+ console.error('❌ Error al verificar el componente:', error);
72
+ return false;
73
+ }
74
+ }
56
75
  }
57
76
 
58
77
  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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "scripts": {
package/post.js CHANGED
@@ -2,6 +2,8 @@ import fs from 'fs';
2
2
  import { fileURLToPath } from 'url';
3
3
  import path from 'path';
4
4
 
5
+ import initializeProject from './commands/init/init.js';
6
+
5
7
  const __filename = fileURLToPath(import.meta.url);
6
8
  const __dirname = path.dirname(__filename);
7
9
  const projectName = path.basename(__dirname); // Obtiene el nombre de la carpeta actual
@@ -20,7 +22,6 @@ 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';
@@ -30,9 +31,13 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
30
31
 
31
32
  // add type module
32
33
  projectPackageJson.type = 'module';
34
+ projectPackageJson.engines = {
35
+ "node": "20.x"
36
+ };
33
37
 
34
38
  // Escribe el nuevo contenido en el package.json del proyecto
35
- return fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2), 'utf8');
39
+ fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2), 'utf8');
40
+ return initializeProject(projectName);
36
41
  })
37
42
  .then(() => {
38
43
  console.log('SliceJS CLI commands added to package.json.');
@@ -46,7 +51,6 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
46
51
  description: 'Project description',
47
52
  main: 'api/index.js',
48
53
  scripts: {
49
- 'slice:init': 'node node_modules/slicejs-cli/client.js init',
50
54
  'slice:create': 'node node_modules/slicejs-cli/client.js component create',
51
55
  'slice:list': 'node node_modules/slicejs-cli/client.js component list',
52
56
  'slice:delete': 'node node_modules/slicejs-cli/client.js component delete',
@@ -56,10 +60,14 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
56
60
  keywords: [],
57
61
  author: '',
58
62
  license: 'ISC',
59
- type: 'module'
63
+ type: 'module',
64
+ engines: {
65
+ "node": "20.x"
66
+ }
60
67
  };
61
68
  // Guardamos el nuevo package.json
62
- return fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(defaultPackageJson, null, 2), 'utf8');
69
+ fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(defaultPackageJson, null, 2), 'utf8');
70
+ return initializeProject(projectName);
63
71
  } else {
64
72
  console.error('Error:', err);
65
73
  }
@@ -69,4 +77,5 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
69
77
  })
70
78
  .catch(err => {
71
79
  console.error('Error:', err);
72
- });
80
+ })
81
+