slicejs-cli 2.0.1 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "commander": "^12.0.0",
21
21
  "fs-extra": "^11.2.0",
22
- "inquirer": "^12.4.2"
22
+ "inquirer": "^12.4.2",
23
+ "slicejs-web-framework": "^1.0.1"
23
24
  }
24
25
  }
@@ -1,111 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- const __dirname = path.dirname(new URL(import.meta.url).pathname);
5
-
6
- function modifyComponent(componentName, category, addProperties, removeProperties) {
7
- if (!componentName) {
8
- console.error('Component name is required');
9
- return;
10
- }
11
-
12
- if (!isValidComponentName(componentName)) {
13
- console.error('Invalid component name. Please use only alphanumeric characters and start with a letter.');
14
- return;
15
- }
16
-
17
- if (!['Service', 'Visual', 'Provider', 'Structural'].includes(category)) {
18
- console.error('Invalid category. Please use one of the following categories: Service, Visual, Provider, Structural');
19
- return;
20
- }
21
-
22
- const fileName = `${componentName}.js`;
23
- const componentPath = path.join('Components', category, fileName);
24
-
25
- if (!fs.existsSync(componentPath)) {
26
- console.error(`Component '${componentName}' does not exist.`);
27
- return;
28
- }
29
-
30
- let componentContent = fs.readFileSync(componentPath, 'utf-8');
31
- let existingProperties = extractProperties(componentContent);
32
-
33
- addProperties.forEach(property => {
34
- if (!existingProperties.includes(property)) {
35
- existingProperties.push(property);
36
- console.log(`Property '${property}' added to component '${componentName}'.`);
37
- // Agregar getters y setters al componente
38
- componentContent = addGetterSetter(componentContent, property);
39
- } else {
40
- console.log(`Property '${property}' already exists in component '${componentName}'.`);
41
- }
42
- });
43
-
44
- removeProperties.forEach(property => {
45
- if (existingProperties.includes(property)) {
46
- existingProperties = existingProperties.filter(prop => prop !== property);
47
- console.log(`Property '${property}' removed from component '${componentName}'.`);
48
- componentContent = removeGetterSetter(componentContent, property);
49
- } else {
50
- console.log(`Property '${property}' does not exist in component '${componentName}'.`);
51
- }
52
- });
53
-
54
- componentContent = updateComponentProps(componentContent, existingProperties);
55
- fs.writeFileSync(componentPath, componentContent);
56
- console.log(`Component '${componentName}' modified successfully.`);
57
- }
58
-
59
- function isValidComponentName(componentName) {
60
- const regex = /^[a-zA-Z][a-zA-Z0-9]*$/;
61
- return regex.test(componentName);
62
- }
63
-
64
- function extractProperties(componentContent) {
65
- const propRegex = /this\.debuggerProps\s*=\s*\[(.*?)\];/s;
66
- const match = componentContent.match(propRegex);
67
- if (match && match[1]) {
68
- return match[1].split(',').map(prop => prop.trim().replace(/['"]/g, ''));
69
- }
70
- return [];
71
- }
72
-
73
- function addGetterSetter(componentContent, property) {
74
- // Agregar los métodos getters y setters al componente
75
- const getterSetterCode = `
76
- get ${property}() {
77
- return this._${property};
78
- }
79
-
80
- set ${property}(value) {
81
- this._${property} = value;
82
- }\n\n`;
83
-
84
- const classEndIndex = componentContent.lastIndexOf('}');
85
- if (classEndIndex !== -1) {
86
- const updatedComponentContent = componentContent.slice(0, classEndIndex) + getterSetterCode + componentContent.slice(classEndIndex);
87
- return updatedComponentContent;
88
- }
89
- return componentContent;
90
- }
91
-
92
- function removeGetterSetter(componentContent, property) {
93
- // Eliminar los métodos getters y setters del componente
94
- const getterSetterRegex = new RegExp(`get ${property}\\(\\)\\s*{[^}]+}\\s*set ${property}\\([^)]+\\)\\s*{[^}]+}`);
95
-
96
- const updatedComponentContent = componentContent.replace(getterSetterRegex, '');
97
- return updatedComponentContent;
98
- }
99
-
100
- function updateComponentProps(componentContent, properties) {
101
- const updatedPropsList = properties.map(prop => `'${prop}'`).join(', ');
102
- const propIndex = componentContent.indexOf('this.debuggerProps = [');
103
- const propsStartIndex = componentContent.indexOf('[', propIndex);
104
- const propsEndIndex = componentContent.indexOf(']', propIndex);
105
- const updatedComponentContent = `${componentContent.slice(0, propsStartIndex + 1)}${updatedPropsList}${componentContent.slice(propsEndIndex)}`;
106
- return updatedComponentContent;
107
- }
108
-
109
- export default modifyComponent;
110
-
111
- modifyComponent('Input', 'Visual', ['placeholder', 'conditions'], []);
@@ -1,151 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import Validations from '../Validations.js';
4
- const __dirname = path.dirname(new URL(import.meta.url).pathname);
5
- import Print from '../Print.js';
6
-
7
- function modifyComponent(componentName, category, addProperties, removeProperties) {
8
- if (!componentName) {
9
- Print.error('Component name is required');
10
- return;
11
- }
12
-
13
- if (!Validations.isValidComponentName(componentName)) {
14
- Print.error('Invalid component name. Please use only alphanumeric characters and start with a letter.');
15
- return;
16
- }
17
-
18
-
19
-
20
-
21
- let flagCategory = Validations.isValidCategory(category);
22
-
23
- if (!flagCategory.isValid) {
24
- Print.error('Invalid category. Please use one of the following categories: Service, Visual, Provider, Structural');
25
- return;
26
- }
27
-
28
- category = flagCategory.category;
29
-
30
- let componentDir = path.join(__dirname, '../../../../src/Components', category, componentName);
31
- componentDir = componentDir.slice(1);
32
-
33
- // let componentPath = path.join(componentDir, fileName);
34
- //componentPath=componentPath.slice(1);
35
-
36
- if (!fs.existsSync(componentPath)) {
37
- Print.error(`Component '${componentName}' does not exist.`);
38
- return;
39
- }
40
-
41
-
42
- let componentContent = fs.readFileSync(componentPath, 'utf-8');
43
- let existingProperties = extractProperties(componentContent);
44
-
45
- addProperties.forEach(property => {
46
- if (!existingProperties.includes(property)) {
47
- existingProperties.push(property);
48
- Print.success(`Property '${property}' added to component '${componentName}'.`);
49
- // Verificar si existen getters y setters para la propiedad y agregarlos si es necesario
50
- componentContent = addGetterSetterIfNeeded(componentContent, property);
51
- } else {
52
- Print.error(`Property '${property}' already exists in component '${componentName}'.`);
53
- }
54
- });
55
-
56
- removeProperties.forEach(property => {
57
- if (existingProperties.includes(property)) {
58
- existingProperties = existingProperties.filter(prop => prop !== property);
59
- Print.success(`Property '${property}' removed from component '${componentName}'.`);
60
- componentContent = removePropertyIfNeeded(componentContent, property);
61
- } else {
62
- Print.error(`Property '${property}' does not exist in component '${componentName}'.`);
63
- }
64
- });
65
-
66
- componentContent = updateComponentProps(componentContent, existingProperties);
67
- fs.writeFileSync(componentPath, componentContent);
68
- Print.success(`Component '${componentName}' modified successfully.`);
69
- }
70
-
71
-
72
- function extractProperties(componentContent) {
73
- const propRegex = /this\.debuggerProps\s*=\s*\[(.*?)\];/s;
74
- const match = componentContent.match(propRegex);
75
- if (match && match[1]) {
76
- return match[1].split(',').map(prop => prop.trim().replace(/['"]/g, ''));
77
- }
78
- return [];
79
- }
80
-
81
- function addGetterSetterIfNeeded(componentContent, property) {
82
- // Verificar si existen getters y setters para la propiedad
83
- const hasGetterSetter = hasGetterSetterForProperty(componentContent, property);
84
- if (!hasGetterSetter) {
85
- // Agregar getters y setters al componente
86
- componentContent = addGetterSetter(componentContent, property);
87
- }
88
- return componentContent;
89
- }
90
-
91
- function removePropertyIfNeeded(componentContent, property) {
92
- // Eliminar la propiedad de debuggerProps si está presente
93
- const propRegex = /this\.debuggerProps\s*=\s*\[(.*?)\];/s;
94
- const match = componentContent.match(propRegex);
95
- if (match && match[1]) {
96
- let props = match[1].split(',').map(prop => prop.trim().replace(/['"]/g, ''));
97
- const propIndex = props.indexOf(property);
98
- if (propIndex !== -1) {
99
- props.splice(propIndex, 1);
100
- componentContent = componentContent.replace(propRegex, `this.debuggerProps = [${props.map(prop => `'${prop}'`).join(', ')}];`);
101
- }
102
- }
103
-
104
- // Eliminar los getters y setters de la propiedad
105
- componentContent = removeGetterSetter(componentContent, property);
106
-
107
- return componentContent;
108
- }
109
-
110
- function hasGetterSetterForProperty(componentContent, property) {
111
- const getterRegex = new RegExp(`get ${property}\\(\\)\\s*{`);
112
- const setterRegex = new RegExp(`set ${property}\\([^)]+\\)\\s*{`);
113
- return getterRegex.test(componentContent) && setterRegex.test(componentContent);
114
- }
115
-
116
- function addGetterSetter(componentContent, property) {
117
- // Agregar los métodos getters y setters al componente
118
- const getterSetterCode = `
119
- get ${property}() {
120
- return this._${property};
121
- }
122
-
123
- set ${property}(value) {
124
- this._${property} = value;
125
- }\n\n`;
126
-
127
- const classEndIndex = componentContent.lastIndexOf('}');
128
- if (classEndIndex !== -1) {
129
- const updatedComponentContent = componentContent.slice(0, classEndIndex) + getterSetterCode + componentContent.slice(classEndIndex);
130
- return updatedComponentContent;
131
- }
132
- return componentContent;
133
- }
134
-
135
- function removeGetterSetter(componentContent, property) {
136
- // Eliminar los métodos getters y setters del componente
137
- const getterSetterRegex = new RegExp(`get ${property}\\(\\)\\s*{[^}]+}\\s*set ${property}\\([^)]+\\)\\s*{[^}]+}`);
138
- return componentContent.replace(getterSetterRegex, '');
139
- }
140
-
141
- function updateComponentProps(componentContent, properties) {
142
- const updatedPropsList = properties.map(prop => `'${prop}'`).join(', ');
143
- const propIndex = componentContent.indexOf('this.debuggerProps = [');
144
- const propsStartIndex = componentContent.indexOf('[', propIndex);
145
- const propsEndIndex = componentContent.indexOf(']', propIndex);
146
- const updatedComponentContent = `${componentContent.slice(0, propsStartIndex + 1)}${updatedPropsList}${componentContent.slice(propsEndIndex)}`;
147
- return updatedComponentContent;
148
- }
149
-
150
- export default modifyComponent;
151
-