@wire-dsl/cli 0.0.1 → 0.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/LICENSE CHANGED
@@ -1,21 +1,36 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 WireDSL Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WireDSL Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ ## Third-Party Components & Assets
26
+
27
+ ### Feather Icons
28
+
29
+ This project includes icons from Feather Icons (https://feathericons.com), created by Cole Bemis and contributors.
30
+
31
+ - **License**: MIT License
32
+ - **Repository**: https://github.com/feathericons/feather
33
+ - **Location in project**: `packages/core/src/renderer/icons/`
34
+ - **Full details**: See `packages/core/src/renderer/icons/ICONS-LICENSE.md`
35
+
36
+ Feather Icons are used under the terms of the MIT License, which is fully compatible with this project's MIT License.
@@ -0,0 +1,253 @@
1
+ // src/cli.ts
2
+ import { program } from "commander";
3
+
4
+ // src/commands/render.ts
5
+ import { readFile, mkdir, stat } from "fs/promises";
6
+ import path from "path";
7
+ import chokidar from "chokidar";
8
+ import { LayoutEngine, SVGRenderer, generateIR, parseWireDSL, exportSVG, exportPNG, exportMultipagePDF } from "@wire-dsl/core";
9
+ var modules = {};
10
+ async function loadDependencies() {
11
+ if (!modules.chalk) {
12
+ const chalkModule = await import("chalk");
13
+ modules.chalk = chalkModule.default;
14
+ }
15
+ if (!modules.ora) {
16
+ try {
17
+ const oraModule = await import("ora");
18
+ modules.ora = oraModule.default;
19
+ } catch {
20
+ modules.ora = (msg) => ({
21
+ start: function() {
22
+ return this;
23
+ },
24
+ succeed: function() {
25
+ return this;
26
+ },
27
+ fail: function() {
28
+ return this;
29
+ }
30
+ });
31
+ }
32
+ }
33
+ return modules;
34
+ }
35
+ async function isDirectory(filePath) {
36
+ try {
37
+ const stats = await stat(filePath);
38
+ return stats.isDirectory();
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ function sanitizeScreenName(name) {
44
+ return name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
45
+ }
46
+ function detectFormat(filePath) {
47
+ const ext = path.extname(filePath).toLowerCase();
48
+ if (ext === ".pdf") return "pdf";
49
+ if (ext === ".png") return "png";
50
+ return "svg";
51
+ }
52
+ function resolveOutputFormat(options) {
53
+ if (options.pdf) return { format: "pdf", outputPath: options.pdf };
54
+ if (options.png) return { format: "png", outputPath: options.png };
55
+ if (options.svg) return { format: "svg", outputPath: options.svg };
56
+ if (options.out) {
57
+ return { format: detectFormat(options.out), outputPath: options.out };
58
+ }
59
+ return { format: "svg" };
60
+ }
61
+ var renderCommand = async (input, options = {}) => {
62
+ const resolvedInputPath = path.resolve(process.cwd(), input);
63
+ const { format, outputPath } = resolveOutputFormat(options);
64
+ const { chalk: chalk3, ora } = await loadDependencies();
65
+ const renderOnce = async () => {
66
+ const spinner = ora(`Rendering ${input}`).start();
67
+ try {
68
+ const source = await readFile(resolvedInputPath, "utf8");
69
+ const ast = parseWireDSL(source);
70
+ const ir = generateIR(ast);
71
+ const layout = new LayoutEngine(ir).calculate();
72
+ const baseViewport = ir.project.screens[0]?.viewport ?? { width: 1280, height: 720 };
73
+ let screensToRender = ir.project.screens;
74
+ if (options.screen) {
75
+ const found = ir.project.screens.find(
76
+ (s) => s.name.toLowerCase() === options.screen.toLowerCase()
77
+ );
78
+ if (!found) {
79
+ spinner.fail(`Screen not found: ${options.screen}`);
80
+ console.error(
81
+ chalk3.red(`Available screens: ${ir.project.screens.map((s) => s.name).join(", ")}`)
82
+ );
83
+ process.exitCode = 1;
84
+ return;
85
+ }
86
+ screensToRender = [found];
87
+ }
88
+ const basename = path.basename(resolvedInputPath, path.extname(resolvedInputPath));
89
+ const multiScreen = screensToRender.length > 1;
90
+ const renderedScreens = screensToRender.map((screen) => {
91
+ const viewport = screen.viewport ?? baseViewport;
92
+ const width = options.width ?? viewport.width;
93
+ const height = options.height ?? viewport.height;
94
+ const renderer = new SVGRenderer(ir, layout, {
95
+ width,
96
+ height,
97
+ theme: options.theme ?? "light",
98
+ includeLabels: true,
99
+ screenName: screen.name
100
+ });
101
+ return {
102
+ name: screen.name,
103
+ svg: renderer.render(),
104
+ width,
105
+ height
106
+ };
107
+ });
108
+ if (!outputPath) {
109
+ spinner.succeed("Rendered SVG");
110
+ process.stdout.write(renderedScreens[0].svg + "\n");
111
+ return;
112
+ }
113
+ const renderedFiles = [];
114
+ if (format === "pdf") {
115
+ let pdfPath = outputPath;
116
+ const isDir = await isDirectory(outputPath);
117
+ if (isDir) {
118
+ pdfPath = path.join(outputPath, `${basename}.pdf`);
119
+ } else if (!pdfPath.endsWith(".pdf")) {
120
+ pdfPath += ".pdf";
121
+ }
122
+ await exportMultipagePDF(renderedScreens, pdfPath);
123
+ renderedFiles.push(pdfPath);
124
+ spinner.succeed(
125
+ `PDF written to ${chalk3.cyan(pdfPath)} (${renderedScreens.length} page${renderedScreens.length > 1 ? "s" : ""})`
126
+ );
127
+ } else if (format === "png") {
128
+ const isDir = await isDirectory(outputPath);
129
+ let filePaths = [];
130
+ if (multiScreen && !isDir) {
131
+ spinner.warn("PNG export with multiple screens requires a directory");
132
+ const outputDir = path.dirname(outputPath);
133
+ await mkdir(outputDir, { recursive: true }).catch(() => {
134
+ });
135
+ for (const screen of renderedScreens) {
136
+ const sanitizedName = sanitizeScreenName(screen.name);
137
+ const fileName = `${basename}-${sanitizedName}.png`;
138
+ const filePath = path.join(outputDir, fileName);
139
+ await exportPNG(screen.svg, filePath, screen.width, screen.height);
140
+ filePaths.push(filePath);
141
+ }
142
+ } else if (multiScreen || isDir) {
143
+ const outputDir = isDir ? outputPath : path.dirname(outputPath);
144
+ await mkdir(outputDir, { recursive: true }).catch(() => {
145
+ });
146
+ for (const screen of renderedScreens) {
147
+ const sanitizedName = sanitizeScreenName(screen.name);
148
+ const fileName = multiScreen ? `${basename}-${sanitizedName}.png` : path.basename(outputPath).endsWith(".png") ? path.basename(outputPath) : `${basename}.png`;
149
+ const filePath = path.join(outputDir, fileName);
150
+ await exportPNG(screen.svg, filePath, screen.width, screen.height);
151
+ filePaths.push(filePath);
152
+ }
153
+ } else {
154
+ const outputDir = path.dirname(outputPath);
155
+ await mkdir(outputDir, { recursive: true }).catch(() => {
156
+ });
157
+ const screen = renderedScreens[0];
158
+ await exportPNG(screen.svg, outputPath, screen.width, screen.height);
159
+ filePaths.push(outputPath);
160
+ }
161
+ const renderedFiles2 = filePaths;
162
+ if (renderedFiles2.length === 1) {
163
+ spinner.succeed(`PNG written to ${chalk3.cyan(renderedFiles2[0])}`);
164
+ } else {
165
+ spinner.succeed(`${renderedFiles2.length} PNG files written:`);
166
+ renderedFiles2.forEach((file) => console.log(` ${chalk3.cyan(file)}`));
167
+ }
168
+ } else {
169
+ let outputDir = outputPath;
170
+ const isDir = await isDirectory(outputPath);
171
+ if (multiScreen || isDir) {
172
+ if (!isDir) {
173
+ outputDir = path.dirname(outputPath);
174
+ }
175
+ await mkdir(outputDir, { recursive: true }).catch(() => {
176
+ });
177
+ for (const screen of renderedScreens) {
178
+ const sanitizedName = sanitizeScreenName(screen.name);
179
+ const fileName = `${basename}-${sanitizedName}.svg`;
180
+ const filePath = path.join(outputDir, fileName);
181
+ await exportSVG(screen.svg, filePath);
182
+ renderedFiles.push(filePath);
183
+ }
184
+ spinner.succeed(`${renderedFiles.length} SVG files written:`);
185
+ renderedFiles.forEach((file) => console.log(` ${chalk3.cyan(file)}`));
186
+ } else {
187
+ await exportSVG(renderedScreens[0].svg, outputPath);
188
+ spinner.succeed(`SVG written to ${chalk3.cyan(outputPath)}`);
189
+ }
190
+ }
191
+ } catch (error) {
192
+ spinner.fail("Render failed");
193
+ const message = error?.message || "Unknown error";
194
+ console.error(chalk3.red(message));
195
+ process.exitCode = 1;
196
+ }
197
+ };
198
+ await renderOnce();
199
+ if (options.watch) {
200
+ console.log(chalk3.cyan(`Watching for changes: ${resolvedInputPath}`));
201
+ const watcher = chokidar.watch(resolvedInputPath, { ignoreInitial: true });
202
+ watcher.on("change", async () => {
203
+ await renderOnce();
204
+ });
205
+ }
206
+ };
207
+
208
+ // src/commands/validate.ts
209
+ import chalk from "chalk";
210
+ var validateCommand = async (input) => {
211
+ console.log(chalk.yellow("Validating:"), input);
212
+ };
213
+
214
+ // src/commands/init.ts
215
+ import chalk2 from "chalk";
216
+ var initCommand = async (name) => {
217
+ const projectName = name || "wire-project";
218
+ console.log(chalk2.green("Initializing:"), projectName);
219
+ };
220
+
221
+ // src/cli.ts
222
+ program.name("wire").description("WireDSL - Wireframes as Code").version("0.0.1", "-v, --version");
223
+ program.command("render <input>").description("Render .wire file (default: PDF when saving, SVG to stdout)").option(
224
+ "-o, --out <path>, --output <path>",
225
+ "Output path (auto-detects format: .pdf/.svg/.png or directory for PDF)"
226
+ ).option("--svg <path>", "Force SVG output (file or directory for multiple files)").option("--pdf <path>", "Force PDF output (single file with all screens as pages)").option("--png <path>", "Force PNG output (directory for multiple files)").option("-s, --screen <name>", "Render specific screen by name (defaults to all screens)").option("--width <number>", "Override viewport width").option("--height <number>", "Override viewport height").option("--theme <theme>", "Theme (light|dark)", "light").option("-w, --watch", "Watch input file and re-render on changes").action((input, options) => {
227
+ const width = options.width ? Number(options.width) : void 0;
228
+ const height = options.height ? Number(options.height) : void 0;
229
+ const theme = options.theme === "dark" ? "dark" : "light";
230
+ return renderCommand(input, {
231
+ out: options.out,
232
+ svg: options.svg,
233
+ pdf: options.pdf,
234
+ png: options.png,
235
+ screen: options.screen,
236
+ width,
237
+ height,
238
+ theme,
239
+ watch: Boolean(options.watch)
240
+ });
241
+ });
242
+ program.command("validate <input>").description("Validate .wire file syntax").action(validateCommand);
243
+ program.command("init [name]").description("Initialize a new WireDSL project").action(initCommand);
244
+ program.parse(process.argv);
245
+ if (!process.argv.slice(2).length) {
246
+ program.outputHelp();
247
+ }
248
+
249
+ export {
250
+ renderCommand,
251
+ validateCommand,
252
+ initCommand
253
+ };
package/dist/cli.cjs ADDED
@@ -0,0 +1,272 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli.ts
27
+ var import_commander = require("commander");
28
+
29
+ // src/commands/render.ts
30
+ var import_promises = require("fs/promises");
31
+ var import_path = __toESM(require("path"), 1);
32
+ var import_chokidar = __toESM(require("chokidar"), 1);
33
+ var import_core = require("@wire-dsl/core");
34
+ var modules = {};
35
+ async function loadDependencies() {
36
+ if (!modules.chalk) {
37
+ const chalkModule = await import("chalk");
38
+ modules.chalk = chalkModule.default;
39
+ }
40
+ if (!modules.ora) {
41
+ try {
42
+ const oraModule = await import("ora");
43
+ modules.ora = oraModule.default;
44
+ } catch {
45
+ modules.ora = (msg) => ({
46
+ start: function() {
47
+ return this;
48
+ },
49
+ succeed: function() {
50
+ return this;
51
+ },
52
+ fail: function() {
53
+ return this;
54
+ }
55
+ });
56
+ }
57
+ }
58
+ return modules;
59
+ }
60
+ async function isDirectory(filePath) {
61
+ try {
62
+ const stats = await (0, import_promises.stat)(filePath);
63
+ return stats.isDirectory();
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ function sanitizeScreenName(name) {
69
+ return name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
70
+ }
71
+ function detectFormat(filePath) {
72
+ const ext = import_path.default.extname(filePath).toLowerCase();
73
+ if (ext === ".pdf") return "pdf";
74
+ if (ext === ".png") return "png";
75
+ return "svg";
76
+ }
77
+ function resolveOutputFormat(options) {
78
+ if (options.pdf) return { format: "pdf", outputPath: options.pdf };
79
+ if (options.png) return { format: "png", outputPath: options.png };
80
+ if (options.svg) return { format: "svg", outputPath: options.svg };
81
+ if (options.out) {
82
+ return { format: detectFormat(options.out), outputPath: options.out };
83
+ }
84
+ return { format: "svg" };
85
+ }
86
+ var renderCommand = async (input, options = {}) => {
87
+ const resolvedInputPath = import_path.default.resolve(process.cwd(), input);
88
+ const { format, outputPath } = resolveOutputFormat(options);
89
+ const { chalk: chalk3, ora } = await loadDependencies();
90
+ const renderOnce = async () => {
91
+ const spinner = ora(`Rendering ${input}`).start();
92
+ try {
93
+ const source = await (0, import_promises.readFile)(resolvedInputPath, "utf8");
94
+ const ast = (0, import_core.parseWireDSL)(source);
95
+ const ir = (0, import_core.generateIR)(ast);
96
+ const layout = new import_core.LayoutEngine(ir).calculate();
97
+ const baseViewport = ir.project.screens[0]?.viewport ?? { width: 1280, height: 720 };
98
+ let screensToRender = ir.project.screens;
99
+ if (options.screen) {
100
+ const found = ir.project.screens.find(
101
+ (s) => s.name.toLowerCase() === options.screen.toLowerCase()
102
+ );
103
+ if (!found) {
104
+ spinner.fail(`Screen not found: ${options.screen}`);
105
+ console.error(
106
+ chalk3.red(`Available screens: ${ir.project.screens.map((s) => s.name).join(", ")}`)
107
+ );
108
+ process.exitCode = 1;
109
+ return;
110
+ }
111
+ screensToRender = [found];
112
+ }
113
+ const basename = import_path.default.basename(resolvedInputPath, import_path.default.extname(resolvedInputPath));
114
+ const multiScreen = screensToRender.length > 1;
115
+ const renderedScreens = screensToRender.map((screen) => {
116
+ const viewport = screen.viewport ?? baseViewport;
117
+ const width = options.width ?? viewport.width;
118
+ const height = options.height ?? viewport.height;
119
+ const renderer = new import_core.SVGRenderer(ir, layout, {
120
+ width,
121
+ height,
122
+ theme: options.theme ?? "light",
123
+ includeLabels: true,
124
+ screenName: screen.name
125
+ });
126
+ return {
127
+ name: screen.name,
128
+ svg: renderer.render(),
129
+ width,
130
+ height
131
+ };
132
+ });
133
+ if (!outputPath) {
134
+ spinner.succeed("Rendered SVG");
135
+ process.stdout.write(renderedScreens[0].svg + "\n");
136
+ return;
137
+ }
138
+ const renderedFiles = [];
139
+ if (format === "pdf") {
140
+ let pdfPath = outputPath;
141
+ const isDir = await isDirectory(outputPath);
142
+ if (isDir) {
143
+ pdfPath = import_path.default.join(outputPath, `${basename}.pdf`);
144
+ } else if (!pdfPath.endsWith(".pdf")) {
145
+ pdfPath += ".pdf";
146
+ }
147
+ await (0, import_core.exportMultipagePDF)(renderedScreens, pdfPath);
148
+ renderedFiles.push(pdfPath);
149
+ spinner.succeed(
150
+ `PDF written to ${chalk3.cyan(pdfPath)} (${renderedScreens.length} page${renderedScreens.length > 1 ? "s" : ""})`
151
+ );
152
+ } else if (format === "png") {
153
+ const isDir = await isDirectory(outputPath);
154
+ let filePaths = [];
155
+ if (multiScreen && !isDir) {
156
+ spinner.warn("PNG export with multiple screens requires a directory");
157
+ const outputDir = import_path.default.dirname(outputPath);
158
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
159
+ });
160
+ for (const screen of renderedScreens) {
161
+ const sanitizedName = sanitizeScreenName(screen.name);
162
+ const fileName = `${basename}-${sanitizedName}.png`;
163
+ const filePath = import_path.default.join(outputDir, fileName);
164
+ await (0, import_core.exportPNG)(screen.svg, filePath, screen.width, screen.height);
165
+ filePaths.push(filePath);
166
+ }
167
+ } else if (multiScreen || isDir) {
168
+ const outputDir = isDir ? outputPath : import_path.default.dirname(outputPath);
169
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
170
+ });
171
+ for (const screen of renderedScreens) {
172
+ const sanitizedName = sanitizeScreenName(screen.name);
173
+ const fileName = multiScreen ? `${basename}-${sanitizedName}.png` : import_path.default.basename(outputPath).endsWith(".png") ? import_path.default.basename(outputPath) : `${basename}.png`;
174
+ const filePath = import_path.default.join(outputDir, fileName);
175
+ await (0, import_core.exportPNG)(screen.svg, filePath, screen.width, screen.height);
176
+ filePaths.push(filePath);
177
+ }
178
+ } else {
179
+ const outputDir = import_path.default.dirname(outputPath);
180
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
181
+ });
182
+ const screen = renderedScreens[0];
183
+ await (0, import_core.exportPNG)(screen.svg, outputPath, screen.width, screen.height);
184
+ filePaths.push(outputPath);
185
+ }
186
+ const renderedFiles2 = filePaths;
187
+ if (renderedFiles2.length === 1) {
188
+ spinner.succeed(`PNG written to ${chalk3.cyan(renderedFiles2[0])}`);
189
+ } else {
190
+ spinner.succeed(`${renderedFiles2.length} PNG files written:`);
191
+ renderedFiles2.forEach((file) => console.log(` ${chalk3.cyan(file)}`));
192
+ }
193
+ } else {
194
+ let outputDir = outputPath;
195
+ const isDir = await isDirectory(outputPath);
196
+ if (multiScreen || isDir) {
197
+ if (!isDir) {
198
+ outputDir = import_path.default.dirname(outputPath);
199
+ }
200
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
201
+ });
202
+ for (const screen of renderedScreens) {
203
+ const sanitizedName = sanitizeScreenName(screen.name);
204
+ const fileName = `${basename}-${sanitizedName}.svg`;
205
+ const filePath = import_path.default.join(outputDir, fileName);
206
+ await (0, import_core.exportSVG)(screen.svg, filePath);
207
+ renderedFiles.push(filePath);
208
+ }
209
+ spinner.succeed(`${renderedFiles.length} SVG files written:`);
210
+ renderedFiles.forEach((file) => console.log(` ${chalk3.cyan(file)}`));
211
+ } else {
212
+ await (0, import_core.exportSVG)(renderedScreens[0].svg, outputPath);
213
+ spinner.succeed(`SVG written to ${chalk3.cyan(outputPath)}`);
214
+ }
215
+ }
216
+ } catch (error) {
217
+ spinner.fail("Render failed");
218
+ const message = error?.message || "Unknown error";
219
+ console.error(chalk3.red(message));
220
+ process.exitCode = 1;
221
+ }
222
+ };
223
+ await renderOnce();
224
+ if (options.watch) {
225
+ console.log(chalk3.cyan(`Watching for changes: ${resolvedInputPath}`));
226
+ const watcher = import_chokidar.default.watch(resolvedInputPath, { ignoreInitial: true });
227
+ watcher.on("change", async () => {
228
+ await renderOnce();
229
+ });
230
+ }
231
+ };
232
+
233
+ // src/commands/validate.ts
234
+ var import_chalk = __toESM(require("chalk"), 1);
235
+ var validateCommand = async (input) => {
236
+ console.log(import_chalk.default.yellow("Validating:"), input);
237
+ };
238
+
239
+ // src/commands/init.ts
240
+ var import_chalk2 = __toESM(require("chalk"), 1);
241
+ var initCommand = async (name) => {
242
+ const projectName = name || "wire-project";
243
+ console.log(import_chalk2.default.green("Initializing:"), projectName);
244
+ };
245
+
246
+ // src/cli.ts
247
+ import_commander.program.name("wire").description("WireDSL - Wireframes as Code").version("0.0.1", "-v, --version");
248
+ import_commander.program.command("render <input>").description("Render .wire file (default: PDF when saving, SVG to stdout)").option(
249
+ "-o, --out <path>, --output <path>",
250
+ "Output path (auto-detects format: .pdf/.svg/.png or directory for PDF)"
251
+ ).option("--svg <path>", "Force SVG output (file or directory for multiple files)").option("--pdf <path>", "Force PDF output (single file with all screens as pages)").option("--png <path>", "Force PNG output (directory for multiple files)").option("-s, --screen <name>", "Render specific screen by name (defaults to all screens)").option("--width <number>", "Override viewport width").option("--height <number>", "Override viewport height").option("--theme <theme>", "Theme (light|dark)", "light").option("-w, --watch", "Watch input file and re-render on changes").action((input, options) => {
252
+ const width = options.width ? Number(options.width) : void 0;
253
+ const height = options.height ? Number(options.height) : void 0;
254
+ const theme = options.theme === "dark" ? "dark" : "light";
255
+ return renderCommand(input, {
256
+ out: options.out,
257
+ svg: options.svg,
258
+ pdf: options.pdf,
259
+ png: options.png,
260
+ screen: options.screen,
261
+ width,
262
+ height,
263
+ theme,
264
+ watch: Boolean(options.watch)
265
+ });
266
+ });
267
+ import_commander.program.command("validate <input>").description("Validate .wire file syntax").action(validateCommand);
268
+ import_commander.program.command("init [name]").description("Initialize a new WireDSL project").action(initCommand);
269
+ import_commander.program.parse(process.argv);
270
+ if (!process.argv.slice(2).length) {
271
+ import_commander.program.outputHelp();
272
+ }
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "./chunk-MVVC2C2L.js";
package/dist/index.cjs ADDED
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ initCommand: () => initCommand,
34
+ renderCommand: () => renderCommand,
35
+ validateCommand: () => validateCommand
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/cli.ts
40
+ var import_commander = require("commander");
41
+
42
+ // src/commands/render.ts
43
+ var import_promises = require("fs/promises");
44
+ var import_path = __toESM(require("path"), 1);
45
+ var import_chokidar = __toESM(require("chokidar"), 1);
46
+ var import_core = require("@wire-dsl/core");
47
+ var modules = {};
48
+ async function loadDependencies() {
49
+ if (!modules.chalk) {
50
+ const chalkModule = await import("chalk");
51
+ modules.chalk = chalkModule.default;
52
+ }
53
+ if (!modules.ora) {
54
+ try {
55
+ const oraModule = await import("ora");
56
+ modules.ora = oraModule.default;
57
+ } catch {
58
+ modules.ora = (msg) => ({
59
+ start: function() {
60
+ return this;
61
+ },
62
+ succeed: function() {
63
+ return this;
64
+ },
65
+ fail: function() {
66
+ return this;
67
+ }
68
+ });
69
+ }
70
+ }
71
+ return modules;
72
+ }
73
+ async function isDirectory(filePath) {
74
+ try {
75
+ const stats = await (0, import_promises.stat)(filePath);
76
+ return stats.isDirectory();
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ function sanitizeScreenName(name) {
82
+ return name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
83
+ }
84
+ function detectFormat(filePath) {
85
+ const ext = import_path.default.extname(filePath).toLowerCase();
86
+ if (ext === ".pdf") return "pdf";
87
+ if (ext === ".png") return "png";
88
+ return "svg";
89
+ }
90
+ function resolveOutputFormat(options) {
91
+ if (options.pdf) return { format: "pdf", outputPath: options.pdf };
92
+ if (options.png) return { format: "png", outputPath: options.png };
93
+ if (options.svg) return { format: "svg", outputPath: options.svg };
94
+ if (options.out) {
95
+ return { format: detectFormat(options.out), outputPath: options.out };
96
+ }
97
+ return { format: "svg" };
98
+ }
99
+ var renderCommand = async (input, options = {}) => {
100
+ const resolvedInputPath = import_path.default.resolve(process.cwd(), input);
101
+ const { format, outputPath } = resolveOutputFormat(options);
102
+ const { chalk: chalk3, ora } = await loadDependencies();
103
+ const renderOnce = async () => {
104
+ const spinner = ora(`Rendering ${input}`).start();
105
+ try {
106
+ const source = await (0, import_promises.readFile)(resolvedInputPath, "utf8");
107
+ const ast = (0, import_core.parseWireDSL)(source);
108
+ const ir = (0, import_core.generateIR)(ast);
109
+ const layout = new import_core.LayoutEngine(ir).calculate();
110
+ const baseViewport = ir.project.screens[0]?.viewport ?? { width: 1280, height: 720 };
111
+ let screensToRender = ir.project.screens;
112
+ if (options.screen) {
113
+ const found = ir.project.screens.find(
114
+ (s) => s.name.toLowerCase() === options.screen.toLowerCase()
115
+ );
116
+ if (!found) {
117
+ spinner.fail(`Screen not found: ${options.screen}`);
118
+ console.error(
119
+ chalk3.red(`Available screens: ${ir.project.screens.map((s) => s.name).join(", ")}`)
120
+ );
121
+ process.exitCode = 1;
122
+ return;
123
+ }
124
+ screensToRender = [found];
125
+ }
126
+ const basename = import_path.default.basename(resolvedInputPath, import_path.default.extname(resolvedInputPath));
127
+ const multiScreen = screensToRender.length > 1;
128
+ const renderedScreens = screensToRender.map((screen) => {
129
+ const viewport = screen.viewport ?? baseViewport;
130
+ const width = options.width ?? viewport.width;
131
+ const height = options.height ?? viewport.height;
132
+ const renderer = new import_core.SVGRenderer(ir, layout, {
133
+ width,
134
+ height,
135
+ theme: options.theme ?? "light",
136
+ includeLabels: true,
137
+ screenName: screen.name
138
+ });
139
+ return {
140
+ name: screen.name,
141
+ svg: renderer.render(),
142
+ width,
143
+ height
144
+ };
145
+ });
146
+ if (!outputPath) {
147
+ spinner.succeed("Rendered SVG");
148
+ process.stdout.write(renderedScreens[0].svg + "\n");
149
+ return;
150
+ }
151
+ const renderedFiles = [];
152
+ if (format === "pdf") {
153
+ let pdfPath = outputPath;
154
+ const isDir = await isDirectory(outputPath);
155
+ if (isDir) {
156
+ pdfPath = import_path.default.join(outputPath, `${basename}.pdf`);
157
+ } else if (!pdfPath.endsWith(".pdf")) {
158
+ pdfPath += ".pdf";
159
+ }
160
+ await (0, import_core.exportMultipagePDF)(renderedScreens, pdfPath);
161
+ renderedFiles.push(pdfPath);
162
+ spinner.succeed(
163
+ `PDF written to ${chalk3.cyan(pdfPath)} (${renderedScreens.length} page${renderedScreens.length > 1 ? "s" : ""})`
164
+ );
165
+ } else if (format === "png") {
166
+ const isDir = await isDirectory(outputPath);
167
+ let filePaths = [];
168
+ if (multiScreen && !isDir) {
169
+ spinner.warn("PNG export with multiple screens requires a directory");
170
+ const outputDir = import_path.default.dirname(outputPath);
171
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
172
+ });
173
+ for (const screen of renderedScreens) {
174
+ const sanitizedName = sanitizeScreenName(screen.name);
175
+ const fileName = `${basename}-${sanitizedName}.png`;
176
+ const filePath = import_path.default.join(outputDir, fileName);
177
+ await (0, import_core.exportPNG)(screen.svg, filePath, screen.width, screen.height);
178
+ filePaths.push(filePath);
179
+ }
180
+ } else if (multiScreen || isDir) {
181
+ const outputDir = isDir ? outputPath : import_path.default.dirname(outputPath);
182
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
183
+ });
184
+ for (const screen of renderedScreens) {
185
+ const sanitizedName = sanitizeScreenName(screen.name);
186
+ const fileName = multiScreen ? `${basename}-${sanitizedName}.png` : import_path.default.basename(outputPath).endsWith(".png") ? import_path.default.basename(outputPath) : `${basename}.png`;
187
+ const filePath = import_path.default.join(outputDir, fileName);
188
+ await (0, import_core.exportPNG)(screen.svg, filePath, screen.width, screen.height);
189
+ filePaths.push(filePath);
190
+ }
191
+ } else {
192
+ const outputDir = import_path.default.dirname(outputPath);
193
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
194
+ });
195
+ const screen = renderedScreens[0];
196
+ await (0, import_core.exportPNG)(screen.svg, outputPath, screen.width, screen.height);
197
+ filePaths.push(outputPath);
198
+ }
199
+ const renderedFiles2 = filePaths;
200
+ if (renderedFiles2.length === 1) {
201
+ spinner.succeed(`PNG written to ${chalk3.cyan(renderedFiles2[0])}`);
202
+ } else {
203
+ spinner.succeed(`${renderedFiles2.length} PNG files written:`);
204
+ renderedFiles2.forEach((file) => console.log(` ${chalk3.cyan(file)}`));
205
+ }
206
+ } else {
207
+ let outputDir = outputPath;
208
+ const isDir = await isDirectory(outputPath);
209
+ if (multiScreen || isDir) {
210
+ if (!isDir) {
211
+ outputDir = import_path.default.dirname(outputPath);
212
+ }
213
+ await (0, import_promises.mkdir)(outputDir, { recursive: true }).catch(() => {
214
+ });
215
+ for (const screen of renderedScreens) {
216
+ const sanitizedName = sanitizeScreenName(screen.name);
217
+ const fileName = `${basename}-${sanitizedName}.svg`;
218
+ const filePath = import_path.default.join(outputDir, fileName);
219
+ await (0, import_core.exportSVG)(screen.svg, filePath);
220
+ renderedFiles.push(filePath);
221
+ }
222
+ spinner.succeed(`${renderedFiles.length} SVG files written:`);
223
+ renderedFiles.forEach((file) => console.log(` ${chalk3.cyan(file)}`));
224
+ } else {
225
+ await (0, import_core.exportSVG)(renderedScreens[0].svg, outputPath);
226
+ spinner.succeed(`SVG written to ${chalk3.cyan(outputPath)}`);
227
+ }
228
+ }
229
+ } catch (error) {
230
+ spinner.fail("Render failed");
231
+ const message = error?.message || "Unknown error";
232
+ console.error(chalk3.red(message));
233
+ process.exitCode = 1;
234
+ }
235
+ };
236
+ await renderOnce();
237
+ if (options.watch) {
238
+ console.log(chalk3.cyan(`Watching for changes: ${resolvedInputPath}`));
239
+ const watcher = import_chokidar.default.watch(resolvedInputPath, { ignoreInitial: true });
240
+ watcher.on("change", async () => {
241
+ await renderOnce();
242
+ });
243
+ }
244
+ };
245
+
246
+ // src/commands/validate.ts
247
+ var import_chalk = __toESM(require("chalk"), 1);
248
+ var validateCommand = async (input) => {
249
+ console.log(import_chalk.default.yellow("Validating:"), input);
250
+ };
251
+
252
+ // src/commands/init.ts
253
+ var import_chalk2 = __toESM(require("chalk"), 1);
254
+ var initCommand = async (name) => {
255
+ const projectName = name || "wire-project";
256
+ console.log(import_chalk2.default.green("Initializing:"), projectName);
257
+ };
258
+
259
+ // src/cli.ts
260
+ import_commander.program.name("wire").description("WireDSL - Wireframes as Code").version("0.0.1", "-v, --version");
261
+ import_commander.program.command("render <input>").description("Render .wire file (default: PDF when saving, SVG to stdout)").option(
262
+ "-o, --out <path>, --output <path>",
263
+ "Output path (auto-detects format: .pdf/.svg/.png or directory for PDF)"
264
+ ).option("--svg <path>", "Force SVG output (file or directory for multiple files)").option("--pdf <path>", "Force PDF output (single file with all screens as pages)").option("--png <path>", "Force PNG output (directory for multiple files)").option("-s, --screen <name>", "Render specific screen by name (defaults to all screens)").option("--width <number>", "Override viewport width").option("--height <number>", "Override viewport height").option("--theme <theme>", "Theme (light|dark)", "light").option("-w, --watch", "Watch input file and re-render on changes").action((input, options) => {
265
+ const width = options.width ? Number(options.width) : void 0;
266
+ const height = options.height ? Number(options.height) : void 0;
267
+ const theme = options.theme === "dark" ? "dark" : "light";
268
+ return renderCommand(input, {
269
+ out: options.out,
270
+ svg: options.svg,
271
+ pdf: options.pdf,
272
+ png: options.png,
273
+ screen: options.screen,
274
+ width,
275
+ height,
276
+ theme,
277
+ watch: Boolean(options.watch)
278
+ });
279
+ });
280
+ import_commander.program.command("validate <input>").description("Validate .wire file syntax").action(validateCommand);
281
+ import_commander.program.command("init [name]").description("Initialize a new WireDSL project").action(initCommand);
282
+ import_commander.program.parse(process.argv);
283
+ if (!process.argv.slice(2).length) {
284
+ import_commander.program.outputHelp();
285
+ }
286
+ // Annotate the CommonJS export names for ESM import in node:
287
+ 0 && (module.exports = {
288
+ initCommand,
289
+ renderCommand,
290
+ validateCommand
291
+ });
@@ -0,0 +1,18 @@
1
+ type RenderOptions = {
2
+ out?: string;
3
+ svg?: string;
4
+ pdf?: string;
5
+ png?: string;
6
+ screen?: string;
7
+ theme?: 'light' | 'dark';
8
+ width?: number;
9
+ height?: number;
10
+ watch?: boolean;
11
+ };
12
+ declare const renderCommand: (input: string, options?: RenderOptions) => Promise<void>;
13
+
14
+ declare const validateCommand: (input: string) => Promise<void>;
15
+
16
+ declare const initCommand: (name?: string) => Promise<void>;
17
+
18
+ export { initCommand, renderCommand, validateCommand };
@@ -0,0 +1,18 @@
1
+ type RenderOptions = {
2
+ out?: string;
3
+ svg?: string;
4
+ pdf?: string;
5
+ png?: string;
6
+ screen?: string;
7
+ theme?: 'light' | 'dark';
8
+ width?: number;
9
+ height?: number;
10
+ watch?: boolean;
11
+ };
12
+ declare const renderCommand: (input: string, options?: RenderOptions) => Promise<void>;
13
+
14
+ declare const validateCommand: (input: string) => Promise<void>;
15
+
16
+ declare const initCommand: (name?: string) => Promise<void>;
17
+
18
+ export { initCommand, renderCommand, validateCommand };
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ initCommand,
3
+ renderCommand,
4
+ validateCommand
5
+ } from "./chunk-MVVC2C2L.js";
6
+ export {
7
+ initCommand,
8
+ renderCommand,
9
+ validateCommand
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wire-dsl/cli",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "description": "WireDSL CLI - Command-line tool for wireframe generation and validation",
5
5
  "type": "module",
6
6
  "exports": {
@@ -31,20 +31,20 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "chalk": "^5.0.0",
35
- "commander": "^11.0.0",
36
- "ora": "^7.0.0",
37
- "sharp": "^0.33.0",
38
- "@wire-dsl/core": "0.0.1"
34
+ "chokidar": "5.0.0",
35
+ "chalk": "5.6.2",
36
+ "commander": "14.0.2",
37
+ "ora": "9.1.0",
38
+ "@wire-dsl/core": "0.1.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/node": "^20.10.0",
42
- "@typescript-eslint/eslint-plugin": "^6.16.0",
43
- "@typescript-eslint/parser": "^6.16.0",
44
- "eslint": "^8.56.0",
45
- "tsup": "^8.0.0",
46
- "typescript": "^5.3.0",
47
- "vitest": "^1.0.0"
41
+ "@types/node": "25.0.9",
42
+ "@typescript-eslint/eslint-plugin": "8.53.1",
43
+ "@typescript-eslint/parser": "8.53.1",
44
+ "eslint": "9.39.2",
45
+ "tsup": "8.5.1",
46
+ "typescript": "5.9.3",
47
+ "vitest": "4.0.17"
48
48
  },
49
49
  "engines": {
50
50
  "node": ">=20.0.0"