@getvitops/cli 0.1.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,80 @@
1
+ # @getvitops/cli
2
+
3
+ CLI for the Vitops design-system generator. Turn a `design-system.json` into Bricks, CSS, or
4
+ Tailwind v4 output.
5
+
6
+ ```sh
7
+ # scaffold a starter config (stamps a $schema for editor autocomplete)
8
+ npx vitops init
9
+
10
+ # validate it against the schema
11
+ npx vitops validate design-system.json
12
+
13
+ # generate output (comma-separate formats)
14
+ npx vitops generate --input design-system.json --format tailwind --out src/styles
15
+ npx vitops generate --format bricks,css --out dist
16
+ ```
17
+
18
+ ## Commands
19
+
20
+ | command | does |
21
+ | -------------------------------------------------- | --------------------------------------------- |
22
+ | `vitops init [--out design-system.json] [--force]` | write a starter config with `$schema` |
23
+ | `vitops validate <file>` | schema-check (non-zero exit on error) |
24
+ | `vitops generate -i <file> -f <formats> -o <dir>` | generate `bricks` / `css` / `tailwind` output |
25
+
26
+ ## Using the output
27
+
28
+ **Tailwind / Astro (EmDash).** Generate into your styles dir and import it (Tailwind v4):
29
+
30
+ ```sh
31
+ vitops generate --input design-system.json --format tailwind --out src/styles
32
+ ```
33
+
34
+ ```css
35
+ @import './styles/tailwind.css';
36
+ ```
37
+
38
+ (Or use [`@getvitops/vite`](https://www.npmjs.com/package/@getvitops/vite) to generate on
39
+ build/dev automatically.)
40
+
41
+ **WordPress / Bricks.** `--format bricks` writes a full, deployable theme payload: the CSS
42
+ bundle, the Bricks color/variable import JSON, the JS bundles, the custom `bricks/` elements,
43
+ and the `docs/` reference. Generate it into your Bricks **child theme's `dist/` directory**:
44
+
45
+ ```sh
46
+ vitops generate --input design-system.json --format bricks --out wp-content/themes/bricks-child/dist
47
+ ```
48
+
49
+ Then wire it up **once** — add this to the child theme's `functions.php` so the deployed loader
50
+ registers the elements and enqueues the CSS/JS:
51
+
52
+ ```php
53
+ // Load the Vitops design system (elements + enqueued assets), if deployed.
54
+ $vitops = get_stylesheet_directory() . '/dist/bricks/load.php';
55
+ if ( file_exists( $vitops ) ) {
56
+ require_once $vitops;
57
+ }
58
+ ```
59
+
60
+ `dist/bricks/load.php` registers every element under a "Vitops" builder category, enqueues
61
+ `styles.min.css` + the JS bundles (versioned by mtime for cache-busting), and serves the
62
+ `docs/` bundle at `<theme>/dist/docs/`. Import `dist/bricks-colors-*.json` and
63
+ `dist/bricks-variables.json` into Bricks' Color + Variables managers.
64
+
65
+ ### Shipping the output
66
+
67
+ The CLI only writes files — how they reach WordPress is up to you:
68
+
69
+ - **Local dev (WPLocal etc.):** point `--out` straight at the site's theme `dist/`, or symlink
70
+ that `dist/` to your build output once so every regenerate is picked up automatically.
71
+ - **Remote:** rsync the generated directory to the theme over SSH —
72
+
73
+ ```sh
74
+ rsync -avz --delete dist/ user@host:wp-content/themes/bricks-child/dist/
75
+ ```
76
+
77
+ - **CI:** run `vitops generate --format bricks` in your pipeline and deploy the artifact the
78
+ same way you deploy the rest of the theme.
79
+
80
+ Powered by [`@getvitops/generator`](https://www.npmjs.com/package/@getvitops/generator).
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs ADDED
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { resolve } from "node:path";
5
+ import { SCHEMA_URL, defaultConfig, generate, validate } from "@getvitops/generator";
6
+ import { generateFavicons } from "@getvitops/utils";
7
+
8
+ //#region src/cli.ts
9
+ /**
10
+ * `vitops` — CLI for the Vitops design-system generator.
11
+ *
12
+ * vitops generate --input <json> --format <bricks|css|tailwind[,…]> --out <dir>
13
+ * vitops init [--out design-system.json] [--force]
14
+ * vitops validate <design-system.json>
15
+ * vitops favicon --input <svg|png> --out <dir> [--low-res <svg|png>]
16
+ *
17
+ * Thin wrapper over @getvitops/generator (generation) and @getvitops/utils (favicons).
18
+ * Every client brings their own consumer-editable design-system.json.
19
+ */
20
+ const FORMATS = new Set([
21
+ "bricks",
22
+ "css",
23
+ "tailwind"
24
+ ]);
25
+ const HELP = `vitops — generate design-system outputs from a design-system.json
26
+
27
+ Usage:
28
+ vitops generate [options] Generate platform output from a config
29
+ vitops init [options] Scaffold a starter design-system.json
30
+ vitops validate <file> Validate a config against the schema
31
+ vitops favicon [options] Generate a favicon set from a source image
32
+
33
+ Generate options:
34
+ -i, --input <path> Config file (default: ./design-system.json)
35
+ -f, --format <list> bricks | css | tailwind (comma-separated; default: bricks)
36
+ -o, --out <dir> Output directory (default: ./dist)
37
+
38
+ Init options:
39
+ -o, --out <path> Where to write (default: ./design-system.json)
40
+ --force Overwrite an existing file
41
+
42
+ Favicon options:
43
+ -i, --input <path> Source SVG or PNG (required)
44
+ -o, --out <dir> Output directory (default: ./public)
45
+ --low-res <path> Optional simplified source for the 16px icon
46
+
47
+ Common:
48
+ -h, --help Show this help
49
+ `;
50
+ function fail(msg) {
51
+ console.error(`✖ ${msg}`);
52
+ process.exit(1);
53
+ }
54
+ async function cmdGenerate(argv) {
55
+ const { values } = parseArgs({
56
+ args: argv,
57
+ options: {
58
+ input: {
59
+ type: "string",
60
+ short: "i",
61
+ default: "design-system.json"
62
+ },
63
+ format: {
64
+ type: "string",
65
+ short: "f",
66
+ default: "bricks"
67
+ },
68
+ out: {
69
+ type: "string",
70
+ short: "o",
71
+ default: "dist"
72
+ }
73
+ },
74
+ allowPositionals: false
75
+ });
76
+ const input = resolve(values.input);
77
+ if (!existsSync(input)) fail(`config not found: ${input}`);
78
+ const formats = values.format.split(",").map((f) => f.trim()).filter(Boolean);
79
+ for (const f of formats) if (!FORMATS.has(f)) fail(`unknown format "${f}" (expected: bricks | css | tailwind)`);
80
+ for (const format of formats) try {
81
+ const res = await generate({
82
+ input,
83
+ format,
84
+ outDir: values.out
85
+ });
86
+ console.log(`✓ ${format} → ${res.outDir} (${res.written.length} paths)`);
87
+ } catch (err) {
88
+ fail(err.message);
89
+ }
90
+ }
91
+ function cmdInit(argv) {
92
+ const { values } = parseArgs({
93
+ args: argv,
94
+ options: {
95
+ out: {
96
+ type: "string",
97
+ short: "o",
98
+ default: "design-system.json"
99
+ },
100
+ force: {
101
+ type: "boolean",
102
+ default: false
103
+ }
104
+ },
105
+ allowPositionals: false
106
+ });
107
+ const out = resolve(values.out);
108
+ if (existsSync(out) && !values.force) fail(`${out} already exists (use --force to overwrite)`);
109
+ writeFileSync(out, JSON.stringify(defaultConfig(), null, 2) + "\n");
110
+ console.log(`✓ wrote ${out}`);
111
+ console.log(` Edit it, then: vitops generate --input ${values.out} --format tailwind --out src/styles`);
112
+ console.log(` Editors read the "$schema" (${SCHEMA_URL}) for autocomplete + validation.`);
113
+ }
114
+ function cmdValidate(argv) {
115
+ const { values, positionals } = parseArgs({
116
+ args: argv,
117
+ options: { input: {
118
+ type: "string",
119
+ short: "i"
120
+ } },
121
+ allowPositionals: true
122
+ });
123
+ const path = resolve(positionals[0] ?? values.input ?? "design-system.json");
124
+ if (!existsSync(path)) fail(`config not found: ${path}`);
125
+ let raw;
126
+ try {
127
+ raw = JSON.parse(readFileSync(path, "utf8"));
128
+ } catch (err) {
129
+ fail(`could not parse JSON: ${err.message}`);
130
+ }
131
+ const result = validate(raw);
132
+ if (result.ok) {
133
+ console.log(`✓ ${path} is valid`);
134
+ return;
135
+ }
136
+ console.error(`✖ ${path} is invalid:`);
137
+ for (const e of result.errors) console.error(` • ${e.path.join(".") || "(root)"}: ${e.message}`);
138
+ process.exit(1);
139
+ }
140
+ async function cmdFavicon(argv) {
141
+ const { values } = parseArgs({
142
+ args: argv,
143
+ options: {
144
+ input: {
145
+ type: "string",
146
+ short: "i"
147
+ },
148
+ out: {
149
+ type: "string",
150
+ short: "o",
151
+ default: "public"
152
+ },
153
+ "low-res": { type: "string" }
154
+ },
155
+ allowPositionals: false
156
+ });
157
+ if (!values.input) fail("favicon: --input <svg|png> is required");
158
+ const source = resolve(values.input);
159
+ if (!existsSync(source)) fail(`source not found: ${source}`);
160
+ try {
161
+ const written = await generateFavicons({
162
+ source,
163
+ outputDir: values.out,
164
+ ...values["low-res"] ? { lowResSource: resolve(values["low-res"]) } : {}
165
+ });
166
+ console.log(`✓ favicons → ${values.out} (${written.length} files)`);
167
+ } catch (err) {
168
+ fail(err.message);
169
+ }
170
+ }
171
+ async function main() {
172
+ const [command, ...rest] = process.argv.slice(2);
173
+ if (!command || command === "-h" || command === "--help" || command === "help") {
174
+ console.log(HELP);
175
+ return;
176
+ }
177
+ switch (command) {
178
+ case "generate": return cmdGenerate(rest);
179
+ case "init": return cmdInit(rest);
180
+ case "validate": return cmdValidate(rest);
181
+ case "favicon": return cmdFavicon(rest);
182
+ default: fail(`unknown command "${command}" (expected: generate | init | validate). Try: vitops --help`);
183
+ }
184
+ }
185
+ main().catch((err) => fail(err.message));
186
+
187
+ //#endregion
188
+ export { };
189
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `vitops` — CLI for the Vitops design-system generator.\n *\n * vitops generate --input <json> --format <bricks|css|tailwind[,…]> --out <dir>\n * vitops init [--out design-system.json] [--force]\n * vitops validate <design-system.json>\n * vitops favicon --input <svg|png> --out <dir> [--low-res <svg|png>]\n *\n * Thin wrapper over @getvitops/generator (generation) and @getvitops/utils (favicons).\n * Every client brings their own consumer-editable design-system.json.\n */\nimport { parseArgs } from 'node:util';\nimport { writeFileSync, existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { generate, validate, defaultConfig, SCHEMA_URL, type Format } from '@getvitops/generator';\nimport { generateFavicons } from '@getvitops/utils';\n\nconst FORMATS = new Set<Format>(['bricks', 'css', 'tailwind']);\n\nconst HELP = `vitops — generate design-system outputs from a design-system.json\n\nUsage:\n vitops generate [options] Generate platform output from a config\n vitops init [options] Scaffold a starter design-system.json\n vitops validate <file> Validate a config against the schema\n vitops favicon [options] Generate a favicon set from a source image\n\nGenerate options:\n -i, --input <path> Config file (default: ./design-system.json)\n -f, --format <list> bricks | css | tailwind (comma-separated; default: bricks)\n -o, --out <dir> Output directory (default: ./dist)\n\nInit options:\n -o, --out <path> Where to write (default: ./design-system.json)\n --force Overwrite an existing file\n\nFavicon options:\n -i, --input <path> Source SVG or PNG (required)\n -o, --out <dir> Output directory (default: ./public)\n --low-res <path> Optional simplified source for the 16px icon\n\nCommon:\n -h, --help Show this help\n`;\n\nfunction fail(msg: string): never {\n console.error(`✖ ${msg}`);\n process.exit(1);\n}\n\nasync function cmdGenerate(argv: string[]) {\n const { values } = parseArgs({\n args: argv,\n options: {\n input: { type: 'string', short: 'i', default: 'design-system.json' },\n format: { type: 'string', short: 'f', default: 'bricks' },\n out: { type: 'string', short: 'o', default: 'dist' },\n },\n allowPositionals: false,\n });\n const input = resolve(values.input as string);\n if (!existsSync(input)) fail(`config not found: ${input}`);\n const formats = (values.format as string)\n .split(',')\n .map((f) => f.trim())\n .filter(Boolean);\n for (const f of formats)\n if (!FORMATS.has(f as Format))\n fail(`unknown format \"${f}\" (expected: bricks | css | tailwind)`);\n\n for (const format of formats as Format[]) {\n try {\n const res = await generate({ input, format, outDir: values.out as string });\n console.log(`✓ ${format} → ${res.outDir} (${res.written.length} paths)`);\n } catch (err) {\n fail((err as Error).message);\n }\n }\n}\n\nfunction cmdInit(argv: string[]) {\n const { values } = parseArgs({\n args: argv,\n options: {\n out: { type: 'string', short: 'o', default: 'design-system.json' },\n force: { type: 'boolean', default: false },\n },\n allowPositionals: false,\n });\n const out = resolve(values.out as string);\n if (existsSync(out) && !values.force) fail(`${out} already exists (use --force to overwrite)`);\n writeFileSync(out, JSON.stringify(defaultConfig(), null, 2) + '\\n');\n console.log(`✓ wrote ${out}`);\n console.log(\n ` Edit it, then: vitops generate --input ${values.out} --format tailwind --out src/styles`,\n );\n console.log(` Editors read the \"$schema\" (${SCHEMA_URL}) for autocomplete + validation.`);\n}\n\nfunction cmdValidate(argv: string[]) {\n const { values, positionals } = parseArgs({\n args: argv,\n options: { input: { type: 'string', short: 'i' } },\n allowPositionals: true,\n });\n const path = resolve((positionals[0] ?? values.input ?? 'design-system.json') as string);\n if (!existsSync(path)) fail(`config not found: ${path}`);\n let raw: unknown;\n try {\n raw = JSON.parse(readFileSync(path, 'utf8'));\n } catch (err) {\n fail(`could not parse JSON: ${(err as Error).message}`);\n }\n const result = validate(raw);\n if (result.ok) {\n console.log(`✓ ${path} is valid`);\n return;\n }\n console.error(`✖ ${path} is invalid:`);\n for (const e of result.errors) console.error(` • ${e.path.join('.') || '(root)'}: ${e.message}`);\n process.exit(1);\n}\n\nasync function cmdFavicon(argv: string[]) {\n const { values } = parseArgs({\n args: argv,\n options: {\n input: { type: 'string', short: 'i' },\n out: { type: 'string', short: 'o', default: 'public' },\n 'low-res': { type: 'string' },\n },\n allowPositionals: false,\n });\n if (!values.input) fail('favicon: --input <svg|png> is required');\n const source = resolve(values.input as string);\n if (!existsSync(source)) fail(`source not found: ${source}`);\n try {\n const written = await generateFavicons({\n source,\n outputDir: values.out as string,\n ...(values['low-res'] ? { lowResSource: resolve(values['low-res'] as string) } : {}),\n });\n console.log(`✓ favicons → ${values.out} (${written.length} files)`);\n } catch (err) {\n fail((err as Error).message);\n }\n}\n\nasync function main() {\n const [command, ...rest] = process.argv.slice(2);\n if (!command || command === '-h' || command === '--help' || command === 'help') {\n console.log(HELP);\n return;\n }\n switch (command) {\n case 'generate':\n return cmdGenerate(rest);\n case 'init':\n return cmdInit(rest);\n case 'validate':\n return cmdValidate(rest);\n case 'favicon':\n return cmdFavicon(rest);\n default:\n fail(\n `unknown command \"${command}\" (expected: generate | init | validate). Try: vitops --help`,\n );\n }\n}\n\nmain().catch((err) => fail((err as Error).message));\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAM,UAAU,IAAI,IAAY;CAAC;CAAU;CAAO;AAAU,CAAC;AAE7D,MAAM,OAAO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,IAAI,CAAC,WAAW,MAAM,GAAG,KAAK,qBAAqB,QAAQ;CAC3D,IAAI;EACF,MAAM,UAAU,MAAM,iBAAiB;GACrC;GACA,WAAW,OAAO;GAClB,GAAI,OAAO,aAAa,EAAE,cAAc,QAAQ,OAAO,UAAoB,EAAE,IAAI,CAAC;EACpF,CAAC;EACD,QAAQ,IAAI,gBAAgB,OAAO,IAAI,IAAI,QAAQ,OAAO,QAAQ;CACpE,SAAS,KAAK;EACZ,KAAM,IAAc,OAAO;CAC7B;AACF;AAEA,eAAe,OAAO;CACpB,MAAM,CAAC,SAAS,GAAG,QAAQ,QAAQ,KAAK,MAAM,CAAC;CAC/C,IAAI,CAAC,WAAW,YAAY,QAAQ,YAAY,YAAY,YAAY,QAAQ;EAC9E,QAAQ,IAAI,IAAI;EAChB;CACF;CACA,QAAQ,SAAR;EACE,KAAK,YACH,OAAO,YAAY,IAAI;EACzB,KAAK,QACH,OAAO,QAAQ,IAAI;EACrB,KAAK,YACH,OAAO,YAAY,IAAI;EACzB,KAAK,WACH,OAAO,WAAW,IAAI;EACxB,SACE,KACE,oBAAoB,QAAQ,6DAC9B;CACJ;AACF;AAEA,KAAK,CAAC,CAAC,OAAO,QAAQ,KAAM,IAAc,OAAO,CAAC"}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@getvitops/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for the Vitops design-system generator: generate, init, and validate a design-system.json.",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "vitops": "./dist/cli.mjs"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/cli.d.mts",
16
+ "import": "./dist/cli.mjs"
17
+ }
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "@getvitops/generator": "0.1.0",
24
+ "@getvitops/utils": "0.1.0"
25
+ }
26
+ }