slicejs-cli 2.0.8 → 2.0.10

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
@@ -70,10 +70,6 @@ componentCommand
70
70
  choices: categories,
71
71
  }])
72
72
 
73
- validations.categories = validations.loadConfig().paths.components; // Cargamos las categorías al instanciar
74
-
75
-
76
-
77
73
  if(validations.getCategoryType(answers.category)==='Visual'){
78
74
  const properties = await inquirer.prompt([
79
75
  {
@@ -6,7 +6,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
6
 
7
7
  class Validations {
8
8
  constructor() {
9
-
9
+ this.config = this.loadConfig(); // Cargamos la configuración solo una vez al instanciar
10
+ this.categories = this.config?.paths?.components;
10
11
 
11
12
  }
12
13
 
@@ -19,7 +20,11 @@ class Validations {
19
20
  loadConfig() {
20
21
  try {
21
22
  const configPath = path.join(__dirname, '../../../src/sliceConfig.json');
23
+ if (!fs.existsSync(configPath)) {
24
+ return null; // Evitar error si no existe
25
+ }
22
26
  const rawData = fs.readFileSync(configPath, 'utf-8');
27
+
23
28
  return JSON.parse(rawData);
24
29
  } catch (error) {
25
30
  console.error(`Error cargando configuración: ${error.message}`);
@@ -7,32 +7,51 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
7
  export default async function initializeProject(projectType) {
8
8
  try {
9
9
  // Directorio de origen en el paquete
10
- let sliceBaseDir = path.join(__dirname, '../','../','../','node_modules','slicejs-web-framework')
11
- let apiDir = `${sliceBaseDir}/api`
12
- let srcDir = `${sliceBaseDir}/src`
13
-
14
- let destinationApi = path.join(__dirname, '../../../../api')
15
- let destinationSrc = path.join(__dirname, '../../../../src')
16
-
10
+ let sliceBaseDir = path.join(__dirname, '../../../slicejs-web-framework');
11
+ let apiDir = path.join(sliceBaseDir, 'api');
12
+ let srcDir = path.join(sliceBaseDir, 'src');
13
+
14
+ let destinationApi = path.join(__dirname, '../../../../api');
15
+ let destinationSrc = path.join(__dirname, '../../../../src');
16
+
17
+ try {
18
+ // Verificar si los directorios de origen existen
19
+ if (!fs.existsSync(sliceBaseDir)) throw new Error(`No se encontró el directorio base: ${sliceBaseDir}`);
20
+ if (!fs.existsSync(apiDir)) throw new Error(`No se encontró la carpeta api: ${apiDir}`);
21
+ if (!fs.existsSync(srcDir)) throw new Error(`No se encontró la carpeta src: ${srcDir}`);
22
+ } catch (error) {
23
+ Print.error('Error validando directorios de origen:', error.message);
24
+ return;
25
+ }
17
26
 
18
- // Verificar si el directorio de destino ya existe
19
- if (fs.existsSync(destinationApi)) {
20
- Print.error('El proyecto ya cuenta con un directorio "api". No es posible inicializar el proyecto nuevamente');
27
+ try {
28
+ // Verificar si los directorios de destino ya existen
29
+ if (fs.existsSync(destinationApi)) throw new Error(`El directorio "api" ya existe: ${destinationApi}`);
30
+ if (fs.existsSync(destinationSrc)) throw new Error(`El directorio "src" ya existe: ${destinationSrc}`);
31
+ } catch (error) {
32
+ Print.error('Error validando directorios de destino:', error.message);
21
33
  return;
22
34
  }
23
35
 
24
- if (fs.existsSync(destinationSrc)) {
25
- Print.error('El proyecto ya cuenta con un directorio "src". No es posible inicializar el proyecto nuevamente');
36
+ try {
37
+ // Copiar las carpetas
38
+ await fs.copy(apiDir, destinationApi, { recursive: true });
39
+ Print.success('Carpeta "api" copiada correctamente.');
40
+ } catch (error) {
41
+ Print.error('Error copiando la carpeta "api":', error.message);
26
42
  return;
27
43
  }
28
44
 
29
- await fs.copy(apiDir, destinationApi , { recursive: true });
30
- await fs.copy(srcDir, destinationSrc , { recursive: true });
45
+ try {
46
+ await fs.copy(srcDir, destinationSrc, { recursive: true });
47
+ Print.success('Carpeta "src" copiada correctamente.');
48
+ } catch (error) {
49
+ Print.error('Error copiando la carpeta "src":', error.message);
50
+ return;
51
+ }
31
52
 
32
53
  Print.success('Proyecto inicializado correctamente.');
33
54
  } catch (error) {
34
- Print.error('Error al inicializar el proyecto:', error);
55
+ Print.error('Error inesperado al inicializar el proyecto:', error.message);
35
56
  }
36
57
  }
37
-
38
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "scripts": {
package/post.js CHANGED
@@ -27,6 +27,9 @@ fs.promises.access(projectPackageJsonPath, fs.constants.F_OK)
27
27
  projectPackageJson.scripts['run'] = 'node api/index.js';
28
28
  projectPackageJson.scripts['slice:start'] = 'node api/index.js';
29
29
  projectPackageJson.scripts['development'] = 'node api/index.js';
30
+
31
+ // add type module
32
+ projectPackageJson.type = 'module';
30
33
 
31
34
  // Escribe el nuevo contenido en el package.json del proyecto
32
35
  return fs.promises.writeFile(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2), 'utf8');