@orxataguy/tyr 1.0.3 → 1.0.5
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/package.json +2 -3
- package/src/core/Kernel.ts +21 -4
- package/src/core/sys/ai.ts +3 -3
- package/src/core/sys/config.ts +52 -27
- package/src/core/sys/doc.ts +1 -1
- package/config/map.yml +0 -4
- package/src/commands/di.tyr.ts +0 -113
- package/src/commands/dw.tyr.ts +0 -116
- package/src/commands/install.tyr.ts +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orxataguy/tyr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tyr": "./bin/tyr.js"
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"bin/",
|
|
13
|
-
"src/"
|
|
14
|
-
"config/"
|
|
13
|
+
"src/"
|
|
15
14
|
],
|
|
16
15
|
"scripts": {
|
|
17
16
|
"test": "vitest run",
|
package/src/core/Kernel.ts
CHANGED
|
@@ -86,7 +86,8 @@ export class Kernel {
|
|
|
86
86
|
console.log('Usage: tyr <command> [args...]');
|
|
87
87
|
console.log(' tyr --config Configure Tyr for the first time');
|
|
88
88
|
console.log(' tyr --version Show version');
|
|
89
|
-
console.log(' tyr --update
|
|
89
|
+
console.log(' tyr --update Pull latest changes from the linked ~/.tyr repo');
|
|
90
|
+
console.log(' tyr --upgrade Upgrade Tyr to the latest npm version');
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -98,14 +99,30 @@ export class Kernel {
|
|
|
98
99
|
return;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
// --update
|
|
102
|
+
// --update: pull latest changes from the linked ~/.tyr git repo
|
|
102
103
|
if (commandName === '--update') {
|
|
104
|
+
const shell = this.container.get().shell;
|
|
105
|
+
const gitDir = path.join(this.userRoot, '.git');
|
|
106
|
+
if (!fs.existsSync(gitDir)) {
|
|
107
|
+
console.log('~/.tyr no está vinculado a ningún repositorio git.');
|
|
108
|
+
console.log('Ejecuta: tyr --config --repo <url> para vincularlo.');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
console.log('Actualizando ~/.tyr desde el repositorio...');
|
|
112
|
+
shell.cd(this.userRoot);
|
|
113
|
+
await shell.exec('git pull');
|
|
114
|
+
console.log('Actualización completada.');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// --upgrade: update the Tyr npm package itself
|
|
119
|
+
if (commandName === '--upgrade') {
|
|
103
120
|
const pkgPath = path.resolve(this.frameworkRoot, 'package.json');
|
|
104
121
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
105
122
|
const shell = this.container.get().shell;
|
|
106
|
-
console.log(`
|
|
123
|
+
console.log(`Actualizando ${pkg.name}...`);
|
|
107
124
|
await shell.exec(`npm update -g ${pkg.name}`);
|
|
108
|
-
console.log('
|
|
125
|
+
console.log('Actualización completada. Ejecuta tyr --version para confirmar.');
|
|
109
126
|
return;
|
|
110
127
|
}
|
|
111
128
|
|
package/src/core/sys/ai.ts
CHANGED
|
@@ -111,7 +111,7 @@ REGLAS:export default;async(args:string[]);task() p/errores;fail() p/validar;Tes
|
|
|
111
111
|
Responde SOLO código TS sin explicaciones ni backticks.`;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
export default function ai({ logger, fs: tyrFs,
|
|
114
|
+
export default function ai({ logger, fs: tyrFs, userRoot, run, fail }: TyrContext) {
|
|
115
115
|
return async (args: string[]) => {
|
|
116
116
|
const commandName = args[0];
|
|
117
117
|
const prompt = args.slice(1).join(' ');
|
|
@@ -153,8 +153,8 @@ export default function ai({ logger, fs: tyrFs, frameworkRoot, run, fail }: TyrC
|
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
const filePath = path.
|
|
156
|
+
const filePath = path.join(userRoot, 'commands', `${commandName}.tyr.ts`);
|
|
157
157
|
await tyrFs.write(filePath, code);
|
|
158
|
-
logger.success(`'${commandName}' ->
|
|
158
|
+
logger.success(`'${commandName}' -> ~/.tyr/commands/${commandName}.tyr.ts`);
|
|
159
159
|
};
|
|
160
160
|
}
|
package/src/core/sys/config.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import yaml from 'js-yaml';
|
|
3
2
|
import { homedir, platform } from 'os';
|
|
4
|
-
import { existsSync, cpSync, rmSync } from 'fs';
|
|
3
|
+
import { existsSync, cpSync, rmSync, mkdirSync, readdirSync } from 'fs';
|
|
5
4
|
import { execSync } from 'child_process';
|
|
6
5
|
import type { TyrContext } from '../Kernel';
|
|
7
6
|
|
|
@@ -13,7 +12,40 @@ function removeDirRecursive(dirPath: string): void {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
function clearDirExceptLogs(dirPath: string): void {
|
|
16
|
+
if (!existsSync(dirPath)) return;
|
|
17
|
+
for (const entry of readdirSync(dirPath, { withFileTypes: true })) {
|
|
18
|
+
if (entry.name === 'logs') continue;
|
|
19
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
removeDirRecursive(fullPath);
|
|
22
|
+
} else {
|
|
23
|
+
rmSync(fullPath, { force: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function copyDirContents(srcDir: string, destDir: string): void {
|
|
29
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
30
|
+
cpSync(
|
|
31
|
+
path.join(srcDir, entry.name),
|
|
32
|
+
path.join(destDir, entry.name),
|
|
33
|
+
{ recursive: true, force: true },
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function backupUserRoot(userRoot: string, backupPath: string): void {
|
|
39
|
+
mkdirSync(backupPath, { recursive: true });
|
|
40
|
+
for (const entry of readdirSync(userRoot, { withFileTypes: true })) {
|
|
41
|
+
if (entry.name === 'logs') continue;
|
|
42
|
+
cpSync(
|
|
43
|
+
path.join(userRoot, entry.name),
|
|
44
|
+
path.join(backupPath, entry.name),
|
|
45
|
+
{ recursive: true },
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
17
49
|
|
|
18
50
|
function detectShellRcFile(homeDir: string): string | null {
|
|
19
51
|
const shell = process.env.SHELL || '';
|
|
@@ -27,8 +59,6 @@ function detectShellRcFile(homeDir: string): string | null {
|
|
|
27
59
|
return fallbacks.find(p => existsSync(p)) ?? path.join(homeDir, '.bashrc');
|
|
28
60
|
}
|
|
29
61
|
|
|
30
|
-
// ─── File templates ───────────────────────────────────────────────────────────
|
|
31
|
-
|
|
32
62
|
const ENV_TEMPLATE = `# ~/.tyr/.env
|
|
33
63
|
# Variables de entorno para Tyr. Este archivo nunca debe subirse a git.
|
|
34
64
|
#
|
|
@@ -77,8 +107,6 @@ const PS_PLUGINS_TEMPLATE = `# ~/.tyr/plugins.ps1
|
|
|
77
107
|
# Import-Module PSReadLine
|
|
78
108
|
`;
|
|
79
109
|
|
|
80
|
-
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
81
|
-
|
|
82
110
|
function makeTimestamp(): string {
|
|
83
111
|
const now = new Date();
|
|
84
112
|
const pad = (n: number) => String(n).padStart(2, '0');
|
|
@@ -113,8 +141,6 @@ async function configureWindowsShell(tyrFs: any, logger: any, aliasesPath: strin
|
|
|
113
141
|
logger.info('Reinicia PowerShell para aplicar los cambios.');
|
|
114
142
|
}
|
|
115
143
|
|
|
116
|
-
// ─── Main ─────────────────────────────────────────────────────────────────────
|
|
117
|
-
|
|
118
144
|
export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrContext) {
|
|
119
145
|
return async (args: string[]) => {
|
|
120
146
|
const homeDir = homedir();
|
|
@@ -132,37 +158,40 @@ export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrC
|
|
|
132
158
|
return;
|
|
133
159
|
}
|
|
134
160
|
|
|
135
|
-
|
|
136
|
-
let backupPath: string | null = null;
|
|
161
|
+
let backupPath: string | null = null;
|
|
137
162
|
if (existsSync(userRoot)) {
|
|
138
163
|
backupPath = `${userRoot}.bak.${makeTimestamp()}`;
|
|
139
|
-
|
|
140
|
-
removeDirRecursive(userRoot);
|
|
164
|
+
backupUserRoot(userRoot, backupPath);
|
|
141
165
|
logger.warn(`Configuración anterior respaldada en: ${backupPath}`);
|
|
142
166
|
}
|
|
143
167
|
|
|
144
|
-
|
|
145
|
-
let repoHasContent = false;
|
|
168
|
+
let repoHasContent = false;
|
|
146
169
|
if (repoUrl) {
|
|
170
|
+
const tempDir = `${userRoot}.setup-temp`;
|
|
171
|
+
if (existsSync(tempDir)) {
|
|
172
|
+
try { removeDirRecursive(tempDir); } catch {}
|
|
173
|
+
}
|
|
174
|
+
|
|
147
175
|
logger.info(`\nClonando repositorio: ${repoUrl}`);
|
|
148
176
|
try {
|
|
149
|
-
await shell.exec(`git clone "${repoUrl}" "${
|
|
177
|
+
await shell.exec(`git clone "${repoUrl}" "${tempDir}"`);
|
|
150
178
|
} catch (e) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
cpSync(backupPath, userRoot, { recursive: true });
|
|
154
|
-
removeDirRecursive(backupPath);
|
|
155
|
-
logger.warn('Error al clonar. Configuración anterior restaurada.');
|
|
179
|
+
if (existsSync(tempDir)) {
|
|
180
|
+
try { removeDirRecursive(tempDir); } catch {}
|
|
156
181
|
}
|
|
157
182
|
throw e;
|
|
158
183
|
}
|
|
159
|
-
|
|
184
|
+
|
|
185
|
+
repoHasContent = existsSync(path.join(tempDir, 'map.yml'));
|
|
160
186
|
logger.success(repoHasContent
|
|
161
187
|
? 'Repositorio clonado con configuración existente.'
|
|
162
188
|
: 'Repositorio vacío — iniciando configuración por defecto...');
|
|
189
|
+
|
|
190
|
+
clearDirExceptLogs(userRoot);
|
|
191
|
+
copyDirContents(tempDir, userRoot);
|
|
192
|
+
try { removeDirRecursive(tempDir); } catch {}
|
|
163
193
|
}
|
|
164
194
|
|
|
165
|
-
// ── 3. Initialize if needed (no repo, or repo was empty) ──────────────
|
|
166
195
|
if (!repoHasContent) {
|
|
167
196
|
logger.info('\nInicializando ~/.tyr...\n');
|
|
168
197
|
|
|
@@ -181,19 +210,16 @@ export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrC
|
|
|
181
210
|
logger.success(`Archivo creado: ${pluginsPath}`);
|
|
182
211
|
}
|
|
183
212
|
|
|
184
|
-
// Write map.yml
|
|
185
213
|
const mapPath = path.join(userRoot, 'map.yml');
|
|
186
214
|
await tyrFs.write(mapPath, 'commands: {}\n');
|
|
187
215
|
logger.success(`Archivo creado: ${mapPath}`);
|
|
188
216
|
|
|
189
|
-
// Write .env template
|
|
190
217
|
const envPath = path.join(userRoot, '.env');
|
|
191
218
|
if (!tyrFs.exists(envPath)) {
|
|
192
219
|
await tyrFs.write(envPath, ENV_TEMPLATE);
|
|
193
220
|
logger.success(`Archivo creado: ${envPath}`);
|
|
194
221
|
}
|
|
195
222
|
|
|
196
|
-
// If linked to a repo, commit and push
|
|
197
223
|
if (repoUrl) {
|
|
198
224
|
logger.info('\nSubiendo configuración inicial al repositorio...');
|
|
199
225
|
shell.cd(userRoot);
|
|
@@ -208,7 +234,6 @@ export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrC
|
|
|
208
234
|
}
|
|
209
235
|
}
|
|
210
236
|
|
|
211
|
-
// ── 4. Configure shell (always) ────────────────────────────────────────
|
|
212
237
|
const aliasesPath = path.join(userRoot, `aliases${ext}`);
|
|
213
238
|
const pluginsPath = path.join(userRoot, `plugins${ext}`);
|
|
214
239
|
|
package/src/core/sys/doc.ts
CHANGED
|
@@ -304,7 +304,7 @@ if (!fs.existsSync('./package.json')) {
|
|
|
304
304
|
await run('ai', [name, prompt]);
|
|
305
305
|
|
|
306
306
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
307
|
-
res.end(JSON.stringify({ success: true, message: `Comando '${name}' generado correctamente en
|
|
307
|
+
res.end(JSON.stringify({ success: true, message: `Comando '${name}' generado correctamente en ~/.tyr/commands/${name}.tyr.ts` }));
|
|
308
308
|
} catch (e: any) {
|
|
309
309
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
310
310
|
res.end(JSON.stringify({ success: false, message: e.message || 'Error al generar el comando.' }));
|
package/config/map.yml
DELETED
package/src/commands/di.tyr.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { TyrContext } from '../core/Kernel';
|
|
2
|
-
|
|
3
|
-
export default ({ task, fail, logger, shell, db, git, fs }: TyrContext) => {
|
|
4
|
-
/**
|
|
5
|
-
* @method extractBranchName
|
|
6
|
-
* @description Extrae el nombre de rama de una URL o devuelve el nombre tal cual
|
|
7
|
-
*/
|
|
8
|
-
const extractBranchName = (input: string): string => {
|
|
9
|
-
if (input.includes('/')) {
|
|
10
|
-
const parts = input.split('/');
|
|
11
|
-
return parts[parts.length - 1];
|
|
12
|
-
}
|
|
13
|
-
return input;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return async (args: string[]) => {
|
|
17
|
-
|
|
18
|
-
// Validación de argumentos
|
|
19
|
-
if (args.length === 0) {
|
|
20
|
-
fail(
|
|
21
|
-
'No se especificó la URL del cliente',
|
|
22
|
-
'Uso: clone-client <url-cliente> [url-rama-opcional]'
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const clientUrl = args[0];
|
|
27
|
-
const branchUrlOrName = args[1] || null;
|
|
28
|
-
|
|
29
|
-
logger.info('Navegando al directorio de clientes...');
|
|
30
|
-
shell.cd('~/dev/wolbenvironment/dev/online-booking/htdocs/datosBroker');
|
|
31
|
-
|
|
32
|
-
const broker = await task('Buscando broker en la base de datos', async () => {
|
|
33
|
-
const result = await db.searchBrokerOnDB(clientUrl);
|
|
34
|
-
|
|
35
|
-
if (!result) {
|
|
36
|
-
fail(
|
|
37
|
-
`No se encontró broker para la URL: ${clientUrl}`,
|
|
38
|
-
'Verifica que la URL sea correcta y esté registrada en la BD'
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
logger.success(`Broker encontrado: ${result}`);
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const brokerPath = `~/dev/wolbenvironment/dev/online-booking/htdocs/datosBroker/${broker}`;
|
|
47
|
-
const dirExists = fs.exists(brokerPath);
|
|
48
|
-
|
|
49
|
-
if (dirExists) {
|
|
50
|
-
logger.warn(`El directorio '${broker}' ya existe`);
|
|
51
|
-
|
|
52
|
-
const choice = await shell.input(
|
|
53
|
-
'¿Qué deseas hacer? (s)obrescribir / (m)antener / (r)enombrar: '
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (choice.toLowerCase() === 'm' || choice.toLowerCase() === 'mantener') {
|
|
57
|
-
logger.info('Manteniendo directorio existente. Finalizando...');
|
|
58
|
-
return;
|
|
59
|
-
} else if (choice.toLowerCase() === 'r' || choice.toLowerCase() === 'renombrar') {
|
|
60
|
-
await task('Renombrando directorio existente', async () => {
|
|
61
|
-
await shell.exec(`mv ${broker} ${broker}.bak`);
|
|
62
|
-
logger.success(`Directorio renombrado a: ${broker}.bak`);
|
|
63
|
-
});
|
|
64
|
-
} else if (choice.toLowerCase() === 's' || choice.toLowerCase() === 'sobrescribir') {
|
|
65
|
-
await task('Eliminando directorio existente', async () => {
|
|
66
|
-
await shell.exec(`rm -rf ${broker}`);
|
|
67
|
-
logger.success('Directorio eliminado');
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
fail('Opción no válida', 'Usa: s (sobrescribir), m (mantener) o r (renombrar)');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const repoUrl = `git@github.com:Avantio/${broker}`;
|
|
75
|
-
logger.info(`Repositorio: ${repoUrl}`);
|
|
76
|
-
|
|
77
|
-
const loader = shell.showLoader('Clonando repositorio desde GitHub...');
|
|
78
|
-
|
|
79
|
-
await task('Clonando repositorio', async () => {
|
|
80
|
-
await git.clone(repoUrl);
|
|
81
|
-
loader.stop();
|
|
82
|
-
logger.success('Repositorio clonado exitosamente');
|
|
83
|
-
}, false, () => loader.stop());
|
|
84
|
-
|
|
85
|
-
shell.cd(broker);
|
|
86
|
-
|
|
87
|
-
let branchName: string;
|
|
88
|
-
|
|
89
|
-
if (branchUrlOrName) {
|
|
90
|
-
branchName = extractBranchName(branchUrlOrName);
|
|
91
|
-
logger.info(`Rama extraída: ${branchName}`);
|
|
92
|
-
} else {
|
|
93
|
-
const answer = await shell.input('🌿 ¿Qué rama quieres usar? (nombre o URL): ');
|
|
94
|
-
branchName = extractBranchName(answer);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
await task(`Cambiando a la rama: ${branchName}`, async () => {
|
|
98
|
-
if (branchName.length > 0) {
|
|
99
|
-
await shell.exec(`git checkout -b ${branchName}`);
|
|
100
|
-
logger.success(`Ahora estás en la rama: ${branchName}`);
|
|
101
|
-
} else {
|
|
102
|
-
logger.info('No se va a generar ninguna rama nueva')
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
logger.success(`Repositorio ${broker} clonado y configurado exitosamente`);
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// export const Test = {
|
|
112
|
-
// args: []
|
|
113
|
-
// }
|
package/src/commands/dw.tyr.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { TyrContext } from '../core/Kernel';
|
|
2
|
-
|
|
3
|
-
export default ({ task, fail, logger, shell, db, git, fs }: TyrContext) => {
|
|
4
|
-
/**
|
|
5
|
-
* @method extractBranchName
|
|
6
|
-
* @description Extrae el nombre de rama de una URL o devuelve el nombre tal cual
|
|
7
|
-
*/
|
|
8
|
-
const extractBranchName = (input: string): string => {
|
|
9
|
-
if (input.includes('/')) {
|
|
10
|
-
const parts = input.split('/');
|
|
11
|
-
return parts[parts.length - 1];
|
|
12
|
-
}
|
|
13
|
-
return input;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return async (args: string[]) => {
|
|
17
|
-
|
|
18
|
-
// Validación de argumentos
|
|
19
|
-
if (args.length === 0) {
|
|
20
|
-
fail(
|
|
21
|
-
'No se especificó la URL del cliente',
|
|
22
|
-
'Uso: clone-client <url-cliente> [url-rama-opcional]'
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const clientUrl = args[0];
|
|
27
|
-
const branchUrlOrName = args[1] || null;
|
|
28
|
-
|
|
29
|
-
logger.info('Navegando al directorio de clientes...');
|
|
30
|
-
shell.cd('~/dev/wolbenvironment/dev/websITS/clients');
|
|
31
|
-
console.log("Lanzo con url:", clientUrl)
|
|
32
|
-
const broker = await task('Buscando broker en la base de datos', async () => {
|
|
33
|
-
const result = await db.searchBrokerOnDB(clientUrl);
|
|
34
|
-
|
|
35
|
-
if (!result) {
|
|
36
|
-
fail(
|
|
37
|
-
`No se encontró broker para la URL: ${clientUrl}`,
|
|
38
|
-
'Verifica que la URL sea correcta y esté registrada en la BD'
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
logger.success(`Broker encontrado: ${result}`);
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const brokerPath = `~/dev/wolbenvironment/dev/websITS/clients/${broker}`;
|
|
47
|
-
const dirExists = fs.exists(brokerPath);
|
|
48
|
-
|
|
49
|
-
if (dirExists) {
|
|
50
|
-
logger.warn(`El directorio '${broker}' ya existe`);
|
|
51
|
-
|
|
52
|
-
const choice = await shell.input(
|
|
53
|
-
'¿Qué deseas hacer? (s)obrescribir / (m)antener / (r)enombrar: '
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (choice.toLowerCase() === 'm' || choice.toLowerCase() === 'mantener') {
|
|
57
|
-
logger.info('Manteniendo directorio existente. Finalizando...');
|
|
58
|
-
return;
|
|
59
|
-
} else if (choice.toLowerCase() === 'r' || choice.toLowerCase() === 'renombrar') {
|
|
60
|
-
await task('Renombrando directorio existente', async () => {
|
|
61
|
-
await shell.exec(`mv ${broker} ${broker}.bak`);
|
|
62
|
-
logger.success(`Directorio renombrado a: ${broker}.bak`);
|
|
63
|
-
});
|
|
64
|
-
} else if (choice.toLowerCase() === 's' || choice.toLowerCase() === 'sobrescribir') {
|
|
65
|
-
await task('Eliminando directorio existente', async () => {
|
|
66
|
-
await shell.exec(`rm -rf ${broker}`);
|
|
67
|
-
logger.success('Directorio eliminado');
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
fail('Opción no válida', 'Usa: s (sobrescribir), m (mantener) o r (renombrar)');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const repoUrl = `git@github.com:Avantio/${broker}`;
|
|
75
|
-
logger.info(`Repositorio: ${repoUrl}`);
|
|
76
|
-
|
|
77
|
-
const loader = shell.showLoader('Clonando repositorio desde GitHub...');
|
|
78
|
-
|
|
79
|
-
await task('Clonando repositorio', async () => {
|
|
80
|
-
await git.clone(repoUrl);
|
|
81
|
-
loader.stop();
|
|
82
|
-
logger.success('Repositorio clonado exitosamente');
|
|
83
|
-
}, false, () => loader.stop());
|
|
84
|
-
|
|
85
|
-
shell.cd(broker);
|
|
86
|
-
|
|
87
|
-
let branchName: string;
|
|
88
|
-
|
|
89
|
-
if (branchUrlOrName) {
|
|
90
|
-
branchName = extractBranchName(branchUrlOrName);
|
|
91
|
-
logger.info(`Rama extraída: ${branchName}`);
|
|
92
|
-
} else {
|
|
93
|
-
const answer = await shell.input('🌿 ¿Qué rama quieres usar? (nombre o URL): ');
|
|
94
|
-
branchName = extractBranchName(answer);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
await task(`Cambiando a la rama: ${branchName}`, async () => {
|
|
98
|
-
if (branchName.length > 0) {
|
|
99
|
-
await shell.exec(`git checkout -b ${branchName}`);
|
|
100
|
-
logger.success(`Ahora estás en la rama: ${branchName}`);
|
|
101
|
-
} else {
|
|
102
|
-
logger.info('No se va a generar ninguna rama nueva')
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
logger.success(`Repositorio ${broker} clonado y configurado exitosamente`);
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// export const Test = {
|
|
111
|
-
// args: ['https://www.feelporto.com/'],
|
|
112
|
-
// mockInputs: {
|
|
113
|
-
// 'sobrescribir': 'm',
|
|
114
|
-
// 'rama': ''
|
|
115
|
-
// }
|
|
116
|
-
// }
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { TyrContext } from '../core/Kernel';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { homedir } from 'os';
|
|
4
|
-
|
|
5
|
-
export default ({ task, fail, logger, fs }: TyrContext) => {
|
|
6
|
-
return async (_args: string[]) => {
|
|
7
|
-
const homeDir = homedir();
|
|
8
|
-
const userRoot = path.join(homeDir, '.tyr');
|
|
9
|
-
|
|
10
|
-
const aliasesTemplatePath = path.join(homeDir, 'avantio', 'framework', 'core', 'include', 'bin', 'aliases.template.sh');
|
|
11
|
-
const pluginsTemplatePath = path.join(homeDir, 'avantio', 'framework', 'core', 'include', 'bin', 'plugins.template.sh');
|
|
12
|
-
|
|
13
|
-
const aliasesTarget = path.join(userRoot, 'aliases');
|
|
14
|
-
const pluginsTarget = path.join(userRoot, 'plugins');
|
|
15
|
-
|
|
16
|
-
await task('Verificando configuración de Tyr', async () => {
|
|
17
|
-
if (!fs.exists(userRoot)) {
|
|
18
|
-
fail(
|
|
19
|
-
'El directorio ~/.tyr no existe.',
|
|
20
|
-
"Ejecuta 'tyr --config' antes de continuar."
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
logger.success(`Directorio ~/.tyr encontrado: ${userRoot}`);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await task('Verificando templates de Avantio', async () => {
|
|
27
|
-
if (!fs.exists(aliasesTemplatePath)) {
|
|
28
|
-
fail(
|
|
29
|
-
`Template de aliases no encontrado: ${aliasesTemplatePath}`,
|
|
30
|
-
'Verifica que el framework de Avantio esté correctamente instalado.'
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
if (!fs.exists(pluginsTemplatePath)) {
|
|
34
|
-
fail(
|
|
35
|
-
`Template de plugins no encontrado: ${pluginsTemplatePath}`,
|
|
36
|
-
'Verifica que el framework de Avantio esté correctamente instalado.'
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
logger.success('Templates de Avantio encontrados.');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
await task('Copiando aliases de Avantio', async () => {
|
|
43
|
-
const content = await fs.read(aliasesTemplatePath);
|
|
44
|
-
if (!content) fail('No se pudo leer aliases.template.sh');
|
|
45
|
-
await fs.write(aliasesTarget, content!);
|
|
46
|
-
logger.success(`Aliases copiados a: ${aliasesTarget}`);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await task('Copiando plugins de Avantio', async () => {
|
|
50
|
-
const content = await fs.read(pluginsTemplatePath);
|
|
51
|
-
if (!content) fail('No se pudo leer plugins.template.sh');
|
|
52
|
-
await fs.write(pluginsTarget, content!);
|
|
53
|
-
logger.success(`Plugins copiados a: ${pluginsTarget}`);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
logger.success('\nInstalación de Avantio completada.');
|
|
57
|
-
logger.info(` aliases → ${aliasesTarget}`);
|
|
58
|
-
logger.info(` plugins → ${pluginsTarget}`);
|
|
59
|
-
logger.warn('\nRecuerda recargar tu shell para aplicar los cambios.');
|
|
60
|
-
};
|
|
61
|
-
};
|