@openuji/speculator 0.3.0 → 0.3.2

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/README.md CHANGED
@@ -50,4 +50,24 @@ parseMarkdown('# Title', { markdownOptions: { extensions: [anchor] } });
50
50
  Each entry can be a plugin function or a `[plugin, options]` tuple and will be
51
51
  installed after the built-in ReSpec shorthand plugins.
52
52
 
53
+ ## Mermaid diagrams
54
+
55
+ Render [Mermaid](https://mermaid.js.org/) code blocks by enabling the
56
+ `mermaid` option when parsing Markdown:
57
+
58
+ ```ts
59
+ import { parseMarkdown } from '@openui/speculator';
60
+
61
+ const md = '```mermaid\nflowchart TD;A-->B;\n```';
62
+ const html = parseMarkdown(md, { mermaid: true });
63
+ ```
64
+
65
+ Configuration can be passed directly to Mermaid if needed:
66
+
67
+ ```ts
68
+ parseMarkdown(md, {
69
+ mermaid: { theme: 'forest' },
70
+ });
71
+ ```
72
+
53
73
 
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+
6
+ // Delegate to compiled CLI module
7
+ import { exportAssertions as doExportAssertions } from '../dist/cli/export-assertions.js';
8
+
9
+ function printUsage() {
10
+ const help = `
11
+ speculator <command> [options]
12
+
13
+ Commands:
14
+ export:assertion Export RFC2119 assertions to JSON
15
+
16
+ export:assertion options:
17
+ --input <path> Path to an index.spec.html (alternative to --spec/--version)
18
+ --spec <shortname> Spec shortname (e.g., ujse)
19
+ --version <version> Version (e.g., 1.0 or 1.0-draft)
20
+ --spec-dir <dir> Root directory containing product specs (default: env SPEC_DIR or ./spec)
21
+ --base <url> Base URL used to build assertion URLs (e.g., https://spec.openuji.dev/ujse/1.0/)
22
+ --out <file> Output file (default: assertions.json)
23
+ --strict Exit non-zero if multiple keywords found in a block
24
+ --help Show help
25
+ `;
26
+ process.stdout.write(help);
27
+ }
28
+
29
+ function parseArgs(argv) {
30
+ const args = {};
31
+ for (let i = 0; i < argv.length; i++) {
32
+ const a = argv[i];
33
+ if (!a.startsWith('--')) continue;
34
+ const key = a.slice(2);
35
+ const next = argv[i + 1];
36
+ if (key === 'strict' || key === 'help') {
37
+ args[key] = true;
38
+ } else if (next && !next.startsWith('--')) {
39
+ args[key] = next;
40
+ i++;
41
+ } else {
42
+ args[key] = true;
43
+ }
44
+ }
45
+ return args;
46
+ }
47
+
48
+ async function exportAssertions(rest) {
49
+ const args = parseArgs(rest);
50
+ if (args.help) {
51
+ printUsage();
52
+ process.exit(0);
53
+ }
54
+ const { exitCode } = await doExportAssertions(rest);
55
+ process.exit(exitCode);
56
+ }
57
+
58
+ async function main() {
59
+ const [, , cmd, ...rest] = process.argv;
60
+ if (!cmd || cmd === '--help' || cmd === 'help') {
61
+ printUsage();
62
+ process.exit(0);
63
+ }
64
+ if (cmd === 'export:assertion' || cmd === 'export:assertions') {
65
+ await exportAssertions(rest);
66
+ return;
67
+ }
68
+ process.stderr.write(`Unknown command: ${cmd}\n\n`);
69
+ printUsage();
70
+ process.exit(1);
71
+ }
72
+
73
+ main().catch(err => {
74
+ console.error(err);
75
+ process.exit(1);
76
+ });