slicejs-cli 1.0.30 → 1.0.32

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
@@ -3,6 +3,7 @@ import initializeProject from "./commands/init/init.js";
3
3
  import createComponent from "./commands/createComponent/createComponent.js";
4
4
  import modifyComponent from "./commands/modifyComponent/modifyComponent.js";
5
5
  import listComponents from "./commands/listComponents/listComponents.js";
6
+ import deleteComponent from "./commands/deleteComponent/deleteComponent.js";
6
7
 
7
8
  const sliceClient = program;
8
9
 
@@ -14,6 +15,7 @@ sliceClient
14
15
  .command('init <projectType>')
15
16
  .description('Initialize the project')
16
17
  .action((projectType) => {
18
+ if(!projectType) projectType = 'basic';
17
19
  initializeProject(projectType);
18
20
  });
19
21
 
@@ -26,6 +28,7 @@ sliceClient
26
28
  const { Category, Properties } = options;
27
29
  const propertiesList = Properties ? Properties.split(',') : [];
28
30
  createComponent(componentName, Category, propertiesList);
31
+ listComponents();
29
32
 
30
33
  });
31
34
 
@@ -43,6 +46,14 @@ sliceClient
43
46
  modifyComponent(componentName,Category, addProperties, removeProperties);
44
47
  });
45
48
 
49
+ sliceClient.command('delete <componentName>')
50
+ .description('Delete an existing component')
51
+ .option('-category <category>', 'Component category')
52
+ .action((componentName, options) => {
53
+ const { Category } = options;
54
+ deleteComponent(componentName, Category);
55
+ });
56
+
46
57
  // Comando para listar todos los componentes
47
58
  sliceClient
48
59
  .command('list')
@@ -3,6 +3,7 @@ import componentTemplate from './componentTemplate.js';
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
5
5
  import { fileURLToPath } from 'url';
6
+ import Validations from '../Validations.js';
6
7
 
7
8
  const __dirname = path.dirname(new URL(import.meta.url).pathname);
8
9
 
@@ -13,43 +14,26 @@ function createComponent(componentName, category, properties) {
13
14
  return;
14
15
  }
15
16
 
16
- if (!isValidComponentName(componentName)) {
17
+ if (!Validations.isValidComponentName(componentName)) {
17
18
  console.error('Invalid component name. Please use only alphanumeric characters and start with a letter.');
18
19
  return;
19
20
  }
20
21
 
21
- const categoryVariations = {
22
- 'Service': ['service', 'servicio', 'serv'],
23
- 'Visual': ['visual', 'vis'],
24
- 'Provider': ['provider', 'proveedor', 'prov'],
25
- 'Structural': ['structural', 'estructural', 'est']
26
- };
22
+ let flagCategory = Validations.isValidCategory(category);
27
23
 
28
24
 
29
-
30
- // Verificar si la categoría es válida
31
- let categoryIsValid = false;
32
- Object.keys(categoryVariations).forEach(validCategory => {
33
- if (categoryVariations[validCategory].includes(category.toLowerCase())) {
34
- category = validCategory
35
- categoryIsValid = true;
36
- }
37
- });
38
-
39
- if (!categoryIsValid) {
25
+ if (!flagCategory.isValid) {
40
26
  console.error('Invalid category. Please use one of the following categories: Service, Visual, Provider, Structural');
41
27
  return;
42
28
  }
29
+ category = flagCategory.category;
43
30
 
44
31
  // Crear el nombre de la clase y del archivo
45
32
  const className = componentName.charAt(0).toUpperCase() + componentName.slice(1);
46
33
  const fileName = `${className}.js`;
47
34
  const template = componentTemplate(className, properties);
48
35
 
49
-
50
-
51
36
  // Determinar la ruta del archivo
52
-
53
37
  let componentDir = path.join(__dirname, '../../../../Slice/Components', category, className);
54
38
  componentDir=componentDir.slice(1);
55
39
  // Asegurarse de que el directorio del componente exista
@@ -74,11 +58,6 @@ function createComponent(componentName, category, properties) {
74
58
  console.log(`Component '${componentName}' created successfully.`);
75
59
  }
76
60
 
77
- function isValidComponentName(componentName) {
78
- // Expresión regular para verificar si el nombre contiene caracteres especiales
79
- const regex = /^[a-zA-Z][a-zA-Z0-9]*$/;
80
- return regex.test(componentName);
81
- }
82
61
 
83
62
  export default createComponent;
84
63
 
@@ -0,0 +1,42 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import Validations from '../Validations.js';
4
+
5
+ const __dirname = path.dirname(new URL(import.meta.url).pathname);
6
+
7
+ function deleteComponent(componentName, category) {
8
+ if (!componentName) {
9
+ console.error('Component name is required');
10
+ return;
11
+ }
12
+
13
+ if (!Validations.isValidComponentName(componentName)) {
14
+ console.error('Invalid component name. Please use only alphanumeric characters and start with a letter.');
15
+ return;
16
+ }
17
+
18
+ let flagCategory = Validations.isValidCategory(category);
19
+
20
+ if (!flagCategory.isValid) {
21
+ console.error('Invalid category. Please use one of the following categories: Service, Visual, Provider, Structural');
22
+ return;
23
+ }
24
+ category = flagCategory.category;
25
+
26
+ // Construir la ruta del directorio del componente
27
+ let componentDir = path.join(__dirname, '../../../../Slice/Components', category, componentName);
28
+ componentDir = componentDir.slice(1);
29
+
30
+ // Verificar si el directorio del componente existe
31
+ if (!fs.existsSync(componentDir)) {
32
+ console.error(`Component '${componentName}' does not exist.`);
33
+ return;
34
+ }
35
+
36
+ // Eliminar el directorio del componente y su contenido
37
+ fs.removeSync(componentDir);
38
+
39
+ console.log(`Component '${componentName}' deleted successfully.`);
40
+ }
41
+
42
+ export default deleteComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Command client for developing web applications with Slice.js",
5
5
  "main": "client.js",
6
6
  "scripts": {
package/post.js CHANGED
@@ -20,7 +20,8 @@ fs.promises.readFile(projectPackageJsonPath, 'utf8')
20
20
  projectPackageJson.scripts['slice:create'] = 'node node_modules/slicejs-cli/client.js create';
21
21
  projectPackageJson.scripts['slice:modify'] = 'node node_modules/slicejs-cli/client.js modify';
22
22
  projectPackageJson.scripts['slice:list'] = 'node node_modules/slicejs-cli/client.js list';
23
-
23
+ projectPackageJson.scripts['slice:delete'] = 'node node_modules/slicejs-cli/client.js delete';
24
+
24
25
  // Escribe el nuevo contenido en el package.json del proyecto
25
26
  return fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2), 'utf8');
26
27
  })
@@ -1,16 +0,0 @@
1
- export default function formatComponentCode(componentContent) {
2
- // Eliminar espacios en blanco redundantes
3
- componentContent = componentContent.replace(/\n\s*\n/g, '\n\n');
4
-
5
- // Agregar espacios en blanco después de llaves y paréntesis
6
- componentContent = componentContent.replace(/(\{|;|\(|\)|\})/g, '$1\n ');
7
-
8
- // Eliminar espacios en blanco al final de las líneas
9
- componentContent = componentContent.replace(/\s+$/gm, '');
10
-
11
- // Reemplazar múltiples espacios con uno solo
12
- componentContent = componentContent.replace(/ {2,}/g, ' ');
13
-
14
- return componentContent.trim() + '\n';
15
- }
16
-