@mdocui/cli 0.0.1 → 0.4.0

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 ADDED
@@ -0,0 +1,79 @@
1
+ # @mdocui/cli
2
+
3
+ CLI for [mdocUI](https://github.com/mdocui/mdocui) — scaffold projects, generate system prompts, and preview output.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npx @mdocui/cli init
9
+ ```
10
+
11
+ Or install globally:
12
+
13
+ ```bash
14
+ pnpm add -g @mdocui/cli
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ### `init`
20
+
21
+ Scaffold a new mdocUI config file with starter components.
22
+
23
+ ```bash
24
+ npx @mdocui/cli init
25
+ ```
26
+
27
+ Creates:
28
+ - `mdocui.config.ts` — component definitions and config
29
+ - `generated/` — output directory for system prompts
30
+
31
+ ### `generate`
32
+
33
+ Generate a system prompt from your component registry and write it to a file.
34
+
35
+ ```bash
36
+ npx @mdocui/cli generate
37
+ ```
38
+
39
+ Reads `mdocui.config.ts` and writes the prompt to the configured `output` path (default: `system-prompt.txt`).
40
+
41
+ ### `preview`
42
+
43
+ Print the generated system prompt to stdout for review.
44
+
45
+ ```bash
46
+ npx @mdocui/cli preview
47
+ ```
48
+
49
+ ## Config File
50
+
51
+ ```typescript
52
+ // mdocui.config.ts
53
+ import { defineComponent } from '@mdocui/core'
54
+ import { z } from 'zod'
55
+
56
+ const button = defineComponent({
57
+ name: 'button',
58
+ description: 'Clickable action button',
59
+ props: z.object({
60
+ action: z.string().describe('Action to perform'),
61
+ label: z.string().describe('Button text'),
62
+ }),
63
+ children: 'none',
64
+ })
65
+
66
+ export default {
67
+ components: [button],
68
+ output: './generated/system-prompt.txt',
69
+ preamble: 'You are a helpful assistant.',
70
+ additionalRules: ['End responses with follow-up buttons'],
71
+ groups: [{ name: 'Interactive', components: ['button'] }],
72
+ }
73
+ ```
74
+
75
+ ## Links
76
+
77
+ - [GitHub Repository](https://github.com/mdocui/mdocui)
78
+ - [@mdocui/core](https://github.com/mdocui/mdocui/tree/main/packages/core)
79
+ - [@mdocui/react](https://github.com/mdocui/mdocui/tree/main/packages/react)
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/commands/generate.ts
4
+ import fs2 from "fs";
5
+ import path2 from "path";
6
+ import { ComponentRegistry, generatePrompt } from "@mdocui/core";
7
+
8
+ // src/config.ts
9
+ import { pathToFileURL } from "url";
10
+ import path from "path";
11
+ import fs from "fs";
12
+ var CONFIG_FILES = [
13
+ "mdocui.config.ts",
14
+ "mdocui.config.js",
15
+ "mdocui.config.mjs"
16
+ ];
17
+ async function loadConfig(cwd2) {
18
+ for (const name of CONFIG_FILES) {
19
+ const configPath = path.resolve(cwd2, name);
20
+ if (!fs.existsSync(configPath)) continue;
21
+ const url = pathToFileURL(configPath).href;
22
+ const mod = await import(url);
23
+ const config = mod.default ?? mod;
24
+ if (!config.components || !Array.isArray(config.components)) {
25
+ throw new Error(`${name}: "components" must be an array of ComponentDefinition`);
26
+ }
27
+ return config;
28
+ }
29
+ throw new Error(
30
+ `No config file found. Create one of: ${CONFIG_FILES.join(", ")}`
31
+ );
32
+ }
33
+ function toPromptOptions(config) {
34
+ return {
35
+ preamble: config.preamble,
36
+ additionalRules: config.additionalRules,
37
+ examples: config.examples,
38
+ groups: config.groups
39
+ };
40
+ }
41
+
42
+ // src/commands/generate.ts
43
+ async function generate(cwd2) {
44
+ const config = await loadConfig(cwd2);
45
+ const registry = new ComponentRegistry();
46
+ registry.registerAll(config.components);
47
+ const prompt = generatePrompt(registry, toPromptOptions(config));
48
+ const outputPath = path2.resolve(cwd2, config.output ?? "system-prompt.txt");
49
+ fs2.mkdirSync(path2.dirname(outputPath), { recursive: true });
50
+ fs2.writeFileSync(outputPath, prompt, "utf-8");
51
+ console.log(`Generated system prompt \u2192 ${path2.relative(cwd2, outputPath)}`);
52
+ console.log(`${registry.names().length} components, ${prompt.length} chars`);
53
+ }
54
+
55
+ // src/commands/init.ts
56
+ import fs3 from "fs";
57
+ import path3 from "path";
58
+ var CONFIG_TEMPLATE = `import { defineComponent } from '@mdocui/core'
59
+ import { z } from 'zod'
60
+
61
+ const button = defineComponent({
62
+ name: 'button',
63
+ description: 'Clickable action button',
64
+ props: z.object({
65
+ action: z.string().describe('Action to perform'),
66
+ label: z.string().describe('Button text'),
67
+ }),
68
+ children: 'none',
69
+ })
70
+
71
+ const callout = defineComponent({
72
+ name: 'callout',
73
+ description: 'Highlighted message block',
74
+ props: z.object({
75
+ type: z.enum(['info', 'warning', 'error', 'success']).describe('Severity'),
76
+ title: z.string().optional().describe('Heading'),
77
+ }),
78
+ children: 'any',
79
+ })
80
+
81
+ export default {
82
+ components: [button, callout],
83
+ output: './generated/system-prompt.txt',
84
+ preamble: 'You are a helpful assistant.',
85
+ additionalRules: [
86
+ 'End responses with follow-up buttons using action="continue"',
87
+ ],
88
+ }
89
+ `;
90
+ async function init(cwd2) {
91
+ const configPath = path3.resolve(cwd2, "mdocui.config.ts");
92
+ const generatedDir = path3.resolve(cwd2, "generated");
93
+ if (fs3.existsSync(configPath)) {
94
+ console.log("mdocui.config.ts already exists \u2014 skipping");
95
+ return;
96
+ }
97
+ fs3.writeFileSync(configPath, CONFIG_TEMPLATE, "utf-8");
98
+ fs3.mkdirSync(generatedDir, { recursive: true });
99
+ fs3.writeFileSync(
100
+ path3.resolve(generatedDir, ".gitkeep"),
101
+ "",
102
+ "utf-8"
103
+ );
104
+ console.log("Created:");
105
+ console.log(" mdocui.config.ts \u2014 component definitions + config");
106
+ console.log(" generated/ \u2014 output directory for system prompts");
107
+ console.log("");
108
+ console.log("Next steps:");
109
+ console.log(" 1. Edit mdocui.config.ts \u2014 add your components");
110
+ console.log(" 2. Run: npx @mdocui/cli generate");
111
+ }
112
+
113
+ // src/commands/preview.ts
114
+ import { ComponentRegistry as ComponentRegistry2, generatePrompt as generatePrompt2 } from "@mdocui/core";
115
+ async function preview(cwd2) {
116
+ const config = await loadConfig(cwd2);
117
+ const registry = new ComponentRegistry2();
118
+ registry.registerAll(config.components);
119
+ const prompt = generatePrompt2(registry, toPromptOptions(config));
120
+ console.log(prompt);
121
+ }
122
+
123
+ // src/index.ts
124
+ var args = process.argv.slice(2);
125
+ var command = args[0];
126
+ var cwd = process.cwd();
127
+ async function main() {
128
+ switch (command) {
129
+ case "generate":
130
+ await generate(cwd);
131
+ break;
132
+ case "preview":
133
+ await preview(cwd);
134
+ break;
135
+ case "init":
136
+ await init(cwd);
137
+ break;
138
+ case "--help":
139
+ case "-h":
140
+ case void 0:
141
+ printHelp();
142
+ break;
143
+ default:
144
+ console.error(`Unknown command: ${command}`);
145
+ printHelp();
146
+ process.exit(1);
147
+ }
148
+ }
149
+ function printHelp() {
150
+ console.log(`
151
+ mdocui \u2014 CLI for mdocUI generative UI library
152
+
153
+ Commands:
154
+ init Scaffold a new mdocui config file
155
+ generate Generate system prompt from component registry
156
+ preview Print generated system prompt to stdout
157
+
158
+ Usage:
159
+ npx @mdocui/cli init
160
+ npx @mdocui/cli generate
161
+ npx @mdocui/cli preview
162
+ `);
163
+ }
164
+ main().catch((err) => {
165
+ console.error(err.message);
166
+ process.exit(1);
167
+ });
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/generate.ts","../src/config.ts","../src/commands/init.ts","../src/commands/preview.ts","../src/index.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { ComponentRegistry, generatePrompt } from '@mdocui/core'\nimport { loadConfig, toPromptOptions } from '../config'\n\nexport async function generate(cwd: string) {\n\tconst config = await loadConfig(cwd)\n\tconst registry = new ComponentRegistry()\n\tregistry.registerAll(config.components)\n\n\tconst prompt = generatePrompt(registry, toPromptOptions(config))\n\tconst outputPath = path.resolve(cwd, config.output ?? 'system-prompt.txt')\n\n\tfs.mkdirSync(path.dirname(outputPath), { recursive: true })\n\tfs.writeFileSync(outputPath, prompt, 'utf-8')\n\n\tconsole.log(`Generated system prompt → ${path.relative(cwd, outputPath)}`)\n\tconsole.log(`${registry.names().length} components, ${prompt.length} chars`)\n}\n","import { pathToFileURL } from 'node:url'\nimport path from 'node:path'\nimport fs from 'node:fs'\nimport type { ComponentDefinition, ComponentGroup, PromptOptions } from '@mdocui/core'\n\nexport interface MdocUIConfig {\n\tcomponents: ComponentDefinition[]\n\toutput?: string\n\tpreamble?: string\n\tadditionalRules?: string[]\n\texamples?: string[]\n\tgroups?: ComponentGroup[]\n}\n\nconst CONFIG_FILES = [\n\t'mdocui.config.ts',\n\t'mdocui.config.js',\n\t'mdocui.config.mjs',\n]\n\nexport async function loadConfig(cwd: string): Promise<MdocUIConfig> {\n\tfor (const name of CONFIG_FILES) {\n\t\tconst configPath = path.resolve(cwd, name)\n\t\tif (!fs.existsSync(configPath)) continue\n\n\t\tconst url = pathToFileURL(configPath).href\n\t\tconst mod = await import(url)\n\t\tconst config = mod.default ?? mod\n\n\t\tif (!config.components || !Array.isArray(config.components)) {\n\t\t\tthrow new Error(`${name}: \"components\" must be an array of ComponentDefinition`)\n\t\t}\n\n\t\treturn config as MdocUIConfig\n\t}\n\n\tthrow new Error(\n\t\t`No config file found. Create one of: ${CONFIG_FILES.join(', ')}`,\n\t)\n}\n\nexport function toPromptOptions(config: MdocUIConfig): PromptOptions {\n\treturn {\n\t\tpreamble: config.preamble,\n\t\tadditionalRules: config.additionalRules,\n\t\texamples: config.examples,\n\t\tgroups: config.groups,\n\t}\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nconst CONFIG_TEMPLATE = `import { defineComponent } from '@mdocui/core'\nimport { z } from 'zod'\n\nconst button = defineComponent({\n name: 'button',\n description: 'Clickable action button',\n props: z.object({\n action: z.string().describe('Action to perform'),\n label: z.string().describe('Button text'),\n }),\n children: 'none',\n})\n\nconst callout = defineComponent({\n name: 'callout',\n description: 'Highlighted message block',\n props: z.object({\n type: z.enum(['info', 'warning', 'error', 'success']).describe('Severity'),\n title: z.string().optional().describe('Heading'),\n }),\n children: 'any',\n})\n\nexport default {\n components: [button, callout],\n output: './generated/system-prompt.txt',\n preamble: 'You are a helpful assistant.',\n additionalRules: [\n 'End responses with follow-up buttons using action=\"continue\"',\n ],\n}\n`\n\nexport async function init(cwd: string) {\n\tconst configPath = path.resolve(cwd, 'mdocui.config.ts')\n\tconst generatedDir = path.resolve(cwd, 'generated')\n\n\tif (fs.existsSync(configPath)) {\n\t\tconsole.log('mdocui.config.ts already exists — skipping')\n\t\treturn\n\t}\n\n\tfs.writeFileSync(configPath, CONFIG_TEMPLATE, 'utf-8')\n\tfs.mkdirSync(generatedDir, { recursive: true })\n\tfs.writeFileSync(\n\t\tpath.resolve(generatedDir, '.gitkeep'),\n\t\t'',\n\t\t'utf-8',\n\t)\n\n\tconsole.log('Created:')\n\tconsole.log(' mdocui.config.ts — component definitions + config')\n\tconsole.log(' generated/ — output directory for system prompts')\n\tconsole.log('')\n\tconsole.log('Next steps:')\n\tconsole.log(' 1. Edit mdocui.config.ts — add your components')\n\tconsole.log(' 2. Run: npx @mdocui/cli generate')\n}\n","import { ComponentRegistry, generatePrompt } from '@mdocui/core'\nimport { loadConfig, toPromptOptions } from '../config'\n\nexport async function preview(cwd: string) {\n\tconst config = await loadConfig(cwd)\n\tconst registry = new ComponentRegistry()\n\tregistry.registerAll(config.components)\n\n\tconst prompt = generatePrompt(registry, toPromptOptions(config))\n\tconsole.log(prompt)\n}\n","import { generate } from './commands/generate'\nimport { init } from './commands/init'\nimport { preview } from './commands/preview'\n\nconst args = process.argv.slice(2)\nconst command = args[0]\nconst cwd = process.cwd()\n\nasync function main() {\n\tswitch (command) {\n\t\tcase 'generate':\n\t\t\tawait generate(cwd)\n\t\t\tbreak\n\t\tcase 'preview':\n\t\t\tawait preview(cwd)\n\t\t\tbreak\n\t\tcase 'init':\n\t\t\tawait init(cwd)\n\t\t\tbreak\n\t\tcase '--help':\n\t\tcase '-h':\n\t\tcase undefined:\n\t\t\tprintHelp()\n\t\t\tbreak\n\t\tdefault:\n\t\t\tconsole.error(`Unknown command: ${command}`)\n\t\t\tprintHelp()\n\t\t\tprocess.exit(1)\n\t}\n}\n\nfunction printHelp() {\n\tconsole.log(`\nmdocui — CLI for mdocUI generative UI library\n\nCommands:\n init Scaffold a new mdocui config file\n generate Generate system prompt from component registry\n preview Print generated system prompt to stdout\n\nUsage:\n npx @mdocui/cli init\n npx @mdocui/cli generate\n npx @mdocui/cli preview\n`)\n}\n\nmain().catch((err) => {\n\tconsole.error(err.message)\n\tprocess.exit(1)\n})\n"],"mappings":";;;AAAA,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,SAAS,mBAAmB,sBAAsB;;;ACFlD,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,OAAO,QAAQ;AAYf,IAAM,eAAe;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACD;AAEA,eAAsB,WAAWC,MAAoC;AACpE,aAAW,QAAQ,cAAc;AAChC,UAAM,aAAa,KAAK,QAAQA,MAAK,IAAI;AACzC,QAAI,CAAC,GAAG,WAAW,UAAU,EAAG;AAEhC,UAAM,MAAM,cAAc,UAAU,EAAE;AACtC,UAAM,MAAM,MAAM,OAAO;AACzB,UAAM,SAAS,IAAI,WAAW;AAE9B,QAAI,CAAC,OAAO,cAAc,CAAC,MAAM,QAAQ,OAAO,UAAU,GAAG;AAC5D,YAAM,IAAI,MAAM,GAAG,IAAI,wDAAwD;AAAA,IAChF;AAEA,WAAO;AAAA,EACR;AAEA,QAAM,IAAI;AAAA,IACT,wCAAwC,aAAa,KAAK,IAAI,CAAC;AAAA,EAChE;AACD;AAEO,SAAS,gBAAgB,QAAqC;AACpE,SAAO;AAAA,IACN,UAAU,OAAO;AAAA,IACjB,iBAAiB,OAAO;AAAA,IACxB,UAAU,OAAO;AAAA,IACjB,QAAQ,OAAO;AAAA,EAChB;AACD;;;AD3CA,eAAsB,SAASC,MAAa;AAC3C,QAAM,S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,IAAI,aAAa;AACzB,UAAQ,IAAI,uDAAkD;AAC9D,UAAQ,IAAI,oCAAoC;AACjD;;;AC5DA,SAAS,qBAAAE,oBAAmB,kBAAAC,uBAAsB;AAGlD,eAAsB,QAAQC,MAAa;AAC1C,QAAM,SAAS,MAAM,WAAWA,IAAG;AACnC,QAAM,WAAW,IAAIC,mBAAkB;AACvC,WAAS,YAAY,OAAO,UAAU;AAEtC,QAAM,SAASC,gBAAe,UAAU,gBAAgB,MAAM,CAAC;AAC/D,UAAQ,IAAI,MAAM;AACnB;;;ACNA,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,UAAU,KAAK,CAAC;AACtB,IAAM,MAAM,QAAQ,IAAI;AAExB,eAAe,OAAO;AACrB,UAAQ,SAAS;AAAA,IAChB,KAAK;AACJ,YAAM,SAAS,GAAG;AAClB;AAAA,IACD,KAAK;AACJ,YAAM,QAAQ,GAAG;AACjB;AAAA,IACD,KAAK;AACJ,YAAM,KAAK,GAAG;AACd;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,gBAAU;AACV;AAAA,IACD;AACC,cAAQ,MAAM,oBAAoB,OAAO,EAAE;AAC3C,gBAAU;AACV,cAAQ,KAAK,CAAC;AAAA,EAChB;AACD;AAEA,SAAS,YAAY;AACpB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAYZ;AACD;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACrB,UAAQ,MAAM,IAAI,OAAO;AACzB,UAAQ,KAAK,CAAC;AACf,CAAC;","names":["fs","path","cwd","cwd","path","fs","fs","path","cwd","ComponentRegistry","generatePrompt","cwd","ComponentRegistry","generatePrompt"]}
package/package.json CHANGED
@@ -1,16 +1,24 @@
1
1
  {
2
2
  "name": "@mdocui/cli",
3
- "version": "0.0.1",
3
+ "version": "0.4.0",
4
4
  "description": "CLI for mdocUI — scaffold, generate system prompts, preview",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "mdocui": "./dist/index.js"
8
8
  },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
9
11
  "files": [
10
12
  "dist"
11
13
  ],
12
14
  "dependencies": {
13
- "@mdocui/core": "0.1.2"
15
+ "zod": "^4.3.0",
16
+ "@mdocui/core": "0.4.0"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^25.5.0",
20
+ "tsup": "^8.5.1",
21
+ "vitest": "^4.1.0"
14
22
  },
15
23
  "license": "MIT",
16
24
  "repository": {
@@ -22,7 +30,8 @@
22
30
  "access": "public"
23
31
  },
24
32
  "scripts": {
25
- "build": "echo 'stub — no build yet'",
33
+ "build": "tsup",
34
+ "test": "vitest run",
26
35
  "clean": "rm -rf dist"
27
36
  }
28
37
  }