utn-cli 2.1.18 → 2.1.20
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/commands/backend.js +64 -40
- package/package.json +1 -1
- package/templates/backend/InformacionDelModulo.json +0 -4
- package/templates/backend/servicios/Nucleo/InformacionDelModulo.js +96 -0
- package/templates/backend/servicios/Nucleo/Miscelaneas.js +2451 -92
- package/templates/backend/servicios/InformacionDelModulo.js +0 -193
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Archivos.js +0 -329
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Autenticacion.js +0 -388
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/InicializacionDelModulo.js +0 -254
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Modulos.js +0 -261
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Notificaciones.js +0 -82
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Personas.js +0 -93
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Reportes.js +0 -370
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/TareasProgramadas.js +0 -105
package/commands/backend.js
CHANGED
|
@@ -11,90 +11,114 @@ async function inicializarProyectoBackend() {
|
|
|
11
11
|
const informacionDeRutaDelModuloJson = JSON.parse(fs.readFileSync(rutaDelModuloJson, 'utf-8'));
|
|
12
12
|
console.log(`Versión de utn-backend (a través de utn-cli): ${informacionDeRutaDelModuloJson.version}.`);
|
|
13
13
|
|
|
14
|
-
const rutaDeMiscelaneas = path.join(process.cwd(), 'servicios/Nucleo/
|
|
14
|
+
const rutaDeMiscelaneas = path.join(process.cwd(), 'servicios/Nucleo/Miscelaneas.js');
|
|
15
15
|
reemplazarContenidoEnArchivo(rutaDeMiscelaneas, 'VERSION_DEL_NUCLEO', informacionDeRutaDelModuloJson.version);
|
|
16
16
|
|
|
17
17
|
const rutaDeInformacionDelModuloJson = path.join(process.cwd(), 'InformacionDelModulo.json');
|
|
18
|
+
// Check if InformacionDelModulo.json exists, if not, it's an init scenario.
|
|
18
19
|
if (!fs.existsSync(rutaDeInformacionDelModuloJson)) {
|
|
19
20
|
console.error('InformacionDelModulo.json not found. This should be present after copying templates.');
|
|
20
21
|
closeReadLine();
|
|
21
22
|
process.exit(1);
|
|
22
23
|
}
|
|
23
24
|
let informacionDelModuloJson = JSON.parse(fs.readFileSync(rutaDeInformacionDelModuloJson, 'utf-8'));
|
|
25
|
+
const rutaDeInformacionDelModulo = path.join(process.cwd(), 'servicios/Nucleo/InformacionDelModulo.js');
|
|
26
|
+
fs.unlinkSync(path.join(process.cwd(), 'servicios/InformacionDelModulo.js'));
|
|
24
27
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
// el reemplazarContenidoEnArchivo solo se usa para archivos externos (package.json, db.js, etc.)
|
|
28
|
-
// mediante el specialHandler.
|
|
29
|
-
async function askAndSave(prop, promptText, specialHandler = null) {
|
|
28
|
+
// Helper to ask and replace
|
|
29
|
+
async function askAndReplace(prop, promptText, fileToReplace, placeholder, specialHandler = null) {
|
|
30
30
|
let value = informacionDelModuloJson[prop];
|
|
31
|
-
if (value ===
|
|
31
|
+
if (value === placeholder) {
|
|
32
32
|
value = await hacerPreguntaTrim(promptText);
|
|
33
33
|
informacionDelModuloJson[prop] = value;
|
|
34
34
|
}
|
|
35
35
|
if (specialHandler) {
|
|
36
36
|
specialHandler(value);
|
|
37
37
|
}
|
|
38
|
+
reemplazarContenidoEnArchivo(fileToReplace, placeholder, value);
|
|
38
39
|
return value;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
await
|
|
42
|
-
await
|
|
43
|
-
await
|
|
42
|
+
// const NOMBRE_DEL_PROYECTO = await askAndReplace('NOMBRE_DEL_PROYECTO', '¿Cuál es el nombre del proyecto?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_PROYECTO');
|
|
43
|
+
await askAndReplace('DESCRIPCION_DEL_PROYECTO', '¿Cuál es la descripción del proyecto?: ', rutaDeInformacionDelModulo, 'DESCRIPCION_DEL_PROYECTO');
|
|
44
|
+
await askAndReplace('DETALLE_DEL_PROYECTO', '¿Cuál es el detalle del proyecto?: ', rutaDeInformacionDelModulo, 'DETALLE_DEL_PROYECTO');
|
|
44
45
|
|
|
45
|
-
await
|
|
46
|
+
const NOMBRE_DEL_CANONICO_DEL_PROYECTO = await askAndReplace('NOMBRE_DEL_CANONICO_DEL_PROYECTO', '¿Cuál es el nombre canónico del proyecto?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_CANONICO_DEL_PROYECTO', (val) => {
|
|
46
47
|
const oldFileName = path.join(process.cwd(), 'NOMBRE_DEL_CANONICO_DEL_PROYECTO.rest');
|
|
47
48
|
const newFileName = path.join(process.cwd(), `${val}.rest`);
|
|
48
|
-
if (fs.existsSync(newFileName))
|
|
49
|
+
if (fs.existsSync(newFileName)) {
|
|
50
|
+
// If the new file name already exists, do nothing.
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
49
53
|
if (fs.existsSync(oldFileName)) {
|
|
50
54
|
fs.renameSync(oldFileName, newFileName);
|
|
51
55
|
} else {
|
|
56
|
+
// If the old file doesn't exist and the new one doesn't exist, it might be an update scenario where it was already renamed.
|
|
57
|
+
// Or a fresh init where the file might not be present always. Log for now.
|
|
52
58
|
console.log(`Warning: ${oldFileName} not found during canonical project name rename.`);
|
|
53
59
|
}
|
|
54
60
|
});
|
|
55
61
|
|
|
56
|
-
await
|
|
57
|
-
await
|
|
58
|
-
|
|
59
|
-
await
|
|
60
|
-
|
|
61
|
-
reemplazarContenidoEnArchivo(
|
|
62
|
-
|
|
63
|
-
reemplazarContenidoEnArchivo(
|
|
62
|
+
await askAndReplace('TIPO_DE_TARJETA', '¿Cuál es el tipo de tarjeta? Posibles valores: Área, Proceso, Servicio: ', rutaDeInformacionDelModulo, 'TIPO_DE_TARJETA');
|
|
63
|
+
// await askAndReplace('NOMBRE_DEL_ROL', '¿Cuál es el nombre del rol?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_ROL');
|
|
64
|
+
|
|
65
|
+
const NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS = await askAndReplace('NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', '¿Cuál es el nombre del repositorio de base de datos?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', (val) => {
|
|
66
|
+
const rutaDeVariablesDeCalidad = path.join(process.cwd(), 'variables-calidad.env');
|
|
67
|
+
reemplazarContenidoEnArchivo(rutaDeVariablesDeCalidad, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val);
|
|
68
|
+
const rutaDeVariablesDeDesarrollo = path.join(process.cwd(), 'variables-desarrollo.env');
|
|
69
|
+
reemplazarContenidoEnArchivo(rutaDeVariablesDeDesarrollo, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val);
|
|
70
|
+
const rutaDeVariablesDePruebas = path.join(process.cwd(), 'variables-pruebas.env');
|
|
71
|
+
reemplazarContenidoEnArchivo(rutaDeVariablesDePruebas, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val);
|
|
72
|
+
const rutaDeDB = path.join(process.cwd(), 'servicios/Nucleo/db.js');
|
|
73
|
+
reemplazarContenidoEnArchivo(rutaDeDB, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val.slice(0, -3));
|
|
64
74
|
});
|
|
65
75
|
|
|
66
|
-
await
|
|
67
|
-
|
|
68
|
-
reemplazarContenidoEnArchivo(
|
|
76
|
+
const NOMBRE_DEL_REPOSITORIO_DE_BACKEND = await askAndReplace('NOMBRE_DEL_REPOSITORIO_DE_BACKEND', '¿Cuál es el nombre del repositorio de backend?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_REPOSITORIO_DE_BACKEND', (val) => {
|
|
77
|
+
const rutaPackage = path.join(process.cwd(), 'package.json');
|
|
78
|
+
reemplazarContenidoEnArchivo(rutaPackage, 'nombre_del_repositorio_backend', val);
|
|
79
|
+
const rutaDeserver = path.join(process.cwd(), 'server.js');
|
|
80
|
+
reemplazarContenidoEnArchivo(rutaDeserver, 'NOMBRE_DEL_REPOSITORIO_DE_BACKEND', `${val} corriendo en el puerto 80.`);
|
|
69
81
|
});
|
|
70
82
|
|
|
71
|
-
await
|
|
72
|
-
await
|
|
73
|
-
await
|
|
74
|
-
await
|
|
75
|
-
await
|
|
76
|
-
await
|
|
83
|
+
await askAndReplace('NOMBRE_DEL_REPOSITORIO_DE_FRONTEND', '¿Cuál es el nombre del repositorio de frontend?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_REPOSITORIO_DE_FRONTEND');
|
|
84
|
+
await askAndReplace('NOMBRE_DEL_PERMISO', '¿Cuál es el nombre del permiso?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_PERMISO');
|
|
85
|
+
await askAndReplace('DESCRIPCION_DEL_PERMISO', '¿Cuál es la descripción del permiso?: ', rutaDeInformacionDelModulo, 'DESCRIPCION_DEL_PERMISO');
|
|
86
|
+
// await askAndReplace('MENU_PADRE', '¿Cuál es el nombre canónico del menú padre?: ', rutaDeInformacionDelModulo, 'MENU_PADRE');
|
|
87
|
+
// await askAndReplace('COLOR_DEL_MODULO', '¿Cuál es el color del módulo?: ', rutaDeInformacionDelModulo, 'COLOR_DEL_MODULO');
|
|
88
|
+
await askAndReplace('CORREO_PARA_REPORTES', '¿Cuál es el correo para reportes?: ', rutaDeInformacionDelModulo, 'CORREO_PARA_REPORTES');
|
|
77
89
|
|
|
78
|
-
await
|
|
90
|
+
const nombre_de_desarrollador = await askAndReplace('nombre_de_desarrollador', '¿Cuál es el nombre del desarrollador?: ', path.join(process.cwd(), 'package.json'), 'nombre_de_desarrollador', (val) => {
|
|
79
91
|
reemplazarContenidoEnArchivo(path.join(process.cwd(), 'package.json'), 'nombre_de_desarrollador', `Para la Universidad Técnica Nacional por: ${val}`);
|
|
80
92
|
});
|
|
81
93
|
|
|
82
|
-
await
|
|
94
|
+
await askAndReplace('CEDULA_DEL_DESARROLLADOR', '¿Cuál es el número de cédula del desarrollador?: ', rutaDeInformacionDelModulo, 'CEDULA_DEL_DESARROLLADOR');
|
|
83
95
|
|
|
84
|
-
await
|
|
96
|
+
const url_del_grupo = await askAndReplace('url_del_grupo', '¿Cuál es la URL del grupo en el Git?: ', rutaDeInformacionDelModulo, 'url_del_grupo', (val) => {
|
|
85
97
|
reemplazarContenidoEnArchivo(path.join(process.cwd(), 'package.json'), 'url_del_grupo', val);
|
|
86
98
|
});
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
let BACKENDS_QUE_CONSUME_ESTE_MODULO = informacionDelModuloJson.BACKENDS_QUE_CONSUME_ESTE_MODULO;
|
|
101
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO === 'BACKENDS_QUE_CONSUME_ESTE_MODULO') {
|
|
102
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = await hacerPreguntaTrim('¿Qué backends consume este módulo? Lista separada por coma: ');
|
|
103
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO.trim().length > 0) {
|
|
104
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = BACKENDS_QUE_CONSUME_ESTE_MODULO.split(",").map((x) => "'" + x.trim() + "'").toString();
|
|
105
|
+
} else {
|
|
106
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = "";
|
|
107
|
+
}
|
|
108
|
+
informacionDelModuloJson.BACKENDS_QUE_CONSUME_ESTE_MODULO = BACKENDS_QUE_CONSUME_ESTE_MODULO;
|
|
109
|
+
} else {
|
|
110
|
+
// Already set, but needs formatting for replacement if not empty
|
|
111
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO.trim().length > 0 && !BACKENDS_QUE_CONSUME_ESTE_MODULO.startsWith("'")) {
|
|
112
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = BACKENDS_QUE_CONSUME_ESTE_MODULO.split(",").map((x) => "'" + x.trim() + "'").toString();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO.trim().length > 2) {
|
|
116
|
+
reemplazarContenidoEnArchivo(rutaDeInformacionDelModulo, 'BACKENDS_QUE_CONSUME_ESTE_MODULO', BACKENDS_QUE_CONSUME_ESTE_MODULO);
|
|
117
|
+
} else {
|
|
118
|
+
reemplazarContenidoEnArchivo(rutaDeInformacionDelModulo, 'BACKENDS_QUE_CONSUME_ESTE_MODULO', '');
|
|
95
119
|
}
|
|
96
120
|
|
|
97
|
-
await
|
|
121
|
+
await askAndReplace('VERSION', '¿Cuál es la versión del módulo?: ', rutaDeInformacionDelModulo, 'VERSION');
|
|
98
122
|
|
|
99
123
|
fs.writeFileSync(rutaDeInformacionDelModuloJson, JSON.stringify(informacionDelModuloJson, null, 2));
|
|
100
124
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"NOMBRE_DEL_PROYECTO": "NOMBRE_DEL_PROYECTO",
|
|
3
2
|
"DESCRIPCION_DEL_PROYECTO": "DESCRIPCION_DEL_PROYECTO",
|
|
4
3
|
"DETALLE_DEL_PROYECTO": "DETALLE_DEL_PROYECTO",
|
|
5
4
|
"NOMBRE_DEL_CANONICO_DEL_PROYECTO": "NOMBRE_DEL_CANONICO_DEL_PROYECTO",
|
|
6
5
|
"TIPO_DE_TARJETA": "TIPO_DE_TARJETA",
|
|
7
|
-
"NOMBRE_DEL_ROL": "NOMBRE_DEL_ROL",
|
|
8
6
|
"NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS": "NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS",
|
|
9
7
|
"NOMBRE_DEL_REPOSITORIO_DE_BACKEND": "NOMBRE_DEL_REPOSITORIO_DE_BACKEND",
|
|
10
8
|
"NOMBRE_DEL_REPOSITORIO_DE_FRONTEND": "NOMBRE_DEL_REPOSITORIO_DE_FRONTEND",
|
|
11
9
|
"NOMBRE_DEL_PERMISO": "NOMBRE_DEL_PERMISO",
|
|
12
10
|
"DESCRIPCION_DEL_PERMISO": "DESCRIPCION_DEL_PERMISO",
|
|
13
|
-
"MENU_PADRE": "MENU_PADRE",
|
|
14
|
-
"COLOR_DEL_MODULO": "COLOR_DEL_MODULO",
|
|
15
11
|
"CORREO_PARA_REPORTES": "CORREO_PARA_REPORTES",
|
|
16
12
|
"nombre_de_desarrollador": "nombre_de_desarrollador",
|
|
17
13
|
"CEDULA_DEL_DESARROLLADOR": "CEDULA_DEL_DESARROLLADOR",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const info = require('../../InformacionDelModulo.json');
|
|
2
|
+
const { ejecutarConsultaSIGU } = require('./db.js');
|
|
3
|
+
|
|
4
|
+
const CANONICO = info.NOMBRE_DEL_CANONICO_DEL_PROYECTO;
|
|
5
|
+
|
|
6
|
+
class InformacionDelModulo {
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this._descripcion = info.DESCRIPCION_DEL_PROYECTO;
|
|
10
|
+
this._detalle = info.DETALLE_DEL_PROYECTO;
|
|
11
|
+
this._tipo = info.TIPO_DE_TARJETA;
|
|
12
|
+
this._nombrePermiso = info.NOMBRE_DEL_PERMISO;
|
|
13
|
+
this._descripcionPermiso = info.DESCRIPCION_DEL_PERMISO;
|
|
14
|
+
this._menuPadre = 'DGTI';
|
|
15
|
+
this._correo = info.CORREO_PARA_REPORTES;
|
|
16
|
+
this._version = info.VERSION;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
async cargarDesdeBD() {
|
|
20
|
+
try {
|
|
21
|
+
const rows = await ejecutarConsultaSIGU(
|
|
22
|
+
'SELECT `Descripcion`, `Detalle`, `Tipo`, `Padre`, `Correo`, `Version` FROM `SIGU`.`SIGU_ModulosV2` WHERE `Nombre` = ?',
|
|
23
|
+
[CANONICO]
|
|
24
|
+
);
|
|
25
|
+
if (rows && rows.length > 0) {
|
|
26
|
+
const fila = rows[0];
|
|
27
|
+
if (fila.Descripcion != null) this._descripcion = fila.Descripcion;
|
|
28
|
+
if (fila.Detalle != null) this._detalle = fila.Detalle;
|
|
29
|
+
if (fila.Tipo != null) this._tipo = fila.Tipo;
|
|
30
|
+
if (fila.Padre != null) this._menuPadre = fila.Padre;
|
|
31
|
+
if (fila.Correo != null) this._correo = fila.Correo;
|
|
32
|
+
if (fila.Version != null) this._version = fila.Version.split('$$')[0];
|
|
33
|
+
}
|
|
34
|
+
} catch (_) { /* si hay error, se mantienen los valores del JSON */ }
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const rows = await ejecutarConsultaSIGU(
|
|
38
|
+
'SELECT `Nombre`, `Descripcion` FROM `SIGU`.`SIGU_PermisosV2` WHERE `Modulo` = ?',
|
|
39
|
+
[CANONICO]
|
|
40
|
+
);
|
|
41
|
+
if (rows && rows.length > 0) {
|
|
42
|
+
const permiso = rows[0];
|
|
43
|
+
if (permiso.Nombre != null) this._nombrePermiso = permiso.Nombre;
|
|
44
|
+
if (permiso.Descripcion != null) this._descripcionPermiso = permiso.Descripcion;
|
|
45
|
+
}
|
|
46
|
+
} catch (_) { /* si hay error, se mantienen los valores del JSON */ }
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
getDescripcionDelModulo() {
|
|
50
|
+
return this._descripcion;
|
|
51
|
+
};
|
|
52
|
+
getDetalleDelModulo() {
|
|
53
|
+
return this._detalle;
|
|
54
|
+
};
|
|
55
|
+
getNombreCanonicoDelModulo() {
|
|
56
|
+
return info.NOMBRE_DEL_CANONICO_DEL_PROYECTO;
|
|
57
|
+
};
|
|
58
|
+
getTipoDeCard() {
|
|
59
|
+
return this._tipo;
|
|
60
|
+
};
|
|
61
|
+
getNombreDelRepositorioDeLaBaseDeDatos() {
|
|
62
|
+
return info.NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS;
|
|
63
|
+
};
|
|
64
|
+
getNombreDelRepositorioDelBackend() {
|
|
65
|
+
return info.NOMBRE_DEL_REPOSITORIO_DE_BACKEND;
|
|
66
|
+
};
|
|
67
|
+
getNombreDelRepositorioDelFrontend() {
|
|
68
|
+
return info.NOMBRE_DEL_REPOSITORIO_DE_FRONTEND;
|
|
69
|
+
};
|
|
70
|
+
getNombreDelPermiso() {
|
|
71
|
+
return this._nombrePermiso;
|
|
72
|
+
};
|
|
73
|
+
getDescripcionDelPermiso() {
|
|
74
|
+
return this._descripcionPermiso;
|
|
75
|
+
};
|
|
76
|
+
getMenuPadre() {
|
|
77
|
+
return this._menuPadre;
|
|
78
|
+
};
|
|
79
|
+
getBackEndsQueConsumeEsteModulo() {
|
|
80
|
+
return info.BACKENDS_QUE_CONSUME_ESTE_MODULO;
|
|
81
|
+
};
|
|
82
|
+
getUsuariosConAccesoInicial() {
|
|
83
|
+
return ['111050570', '204540859', '602990078', '109840817', '206860639', '801680123', '111050570'];
|
|
84
|
+
};
|
|
85
|
+
getCorreoParaReportes() {
|
|
86
|
+
return this._correo;
|
|
87
|
+
};
|
|
88
|
+
getVersion() {
|
|
89
|
+
return this._version;
|
|
90
|
+
};
|
|
91
|
+
getUrlDelGrupo() {
|
|
92
|
+
return info.url_del_grupo;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = new InformacionDelModulo();
|