@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.
Files changed (2) hide show
  1. package/bin/jos.js +56 -21
  2. 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'; import yargs from 'yargs'; import fs from 'node:fs';
3
- import { validate } from '../lib/validate.js'; import { resolveJos } from '../lib/resolve.js';
4
- import { run } from '../lib/run.js'; import { serve } from '../lib/serve.js';
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
- .command('validate <file>', 'Validate .jos v0.3.1', y=> y.positional('file',{type:'string'}), argv=>{
11
- const res = validate(argv.file); if (!res.ok) { console.error('Schema errors:', res.errors); process.exit(1); } console.log('OK ✅');
12
- })
13
- .command('run <file>', 'Run task/pipeline', y=> y.positional('file',{type:'string'}), async argv=>{
14
- const { doc } = validate(argv.file); const flags={}; for (const [k,v] of Object.entries(argv)) if (k.startsWith('eval.')) flags[k]=v;
15
- const code = await run(doc, flags); process.exit(code);
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
- .command('doc <file> --out <out>', 'Generate docs', y=> y.positional('file',{type:'string'}).option('out',{type:'string', demandOption:true}), argv=>{
21
- const { doc } = validate(argv.file); const tasks=(doc.tasks||[]).map(t=>`- **${t.id}** \`${t.runner}${t.action?':'+t.action:''}\``).join('\n');
22
- const md = `# ${doc.name}\n\nSchema: ${doc.schema}\n\n## Tasks\n${tasks}\n`; fs.writeFileSync(argv.out, md, 'utf8'); console.log(`Doc written to ${argv.out}`);
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
- .command('pack <file> --out <out>', 'Pack resolved JSON', y=> y.positional('file',{type:'string'}).option('out',{type:'string', demandOption:true}), argv=>{
25
- const doc = resolveJos(argv.file); writeJSON(argv.out, doc); console.log(`Packed to ${out}`);
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
- .command('publish <file>', 'Publish (stub)', y=> y.positional('file',{type:'string'}), argv=>{
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'}), argv=>{
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'}), argv=>{
66
+ .command('lint <path>', 'Lint (stub)', y => y.positional('path', { type: 'string' }), () => {
34
67
  console.warn('[stub] lint TBD');
35
68
  })
36
- .demandCommand(1).help().parse();
69
+ .demandCommand(1)
70
+ .help()
71
+ .parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@josfox/jos",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "JOSFOX CLI \u2014 .jos v3.1 community runtime (validate/run/serve/pack/publish/doc/test/lint)",
5
5
  "license": "MIT",
6
6
  "type": "module",