@orxataguy/tyr 1.0.11-beta.8 → 1.0.11-beta.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orxataguy/tyr",
3
- "version": "1.0.11-beta.8",
3
+ "version": "1.0.11-beta.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tyr": "./bin/tyr.js"
@@ -1,121 +0,0 @@
1
- /**
2
- * build.ts — sistema: tyr build
3
- *
4
- * Compila AOT (Ahead-of-Time) todos los comandos registrados en ~/.tyr/map.yml
5
- * desde TypeScript a JavaScript puro usando esbuild.
6
- *
7
- * El resultado se escribe en ~/.tyr/dist/<basename>.js.
8
- * Una vez compilado, el Kernel detecta automáticamente los ficheros .js en dist/
9
- * y los usa en lugar de los .ts originales, eliminando por completo el coste
10
- * de transpilación en tiempo de ejecución.
11
- *
12
- * Uso:
13
- * tyr build — compila todos los comandos de map.yml
14
- * tyr build --clean — elimina ~/.tyr/dist/ antes de compilar
15
- */
16
-
17
- import path from 'path';
18
- import fs from 'fs';
19
- import yaml from 'js-yaml';
20
- import type { TyrContext } from '../Kernel.js';
21
-
22
- interface MapYml {
23
- commands: Record<string, string>;
24
- aliases?: Record<string, string>;
25
- }
26
-
27
- export default function build({ logger, userRoot }: TyrContext) {
28
- return async (args: string[]) => {
29
- const clean = args.includes('--clean');
30
- const mapPath = path.join(userRoot, 'map.yml');
31
- const distDir = path.join(userRoot, 'dist');
32
-
33
- // ── Leer map.yml ──────────────────────────────────────────────────────
34
- if (!fs.existsSync(mapPath)) {
35
- logger.error(`No se encontró map.yml en ${userRoot}`);
36
- return;
37
- }
38
-
39
- const raw = yaml.load(fs.readFileSync(mapPath, 'utf8')) as MapYml;
40
- const commands = raw?.commands ?? {};
41
- const entries = Object.entries(commands);
42
-
43
- if (entries.length === 0) {
44
- logger.warn('map.yml no contiene comandos. Nada que compilar.');
45
- return;
46
- }
47
-
48
- // ── Limpiar dist/ si se pide ──────────────────────────────────────────
49
- if (clean && fs.existsSync(distDir)) {
50
- fs.rmSync(distDir, { recursive: true, force: true });
51
- logger.info('dist/ eliminado.');
52
- }
53
-
54
- if (!fs.existsSync(distDir)) {
55
- fs.mkdirSync(distDir, { recursive: true });
56
- }
57
-
58
- // ── Importar esbuild dinámicamente (dep de producción en @orxataguy/tyr) ──
59
- // La importación dinámica garantiza que si esbuild no estuviese disponible
60
- // se obtiene un error claro en lugar de un crash al arrancar el framework.
61
- let esbuild: typeof import('esbuild');
62
- try {
63
- esbuild = await import('esbuild');
64
- } catch {
65
- logger.error('esbuild no está disponible. Reinstala: npm install -g @orxataguy/tyr');
66
- return;
67
- }
68
-
69
- // ── Compilar cada comando ─────────────────────────────────────────────
70
- let compiled = 0;
71
- let failed = 0;
72
-
73
- for (const [name, relPath] of entries) {
74
- const srcPath = path.isAbsolute(relPath)
75
- ? relPath
76
- : path.resolve(userRoot, relPath);
77
-
78
- if (!fs.existsSync(srcPath)) {
79
- logger.warn(`[${name}] Fichero no encontrado: ${srcPath} — omitido.`);
80
- failed++;
81
- continue;
82
- }
83
-
84
- const outFile = path.join(
85
- distDir,
86
- path.basename(srcPath).replace(/\.ts$/, '.js'),
87
- );
88
-
89
- try {
90
- await esbuild.build({
91
- entryPoints: [srcPath],
92
- outfile: outFile,
93
- bundle: false, // solo transpila, no empaqueta deps
94
- platform: 'node',
95
- format: 'esm',
96
- target: 'node18',
97
- sourcemap: false, // sin sourcemaps en producción
98
- packages: 'external', // mantiene imports de npm tal cual
99
- logLevel: 'silent',
100
- });
101
- logger.success(`[${name}] → ${path.relative(userRoot, outFile)}`);
102
- compiled++;
103
- } catch (err: any) {
104
- logger.error(`[${name}] Error de compilación: ${err?.message ?? err}`);
105
- failed++;
106
- }
107
- }
108
-
109
- // ── Resumen ────────────────────────────────────────────────────────────
110
- console.log('');
111
- if (compiled > 0) {
112
- logger.success(
113
- `Build completado: ${compiled} comando${compiled !== 1 ? 's' : ''} compilado${compiled !== 1 ? 's' : ''} en dist/`,
114
- );
115
- logger.info('El Kernel usará automáticamente los ficheros compilados en la próxima ejecución.');
116
- }
117
- if (failed > 0) {
118
- logger.warn(`${failed} comando${failed !== 1 ? 's' : ''} no pudieron compilarse.`);
119
- }
120
- };
121
- }