fastdraw 0.2.0 → 0.2.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/README.md +20 -0
- package/dist/cli.js +119 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,6 +55,26 @@ npx fastdraw open docs/example.fdraw # edit in the browser; changes save to t
|
|
|
55
55
|
`fastdraw setup` supports Claude Code, Codex, OpenCode and GitHub Copilot. Chat assistants without a
|
|
56
56
|
shell can read the language from https://fastdraw.dev/llms.txt.
|
|
57
57
|
|
|
58
|
+
### Updating
|
|
59
|
+
|
|
60
|
+
The instructions `setup` writes are short: they tell the agent to run `fastdraw guide`, and the guide,
|
|
61
|
+
the kinds of diagram, the looks, `check` and `render` all come from the fastdraw that runs. Through
|
|
62
|
+
`npx fastdraw` that is the newest release, so most of an update arrives by itself.
|
|
63
|
+
|
|
64
|
+
The instruction files themselves change only when `setup` runs again. Each one carries the version that
|
|
65
|
+
wrote it, and when it is older than the fastdraw running, `fastdraw guide` starts with a note asking the
|
|
66
|
+
agent to tell you. To update them, run this in the repository; it rewrites the skill and replaces only
|
|
67
|
+
FastDraw's own section of `AGENTS.md` or Copilot's instructions:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
npx fastdraw@latest setup # or name them: setup claude agents copilot
|
|
71
|
+
npx fastdraw@latest setup claude --global # if you put the skill in ~/.claude
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If fastdraw is installed on the PATH (`npm install -g fastdraw`), agents use that copy instead of `npx`.
|
|
75
|
+
`fastdraw guide` checks npm for a newer release at most once a day and says so when there is one; update
|
|
76
|
+
with `npm install -g fastdraw@latest`. Set `FASTDRAW_NO_UPDATE_CHECK=1` to turn the check off; it is off on CI.
|
|
77
|
+
|
|
58
78
|
## Features
|
|
59
79
|
|
|
60
80
|
- **Checker.** Finds layout problems by measuring the drawn picture, not just parsing the text.
|
package/dist/cli.js
CHANGED
|
@@ -10307,8 +10307,8 @@ var init_iconSetAll = __esm({
|
|
|
10307
10307
|
});
|
|
10308
10308
|
|
|
10309
10309
|
// src/cli.ts
|
|
10310
|
-
import { readFileSync as
|
|
10311
|
-
import { dirname as
|
|
10310
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, readdirSync as readdirSync2, existsSync as existsSync4, statSync as statSync2 } from "node:fs";
|
|
10311
|
+
import { dirname as dirname5, join as join5, resolve as resolve4, basename as basename2 } from "node:path";
|
|
10312
10312
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
10313
10313
|
|
|
10314
10314
|
// src/node.ts
|
|
@@ -15300,11 +15300,14 @@ function about(md, name2) {
|
|
|
15300
15300
|
|
|
15301
15301
|
// src/setup.ts
|
|
15302
15302
|
import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, existsSync as existsSync3, mkdirSync, realpathSync as realpathSync3, lstatSync as lstatSync3 } from "node:fs";
|
|
15303
|
-
import { join as join3, relative as relative2, sep as sep3 } from "node:path";
|
|
15303
|
+
import { dirname as dirname3, join as join3, relative as relative2, resolve as resolve3, sep as sep3 } from "node:path";
|
|
15304
15304
|
import { homedir } from "node:os";
|
|
15305
15305
|
var TARGETS = ["claude", "agents", "copilot"];
|
|
15306
15306
|
var START = "<!-- fastdraw:start -->";
|
|
15307
15307
|
var END = "<!-- fastdraw:end -->";
|
|
15308
|
+
var STAMP = /<!-- fastdraw-version: ([\d.]+) -->/;
|
|
15309
|
+
var stamp = (version) => `<!-- fastdraw-version: ${version} -->`;
|
|
15310
|
+
var packageVersion = (root2) => JSON.parse(readFileSync3(join3(root2, "package.json"), "utf8")).version;
|
|
15308
15311
|
function snippet(root2) {
|
|
15309
15312
|
return readFileSync3(join3(root2, "agents", "AGENTS-snippet.md"), "utf8").replace(/^<!--.*?-->\s*/s, "").trim();
|
|
15310
15313
|
}
|
|
@@ -15332,8 +15335,9 @@ function prepare(base, file) {
|
|
|
15332
15335
|
if (!st && i < parts.length - 1) mkdirSync(at);
|
|
15333
15336
|
}
|
|
15334
15337
|
}
|
|
15335
|
-
function upsert(base, file, body) {
|
|
15338
|
+
function upsert(base, file, body, version) {
|
|
15336
15339
|
const block = `${START}
|
|
15340
|
+
${stamp(version)}
|
|
15337
15341
|
${body}
|
|
15338
15342
|
${END}`;
|
|
15339
15343
|
prepare(base, file);
|
|
@@ -15358,7 +15362,7 @@ function detect(dir) {
|
|
|
15358
15362
|
return found.length ? found : ["claude", "agents"];
|
|
15359
15363
|
}
|
|
15360
15364
|
function setup(root2, dir, targets, global = false) {
|
|
15361
|
-
const lines = [];
|
|
15365
|
+
const lines = [], version = packageVersion(root2);
|
|
15362
15366
|
const show = (f) => f.startsWith(dir) ? relative2(dir, f) : f.replace(homedir(), "~");
|
|
15363
15367
|
for (const t of targets) {
|
|
15364
15368
|
if (t === "claude") {
|
|
@@ -15367,23 +15371,108 @@ function setup(root2, dir, targets, global = false) {
|
|
|
15367
15371
|
const was = existsSync3(file);
|
|
15368
15372
|
if (global) mkdirSync(base, { recursive: true });
|
|
15369
15373
|
prepare(base, file);
|
|
15370
|
-
|
|
15374
|
+
const skill = readFileSync3(join3(root2, "agents", "claude-skill", "fastdraw", "SKILL.md"), "utf8");
|
|
15375
|
+
writeFileSync3(file, skill.replace(/^(---\r?\n[\s\S]*?\r?\n---\r?\n)/, `$1${stamp(version)}
|
|
15376
|
+
`));
|
|
15371
15377
|
lines.push(`${was ? "updated" : "wrote"} ${show(file)} (Claude Code skill)`);
|
|
15372
15378
|
} else {
|
|
15373
15379
|
const file = t === "agents" ? join3(dir, "AGENTS.md") : join3(dir, ".github", "copilot-instructions.md");
|
|
15374
|
-
lines.push(`${upsert(dir, file, snippet(root2))} ${show(file)} (${t === "agents" ? "Codex, OpenCode and other agents that read AGENTS.md" : "GitHub Copilot"})`);
|
|
15380
|
+
lines.push(`${upsert(dir, file, snippet(root2), version)} ${show(file)} (${t === "agents" ? "Codex, OpenCode and other agents that read AGENTS.md" : "GitHub Copilot"})`);
|
|
15375
15381
|
}
|
|
15376
15382
|
}
|
|
15377
15383
|
return lines;
|
|
15378
15384
|
}
|
|
15385
|
+
function compareVersions(a, b) {
|
|
15386
|
+
const x = a.split(".").map(Number), y = b.split(".").map(Number);
|
|
15387
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) - (y[i] ?? 0);
|
|
15388
|
+
return 0;
|
|
15389
|
+
}
|
|
15390
|
+
function installedSkills(dir, home = homedir()) {
|
|
15391
|
+
const out = [];
|
|
15392
|
+
const look = (target, file, global = false, section = false) => {
|
|
15393
|
+
let text;
|
|
15394
|
+
try {
|
|
15395
|
+
text = readFileSync3(file, "utf8");
|
|
15396
|
+
} catch {
|
|
15397
|
+
return;
|
|
15398
|
+
}
|
|
15399
|
+
if (section && !text.includes(START)) return;
|
|
15400
|
+
out.push({ target, file, version: STAMP.exec(text)?.[1] ?? "", global });
|
|
15401
|
+
};
|
|
15402
|
+
for (let at = resolve3(dir); ; at = dirname3(at)) {
|
|
15403
|
+
look("claude", join3(at, ".claude", "skills", "fastdraw", "SKILL.md"));
|
|
15404
|
+
look("agents", join3(at, "AGENTS.md"), false, true);
|
|
15405
|
+
look("copilot", join3(at, ".github", "copilot-instructions.md"), false, true);
|
|
15406
|
+
if (out.length || existsSync3(join3(at, ".git")) || dirname3(at) === at) break;
|
|
15407
|
+
}
|
|
15408
|
+
if (resolve3(home) !== resolve3(dir)) look("claude", join3(home, ".claude", "skills", "fastdraw", "SKILL.md"), true);
|
|
15409
|
+
return out;
|
|
15410
|
+
}
|
|
15411
|
+
function skillNotes(root2, dir, home = homedir()) {
|
|
15412
|
+
const version = packageVersion(root2), found = installedSkills(dir, home), notes = [];
|
|
15413
|
+
const from = (fs) => [...new Set(fs.map((f) => f.version || "0.2.0 or earlier"))].join(", ");
|
|
15414
|
+
const old = found.filter((f) => !f.version || compareVersions(f.version, version) < 0);
|
|
15415
|
+
const local = old.filter((f) => !f.global), global = old.filter((f) => f.global);
|
|
15416
|
+
if (local.length) {
|
|
15417
|
+
const files = local.map((f) => relative2(resolve3(dir), f.file) || f.file).join(", ");
|
|
15418
|
+
notes.push(`Note: this repository's FastDraw instructions (${files}) are from version ${from(local)}; this fastdraw is ${version}. Tell the person, and to update them run in the repository: npx fastdraw@latest setup ${[...new Set(local.map((f) => f.target))].join(" ")}`);
|
|
15419
|
+
}
|
|
15420
|
+
if (global.length) {
|
|
15421
|
+
notes.push(`Note: the FastDraw skill in ${global[0].file.replace(home, "~")} is from version ${from(global)}; this fastdraw is ${version}. Tell the person, and to update it run: npx fastdraw@latest setup claude --global`);
|
|
15422
|
+
}
|
|
15423
|
+
const newer = found.filter((f) => f.version && compareVersions(f.version, version) > 0);
|
|
15424
|
+
if (newer.length) {
|
|
15425
|
+
notes.push(`Note: this fastdraw is ${version}, older than the FastDraw instructions here (${newer[0].version}). Run it as npx fastdraw@latest instead, or update the installed one: npm install -g fastdraw@latest`);
|
|
15426
|
+
}
|
|
15427
|
+
return notes;
|
|
15428
|
+
}
|
|
15429
|
+
|
|
15430
|
+
// src/update.ts
|
|
15431
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
15432
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
15433
|
+
import { homedir as homedir2 } from "node:os";
|
|
15434
|
+
var DAY = 24 * 60 * 60 * 1e3;
|
|
15435
|
+
var URL2 = "https://registry.npmjs.org/fastdraw/latest";
|
|
15436
|
+
function cacheFile(env = process.env, home = homedir2(), platform = process.platform) {
|
|
15437
|
+
const base = platform === "win32" ? env.LOCALAPPDATA ?? join4(home, "AppData", "Local") : platform === "darwin" ? join4(home, "Library", "Caches") : env.XDG_CACHE_HOME ?? join4(home, ".cache");
|
|
15438
|
+
return join4(base, "fastdraw", "latest.json");
|
|
15439
|
+
}
|
|
15440
|
+
async function fromRegistry() {
|
|
15441
|
+
const r = await fetch(URL2, { signal: AbortSignal.timeout(1500), headers: { accept: "application/json" } });
|
|
15442
|
+
if (!r.ok) throw new Error(`npm answered ${r.status}`);
|
|
15443
|
+
return (await r.json()).version;
|
|
15444
|
+
}
|
|
15445
|
+
async function newerVersion(current, o = {}) {
|
|
15446
|
+
const env = o.env ?? process.env, now = o.now ?? Date.now(), file = o.file ?? cacheFile(env);
|
|
15447
|
+
if (env.FASTDRAW_NO_UPDATE_CHECK || env.CI) return null;
|
|
15448
|
+
let cached = null;
|
|
15449
|
+
try {
|
|
15450
|
+
cached = JSON.parse(readFileSync4(file, "utf8"));
|
|
15451
|
+
} catch {
|
|
15452
|
+
}
|
|
15453
|
+
let latest = cached?.latest ?? null;
|
|
15454
|
+
if (!cached || !(now - cached.checked < DAY)) {
|
|
15455
|
+
try {
|
|
15456
|
+
latest = await (o.fetchLatest ?? fromRegistry)();
|
|
15457
|
+
} catch {
|
|
15458
|
+
latest = null;
|
|
15459
|
+
}
|
|
15460
|
+
try {
|
|
15461
|
+
mkdirSync2(dirname4(file), { recursive: true });
|
|
15462
|
+
writeFileSync4(file, JSON.stringify({ checked: now, latest }));
|
|
15463
|
+
} catch {
|
|
15464
|
+
}
|
|
15465
|
+
}
|
|
15466
|
+
return latest && compareVersions(latest, current) > 0 ? latest : null;
|
|
15467
|
+
}
|
|
15379
15468
|
|
|
15380
15469
|
// src/cli.ts
|
|
15381
|
-
var root =
|
|
15470
|
+
var root = resolve4(dirname5(fileURLToPath2(import.meta.url)), "..");
|
|
15382
15471
|
function isWsl() {
|
|
15383
15472
|
if (process.platform !== "linux") return false;
|
|
15384
15473
|
if (process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP) return true;
|
|
15385
15474
|
try {
|
|
15386
|
-
return /microsoft/i.test(
|
|
15475
|
+
return /microsoft/i.test(readFileSync5("/proc/sys/kernel/osrelease", "utf8"));
|
|
15387
15476
|
} catch {
|
|
15388
15477
|
return false;
|
|
15389
15478
|
}
|
|
@@ -15448,7 +15537,7 @@ ${errors} error(s), ${warns} warning(s), ${hints} hint(s)` : "ok: no problems fo
|
|
|
15448
15537
|
function diagramFiles(paths) {
|
|
15449
15538
|
const files = [];
|
|
15450
15539
|
let folder = false;
|
|
15451
|
-
const walk = (dir) => readdirSync2(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".") && e.name !== "node_modules").flatMap((e) => e.isDirectory() ? walk(
|
|
15540
|
+
const walk = (dir) => readdirSync2(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".") && e.name !== "node_modules").flatMap((e) => e.isDirectory() ? walk(join5(dir, e.name)) : e.isFile() && e.name.endsWith(".fdraw") ? [join5(dir, e.name)] : []);
|
|
15452
15541
|
for (const p of paths) {
|
|
15453
15542
|
if (existsSync4(p) && statSync2(p).isDirectory()) {
|
|
15454
15543
|
folder = true;
|
|
@@ -15508,7 +15597,7 @@ ${files.length} files: ${errors} error(s), ${warns} warning(s), ${hints} hint(s)
|
|
|
15508
15597
|
if (ref) {
|
|
15509
15598
|
look = lookRefText(ref, file);
|
|
15510
15599
|
try {
|
|
15511
|
-
src = withLook(
|
|
15600
|
+
src = withLook(readFileSync5(file, "utf8"), look);
|
|
15512
15601
|
} catch {
|
|
15513
15602
|
}
|
|
15514
15603
|
}
|
|
@@ -15527,7 +15616,7 @@ ${files.length} files: ${errors} error(s), ${warns} warning(s), ${hints} hint(s)
|
|
|
15527
15616
|
if (!dark) continue;
|
|
15528
15617
|
let base = lookOver;
|
|
15529
15618
|
if (!base) try {
|
|
15530
|
-
base = lookOfDiagram(file,
|
|
15619
|
+
base = lookOfDiagram(file, readFileSync5(file, "utf8"));
|
|
15531
15620
|
} catch {
|
|
15532
15621
|
continue;
|
|
15533
15622
|
}
|
|
@@ -15554,11 +15643,11 @@ ${files.length} files: ${errors} error(s), ${warns} warning(s), ${hints} hint(s)
|
|
|
15554
15643
|
for (const { file, out, src, sc, look } of jobs) {
|
|
15555
15644
|
const svg = renderSvg(sc, void 0, { background: !transparent });
|
|
15556
15645
|
const payload = { v: 1, ...readSources(file, sc, src) };
|
|
15557
|
-
if (out.endsWith(".svg"))
|
|
15646
|
+
if (out.endsWith(".svg")) writeFileSync5(out, embed ? embedSvg(svg, payload) : svg);
|
|
15558
15647
|
else {
|
|
15559
15648
|
const fontFiles = withoutLigatureFonts([...bundledFonts(), ...sc.fontFiles ?? []]);
|
|
15560
15649
|
const png = new Uint8Array(new Resvg(svg, { font: { fontFiles, loadSystemFonts: true, defaultFontFamily: "Geist" }, fitTo: { mode: "zoom", value: scale } }).render().asPng());
|
|
15561
|
-
|
|
15650
|
+
writeFileSync5(out, embed ? embedPng(png, payload) : png);
|
|
15562
15651
|
}
|
|
15563
15652
|
const notes = [out.endsWith(".svg") ? "" : `at ${scale}x`, look ? `look ${look}` : "", transparent ? "no background" : "", embed ? "" : "no diagram inside"].filter(Boolean);
|
|
15564
15653
|
console.log(`wrote ${out} (${sc.w}x${sc.h}${notes.length ? ", " + notes.join(", ") : ""})`);
|
|
@@ -15573,7 +15662,7 @@ ${files.length} files: ${errors} error(s), ${warns} warning(s), ${hints} hint(s)
|
|
|
15573
15662
|
console.log(`${out} already exists; choose another path or remove it first`);
|
|
15574
15663
|
process.exit(1);
|
|
15575
15664
|
}
|
|
15576
|
-
|
|
15665
|
+
writeFileSync5(out, DEFAULT_LOOK);
|
|
15577
15666
|
console.log(`wrote ${out}. Point a diagram at it with: look "./${basename2(out)}"`);
|
|
15578
15667
|
} else if (cmd === "preview-look") {
|
|
15579
15668
|
const file = args.find((a, i) => !a.startsWith("-") && args[i - 1] !== "-o");
|
|
@@ -15668,13 +15757,13 @@ ${files.length} files: ${errors} error(s), ${warns} warning(s), ${hints} hint(s)
|
|
|
15668
15757
|
process.exit(1);
|
|
15669
15758
|
}
|
|
15670
15759
|
const svg = renderSvg(sc);
|
|
15671
|
-
if (out.endsWith(".svg"))
|
|
15760
|
+
if (out.endsWith(".svg")) writeFileSync5(out, svg);
|
|
15672
15761
|
else {
|
|
15673
15762
|
const { Resvg } = await import("@resvg/resvg-js");
|
|
15674
15763
|
const lf = lookFonts(file, look);
|
|
15675
15764
|
for (const fam2 of lf.missing) console.log(`warning: no font file found for "${fam2}"; it will be drawn in a fallback font`);
|
|
15676
15765
|
const fontFiles = withoutLigatureFonts([...bundledFonts(), ...lf.files]);
|
|
15677
|
-
|
|
15766
|
+
writeFileSync5(out, new Resvg(svg, { font: { fontFiles, loadSystemFonts: true, defaultFontFamily: "Geist" }, fitTo: { mode: "zoom", value: 2 } }).render().asPng());
|
|
15678
15767
|
}
|
|
15679
15768
|
console.log(`wrote ${out}: ${all.length} styles`);
|
|
15680
15769
|
} else if (cmd === "icons") {
|
|
@@ -15684,25 +15773,32 @@ ${files.length} files: ${errors} error(s), ${warns} warning(s), ${hints} hint(s)
|
|
|
15684
15773
|
console.log(names.length ? names.join("\n") : `no icon${word ? ` for "${word}"` : ""}`);
|
|
15685
15774
|
} else if (cmd === "guide") {
|
|
15686
15775
|
const topic = args[0];
|
|
15687
|
-
const file =
|
|
15688
|
-
const topics = readdirSync2(
|
|
15776
|
+
const file = join5(root, "guide", topic ? `${topic}.md` : "guide.md");
|
|
15777
|
+
const topics = readdirSync2(join5(root, "guide")).filter((f) => f.endsWith(".md") && f !== "guide.md").map((f) => f.slice(0, -3)).sort();
|
|
15689
15778
|
if (topic === "list") {
|
|
15690
15779
|
const width = Math.max(...topics.map((t) => t.length)) + 2;
|
|
15691
|
-
for (const t of topics) console.log(t.padEnd(width) + about(
|
|
15780
|
+
for (const t of topics) console.log(t.padEnd(width) + about(readFileSync5(join5(root, "guide", `${t}.md`), "utf8"), t).line);
|
|
15692
15781
|
process.exit(0);
|
|
15693
15782
|
}
|
|
15694
15783
|
if (!existsSync4(file) || /[\\/]/.test(topic ?? "")) {
|
|
15695
15784
|
console.log(`no guide called "${topic}". Topics: ${topics.join(", ")}`);
|
|
15696
15785
|
process.exit(1);
|
|
15697
15786
|
}
|
|
15698
|
-
|
|
15787
|
+
if (!topic) {
|
|
15788
|
+
const version = packageVersion(root);
|
|
15789
|
+
const notes = skillNotes(root, process.cwd());
|
|
15790
|
+
const newer = await newerVersion(version);
|
|
15791
|
+
if (newer) notes.push(`Note: fastdraw ${newer} is out; this is ${version}. Run it as npx fastdraw@latest, or update the installed one: npm install -g fastdraw@latest`);
|
|
15792
|
+
if (notes.length) console.log(notes.join("\n") + "\n");
|
|
15793
|
+
}
|
|
15794
|
+
console.log(readFileSync5(file, "utf8"));
|
|
15699
15795
|
} else if (cmd === "open") {
|
|
15700
15796
|
const file = args.find((a, i) => !a.startsWith("--") && args[i - 1] !== "--editor");
|
|
15701
15797
|
if (!file || !file.endsWith(".fdraw") || !existsSync4(file)) usage();
|
|
15702
15798
|
const ei = args.indexOf("--editor");
|
|
15703
15799
|
const editor = ei >= 0 ? args[ei + 1] : process.env.FASTDRAW_EDITOR ?? DEFAULT_EDITOR;
|
|
15704
|
-
const s = await serveFolder(
|
|
15705
|
-
console.log(`serving ${
|
|
15800
|
+
const s = await serveFolder(dirname5(resolve4(file)), { editor, open: basename2(file) });
|
|
15801
|
+
console.log(`serving ${dirname5(resolve4(file))} to the editor until this stops (Ctrl-C)
|
|
15706
15802
|
If no browser window opens, open this link:
|
|
15707
15803
|
${s.url}`);
|
|
15708
15804
|
if (!args.includes("--no-browser")) openBrowser(s.url);
|