utn-cli 2.1.10 → 2.1.11
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/backup.js +53 -0
- package/index.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { closeReadLine } from '../utils/index.js';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
|
|
6
|
+
export async function runGlobalBackup() {
|
|
7
|
+
const currentDir = process.cwd();
|
|
8
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
9
|
+
const directories = entries.filter(entry => entry.isDirectory());
|
|
10
|
+
|
|
11
|
+
if (directories.length === 0) {
|
|
12
|
+
console.log('No se encontraron directorios en la carpeta actual.');
|
|
13
|
+
closeReadLine();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let encontroAlguno = false;
|
|
18
|
+
|
|
19
|
+
for (const dir of directories) {
|
|
20
|
+
const fullPath = path.join(currentDir, dir.name);
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(path.join(fullPath, '.git'))) continue;
|
|
23
|
+
|
|
24
|
+
encontroAlguno = true;
|
|
25
|
+
process.chdir(fullPath);
|
|
26
|
+
|
|
27
|
+
console.log(`\n[${dir.name}] Agregando cambios...`);
|
|
28
|
+
try {
|
|
29
|
+
execSync('git add .', { stdio: 'inherit' });
|
|
30
|
+
} catch {
|
|
31
|
+
console.error(`[${dir.name}] Error al ejecutar git add. Continuando...`);
|
|
32
|
+
process.chdir(currentDir);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(`[${dir.name}] Realizando commit de respaldo...`);
|
|
37
|
+
try {
|
|
38
|
+
execSync('git commit -m "* NEW: Respaldo de código"', { stdio: 'inherit' });
|
|
39
|
+
} catch {
|
|
40
|
+
console.log(`[${dir.name}] Sin cambios para hacer commit o el commit falló.`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
process.chdir(currentDir);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!encontroAlguno) {
|
|
47
|
+
console.log('No se encontraron repositorios Git en los directorios actuales.');
|
|
48
|
+
} else {
|
|
49
|
+
console.log('\nRespaldo finalizado en todos los repositorios.');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
closeReadLine();
|
|
53
|
+
}
|
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { initBackend, updateBackend, addServiceBackend, showBackendVersion } fro
|
|
|
9
9
|
import { initFrontend, updateFrontend, cloneFrontendComponent, showFrontendVersion } from './commands/frontend.js';
|
|
10
10
|
import { runGlobalUpdate } from './commands/update.js';
|
|
11
11
|
import { runGlobalPull } from './commands/pull.js';
|
|
12
|
+
import { runGlobalBackup } from './commands/backup.js';
|
|
12
13
|
import { createComponent } from './commands/createComponent.js';
|
|
13
14
|
import { runCommit } from './commands/commit.js';
|
|
14
15
|
|
|
@@ -112,6 +113,13 @@ program.command('pull')
|
|
|
112
113
|
await runGlobalPull();
|
|
113
114
|
});
|
|
114
115
|
|
|
116
|
+
// Define 'backup' command
|
|
117
|
+
program.command('backup')
|
|
118
|
+
.description('Recorre los directorios y realiza un commit de respaldo con el mensaje "* NEW: Respaldo de código" en cada repositorio Git.')
|
|
119
|
+
.action(async () => {
|
|
120
|
+
await runGlobalBackup();
|
|
121
|
+
});
|
|
122
|
+
|
|
115
123
|
// Define 'create-component' command
|
|
116
124
|
program.command('create-component')
|
|
117
125
|
.description('Crea un nuevo servicio en el backend y un componente en el frontend simultáneamente.')
|