Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions bin/plinth-sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ function parseArgs(argv) {
if (a === "-w" || a === "--watch") { args.watch = true; continue; }
if (a === "--check") { args.check = true; continue; }
if (a === "--no-signature") { args.signature = false; continue; }
if (a === "-o" || a === "--out") { args.out = argv[++i]; continue; }
if (a === "-o" || a === "--out") {
const next = argv[i + 1];
if (next === undefined || (next.startsWith("-") && next !== "-")) {
console.error(`plinth-sketch: ${a} requires a value (file path or '-' for stdout)`);
process.exit(2);
}
args.out = next;
i++;
continue;
}
if (a.startsWith("-") && a.length > 1 && a !== "-") {
console.error(`plinth-sketch: unknown option: ${a}`);
process.exit(2);
Expand Down Expand Up @@ -94,22 +103,20 @@ function emitSvg(dsl, args) {
const lay = layout(parsed);
const svg = render(parsed, lay, { signature: args.signature });

// Surface parse warnings on stderr (don't fail unless --check).
// Surface parse errors (unparsed lines) and warnings (undefined-node edges,
// self-loops) on stderr. --check will fail on either; default render won't.
if (parsed.errors.length) {
for (const err of parsed.errors) {
console.error(`plinth-sketch: warning: line ${err.line}: cannot parse: ${err.text}`);
console.error(`plinth-sketch: error: line ${err.line}: cannot parse: ${err.text}`);
}
}
const missing = new Set();
for (const e of parsed.edges) {
if (!parsed.nodes[e.from]) missing.add(e.from);
if (!parsed.nodes[e.to]) missing.add(e.to);
}
if (missing.size) {
console.error(`plinth-sketch: warning: edge references undefined nodes: ${[...missing].join(", ")}`);
const warnings = parsed.warnings || [];
for (const w of warnings) {
const where = w.line ? `line ${w.line}: ` : "";
console.error(`plinth-sketch: warning: ${where}${w.message}`);
}

const hasErrors = parsed.errors.length > 0 || missing.size > 0;
const hasErrors = parsed.errors.length > 0 || warnings.length > 0;
return { svg, hasErrors };
}

Expand Down
2 changes: 1 addition & 1 deletion examples/plinth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading