slicejs-cli 1.0.57 → 2.0.1
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 +137 -53
- package/commands/Validations.js +47 -20
- package/commands/createComponent/VisualComponentTemplate.js +2 -6
- package/commands/createComponent/createComponent.js +15 -12
- package/commands/deleteComponent/deleteComponent.js +3 -8
- package/commands/listComponents/listComponents.js +2 -3
- package/package.json +3 -2
- package/post.js +6 -8
package/client.js
CHANGED
|
@@ -1,64 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import { program } from "commander";
|
|
3
|
+
import inquirer from "inquirer";
|
|
2
4
|
import initializeProject from "./commands/init/init.js";
|
|
3
5
|
import createComponent from "./commands/createComponent/createComponent.js";
|
|
4
|
-
import modifyComponent from "./commands/modifyComponent/modifyComponent.js";
|
|
5
6
|
import listComponents from "./commands/listComponents/listComponents.js";
|
|
6
7
|
import deleteComponent from "./commands/deleteComponent/deleteComponent.js";
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import validations from "./commands/Validations.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
|
|
16
|
+
const loadConfig = () => {
|
|
17
|
+
try {
|
|
18
|
+
const configPath = path.join(__dirname, "../../src/sliceConfig.json");
|
|
19
|
+
const rawData = fs.readFileSync(configPath, "utf-8");
|
|
20
|
+
return JSON.parse(rawData);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(`Error loading configuration: ${error.message}`);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const getCategories = () => {
|
|
28
|
+
const config = loadConfig();
|
|
29
|
+
return config && config.paths?.components ? Object.keys(config.paths.components) : [];
|
|
30
|
+
};
|
|
7
31
|
|
|
8
32
|
const sliceClient = program;
|
|
9
33
|
|
|
10
|
-
sliceClient
|
|
11
|
-
.version('1.0.0')
|
|
12
|
-
.description('Client for managing framework components');
|
|
34
|
+
sliceClient.version("1.0.0").description("CLI for managing framework components");
|
|
13
35
|
|
|
36
|
+
|
|
37
|
+
// INIT COMMAND
|
|
14
38
|
sliceClient
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
39
|
+
.command("init")
|
|
40
|
+
.description("Initialize the project")
|
|
41
|
+
.action(() => {
|
|
42
|
+
initializeProject("basic");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// COMPONENT COMMAND GROUP
|
|
46
|
+
const componentCommand = sliceClient.command("component").description("Manage components");
|
|
47
|
+
|
|
48
|
+
// CREATE COMPONENT
|
|
49
|
+
componentCommand
|
|
50
|
+
.command("create")
|
|
51
|
+
.description("Create a new component")
|
|
52
|
+
.action(async () => {
|
|
53
|
+
const categories = getCategories();
|
|
54
|
+
if (categories.length === 0) {
|
|
55
|
+
console.error("No categories available. Check your configuration.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const answers = await inquirer.prompt([
|
|
60
|
+
{
|
|
61
|
+
type: "input",
|
|
62
|
+
name: "componentName",
|
|
63
|
+
message: "Enter the component name:",
|
|
64
|
+
validate: (input) => (input ? true : "Component name cannot be empty"),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: "list",
|
|
68
|
+
name: "category",
|
|
69
|
+
message: "Select the component category:",
|
|
70
|
+
choices: categories,
|
|
71
|
+
}])
|
|
72
|
+
|
|
73
|
+
if(validations.getCategoryType(answers.category)==='Visual'){
|
|
74
|
+
const properties = await inquirer.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: "input",
|
|
77
|
+
name: "properties",
|
|
78
|
+
message: "Enter the properties (comma separated):",
|
|
79
|
+
validate: (input) => (input ? true : "Properties cannot be empty"),
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
answers.properties = properties.properties.split(",").map((prop) => prop.trim());
|
|
83
|
+
} else {
|
|
84
|
+
answers.properties = [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (createComponent(answers.componentName, answers.category, answers.properties)) {
|
|
88
|
+
listComponents();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// DELETE COMPONENT
|
|
94
|
+
componentCommand
|
|
95
|
+
.command("delete")
|
|
96
|
+
.description("Delete an existing component")
|
|
97
|
+
.action(async () => {
|
|
98
|
+
const categories = getCategories();
|
|
99
|
+
if (categories.length === 0) {
|
|
100
|
+
console.error("No categories available. Check your configuration.");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const answers = await inquirer.prompt([
|
|
105
|
+
{
|
|
106
|
+
type: "input",
|
|
107
|
+
name: "componentName",
|
|
108
|
+
message: "Enter the component name to delete:",
|
|
109
|
+
validate: (input) => (input ? true : "Component name cannot be empty"),
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type: "list",
|
|
113
|
+
name: "category",
|
|
114
|
+
message: "Select the component category:",
|
|
115
|
+
choices: categories,
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
const confirm = await inquirer.prompt([
|
|
120
|
+
{
|
|
121
|
+
type: "confirm",
|
|
122
|
+
name: "confirmation",
|
|
123
|
+
message: `Are you sure you want to delete ${answers.componentName}?`,
|
|
124
|
+
},
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
if (!confirm.confirmation) {
|
|
128
|
+
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if (deleteComponent(answers.componentName, answers.category)) {
|
|
134
|
+
listComponents();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// LIST COMPONENTS
|
|
141
|
+
componentCommand
|
|
142
|
+
.command("list")
|
|
143
|
+
.description("List all components")
|
|
144
|
+
.action(() => {
|
|
145
|
+
listComponents();
|
|
146
|
+
});
|
|
63
147
|
|
|
64
|
-
sliceClient.parse(process.argv);
|
|
148
|
+
sliceClient.parse(process.argv);
|
package/commands/Validations.js
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
class Validations {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.config = this.loadConfig(); // Cargamos la configuración solo una vez al instanciar
|
|
10
|
+
this.categories = this.config?.paths?.components;
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
isValidComponentName(componentName) {
|
|
5
15
|
// Expresión regular para verificar si el nombre contiene caracteres especiales
|
|
6
16
|
const regex = /^[a-zA-Z][a-zA-Z0-9]*$/;
|
|
7
17
|
return regex.test(componentName);
|
|
8
18
|
}
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
loadConfig() {
|
|
21
|
+
try {
|
|
22
|
+
const configPath = path.join(__dirname, '../../../src/sliceConfig.json');
|
|
23
|
+
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
24
|
+
return JSON.parse(rawData);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`Error cargando configuración: ${error.message}`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getCategories() {
|
|
32
|
+
return this.categories; // Usamos las categorías cargadas en el constructor
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getCategoryPath(category) {
|
|
36
|
+
return this.categories[category].path;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getCategoryType(category){
|
|
40
|
+
return this.categories[category].type;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
isValidCategory(category) {
|
|
44
|
+
const availableCategories = Object.keys(this.categories).map(cat => cat.toLowerCase());
|
|
45
|
+
|
|
46
|
+
if (availableCategories.includes(category.toLowerCase())) {
|
|
47
|
+
return { isValid: true, category };
|
|
48
|
+
} else {
|
|
49
|
+
return { isValid: false, category: null };
|
|
50
|
+
}
|
|
26
51
|
}
|
|
52
|
+
}
|
|
27
53
|
|
|
54
|
+
const validations = new Validations();
|
|
28
55
|
|
|
29
|
-
|
|
56
|
+
export default validations;
|
|
@@ -29,10 +29,8 @@ customElements.define("slice-${componentName.toLowerCase()}", ${componentName});
|
|
|
29
29
|
`;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static service(componentName
|
|
33
|
-
|
|
34
|
-
${method}() {}
|
|
35
|
-
`).join('\n');
|
|
32
|
+
static service(componentName) {
|
|
33
|
+
|
|
36
34
|
|
|
37
35
|
return `export default class ${componentName} {
|
|
38
36
|
constructor(props) {
|
|
@@ -42,8 +40,6 @@ customElements.define("slice-${componentName.toLowerCase()}", ${componentName});
|
|
|
42
40
|
init() {
|
|
43
41
|
// Método init
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
${methodDefinitions}
|
|
47
43
|
}
|
|
48
44
|
`;
|
|
49
45
|
}
|
|
@@ -7,8 +7,7 @@ import Validations from '../Validations.js';
|
|
|
7
7
|
import Print from '../Print.js';
|
|
8
8
|
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
9
9
|
|
|
10
|
-
function createComponent(componentName, category, properties
|
|
11
|
-
|
|
10
|
+
function createComponent(componentName, category, properties) {
|
|
12
11
|
if (!componentName) {
|
|
13
12
|
Print.error('Component name is required');
|
|
14
13
|
return;
|
|
@@ -32,28 +31,30 @@ function createComponent(componentName, category, properties, methods) {
|
|
|
32
31
|
const className = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
33
32
|
const fileName = `${className}.js`;
|
|
34
33
|
let template;
|
|
34
|
+
|
|
35
|
+
const type = Validations.getCategoryType(category);
|
|
36
|
+
|
|
35
37
|
|
|
36
|
-
if(
|
|
38
|
+
if(type==='Visual'){
|
|
37
39
|
template = componentTemplates.visual(className, properties);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
if(
|
|
41
|
-
template = componentTemplates.service(className
|
|
42
|
+
if(type==='Service'){
|
|
43
|
+
template = componentTemplates.service(className);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const categoryPath = Validations.getCategoryPath(category);
|
|
47
|
+
|
|
46
48
|
|
|
47
49
|
// Determinar la ruta del archivo
|
|
48
|
-
let componentDir = path.join(__dirname, '../../../../src/
|
|
50
|
+
let componentDir = path.join(__dirname, '../../../../src/', categoryPath, className);
|
|
49
51
|
componentDir=componentDir.slice(1);
|
|
50
|
-
// Asegurarse de que el directorio del componente exista
|
|
51
52
|
fs.ensureDirSync(componentDir);
|
|
52
53
|
|
|
54
|
+
|
|
53
55
|
// Determinar la ruta del archivo
|
|
54
56
|
let componentPath = path.join(componentDir, fileName);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
|
|
57
58
|
|
|
58
59
|
// Verificar si el archivo ya existe
|
|
59
60
|
if (fs.existsSync(componentPath)) {
|
|
@@ -61,10 +62,12 @@ function createComponent(componentName, category, properties, methods) {
|
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
|
|
66
|
+
|
|
64
67
|
// Escribir el código del componente en el archivo
|
|
65
68
|
fs.writeFileSync(componentPath, template);
|
|
66
69
|
|
|
67
|
-
if(
|
|
70
|
+
if(type==='Visual'){
|
|
68
71
|
fs.writeFileSync(`${componentDir}/${className}.css`, '');
|
|
69
72
|
fs.writeFileSync(`${componentDir}/${className}.html`, `<div>${componentName}</div>`);
|
|
70
73
|
}
|
|
@@ -22,17 +22,12 @@ function deleteComponent(componentName, category) {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
category = flagCategory.category;
|
|
25
|
-
|
|
26
|
-
// Determinar la ruta del archivo
|
|
27
|
-
//RUTA PARA CUANDO SE COLOQUE DE USUARIO
|
|
28
|
-
// ../../../../src/Components
|
|
29
|
-
//PARA DEVELOPERS
|
|
30
|
-
// ../../../../Slice/Components
|
|
31
25
|
|
|
26
|
+
const categoryPath = Validations.getCategoryPath(category);
|
|
27
|
+
|
|
32
28
|
|
|
33
|
-
|
|
34
29
|
// Construir la ruta del directorio del componente
|
|
35
|
-
let componentDir = path.join(__dirname, '../../../../src/
|
|
30
|
+
let componentDir = path.join(__dirname, '../../../../src/', categoryPath, componentName);
|
|
36
31
|
componentDir = componentDir.slice(1);
|
|
37
32
|
|
|
38
33
|
// Verificar si el directorio del componente existe
|
|
@@ -11,7 +11,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
11
11
|
*/
|
|
12
12
|
const loadConfig = () => {
|
|
13
13
|
try {
|
|
14
|
-
const configPath = path.join(__dirname, '../../../../
|
|
14
|
+
const configPath = path.join(__dirname, '../../../../src/sliceConfig.json');
|
|
15
15
|
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
16
16
|
return JSON.parse(rawData);
|
|
17
17
|
} catch (error) {
|
|
@@ -28,7 +28,6 @@ const loadConfig = () => {
|
|
|
28
28
|
const listComponents = (folderPath) => {
|
|
29
29
|
try {
|
|
30
30
|
const result = fs.readdirSync(folderPath)
|
|
31
|
-
console.log(`Leyendo carpeta ${folderPath}: ${result.length} archivos encontrados`);
|
|
32
31
|
return result;
|
|
33
32
|
} catch (error) {
|
|
34
33
|
console.error(`Error leyendo carpeta ${folderPath}: ${error.message}`);
|
|
@@ -71,7 +70,7 @@ function listComponentsReal(){
|
|
|
71
70
|
const components = getComponents();
|
|
72
71
|
|
|
73
72
|
// Ruta donde se generará components.js
|
|
74
|
-
const outputPath = path.join(__dirname, '../../../../
|
|
73
|
+
const outputPath = path.join(__dirname, '../../../../src/Components/components.js');
|
|
75
74
|
|
|
76
75
|
// Generar archivo components.js con los componentes detectados
|
|
77
76
|
fs.writeFileSync(outputPath, `const components = ${JSON.stringify(components, null, 2)}; export default components;`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slicejs-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Command client for developing web applications with Slice.js framework",
|
|
5
5
|
"main": "client.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"commander": "^12.0.0",
|
|
21
|
-
"fs-extra": "^11.2.0"
|
|
21
|
+
"fs-extra": "^11.2.0",
|
|
22
|
+
"inquirer": "^12.4.2"
|
|
22
23
|
}
|
|
23
24
|
}
|
package/post.js
CHANGED
|
@@ -21,10 +21,9 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
|
|
|
21
21
|
// Agrega los comandos personalizados a los scripts del proyecto
|
|
22
22
|
projectPackageJson.scripts = projectPackageJson.scripts || {};
|
|
23
23
|
projectPackageJson.scripts['slice:init'] = 'node node_modules/slicejs-cli/client.js init';
|
|
24
|
-
projectPackageJson.scripts['slice:create'] = 'node node_modules/slicejs-cli/client.js create';
|
|
25
|
-
projectPackageJson.scripts['slice:
|
|
26
|
-
projectPackageJson.scripts['slice:
|
|
27
|
-
projectPackageJson.scripts['slice:delete'] = 'node node_modules/slicejs-cli/client.js delete';
|
|
24
|
+
projectPackageJson.scripts['slice:create'] = 'node node_modules/slicejs-cli/client.js component create';
|
|
25
|
+
projectPackageJson.scripts['slice:list'] = 'node node_modules/slicejs-cli/client.js component list';
|
|
26
|
+
projectPackageJson.scripts['slice:delete'] = 'node node_modules/slicejs-cli/client.js component delete';
|
|
28
27
|
|
|
29
28
|
// Escribe el nuevo contenido en el package.json del proyecto
|
|
30
29
|
return fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2), 'utf8');
|
|
@@ -42,10 +41,9 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
|
|
|
42
41
|
main: 'index.js',
|
|
43
42
|
scripts: {
|
|
44
43
|
'slice:init': 'node node_modules/slicejs-cli/client.js init',
|
|
45
|
-
'slice:create': 'node node_modules/slicejs-cli/client.js create',
|
|
46
|
-
'slice:
|
|
47
|
-
'slice:
|
|
48
|
-
'slice:delete': 'node node_modules/slicejs-cli/client.js delete'
|
|
44
|
+
'slice:create': 'node node_modules/slicejs-cli/client.js component create',
|
|
45
|
+
'slice:list': 'node node_modules/slicejs-cli/client.js component list',
|
|
46
|
+
'slice:delete': 'node node_modules/slicejs-cli/client.js component delete'
|
|
49
47
|
},
|
|
50
48
|
keywords: [],
|
|
51
49
|
author: '',
|