slicejs-cli 1.0.25 → 1.0.27

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
+ }
@@ -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,23 @@ 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}'`);
109
- const hasGetterSetter = hasGetterSetterForProperty(componentContent, property);
110
- if (!propInDebuggerProps && hasGetterSetter) {
111
- // Eliminar los getters y setters del componente
112
- componentContent = removeGetterSetter(componentContent, property);
113
- }
114
- return componentContent;
92
+ let updatedComponentContent = componentContent;
93
+
94
+ // Eliminar la propiedad de debuggerProps si está presente
95
+ const debuggerPropsRegex = /this\.debuggerProps\s*=\s*\[(.*?)\];/s;
96
+ updatedComponentContent = updatedComponentContent.replace(debuggerPropsRegex, (match, propsList) => {
97
+ const props = propsList.split(',').map(prop => prop.trim().replace(/['"]/g, ''));
98
+ const propIndex = props.indexOf(property);
99
+ if (propIndex !== -1) {
100
+ props.splice(propIndex, 1);
101
+ }
102
+ return `this.debuggerProps = [${props.map(prop => `'${prop}'`).join(', ')}];`;
103
+ });
104
+
105
+ // Eliminar los getters y setters de la propiedad
106
+ updatedComponentContent = removeGetterSetter(updatedComponentContent, property);
107
+
108
+ return updatedComponentContent;
115
109
  }
116
110
 
117
111
  function hasGetterSetterForProperty(componentContent, property) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Command client for developing web applications with Slice.js",
5
5
  "main": "client.js",
6
6
  "scripts": {