@josfox/jos 3.1.0 → 3.1.1
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/bin/jos.js +56 -21
- package/package.json +1 -1
package/bin/jos.js
CHANGED
|
@@ -1,36 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { hideBin } from 'yargs/helpers';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import { hideBin } from 'yargs/helpers';
|
|
3
|
+
import yargs from 'yargs';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
|
|
6
|
+
import { validate } from '../lib/validate.js';
|
|
7
|
+
import { resolveJos } from '../lib/resolve.js';
|
|
8
|
+
import { run } from '../lib/run.js';
|
|
9
|
+
import { serve } from '../lib/serve.js';
|
|
5
10
|
|
|
6
11
|
function writeJSON(p, data){ fs.writeFileSync(p, JSON.stringify(data, null, 2), 'utf8'); }
|
|
7
12
|
|
|
8
13
|
yargs(hideBin(process.argv))
|
|
9
14
|
.scriptName('jos')
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
17
|
-
.command('serve <file>', 'Run dev server', y=> y.positional('file',{type:'string'}), async argv=>{
|
|
18
|
-
const doc = resolveJos(argv.file); await serve(doc);
|
|
15
|
+
|
|
16
|
+
// 1) VALIDATE: igual que antes
|
|
17
|
+
.command('validate <file>', 'Validate .jos file', y => y.positional('file', { type: 'string' }), argv => {
|
|
18
|
+
const res = validate(argv.file);
|
|
19
|
+
if (!res.ok) { console.error('Schema errors:', res.errors); process.exit(1); }
|
|
20
|
+
console.log('OK ✅');
|
|
19
21
|
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
// 2) RUN: usar resolveJos para tolerar versiones legacy
|
|
24
|
+
.command('run <file>', 'Run task/pipeline', y => y.positional('file', { type: 'string' }), async argv => {
|
|
25
|
+
const doc = resolveJos(argv.file); // <-- antes usaba validate(...)
|
|
26
|
+
const flags = {};
|
|
27
|
+
for (const [k, v] of Object.entries(argv)) if (k.startsWith('eval.')) flags[k] = v;
|
|
28
|
+
const code = await run(doc, flags);
|
|
29
|
+
process.exit(code);
|
|
23
30
|
})
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
|
|
32
|
+
// 3) SERVE: también resolver primero
|
|
33
|
+
.command('serve <file>', 'Run dev server', y => y.positional('file', { type: 'string' }), async argv => {
|
|
34
|
+
const doc = resolveJos(argv.file);
|
|
35
|
+
await serve(doc);
|
|
26
36
|
})
|
|
27
|
-
|
|
37
|
+
|
|
38
|
+
// 4) DOC: se mantiene (usa validate estricto)
|
|
39
|
+
.command('doc <file> --out <out>', 'Generate docs', y => y
|
|
40
|
+
.positional('file', { type: 'string' })
|
|
41
|
+
.option('out', { type: 'string', demandOption: true }),
|
|
42
|
+
argv => {
|
|
43
|
+
const { doc } = validate(argv.file);
|
|
44
|
+
const tasks = (doc.tasks || []).map(t => `- **${t.id}** \`${t.runner}${t.action ? ':' + t.action : ''}\``).join('\n');
|
|
45
|
+
const md = `# ${doc.name}\n\nSchema: ${doc.schema}\n\n## Tasks\n${tasks}\n`;
|
|
46
|
+
fs.writeFileSync(argv.out, md, 'utf8');
|
|
47
|
+
console.log(`Doc written to ${argv.out}`);
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// 5) PACK: corregir el log
|
|
51
|
+
.command('pack <file> --out <out>', 'Pack resolved JSON', y => y
|
|
52
|
+
.positional('file', { type: 'string' })
|
|
53
|
+
.option('out', { type: 'string', demandOption: true }),
|
|
54
|
+
argv => {
|
|
55
|
+
const doc = resolveJos(argv.file);
|
|
56
|
+
writeJSON(argv.out, doc);
|
|
57
|
+
console.log(`Packed to ${argv.out}`); // <-- antes usaba ${out}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
.command('publish <file>', 'Publish (stub)', y => y.positional('file', { type: 'string' }), () => {
|
|
28
61
|
console.warn('[stub] Forge publish not implemented in community build');
|
|
29
62
|
})
|
|
30
|
-
.command('test <file>', 'Run basic checks (stub)', y=> y.positional('file',{type:'string'}),
|
|
63
|
+
.command('test <file>', 'Run basic checks (stub)', y => y.positional('file', { type: 'string' }), () => {
|
|
31
64
|
console.warn('[stub] checks TBD');
|
|
32
65
|
})
|
|
33
|
-
.command('lint <path>', 'Lint (stub)', y=> y.positional('path',{type:'string'}),
|
|
66
|
+
.command('lint <path>', 'Lint (stub)', y => y.positional('path', { type: 'string' }), () => {
|
|
34
67
|
console.warn('[stub] lint TBD');
|
|
35
68
|
})
|
|
36
|
-
.demandCommand(1)
|
|
69
|
+
.demandCommand(1)
|
|
70
|
+
.help()
|
|
71
|
+
.parse();
|