utn-cli 1.0.0
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 +282 -0
- package/commands/db.js +49 -0
- package/commands/frontend.js +225 -0
- package/index.js +98 -0
- package/package.json +27 -0
- package/templates/backend/InformacionDelModulo.json +21 -0
- package/templates/backend/NOMBRE_DEL_CANONICO_DEL_PROYECTO.rest +74 -0
- package/templates/backend/README.md +0 -0
- package/templates/backend/gitignore +3 -0
- package/templates/backend/index.rest +288 -0
- package/templates/backend/package.json +30 -0
- package/templates/backend/reporte.pdf +0 -0
- package/templates/backend/rutas/API.js +49 -0
- package/templates/backend/rutas/Servicio1.js +184 -0
- package/templates/backend/rutas/misc.js +671 -0
- package/templates/backend/rutas/rutas.js +11 -0
- package/templates/backend/server.js +79 -0
- package/templates/backend/servicios/API.js +101 -0
- package/templates/backend/servicios/InformacionDelModulo.js +70 -0
- package/templates/backend/servicios/Nucleo/EnvioDeCorreos.js +45 -0
- package/templates/backend/servicios/Nucleo/ManejadorDeErrores.js +54 -0
- package/templates/backend/servicios/Nucleo/Miscelaneas.js +1901 -0
- package/templates/backend/servicios/Nucleo/Monitoreo.js +65 -0
- package/templates/backend/servicios/Nucleo/db.js +78 -0
- package/templates/backend/servicios/Servicio1.js +118 -0
- package/templates/backend/variables-calidad.env +6 -0
- package/templates/backend/variables-desarrollo.env +6 -0
- package/templates/backend/variables-pruebas.env +6 -0
- package/templates/bd/README.md +78 -0
- package/templates/bd/cumulodb-scripts/gitignore +1 -0
- package/templates/bd/docker-compose.yml +28 -0
- package/templates/bd/docker-scripts/1-crear estructura.sql +29 -0
- package/templates/bd/docker-scripts/2-cambios estructura original.sql +1 -0
- package/templates/bd/docker-scripts/3-insertar datos de prueba.sql +1 -0
- package/templates/bd/docker-scripts/4-crear eventos y rutinas.sql +1 -0
- package/templates/bd/docker-scripts/5-crear vistas.sql +1 -0
- package/templates/bd/docker-scripts/6-calidad.sql +1 -0
- package/templates/bd/docker-scripts/7-pruebas.sql +1 -0
- package/templates/bd/docker-scripts/8-local.sql +1 -0
- package/templates/bd/servidores-scripts/calidad.sql +1 -0
- package/templates/bd/servidores-scripts/datos_iniciales_produccion.sql +1 -0
- package/templates/bd/servidores-scripts/produccion.sql +1 -0
- package/templates/bd/servidores-scripts/pruebas.sql +1 -0
- package/templates/frontend/.vscode/extensions.json +4 -0
- package/templates/frontend/.vscode/launch.json +20 -0
- package/templates/frontend/.vscode/tasks.json +42 -0
- package/templates/frontend/Dockerfile +5 -0
- package/templates/frontend/README.md +59 -0
- package/templates/frontend/angular.json +101 -0
- package/templates/frontend/dist/frontend/3rdpartylicenses.txt +459 -0
- package/templates/frontend/dist/frontend/prerendered-routes.json +3 -0
- package/templates/frontend/docker-compose.yml +5 -0
- package/templates/frontend/editorconfig +17 -0
- package/templates/frontend/gitignore +45 -0
- package/templates/frontend/nginx.conf +12 -0
- package/templates/frontend/package.json +46 -0
- package/templates/frontend/public/favicon.ico +0 -0
- package/templates/frontend/src/app/Componentes/Nucleo/graficos/graficos.component.css +15 -0
- package/templates/frontend/src/app/Componentes/Nucleo/graficos/graficos.component.html +25 -0
- package/templates/frontend/src/app/Componentes/Nucleo/graficos/graficos.component.ts +80 -0
- package/templates/frontend/src/app/Componentes/Nucleo/iframe/iframe.ts +37 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-confirmacion/mensaje-confirmacion.component.css +5 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-confirmacion/mensaje-confirmacion.component.html +22 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-confirmacion/mensaje-confirmacion.ts +64 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-confirmacion-html/mensaje-confirmacion-html.component.css +5 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-confirmacion-html/mensaje-confirmacion-html.component.html +22 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-confirmacion-html/mensaje-confirmacion-html.ts +64 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-informacion/mensaje-informacion.component.css +5 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-informacion/mensaje-informacion.component.html +11 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensaje-informacion/mensaje-informacion.ts +46 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensajes/mensajes.component.css +11 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensajes/mensajes.component.html +17 -0
- package/templates/frontend/src/app/Componentes/Nucleo/mensajes/mensajes.component.ts +43 -0
- package/templates/frontend/src/app/Componentes/Nucleo/reporte-de-incidencias/reporte-de-incidencias.component.css +37 -0
- package/templates/frontend/src/app/Componentes/Nucleo/reporte-de-incidencias/reporte-de-incidencias.component.html +35 -0
- package/templates/frontend/src/app/Componentes/Nucleo/reporte-de-incidencias/reporte-de-incidencias.component.ts +103 -0
- package/templates/frontend/src/app/Componentes/Nucleo/subir-archivo/subir-archivo.component.css +90 -0
- package/templates/frontend/src/app/Componentes/Nucleo/subir-archivo/subir-archivo.component.html +39 -0
- package/templates/frontend/src/app/Componentes/Nucleo/subir-archivo/subir-archivo.component.ts +132 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tabla/paginador-personalizado.ts +17 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tabla/tabla.component.css +332 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tabla/tabla.component.html +166 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tabla/tabla.component.ts +228 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta/tarjeta.component.css +129 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta/tarjeta.component.html +35 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta/tarjeta.component.ts +46 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-modulo/tarjeta-modulo.component.css +92 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-modulo/tarjeta-modulo.component.html +17 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-modulo/tarjeta-modulo.component.ts +42 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-multiple/tarjeta-multiple.component.css +90 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-multiple/tarjeta-multiple.component.html +22 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-multiple/tarjeta-multiple.component.ts +46 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-reporte/tarjeta-reporte.component.css +129 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-reporte/tarjeta-reporte.component.html +20 -0
- package/templates/frontend/src/app/Componentes/Nucleo/tarjeta-reporte/tarjeta-reporte.component.ts +25 -0
- package/templates/frontend/src/app/Componentes/guardar-incapacidad/guardar-incapacidad.component.css +20 -0
- package/templates/frontend/src/app/Componentes/guardar-incapacidad/guardar-incapacidad.component.html +46 -0
- package/templates/frontend/src/app/Componentes/guardar-incapacidad/guardar-incapacidad.component.ts +64 -0
- package/templates/frontend/src/app/Paginas/Nucleo/contenedor-componentes/contenedor-componentes.component.css +142 -0
- package/templates/frontend/src/app/Paginas/Nucleo/contenedor-componentes/contenedor-componentes.component.html +90 -0
- package/templates/frontend/src/app/Paginas/Nucleo/contenedor-componentes/contenedor-componentes.component.ts +139 -0
- package/templates/frontend/src/app/Paginas/contenedor-principal/contenedor-principal.component.css +4 -0
- package/templates/frontend/src/app/Paginas/contenedor-principal/contenedor-principal.component.html +17 -0
- package/templates/frontend/src/app/Paginas/contenedor-principal/contenedor-principal.component.ts +36 -0
- package/templates/frontend/src/app/Paginas/gestion-de-reportes/gestion-de-reportes.component.css +4 -0
- package/templates/frontend/src/app/Paginas/gestion-de-reportes/gestion-de-reportes.component.html +6 -0
- package/templates/frontend/src/app/Paginas/gestion-de-reportes/gestion-de-reportes.component.ts +36 -0
- package/templates/frontend/src/app/Paginas/gestion-graficos/gestion-graficos.component.css +13 -0
- package/templates/frontend/src/app/Paginas/gestion-graficos/gestion-graficos.component.html +13 -0
- package/templates/frontend/src/app/Paginas/gestion-graficos/gestion-graficos.component.ts +75 -0
- package/templates/frontend/src/app/Paginas/gestion-iframe1/gestion-iframe1.component.css +13 -0
- package/templates/frontend/src/app/Paginas/gestion-iframe1/gestion-iframe1.component.html +3 -0
- package/templates/frontend/src/app/Paginas/gestion-iframe1/gestion-iframe1.component.ts +14 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla/gestion-tabla.component.css +13 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla/gestion-tabla.component.html +24 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla/gestion-tabla.component.ts +300 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla-XYZ/gestion-tabla-XYZ.component.css +13 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla-XYZ/gestion-tabla-XYZ.component.html +43 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla-XYZ/gestion-tabla-XYZ.component.ts +305 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla-jefe/gestion-tabla-jefe.component.css +13 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla-jefe/gestion-tabla-jefe.component.html +25 -0
- package/templates/frontend/src/app/Paginas/gestion-tabla-jefe/gestion-tabla-jefe.component.ts +245 -0
- package/templates/frontend/src/app/analytics.module.ts +45 -0
- package/templates/frontend/src/app/app.component.css +0 -0
- package/templates/frontend/src/app/app.component.html +1 -0
- package/templates/frontend/src/app/app.component.ts +10 -0
- package/templates/frontend/src/app/app.config.server.ts +14 -0
- package/templates/frontend/src/app/app.config.ts +27 -0
- package/templates/frontend/src/app/app.routes.ts +16 -0
- package/templates/frontend/src/app/auth.interceptor.ts +26 -0
- package/templates/frontend/src/app/datos-globales.service.ts +45 -0
- package/templates/frontend/src/assets/Puntos.svg +94 -0
- package/templates/frontend/src/index.html +36 -0
- package/templates/frontend/src/main.server.ts +7 -0
- package/templates/frontend/src/main.ts +6 -0
- package/templates/frontend/src/styles.css +14 -0
- package/templates/frontend/tsconfig.app.json +15 -0
- package/templates/frontend/tsconfig.json +27 -0
- package/templates/frontend/tsconfig.spec.json +15 -0
- package/utils/index.js +105 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { limpiarDirectorioActual, copiarDirectorios, hacerPreguntaTrim, reemplazarContenidoEnArchivo, closeReadLine, mostrarVersion } from '../utils/index.js';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs'; // Need fs here for renameSync
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
|
|
8
|
+
async function inicializarProyectoBackend() {
|
|
9
|
+
const rutaDelModuloJson = path.join(__dirname, '../../package.json'); // Main CLI's package.json
|
|
10
|
+
const informacionDeRutaDelModuloJson = JSON.parse(fs.readFileSync(rutaDelModuloJson, 'utf-8'));
|
|
11
|
+
console.log(`Versión de utn-backend (a través de utn-cli): ${informacionDeRutaDelModuloJson.version}.`);
|
|
12
|
+
|
|
13
|
+
const rutaDeMiscelaneas = path.join(process.cwd(), 'servicios/Nucleo/Miscelaneas.js');
|
|
14
|
+
reemplazarContenidoEnArchivo(rutaDeMiscelaneas, 'VERSION_DEL_NUCLEO', informacionDeRutaDelModuloJson.version);
|
|
15
|
+
|
|
16
|
+
const rutaDeInformacionDelModuloJson = path.join(process.cwd(), 'InformacionDelModulo.json');
|
|
17
|
+
// Check if InformacionDelModulo.json exists, if not, it's an init scenario.
|
|
18
|
+
if (!fs.existsSync(rutaDeInformacionDelModuloJson)) {
|
|
19
|
+
console.error('InformacionDelModulo.json not found. This should be present after copying templates.');
|
|
20
|
+
closeReadLine();
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
let informacionDelModuloJson = JSON.parse(fs.readFileSync(rutaDeInformacionDelModuloJson, 'utf-8'));
|
|
24
|
+
const rutaDeInformacionDelModulo = path.join(process.cwd(), 'servicios/InformacionDelModulo.js');
|
|
25
|
+
|
|
26
|
+
// Helper to ask and replace
|
|
27
|
+
async function askAndReplace(prop, promptText, fileToReplace, placeholder, specialHandler = null) {
|
|
28
|
+
let value = informacionDelModuloJson[prop];
|
|
29
|
+
if (value === placeholder) {
|
|
30
|
+
value = await hacerPreguntaTrim(promptText);
|
|
31
|
+
informacionDelModuloJson[prop] = value;
|
|
32
|
+
}
|
|
33
|
+
if (specialHandler) {
|
|
34
|
+
specialHandler(value);
|
|
35
|
+
}
|
|
36
|
+
reemplazarContenidoEnArchivo(fileToReplace, placeholder, value);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NOMBRE_DEL_PROYECTO = await askAndReplace('NOMBRE_DEL_PROYECTO', '¿Cuál es el nombre del proyecto?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_PROYECTO');
|
|
41
|
+
await askAndReplace('DESCRIPCION_DEL_PROYECTO', '¿Cuál es la descripción del proyecto?: ', rutaDeInformacionDelModulo, 'DESCRIPCION_DEL_PROYECTO');
|
|
42
|
+
await askAndReplace('DETALLE_DEL_PROYECTO', '¿Cuál es detalle del proyecto?: ', rutaDeInformacionDelModulo, 'DETALLE_DEL_PROYECTO');
|
|
43
|
+
|
|
44
|
+
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) => {
|
|
45
|
+
const oldFileName = path.join(process.cwd(), 'NOMBRE_DEL_CANONICO_DEL_PROYECTO.rest');
|
|
46
|
+
const newFileName = path.join(process.cwd(), `${val}.rest`);
|
|
47
|
+
if (fs.existsSync(oldFileName)) {
|
|
48
|
+
fs.renameSync(oldFileName, newFileName);
|
|
49
|
+
} else if (!fs.existsSync(newFileName)) {
|
|
50
|
+
// 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.
|
|
51
|
+
// Or a fresh init where the file might not be present always. Log for now.
|
|
52
|
+
console.log(`Warning: ${oldFileName} not found during canonical project name rename.`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
await askAndReplace('TIPO_DE_TARJETA', '¿Cuál es tipo de tarjeta? Posibles valores: Área, Proceso, Servicio: ', rutaDeInformacionDelModulo, 'TIPO_DE_TARJETA');
|
|
57
|
+
await askAndReplace('NOMBRE_DEL_ROL', '¿Cuál es el nombre del rol?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_ROL');
|
|
58
|
+
|
|
59
|
+
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) => {
|
|
60
|
+
const rutaDeVariablesDeCalidad = path.join(process.cwd(), 'variables-calidad.env');
|
|
61
|
+
reemplazarContenidoEnArchivo(rutaDeVariablesDeCalidad, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val);
|
|
62
|
+
const rutaDeVariablesDeDesarrollo = path.join(process.cwd(), 'variables-desarrollo.env');
|
|
63
|
+
reemplazarContenidoEnArchivo(rutaDeVariablesDeDesarrollo, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val);
|
|
64
|
+
const rutaDeVariablesDePruebas = path.join(process.cwd(), 'variables-pruebas.env');
|
|
65
|
+
reemplazarContenidoEnArchivo(rutaDeVariablesDePruebas, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val);
|
|
66
|
+
const rutaDeDB = path.join(process.cwd(), 'servicios/Nucleo/db.js');
|
|
67
|
+
reemplazarContenidoEnArchivo(rutaDeDB, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', val.slice(0, -3));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
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) => {
|
|
71
|
+
const rutaPackage = path.join(process.cwd(), 'package.json');
|
|
72
|
+
reemplazarContenidoEnArchivo(rutaPackage, 'nombre_del_repositorio_backend', val);
|
|
73
|
+
const rutaDeserver = path.join(process.cwd(), 'server.js');
|
|
74
|
+
reemplazarContenidoEnArchivo(rutaDeserver, 'NOMBRE_DEL_REPOSITORIO_DE_BACKEND', `${val} corriendo en el puerto 80.`);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await askAndReplace('NOMBRE_DEL_REPOSITORIO_DE_FRONTEND', '¿Cuál es el nombre del repositorio de frontend?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_REPOSITORIO_DE_FRONTEND');
|
|
78
|
+
await askAndReplace('NOMBRE_DEL_PERMISO', '¿Cuál es el nombre del permiso?: ', rutaDeInformacionDelModulo, 'NOMBRE_DEL_PERMISO');
|
|
79
|
+
await askAndReplace('DESCRIPCION_DEL_PERMISO', '¿Cuál es la descripción del permiso?: ', rutaDeInformacionDelModulo, 'DESCRIPCION_DEL_PERMISO');
|
|
80
|
+
await askAndReplace('MENU_PADRE', '¿Cuál es nombre canónico del menú padre?: ', rutaDeInformacionDelModulo, 'MENU_PADRE');
|
|
81
|
+
await askAndReplace('COLOR_DEL_MODULO', '¿Cuál es el color del módulo?: ', rutaDeInformacionDelModulo, 'COLOR_DEL_MODULO');
|
|
82
|
+
await askAndReplace('CORRECO_PARA_REPORTES', '¿Cuál es correo para reportes?: ', rutaDeInformacionDelModulo, 'CORRECO_PARA_REPORTES');
|
|
83
|
+
|
|
84
|
+
const nombre_de_desarrollador = await askAndReplace('nombre_de_desarrollador', '¿Cuál es el nombre de desarrollador?: ', path.join(process.cwd(), 'package.json'), 'nombre_de_desarrollador', (val) => {
|
|
85
|
+
reemplazarContenidoEnArchivo(path.join(process.cwd(), 'package.json'), 'nombre_de_desarrollador', `Para la Universidad Técnica Nacional por: ${val}`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await askAndReplace('CEDULA_DEL_DESARROLLADOR', '¿Cuál es el número de cédula del desarrollador?: ', rutaDeInformacionDelModulo, 'CEDULA_DEL_DESARROLLADOR');
|
|
89
|
+
|
|
90
|
+
const url_del_grupo = await askAndReplace('url_del_grupo', '¿Cuál es el URL del grupo en el git?: ', path.join(process.cwd(), 'package.json'), 'url_del_grupo', (val) => {
|
|
91
|
+
reemplazarContenidoEnArchivo(path.join(process.cwd(), 'package.json'), 'url_del_grupo', val);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
let BACKENDS_QUE_CONSUME_ESTE_MODULO = informacionDelModuloJson.BACKENDS_QUE_CONSUME_ESTE_MODULO;
|
|
95
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO === 'BACKENDS_QUE_CONSUME_ESTE_MODULO') {
|
|
96
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = await hacerPreguntaTrim('¿Qué backends consume este módulo? Lista separada por coma: ');
|
|
97
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO.trim().length > 0) {
|
|
98
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = BACKENDS_QUE_CONSUME_ESTE_MODULO.split(",").map((x) => "'" + x.trim() + "'").toString();
|
|
99
|
+
} else {
|
|
100
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = "";
|
|
101
|
+
}
|
|
102
|
+
informacionDelModuloJson.BACKENDS_QUE_CONSUME_ESTE_MODULO = BACKENDS_QUE_CONSUME_ESTE_MODULO;
|
|
103
|
+
} else {
|
|
104
|
+
// Already set, but needs formatting for replacement if not empty
|
|
105
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO.trim().length > 0 && !BACKENDS_QUE_CONSUME_ESTE_MODULO.startsWith("'")) {
|
|
106
|
+
BACKENDS_QUE_CONSUME_ESTE_MODULO = BACKENDS_QUE_CONSUME_ESTE_MODULO.split(",").map((x) => "'" + x.trim() + "'").toString();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (BACKENDS_QUE_CONSUME_ESTE_MODULO.trim().length > 2) {
|
|
110
|
+
reemplazarContenidoEnArchivo(rutaDeInformacionDelModulo, 'BACKENDS_QUE_CONSUME_ESTE_MODULO', BACKENDS_QUE_CONSUME_ESTE_MODULO);
|
|
111
|
+
} else {
|
|
112
|
+
reemplazarContenidoEnArchivo(rutaDeInformacionDelModulo, 'BACKENDS_QUE_CONSUME_ESTE_MODULO', '');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await askAndReplace('VERSION', '¿Cuál es versión del módulo?: ', rutaDeInformacionDelModulo, 'VERSION');
|
|
116
|
+
|
|
117
|
+
fs.writeFileSync(rutaDeInformacionDelModuloJson, JSON.stringify(informacionDelModuloJson, null, 2));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function initBackend() {
|
|
121
|
+
console.log('Limpiando directorio actual...');
|
|
122
|
+
limpiarDirectorioActual(['commit-message.txt']);
|
|
123
|
+
console.log('Inicializando el proyecto de backend...');
|
|
124
|
+
|
|
125
|
+
const directoriodePlantillas = path.join(__dirname, '../../templates/backend');
|
|
126
|
+
const directorioDestino = process.cwd();
|
|
127
|
+
|
|
128
|
+
if (!fs.existsSync(directoriodePlantillas)) {
|
|
129
|
+
console.error(`La carpeta de plantillas de Backend no existe en: ${directoriodePlantillas}`);
|
|
130
|
+
closeReadLine();
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
copiarDirectorios(directoriodePlantillas, directorioDestino);
|
|
135
|
+
|
|
136
|
+
// Specific renames for Backend
|
|
137
|
+
const gitignorePath = path.join(directorioDestino, 'gitignore');
|
|
138
|
+
if (fs.existsSync(gitignorePath)) {
|
|
139
|
+
fs.renameSync(gitignorePath, path.join(directorioDestino, '.gitignore'));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
await inicializarProyectoBackend();
|
|
143
|
+
console.log('Proyecto de backend inicializado exitosamente.');
|
|
144
|
+
closeReadLine();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function updateBackend() {
|
|
148
|
+
console.log('Actualizando el proyecto de backend...');
|
|
149
|
+
const archivosAExcluir = ['InformacionDelModulo.json', 'rutas.js', 'Monitoreo.js', 'API.js'];
|
|
150
|
+
const directoriodePlantillas = path.join(__dirname, '../../templates/backend');
|
|
151
|
+
const directorioDestino = process.cwd();
|
|
152
|
+
|
|
153
|
+
if (!fs.existsSync(directoriodePlantillas)) {
|
|
154
|
+
console.error(`La carpeta de plantillas de Backend no existe en: ${directoriodePlantillas}`);
|
|
155
|
+
closeReadLine();
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
copiarDirectorios(directoriodePlantillas, directorioDestino, archivosAExcluir);
|
|
160
|
+
mostrarVersion(path.join(__dirname, '../../package.json')); // Show main CLI version
|
|
161
|
+
console.log('Proyecto de backend actualizado exitosamente.');
|
|
162
|
+
closeReadLine();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function addServiceBackend() {
|
|
166
|
+
let Servicio = await hacerPreguntaTrim('¿Cuál es el nombre del servicio?: ');
|
|
167
|
+
Servicio = Servicio.replace(/\s/g, '');
|
|
168
|
+
const rutaServicioDir = path.join(process.cwd(), 'servicios');
|
|
169
|
+
const rutaRutaDir = path.join(process.cwd(), 'rutas');
|
|
170
|
+
|
|
171
|
+
// Copy template service files
|
|
172
|
+
const templateServicioPath = path.join(rutaServicioDir, 'Servicio1.js');
|
|
173
|
+
const newServicioPath = path.join(rutaServicioDir, Servicio + '.js');
|
|
174
|
+
if (fs.existsSync(templateServicioPath)) { // Ensure template exists
|
|
175
|
+
fs.copyFileSync(templateServicioPath, newServicioPath);
|
|
176
|
+
} else {
|
|
177
|
+
console.error(`Error: Template Servicio1.js not found in ${rutaServicioDir}`);
|
|
178
|
+
closeReadLine();
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const templateRutaPath = path.join(rutaRutaDir, 'Servicio1.js');
|
|
183
|
+
const newRutaPath = path.join(rutaRutaDir, Servicio + '.js');
|
|
184
|
+
if (fs.existsSync(templateRutaPath)) { // Ensure template exists
|
|
185
|
+
fs.copyFileSync(templateRutaPath, newRutaPath);
|
|
186
|
+
} else {
|
|
187
|
+
console.error(`Error: Template Servicio1.js not found in ${rutaRutaDir}`);
|
|
188
|
+
closeReadLine();
|
|
189
|
+
process.exit(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Update rutas.js
|
|
193
|
+
const rutaRutasJs = path.join(rutaRutaDir, 'rutas.js');
|
|
194
|
+
if (fs.existsSync(rutaRutasJs)) {
|
|
195
|
+
let contenidoRutasJs = fs.readFileSync(rutaRutasJs, 'utf-8');
|
|
196
|
+
const nuevaRutaRequire = `const rutasDel${Servicio} = require('./${Servicio}.js');`;
|
|
197
|
+
contenidoRutasJs = contenidoRutasJs.replace(/\s*function asignarRutasAExpress\(app\) {/, `
|
|
198
|
+
${nuevaRutaRequire}
|
|
199
|
+
|
|
200
|
+
function asignarRutasAExpress(app) {`);
|
|
201
|
+
contenidoRutasJs = contenidoRutasJs.replace(/app\.use\('\/Servicio1', rutasDelServicio1\);/, `app.use('/Servicio1', rutasDelServicio1);
|
|
202
|
+
app.use('/${Servicio}', rutasDel${Servicio});`);
|
|
203
|
+
fs.writeFileSync(rutaRutasJs, contenidoRutasJs);
|
|
204
|
+
} else {
|
|
205
|
+
console.error(`Error: rutas.js not found in ${rutaRutaDir}`);
|
|
206
|
+
closeReadLine();
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
reemplazarContenidoEnArchivo(newServicioPath, 'Servicio1', Servicio);
|
|
211
|
+
reemplazarContenidoEnArchivo(newRutaPath, 'Servicio1', Servicio);
|
|
212
|
+
|
|
213
|
+
// Cross-module interaction with Frontend - this needs a different approach in a unified CLI
|
|
214
|
+
// For now, I'll comment out the frontend-related logic as it breaks modularity and
|
|
215
|
+
// assumes frontend project structure relative to backend, which might not be true in a monorepo.
|
|
216
|
+
// This should be handled by a dedicated 'utn frontend add-service' command or similar.
|
|
217
|
+
/*
|
|
218
|
+
const rutaArchivoJson = path.join(process.cwd(), 'InformacionDelModulo.json');
|
|
219
|
+
const contenidoJson = fs.readFileSync(rutaArchivoJson, 'utf8');
|
|
220
|
+
const informacion = JSON.parse(contenidoJson);
|
|
221
|
+
const nombreDelFrontend = informacion.NOMBRE_DEL_REPOSITORIO_DE_FRONTEND;
|
|
222
|
+
const rutaDelFrontEnd = path.join(process.cwd(), '..', nombreDelFrontend, '/src/app/Paginas'); // This path is problematic
|
|
223
|
+
const servicioEnMinuscula = Servicio.toLowerCase();
|
|
224
|
+
const rutaOrigen = path.join(rutaDelFrontEnd, '/gestion-tabla');
|
|
225
|
+
const nombreCarpetaDestino = `/gestion-tabla-${servicioEnMinuscula}`;
|
|
226
|
+
const rutaDestino = path.join(rutaDelFrontEnd, nombreCarpetaDestino);
|
|
227
|
+
try {
|
|
228
|
+
fs.cpSync(rutaOrigen, rutaDestino, { recursive: true });
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error('Hubo un error al copiar la carpeta:', error);
|
|
231
|
+
}
|
|
232
|
+
const archivos = fs.readdirSync(rutaDestino);
|
|
233
|
+
archivos.forEach(archivo => {
|
|
234
|
+
if (archivo.startsWith('gestion-tabla.component')) {
|
|
235
|
+
const nuevoNombre = archivo.replace('gestion-tabla', `gestion-tabla-${servicioEnMinuscula}`);
|
|
236
|
+
const rutaArchivoViejo = path.join(rutaDestino, archivo);
|
|
237
|
+
const rutaArchivoNuevo = path.join(rutaDestino, nuevoNombre);
|
|
238
|
+
fs.renameSync(rutaArchivoViejo, rutaArchivoNuevo);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const rutaArchivoTs = path.join(rutaDestino, `/gestion-tabla-${servicioEnMinuscula}.component.ts`);
|
|
242
|
+
let contenidoTs = fs.readFileSync(rutaArchivoTs, 'utf8');
|
|
243
|
+
contenidoTs = contenidoTs.replace(
|
|
244
|
+
/gestion-tabla\.component/g,
|
|
245
|
+
`gestion-tabla-${servicioEnMinuscula}.component`
|
|
246
|
+
);
|
|
247
|
+
const servicioCapitalizado = Servicio.charAt(0).toUpperCase() + Servicio.slice(1);
|
|
248
|
+
contenidoTs = contenidoTs.replace(
|
|
249
|
+
/export class GestionTablaComponent/,
|
|
250
|
+
`export class GestionTabla${servicioCapitalizado}Component`
|
|
251
|
+
);
|
|
252
|
+
fs.writeFileSync(rutaArchivoTs, contenidoTs, 'utf8');
|
|
253
|
+
const rutaAppRoutes = path.join(rutaDelFrontEnd, '../app.routes.ts');
|
|
254
|
+
const nombreComponente = `GestionTabla${servicioCapitalizado}Component`;
|
|
255
|
+
const rutaComponente = `./Paginas/gestion-tabla-${servicioEnMinuscula}/gestion-tabla-${servicioEnMinuscula}.component`;
|
|
256
|
+
const nuevaLineaImport = `import { ${nombreComponente} } from '${rutaComponente}';`;
|
|
257
|
+
const nuevaLineaRuta = `,
|
|
258
|
+
{ path: '${servicioEnMinuscula}', component: ${nombreComponente} }`;
|
|
259
|
+
let contenidoRoutes = fs.readFileSync(rutaAppRoutes, 'utf8');
|
|
260
|
+
contenidoRoutes = contenidoRoutes.replace(
|
|
261
|
+
/\s*export const routes: Routes = \[/,
|
|
262
|
+
`
|
|
263
|
+
${nuevaLineaImport}
|
|
264
|
+
|
|
265
|
+
export const routes: Routes = [`
|
|
266
|
+
);
|
|
267
|
+
contenidoRoutes = contenidoRoutes.replace(
|
|
268
|
+
/\s*];/,
|
|
269
|
+
`${nuevaLineaRuta}
|
|
270
|
+
];`
|
|
271
|
+
);
|
|
272
|
+
fs.writeFileSync(rutaAppRoutes, contenidoRoutes, 'utf8');
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
console.log(`Servicio ${Servicio} agregado exitosamente.`);
|
|
276
|
+
closeReadLine();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function showBackendVersion() {
|
|
280
|
+
mostrarVersion(path.join(__dirname, '../../package.json'));
|
|
281
|
+
closeReadLine();
|
|
282
|
+
}
|
package/commands/db.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { limpiarDirectorioActual, copiarDirectorios, hacerPregunta, reemplazarContenidoEnArchivo, closeReadLine, mostrarVersion } from '../utils/index.js';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs'; // Import fs here
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
|
|
8
|
+
export async function initDb() {
|
|
9
|
+
console.log('Limpiando directorio actual...');
|
|
10
|
+
limpiarDirectorioActual(['commit-message.txt']); // Assuming this is still relevant for DB
|
|
11
|
+
console.log('Inicializando el proyecto de base de datos...');
|
|
12
|
+
|
|
13
|
+
const directoriodePlantillas = path.join(__dirname, '../../templates/bd');
|
|
14
|
+
const directorioDestino = process.cwd();
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(directoriodePlantillas)) {
|
|
17
|
+
console.error(`La carpeta de plantillas de DB no existe en: ${directoriodePlantillas}`);
|
|
18
|
+
closeReadLine();
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
copiarDirectorios(directoriodePlantillas, directorioDestino);
|
|
23
|
+
|
|
24
|
+
// Specific renames for DB
|
|
25
|
+
// This needs to be handled carefully, as original was 'cumulodb-scripts/gitignore' to 'cumulodb-scripts/.gitignore'
|
|
26
|
+
// and now templates are nested.
|
|
27
|
+
// For now, assume these renames are hardcoded for the template structure.
|
|
28
|
+
const gitignorePath = path.join(directorioDestino, 'cumulodb-scripts/gitignore');
|
|
29
|
+
if (fs.existsSync(gitignorePath)) {
|
|
30
|
+
fs.renameSync(gitignorePath, path.join(directorioDestino, 'cumulodb-scripts/.gitignore'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Initializing project (asking for repo name and replacing)
|
|
34
|
+
const rutaCompose = path.join(process.cwd(), 'docker-compose.yml');
|
|
35
|
+
const rutaCrearEstructuras = path.join(process.cwd(), 'docker-scripts/1-crear estructura.sql');
|
|
36
|
+
|
|
37
|
+
const repositorioDeBaseDeDatos = await hacerPregunta('¿Cuál es el nombre del repositorio de base de datos?: ');
|
|
38
|
+
reemplazarContenidoEnArchivo(rutaCompose, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', repositorioDeBaseDeDatos);
|
|
39
|
+
reemplazarContenidoEnArchivo(rutaCrearEstructuras, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', repositorioDeBaseDeDatos.slice(0, -3)); // Assuming .slice(0,-3) is to remove 'DB' or similar suffix
|
|
40
|
+
|
|
41
|
+
console.log('Proyecto de base de datos inicializado exitosamente.');
|
|
42
|
+
closeReadLine();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function showDbVersion() {
|
|
46
|
+
// Assuming the version for 'db' command comes from the main utn-cli package.json
|
|
47
|
+
mostrarVersion(path.join(__dirname, '../../package.json'));
|
|
48
|
+
closeReadLine();
|
|
49
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { limpiarDirectorioActual, copiarDirectorios, hacerPreguntaTrim, reemplazarContenidoEnArchivo, closeReadLine, mostrarVersion } from '../utils/index.js';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
export async function initFrontend() {
|
|
10
|
+
console.log('Limpiando directorio actual...');
|
|
11
|
+
limpiarDirectorioActual(['commit-message.txt']);
|
|
12
|
+
console.log('Inicializando el proyecto de frontend...');
|
|
13
|
+
|
|
14
|
+
const directoriodePlantillas = path.join(__dirname, '../../templates/frontend');
|
|
15
|
+
const directorioDestino = process.cwd();
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(directoriodePlantillas)) {
|
|
18
|
+
console.error(`La carpeta de plantillas de Frontend no existe en: ${directoriodePlantillas}`);
|
|
19
|
+
closeReadLine();
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
copiarDirectorios(directoriodePlantillas, directorioDestino);
|
|
24
|
+
|
|
25
|
+
// Specific renames for Frontend
|
|
26
|
+
const gitignorePath = path.join(directorioDestino, 'gitignore');
|
|
27
|
+
if (fs.existsSync(gitignorePath)) {
|
|
28
|
+
fs.renameSync(gitignorePath, path.join(directorioDestino, '.gitignore'));
|
|
29
|
+
}
|
|
30
|
+
const editorconfigPath = path.join(directorioDestino, 'editorconfig');
|
|
31
|
+
if (fs.existsSync(editorconfigPath)) {
|
|
32
|
+
fs.renameSync(editorconfigPath, path.join(directorioDestino, '.editorconfig'));
|
|
33
|
+
}
|
|
34
|
+
const vscodePath = path.join(directorioDestino, 'vscode');
|
|
35
|
+
if (fs.existsSync(vscodePath)) {
|
|
36
|
+
fs.renameSync(vscodePath, path.join(directorioDestino, '.vscode'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log('Proyecto de frontend inicializado exitosamente.');
|
|
40
|
+
closeReadLine();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function updateFrontend() {
|
|
44
|
+
console.log('Actualizando el proyecto de frontend...');
|
|
45
|
+
const archivosAExcluir = ['app.routes.ts', 'contenedor-principal.component.css', 'contenedor-principal.component.html', 'contenedor-principal.component.ts', '.vscode', 'dist'];
|
|
46
|
+
const directoriodePlantillas = path.join(__dirname, '../../templates/frontend');
|
|
47
|
+
const directorioDestino = process.cwd();
|
|
48
|
+
|
|
49
|
+
if (!fs.existsSync(directoriodePlantillas)) {
|
|
50
|
+
console.error(`La carpeta de plantillas de Frontend no existe en: ${directoriodePlantillas}`);
|
|
51
|
+
closeReadLine();
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
copiarDirectorios(directoriodePlantillas, directorioDestino, archivosAExcluir);
|
|
56
|
+
mostrarVersion(path.join(__dirname, '../../package.json'));
|
|
57
|
+
console.log('Proyecto de frontend actualizado exitosamente.');
|
|
58
|
+
closeReadLine();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function confirmarPaso(pregunta) {
|
|
62
|
+
const respuesta = await hacerPreguntaTrim(`${pregunta} (Sí/no) [Sí]: `);
|
|
63
|
+
const respuestaNormalizada = respuesta.trim().toLowerCase();
|
|
64
|
+
if (respuesta === '' || respuestaNormalizada === 'si' || respuestaNormalizada === 'sí' || respuestaNormalizada === 's') {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function commitFrontend() {
|
|
71
|
+
// Original commit logic, wrapped
|
|
72
|
+
if (!await confirmarPaso('¿Ya realizó la revisión ortográfica del proyecto?')) return closeReadLine();
|
|
73
|
+
if (!await confirmarPaso('¿Ya realizó el registro de los servicios?')) return closeReadLine();
|
|
74
|
+
if (!await confirmarPaso('¿Ya realizó la revisión con Gemini?')) return closeReadLine();
|
|
75
|
+
if (!await confirmarPaso('¿Todos los endpoints están en el archivo rest?')) return closeReadLine();
|
|
76
|
+
if (!await confirmarPaso('¿Ya realizó el build del frontend?')) return closeReadLine();
|
|
77
|
+
if (!await confirmarPaso('¿Ya realizó el update de los módulos de UTN?')) return closeReadLine();
|
|
78
|
+
if (!await confirmarPaso('¿Ya revisó la visualización en móvil?')) return closeReadLine();
|
|
79
|
+
if (!await confirmarPaso('¿Ya hizo el stage de todos los cambios?')) return closeReadLine();
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
console.log('Ejecutando git commit...');
|
|
83
|
+
execSync('git commit -m "* NEW: Respaldo de código"', { stdio: 'inherit' });
|
|
84
|
+
|
|
85
|
+
console.log('Ejecutando git pull --rebase...');
|
|
86
|
+
execSync('git pull --rebase', { stdio: 'inherit' });
|
|
87
|
+
|
|
88
|
+
console.log('Ejecutando git push...');
|
|
89
|
+
execSync('git push', { stdio: 'inherit' });
|
|
90
|
+
|
|
91
|
+
console.log('Proceso de commit finalizado con éxito.');
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Ocurrió un error al ejecutar los comandos de git.', error.message);
|
|
94
|
+
} finally {
|
|
95
|
+
closeReadLine();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function cloneFrontendComponent() {
|
|
100
|
+
const nombre = await hacerPreguntaTrim('Ingrese el nombre del nuevo componente (se reemplazará XYZ): ');
|
|
101
|
+
if (!nombre) {
|
|
102
|
+
console.error('El nombre es requerido.');
|
|
103
|
+
closeReadLine();
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const titulo = await hacerPreguntaTrim('Ingrese el título para la tarjeta: ');
|
|
108
|
+
const descripcion = await hacerPreguntaTrim('Ingrese la descripción para la tarjeta: ');
|
|
109
|
+
|
|
110
|
+
const nombreLower = nombre.toLowerCase();
|
|
111
|
+
const nombreCapitalizado = nombre.charAt(0).toUpperCase() + nombre.slice(1);
|
|
112
|
+
const nombreClase = `GestionTabla${nombreCapitalizado}Component`;
|
|
113
|
+
const nombreRuta = `gestion-tabla-${nombreLower}`;
|
|
114
|
+
|
|
115
|
+
const rutaFuente = path.join(__dirname, '../../templates/frontend', 'src', 'app', 'Paginas', 'gestion-tabla-XYZ');
|
|
116
|
+
const rutaDestino = path.join(process.cwd(), 'src', 'app', 'Paginas', nombreRuta);
|
|
117
|
+
|
|
118
|
+
if (!fs.existsSync(rutaFuente)) {
|
|
119
|
+
console.error(`No se encontró la carpeta plantilla en: ${rutaFuente}`);
|
|
120
|
+
closeReadLine();
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(rutaDestino)) {
|
|
125
|
+
console.error(`La carpeta destino ya existe: ${rutaDestino}`);
|
|
126
|
+
closeReadLine();
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
console.log(`Clonando carpeta...`);
|
|
131
|
+
|
|
132
|
+
function copiarYReemplazar(fuente, destino) {
|
|
133
|
+
if (!fs.existsSync(destino)) {
|
|
134
|
+
fs.mkdirSync(destino, { recursive: true });
|
|
135
|
+
}
|
|
136
|
+
const entradas = fs.readdirSync(fuente, { withFileTypes: true });
|
|
137
|
+
entradas.forEach((entrada) => {
|
|
138
|
+
const nombreOriginal = entrada.name;
|
|
139
|
+
const nombreNuevo = nombreOriginal.replace(/XYZ/g, nombreLower);
|
|
140
|
+
const rutaFuente = path.join(fuente, nombreOriginal);
|
|
141
|
+
const rutaDestino = path.join(destino, nombreNuevo);
|
|
142
|
+
|
|
143
|
+
if (entrada.isDirectory()) {
|
|
144
|
+
copiarYReemplazar(rutaFuente, rutaDestino);
|
|
145
|
+
} else if (entrada.isFile()) {
|
|
146
|
+
let contenido = fs.readFileSync(rutaFuente, 'utf-8');
|
|
147
|
+
contenido = contenido.replace(/GestionTablaXYZComponent/g, nombreClase);
|
|
148
|
+
contenido = contenido.replace(/XYZ/g, nombreLower);
|
|
149
|
+
fs.writeFileSync(rutaDestino, contenido);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
copiarYReemplazar(rutaFuente, rutaDestino);
|
|
155
|
+
console.log(`Componente creado en: ${rutaDestino}`);
|
|
156
|
+
|
|
157
|
+
// --- Modificar app.routes.ts ---
|
|
158
|
+
console.log('Actualizando app.routes.ts...');
|
|
159
|
+
const rutaRoutes = path.join(process.cwd(), 'src', 'app', 'app.routes.ts');
|
|
160
|
+
if (fs.existsSync(rutaRoutes)) {
|
|
161
|
+
let contenidoRoutes = fs.readFileSync(rutaRoutes, 'utf-8');
|
|
162
|
+
|
|
163
|
+
const lineaImport = `import { ${nombreClase} } from './Paginas/${nombreRuta}/${nombreRuta}.component';`;
|
|
164
|
+
const ultimoImportIndex = contenidoRoutes.lastIndexOf('import {');
|
|
165
|
+
const finUltimoImport = contenidoRoutes.indexOf(';', ultimoImportIndex);
|
|
166
|
+
|
|
167
|
+
if (finUltimoImport !== -1) {
|
|
168
|
+
contenidoRoutes = contenidoRoutes.slice(0, finUltimoImport + 1) + '
|
|
169
|
+
' + lineaImport + contenidoRoutes.slice(finUltimoImport + 1);
|
|
170
|
+
} else {
|
|
171
|
+
contenidoRoutes = lineaImport + '
|
|
172
|
+
' + contenidoRoutes;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const cierreArray = contenidoRoutes.lastIndexOf('];');
|
|
176
|
+
if (cierreArray !== -1) {
|
|
177
|
+
const nuevaRuta = ` { path: '${nombreRuta}', component: ${nombreClase} },`;
|
|
178
|
+
const textoAntesDeCierre = contenidoRoutes.slice(0, cierreArray).trimEnd();
|
|
179
|
+
const necesitaComa = !textoAntesDeCierre.endsWith(',') && !textoAntesDeCierre.endsWith('[');
|
|
180
|
+
|
|
181
|
+
contenidoRoutes = contenidoRoutes.slice(0, cierreArray) +
|
|
182
|
+
(necesitaComa ? ',' : '') + '
|
|
183
|
+
' +
|
|
184
|
+
nuevaRuta + '
|
|
185
|
+
' +
|
|
186
|
+
contenidoRoutes.slice(cierreArray);
|
|
187
|
+
|
|
188
|
+
fs.writeFileSync(rutaRoutes, contenidoRoutes);
|
|
189
|
+
console.log('Ruta agregada exitosamente.');
|
|
190
|
+
} else {
|
|
191
|
+
console.error('No se pudo encontrar el array de rutas en app.routes.ts');
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
console.error(`No se encontró el archivo de rutas en: ${rutaRoutes}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// --- Modificar contenedor-principal.component.html ---
|
|
198
|
+
console.log('Actualizando contenedor-principal.component.html...');
|
|
199
|
+
const rutaHtml = path.join(process.cwd(), 'src', 'app', 'Paginas', 'contenedor-principal', 'contenedor-principal.component.html');
|
|
200
|
+
if (fs.existsSync(rutaHtml)) {
|
|
201
|
+
let contenidoHtml = fs.readFileSync(rutaHtml, 'utf-8');
|
|
202
|
+
|
|
203
|
+
const nuevaTarjeta = ` <app-tarjeta [rutaASeguir]="'${nombreRuta}'" titulo="${titulo}" descripcion="${descripcion}" icono="table_chart"></app-tarjeta>`;
|
|
204
|
+
|
|
205
|
+
const ultimoDiv = contenidoHtml.lastIndexOf('</div>');
|
|
206
|
+
|
|
207
|
+
if (ultimoDiv !== -1) {
|
|
208
|
+
contenidoHtml = contenidoHtml.slice(0, ultimoDiv) + '
|
|
209
|
+
' + nuevaTarjeta + '
|
|
210
|
+
' + contenidoHtml.slice(ultimoDiv);
|
|
211
|
+
fs.writeFileSync(rutaHtml, contenidoHtml);
|
|
212
|
+
console.log('Tarjeta agregada exitosamente.');
|
|
213
|
+
} else {
|
|
214
|
+
console.error('No se encontró un </div> de cierre en el HTML del contenedor principal.');
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
console.error(`No se encontró el archivo HTML en: ${rutaHtml}`);
|
|
218
|
+
}
|
|
219
|
+
closeReadLine();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function showFrontendVersion() {
|
|
223
|
+
mostrarVersion(path.join(__dirname, '../../package.json'));
|
|
224
|
+
closeReadLine();
|
|
225
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { mostrarVersion, getPackageInfo, closeReadLine } from './utils/index.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { initDb, showDbVersion } from './commands/db.js';
|
|
8
|
+
import { initBackend, updateBackend, addServiceBackend, showBackendVersion } from './commands/backend.js';
|
|
9
|
+
import { initFrontend, updateFrontend, cloneFrontendComponent, commitFrontend, showFrontendVersion } from './commands/frontend.js';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
|
|
14
|
+
const program = new Command();
|
|
15
|
+
|
|
16
|
+
const packageInfo = getPackageInfo(path.join(__dirname, 'package.json'));
|
|
17
|
+
|
|
18
|
+
if (packageInfo) {
|
|
19
|
+
program
|
|
20
|
+
.name('utn')
|
|
21
|
+
.description('Herramienta CLI unificada para la gestión de plantillas SIGU UTN.')
|
|
22
|
+
.version(packageInfo.version);
|
|
23
|
+
} else {
|
|
24
|
+
program
|
|
25
|
+
.name('utn')
|
|
26
|
+
.description('Herramienta CLI unificada para la gestión de plantillas SIGU UTN.')
|
|
27
|
+
.version('0.0.0'); // Fallback version
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Define 'db' command
|
|
31
|
+
program.command('db')
|
|
32
|
+
.description('Comandos para la gestión de plantillas de base de datos.')
|
|
33
|
+
.option('--init', 'Inicializa un nuevo proyecto de base de datos.')
|
|
34
|
+
.option('--version', 'Muestra la versión del módulo de base de datos.')
|
|
35
|
+
.action(async (options) => {
|
|
36
|
+
if (options.init) {
|
|
37
|
+
await initDb();
|
|
38
|
+
} else if (options.version) {
|
|
39
|
+
showDbVersion();
|
|
40
|
+
} else {
|
|
41
|
+
console.log('Uso: utn db [--init | --version]');
|
|
42
|
+
closeReadLine();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Define 'backend' command
|
|
47
|
+
program.command('backend')
|
|
48
|
+
.description('Comandos para la gestión de plantillas de backend (Node.js/Express).')
|
|
49
|
+
.option('--init', 'Inicializa un nuevo proyecto de backend.')
|
|
50
|
+
.option('--update', 'Actualiza un proyecto de backend existente.')
|
|
51
|
+
.option('--add-service', 'Agrega un nuevo servicio al proyecto de backend.')
|
|
52
|
+
.option('--version', 'Muestra la versión del módulo de backend.')
|
|
53
|
+
.action(async (options) => {
|
|
54
|
+
if (options.init) {
|
|
55
|
+
await initBackend();
|
|
56
|
+
} else if (options.update) {
|
|
57
|
+
await updateBackend();
|
|
58
|
+
} else if (options.addService) {
|
|
59
|
+
await addServiceBackend();
|
|
60
|
+
} else if (options.version) {
|
|
61
|
+
showBackendVersion();
|
|
62
|
+
} else {
|
|
63
|
+
console.log('Uso: utn backend [--init | --update | --add-service | --version]');
|
|
64
|
+
closeReadLine();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Define 'frontend' command
|
|
69
|
+
program.command('frontend')
|
|
70
|
+
.description('Comandos para la gestión de plantillas de frontend (Angular).')
|
|
71
|
+
.option('--init', 'Inicializa un nuevo proyecto de frontend.')
|
|
72
|
+
.option('--update', 'Actualiza un proyecto de frontend existente.')
|
|
73
|
+
.option('--clone-component', 'Clona un componente existente (e.g., gestion-tabla-XYZ).')
|
|
74
|
+
.option('--commit', 'Realiza un commit siguiendo el flujo de trabajo predefinido.')
|
|
75
|
+
.option('--version', 'Muestra la versión del módulo de frontend.')
|
|
76
|
+
.action(async (options) => {
|
|
77
|
+
if (options.init) {
|
|
78
|
+
await initFrontend();
|
|
79
|
+
} else if (options.update) {
|
|
80
|
+
await updateFrontend();
|
|
81
|
+
} else if (options.cloneComponent) {
|
|
82
|
+
await cloneFrontendComponent();
|
|
83
|
+
} else if (options.commit) {
|
|
84
|
+
await commitFrontend();
|
|
85
|
+
} else if (options.version) {
|
|
86
|
+
showFrontendVersion();
|
|
87
|
+
} else {
|
|
88
|
+
console.log('Uso: utn frontend [--init | --update | --clone-component | --commit | --version]');
|
|
89
|
+
closeReadLine();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
program.parse(process.argv);
|
|
94
|
+
|
|
95
|
+
if (!process.argv.slice(2).length) {
|
|
96
|
+
program.outputHelp();
|
|
97
|
+
closeReadLine();
|
|
98
|
+
}
|