slicejs-cli 1.0.24 → 1.0.26

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.
@@ -0,0 +1,30 @@
1
+ export default class Validations{
2
+ constructor(){}
3
+
4
+ static isValidComponentName(componentName) {
5
+ // Expresión regular para verificar si el nombre contiene caracteres especiales
6
+ const regex = /^[a-zA-Z][a-zA-Z0-9]*$/;
7
+ return regex.test(componentName);
8
+ }
9
+
10
+ static isValidCategory(category){
11
+ const categoryVariations = {
12
+ 'Service': ['service', 'servicio', 'serv'],
13
+ 'Visual': ['visual', 'vis'],
14
+ 'Provider': ['provider', 'proveedor', 'prov'],
15
+ 'Structural': ['structural', 'estructural', 'est']
16
+ };
17
+
18
+ let categoryIsValid = false;
19
+ Object.keys(categoryVariations).forEach(validCategory => {
20
+ if (categoryVariations[validCategory].includes(category.toLowerCase())) {
21
+ category = validCategory
22
+ categoryIsValid = true;
23
+ }
24
+ });
25
+
26
+ return ({isValid: categoryIsValid, category: category})
27
+ }
28
+
29
+
30
+ }
@@ -82,4 +82,3 @@ function isValidComponentName(componentName) {
82
82
 
83
83
  export default createComponent;
84
84
 
85
- createComponent('test', 'Visual', 'hola');
@@ -1,49 +1,38 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import Validations from '../Validations.js';
3
4
 
4
5
  const __dirname = path.dirname(new URL(import.meta.url).pathname);
5
6
 
7
+
6
8
  function modifyComponent(componentName, category, addProperties, removeProperties) {
7
9
  if (!componentName) {
8
10
  console.error('Component name is required');
9
11
  return;
10
12
  }
11
13
 
12
- if (!isValidComponentName(componentName)) {
14
+ if (!Validations.isValidComponentName(componentName)) {
13
15
  console.error('Invalid component name. Please use only alphanumeric characters and start with a letter.');
14
16
  return;
15
17
  }
16
18
 
19
+
20
+
21
+ let flagCategory = Validations.isValidCategory(category);
17
22
 
18
- const categoryVariations = {
19
- 'Service': ['service', 'servicio', 'serv'],
20
- 'Visual': ['visual', 'vis'],
21
- 'Provider': ['provider', 'proveedor', 'prov'],
22
- 'Structural': ['structural', 'estructural', 'est']
23
- };
24
-
25
-
26
-
27
- // Verificar si la categoría es válida
28
- let categoryIsValid = false;
29
- Object.keys(categoryVariations).forEach(validCategory => {
30
- if (categoryVariations[validCategory].includes(category.toLowerCase())) {
31
- category = validCategory
32
- categoryIsValid = true;
33
- }
34
- });
35
-
36
- if (!categoryIsValid) {
23
+ if (!flagCategory.isValid) {
37
24
  console.error('Invalid category. Please use one of the following categories: Service, Visual, Provider, Structural');
38
25
  return;
39
26
  }
40
27
 
28
+ category = flagCategory.category;
29
+
41
30
  const componentDir = path.join(__dirname, '../../../../Slice/Components', category, componentName);
42
31
  const fileName = `${componentName}.js`;
32
+
43
33
  let componentPath = path.join(componentDir, fileName);
44
34
  componentPath=componentPath.slice(1);
45
35
 
46
- console.log(componentPath);
47
36
  if (!fs.existsSync(componentPath)) {
48
37
  console.error(`Component '${componentName}' does not exist.`);
49
38
  return;
@@ -79,10 +68,6 @@ function modifyComponent(componentName, category, addProperties, removePropertie
79
68
  console.log(`Component '${componentName}' modified successfully.`);
80
69
  }
81
70
 
82
- function isValidComponentName(componentName) {
83
- const regex = /^[a-zA-Z][a-zA-Z0-9]*$/;
84
- return regex.test(componentName);
85
- }
86
71
 
87
72
  function extractProperties(componentContent) {
88
73
  const propRegex = /this\.debuggerProps\s*=\s*\[(.*?)\];/s;
@@ -104,14 +89,27 @@ function addGetterSetterIfNeeded(componentContent, property) {
104
89
  }
105
90
 
106
91
  function removePropertyIfNeeded(componentContent, property) {
107
- // Verificar si no está en debuggerProps pero tiene getters y setters
108
- const propInDebuggerProps = componentContent.includes(`'${property}'`);
92
+ let updatedComponentContent = componentContent;
93
+
94
+ // Verificar si la propiedad está en debuggerProps
95
+ const propIndex = componentContent.indexOf(`'${property}'`);
96
+ if (propIndex !== -1) {
97
+ // Eliminar la propiedad de debuggerProps
98
+ const startIndex = componentContent.lastIndexOf('[', propIndex);
99
+ const endIndex = componentContent.indexOf(']', propIndex);
100
+ updatedComponentContent = componentContent.slice(0, startIndex) + componentContent.slice(endIndex + 1);
101
+ console.log(`Property '${property}' removed from debuggerProps.`);
102
+ }
103
+
104
+ // Verificar si la propiedad tiene getters y setters
109
105
  const hasGetterSetter = hasGetterSetterForProperty(componentContent, property);
110
- if (!propInDebuggerProps && hasGetterSetter) {
106
+ if (hasGetterSetter) {
111
107
  // Eliminar los getters y setters del componente
112
- componentContent = removeGetterSetter(componentContent, property);
108
+ updatedComponentContent = removeGetterSetter(updatedComponentContent, property);
109
+ console.log(`Getters and setters removed for property '${property}'.`);
113
110
  }
114
- return componentContent;
111
+
112
+ return updatedComponentContent;
115
113
  }
116
114
 
117
115
  function hasGetterSetterForProperty(componentContent, property) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Command client for developing web applications with Slice.js",
5
5
  "main": "client.js",
6
6
  "scripts": {