@vinena/knobs 0.6.6 → 0.7.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/CHANGELOG.md +8 -0
- package/README.md +11 -5
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/dist/cli.d.ts +95 -0
- package/dist/cli.js +527 -0
- package/dist/edit/keep.d.ts +1 -1
- package/dist/{elementsview-dpm0xmb2.js → elementsview-jg4edt86.js} +6 -6
- package/dist/{elementsview-n26sp8m7.js → elementsview-m33ejs4r.js} +6 -6
- package/dist/{framekit-0as9t6a7.js → framekit-40pzennw.js} +3 -3
- package/dist/{framekit-dknq662p.js → framekit-r16k97n7.js} +3 -3
- package/dist/{index-r1rdj05c.js → index-0qkj2mgb.js} +4 -4
- package/dist/{index-whehz74d.js → index-2jc9dnta.js} +21 -1
- package/dist/{index-7w0nm76e.js → index-3nwycv3p.js} +3 -3
- package/dist/{index-x3sxssbs.js → index-8d1yk9d2.js} +8 -8
- package/dist/{index-ajs4na3f.js → index-cb91vcka.js} +1 -1
- package/dist/{index-20bc9yrj.js → index-fjrrgd9h.js} +1 -1
- package/dist/{index-df35z48z.js → index-q53j8wg5.js} +2 -2
- package/dist/{index-7vb2ct4s.js → index-s6fya8pm.js} +4 -4
- package/dist/{index-dxga6h10.js → index-tqq2ygpj.js} +2 -2
- package/dist/{index-69fvtkcm.js → index-v2v4rmpe.js} +3 -3
- package/dist/{index-t4wrs2a3.js → index-xxbb8y41.js} +3 -3
- package/dist/index.global.js +127 -110
- package/dist/index.js +63 -23
- package/dist/{react-msn10fjb.js → react-0gxs9aef.js} +3 -3
- package/dist/{react-2b7725je.js → react-3ev6rwqz.js} +2 -2
- package/dist/{react-k4pkm1p5.js → react-6ngtb6p9.js} +1 -1
- package/dist/{react-5ekfj7g3.js → react-8nmtt0ge.js} +2 -2
- package/dist/{react-y9gr8yt2.js → react-actmnkwp.js} +1 -1
- package/dist/{react-v08ywmtw.js → react-fq4551ks.js} +4 -4
- package/dist/{react-vbk58f9m.js → react-meve34wp.js} +21 -1
- package/dist/{react-10r2rczp.js → react-vvc4x9kq.js} +4 -4
- package/dist/{react-a1r0nr0g.js → react-zp7fdw8e.js} +8 -8
- package/dist/react.js +63 -23
- package/dist/{replay-461gcdh1.js → replay-m5g8km9y.js} +4 -4
- package/dist/{replay-ehgxp9py.js → replay-pmesjfa3.js} +4 -4
- package/dist/{storageview-5p1y11b5.js → storageview-9a6zm47z.js} +8 -8
- package/dist/{storageview-kxzpnfvr.js → storageview-x62v1c3j.js} +8 -8
- package/dist/ui/icons.d.ts +5 -2
- package/dist/ui/panel.d.ts +2 -0
- package/dist/ui/settings.d.ts +11 -1
- package/package.json +5 -2
- package/skills/{devknobs → knobs}/SKILL.md +18 -18
package/dist/cli.js
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
var MESSAGES = {
|
|
9
|
+
install: {
|
|
10
|
+
npm: "npm i -D @vinena/knobs",
|
|
11
|
+
pnpm: "pnpm add -D @vinena/knobs",
|
|
12
|
+
yarn: "yarn add -D @vinena/knobs",
|
|
13
|
+
bun: "bun add -d @vinena/knobs"
|
|
14
|
+
},
|
|
15
|
+
next: "Render that component once in app/layout (App Router) or pages/_app (Pages Router).",
|
|
16
|
+
entry: 'call if (import.meta.env.DEV) import("@vinena/knobs").then(({ mount }) => mount()); in the client entry, or in a mount effect of the root component in an SSR app.',
|
|
17
|
+
plain: 'add <script src="//unpkg.com/@vinena/knobs/dist/index.global.js"></script> to the page. It mounts itself. Keep it out of the deployed page.',
|
|
18
|
+
production: "Keep knobs out of production builds. A static import stays in the bundle even behind a dev check, so gate the import itself as above. If the project has a build script, run it and check that the output has no knobs.",
|
|
19
|
+
early: 'If the app reads media queries, the time or the user agent while it boots, or renders with React, add the early script as the first element in <head>, in development only: <script src="//unpkg.com/@vinena/knobs/dist/early.global.js"></script>',
|
|
20
|
+
open: "press ⇧K, or click the handle on the right edge of the window, to open the panel.",
|
|
21
|
+
reference: "the full reference, every detail in one file, is at https://knobs.dev/llms-full.txt",
|
|
22
|
+
created: (path) => `created ${path}`,
|
|
23
|
+
changed: (path) => `changed ${path}`,
|
|
24
|
+
unchanged: (path) => `no change: ${path}`,
|
|
25
|
+
unknown: "not found",
|
|
26
|
+
dryRun: "dry run",
|
|
27
|
+
usage: "usage: knobs init [--dry-run]",
|
|
28
|
+
packageJson: "error: package.json",
|
|
29
|
+
writeFailed: (path, code) => `error: ${path} ${code}`
|
|
30
|
+
};
|
|
31
|
+
var MOUNTS = /(?:\bfrom\s*|\bimport\s*\(\s*)(["'])@vinena\/knobs(?:\/react)?\1/;
|
|
32
|
+
function scan(text) {
|
|
33
|
+
const cuts = [];
|
|
34
|
+
const holes = [];
|
|
35
|
+
let inTemplate = false;
|
|
36
|
+
let last = "";
|
|
37
|
+
let lastAt = -1;
|
|
38
|
+
let plainUntil = -1;
|
|
39
|
+
let i = 0;
|
|
40
|
+
while (i < text.length) {
|
|
41
|
+
if (inTemplate) {
|
|
42
|
+
const start = i;
|
|
43
|
+
while (i < text.length && text[i] !== "`" && !(text[i] === "$" && text[i + 1] === "{"))
|
|
44
|
+
i += text[i] === "\\" ? 2 : 1;
|
|
45
|
+
cuts.push({ start, end: Math.min(i, text.length), comment: false });
|
|
46
|
+
if (i >= text.length)
|
|
47
|
+
break;
|
|
48
|
+
if (text[i] === "`") {
|
|
49
|
+
inTemplate = false;
|
|
50
|
+
last = "`";
|
|
51
|
+
i += 1;
|
|
52
|
+
} else {
|
|
53
|
+
holes.push(0);
|
|
54
|
+
inTemplate = false;
|
|
55
|
+
last = "{";
|
|
56
|
+
i += 2;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const c = text[i] ?? "";
|
|
61
|
+
const next = text[i + 1];
|
|
62
|
+
if (c === "/" && next === "/") {
|
|
63
|
+
let end = text.indexOf(`
|
|
64
|
+
`, i);
|
|
65
|
+
if (end < 0)
|
|
66
|
+
end = text.length;
|
|
67
|
+
else if (text[end - 1] === "\r")
|
|
68
|
+
end -= 1;
|
|
69
|
+
cuts.push({ start: i, end, comment: true });
|
|
70
|
+
i = end;
|
|
71
|
+
} else if (c === "/" && next === "*") {
|
|
72
|
+
const close = text.indexOf("*/", i + 2);
|
|
73
|
+
const end = close < 0 ? text.length : close + 2;
|
|
74
|
+
cuts.push({ start: i, end, comment: true });
|
|
75
|
+
i = end;
|
|
76
|
+
} else if (c === "/" && i > plainUntil && (last === "" || "(,=:[!&|?{;".includes(last) || last === ">" && text[lastAt - 1] === "=" || /(?:^|[^\w$.])(?:return|typeof|case|do|else|in|of|new|delete|void|throw|yield|await|instanceof)$/.test(text.slice(Math.max(0, lastAt - 10), lastAt + 1)))) {
|
|
77
|
+
let j = i + 1;
|
|
78
|
+
let inClass = false;
|
|
79
|
+
while (j < text.length && text[j] !== `
|
|
80
|
+
` && (inClass || text[j] !== "/")) {
|
|
81
|
+
if (text[j] === "\\")
|
|
82
|
+
j += 1;
|
|
83
|
+
else if (text[j] === "[")
|
|
84
|
+
inClass = true;
|
|
85
|
+
else if (text[j] === "]")
|
|
86
|
+
inClass = false;
|
|
87
|
+
j += 1;
|
|
88
|
+
}
|
|
89
|
+
if (text[j] === "/") {
|
|
90
|
+
cuts.push({ start: i + 1, end: j, comment: false });
|
|
91
|
+
i = j + 1;
|
|
92
|
+
} else {
|
|
93
|
+
plainUntil = j;
|
|
94
|
+
i += 1;
|
|
95
|
+
}
|
|
96
|
+
last = "/";
|
|
97
|
+
} else if (c === '"' || c === "'") {
|
|
98
|
+
let j = i + 1;
|
|
99
|
+
while (j < text.length && text[j] !== c && text[j] !== `
|
|
100
|
+
`)
|
|
101
|
+
j += text[j] === "\\" ? 2 : 1;
|
|
102
|
+
cuts.push({ start: i + 1, end: Math.min(j, text.length), comment: false });
|
|
103
|
+
i = text[j] === c ? j + 1 : j;
|
|
104
|
+
last = c;
|
|
105
|
+
} else if (c === "`") {
|
|
106
|
+
inTemplate = true;
|
|
107
|
+
i += 1;
|
|
108
|
+
} else {
|
|
109
|
+
const top = holes.length - 1;
|
|
110
|
+
const open = holes[top];
|
|
111
|
+
if (open !== undefined && c === "{")
|
|
112
|
+
holes[top] = open + 1;
|
|
113
|
+
if (open !== undefined && c === "}") {
|
|
114
|
+
if (open === 0) {
|
|
115
|
+
holes.pop();
|
|
116
|
+
inTemplate = true;
|
|
117
|
+
i += 1;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
holes[top] = open - 1;
|
|
121
|
+
}
|
|
122
|
+
if (!/\s/.test(c)) {
|
|
123
|
+
last = c;
|
|
124
|
+
lastAt = i;
|
|
125
|
+
}
|
|
126
|
+
i += 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const blank = (all) => {
|
|
130
|
+
const parts = [];
|
|
131
|
+
let at = 0;
|
|
132
|
+
for (const cut of cuts) {
|
|
133
|
+
if (!all && !cut.comment)
|
|
134
|
+
continue;
|
|
135
|
+
parts.push(text.slice(at, cut.start), " ".repeat(cut.end - cut.start));
|
|
136
|
+
at = cut.end;
|
|
137
|
+
}
|
|
138
|
+
parts.push(text.slice(at));
|
|
139
|
+
return parts.join("");
|
|
140
|
+
};
|
|
141
|
+
return { code: blank(false), bare: blank(true) };
|
|
142
|
+
}
|
|
143
|
+
function lastImportEnd(text, bare) {
|
|
144
|
+
let found = null;
|
|
145
|
+
let from = 0;
|
|
146
|
+
for (;; ) {
|
|
147
|
+
const at = bare.indexOf("import", from);
|
|
148
|
+
if (at < 0)
|
|
149
|
+
return found;
|
|
150
|
+
from = at + 6;
|
|
151
|
+
if (at > 0 && bare[at - 1] !== `
|
|
152
|
+
` || /[\w$]/.test(bare[at + 6] ?? ""))
|
|
153
|
+
continue;
|
|
154
|
+
let quote = from;
|
|
155
|
+
while (quote < bare.length && !"\"';`".includes(bare[quote] ?? "") && !bare.startsWith(`
|
|
156
|
+
import`, quote))
|
|
157
|
+
quote += 1;
|
|
158
|
+
from = quote;
|
|
159
|
+
const q = bare[quote];
|
|
160
|
+
if (q !== '"' && q !== "'")
|
|
161
|
+
continue;
|
|
162
|
+
const clause = bare.slice(at + 6, quote).trimEnd();
|
|
163
|
+
if (clause !== "" && !(clause.endsWith("from") && !/[\w$]/.test(clause.at(-5) ?? "")))
|
|
164
|
+
continue;
|
|
165
|
+
const close = bare.indexOf(q, quote + 1);
|
|
166
|
+
if (close < 0 || !/^ +$/.test(bare.slice(quote + 1, close)))
|
|
167
|
+
continue;
|
|
168
|
+
let end = close + 1;
|
|
169
|
+
if (bare[end] === ";")
|
|
170
|
+
end += 1;
|
|
171
|
+
while (bare[end] === " " || bare[end] === "\t")
|
|
172
|
+
end += 1;
|
|
173
|
+
from = end;
|
|
174
|
+
if (end === text.length || text[end] === `
|
|
175
|
+
`)
|
|
176
|
+
found = text[end - 1] === "\r" ? end - 1 : end;
|
|
177
|
+
else if (text[end] === "\r" && text[end + 1] === `
|
|
178
|
+
`)
|
|
179
|
+
found = end;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function directiveEnd(text, bare) {
|
|
183
|
+
let end = 0;
|
|
184
|
+
let at = 0;
|
|
185
|
+
for (;; ) {
|
|
186
|
+
while (at < bare.length && /\s/.test(bare[at] ?? ""))
|
|
187
|
+
at += 1;
|
|
188
|
+
const directive = /(["'])use \w+\1/y;
|
|
189
|
+
directive.lastIndex = at;
|
|
190
|
+
if (!directive.test(text))
|
|
191
|
+
return end;
|
|
192
|
+
const line = /;?[ \t]*(?:\/\/[^\r\n]*)?\r?\n/y;
|
|
193
|
+
line.lastIndex = directive.lastIndex;
|
|
194
|
+
if (!line.test(text))
|
|
195
|
+
return null;
|
|
196
|
+
end = line.lastIndex;
|
|
197
|
+
at = end;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
var RELATIVE_IMPORTS = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+)(["'])(\.\.?\/[^"']+)\1/g;
|
|
201
|
+
function eolOf(text) {
|
|
202
|
+
return text.includes(`\r
|
|
203
|
+
`) ? `\r
|
|
204
|
+
` : `
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
var MOUNT_LINE = 'if (import.meta.env.DEV) import("@vinena/knobs").then(({ mount }) => mount());';
|
|
208
|
+
var COMPONENT_NAME = "dev-knobs";
|
|
209
|
+
var COMPONENT = [
|
|
210
|
+
'"use client";',
|
|
211
|
+
"",
|
|
212
|
+
'import dynamic from "next/dynamic";',
|
|
213
|
+
"",
|
|
214
|
+
'const DevKnobs = process.env.NODE_ENV === "development" ? dynamic(() => import("@vinena/knobs/react").then((m) => m.DevKnobs), { ssr: false }) : null;',
|
|
215
|
+
"",
|
|
216
|
+
"export function DevPanel() {",
|
|
217
|
+
" return <>{DevKnobs && <DevKnobs />}</>;",
|
|
218
|
+
"}",
|
|
219
|
+
""
|
|
220
|
+
].join(`
|
|
221
|
+
`);
|
|
222
|
+
var COMPONENT_IMPORT = `import { DevPanel } from "./${COMPONENT_NAME}";`;
|
|
223
|
+
var COMPONENT_RENDER = "<DevPanel />";
|
|
224
|
+
function packageManager(files) {
|
|
225
|
+
if (files("pnpm-lock.yaml"))
|
|
226
|
+
return "pnpm";
|
|
227
|
+
if (files("yarn.lock"))
|
|
228
|
+
return "yarn";
|
|
229
|
+
if (files("bun.lock") || files("bun.lockb"))
|
|
230
|
+
return "bun";
|
|
231
|
+
return "npm";
|
|
232
|
+
}
|
|
233
|
+
var SCRIPT_EXTENSIONS = ["tsx", "jsx", "ts", "js"];
|
|
234
|
+
function firstOf(files, stems) {
|
|
235
|
+
for (const stem of stems) {
|
|
236
|
+
for (const extension of SCRIPT_EXTENSIONS) {
|
|
237
|
+
if (files(`${stem}.${extension}`))
|
|
238
|
+
return `${stem}.${extension}`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
function moduleEntry(html, files = () => true) {
|
|
244
|
+
for (const tag of html.replace(/<!--[\s\S]*?-->/g, "").match(/<script\b[^>]*>/gi) ?? []) {
|
|
245
|
+
if (!/\btype\s*=\s*["']module["']/i.test(tag))
|
|
246
|
+
continue;
|
|
247
|
+
const src = /\bsrc\s*=\s*["']([^"']+)["']/i.exec(tag)?.[1];
|
|
248
|
+
if (!src || /^([a-z]+:)?\/\//i.test(src))
|
|
249
|
+
continue;
|
|
250
|
+
const path = src.replace(/^\.?\//, "");
|
|
251
|
+
if (files(path))
|
|
252
|
+
return path;
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
function depends(pkg, name) {
|
|
257
|
+
return ["dependencies", "devDependencies"].some((field) => {
|
|
258
|
+
const listed = typeof pkg === "object" && pkg !== null ? Reflect.get(pkg, field) : null;
|
|
259
|
+
return typeof listed === "object" && listed !== null && name in listed;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function framework(pkg, files, read = () => "") {
|
|
263
|
+
if (pkg === null)
|
|
264
|
+
return { kind: "plain" };
|
|
265
|
+
const has = (name) => depends(pkg, name);
|
|
266
|
+
if (has("next")) {
|
|
267
|
+
const layout = firstOf(files, ["app/layout", "src/app/layout"]);
|
|
268
|
+
if (layout)
|
|
269
|
+
return { kind: "next-app", layout };
|
|
270
|
+
const app = firstOf(files, ["pages/_app", "src/pages/_app"]);
|
|
271
|
+
return app ? { kind: "next-pages", app } : { kind: "unknown" };
|
|
272
|
+
}
|
|
273
|
+
if (has("vite") && files("index.html")) {
|
|
274
|
+
const entry2 = moduleEntry(read("index.html"), files);
|
|
275
|
+
if (entry2)
|
|
276
|
+
return { kind: "entry", entry: entry2, make: false };
|
|
277
|
+
}
|
|
278
|
+
if (has("@sveltejs/kit")) {
|
|
279
|
+
const entry2 = ["src/hooks.client.ts", "src/hooks.client.js"].find(files);
|
|
280
|
+
return { kind: "entry", entry: entry2 ?? "src/hooks.client.ts", make: !entry2 };
|
|
281
|
+
}
|
|
282
|
+
const entry = ["app/entry.client.tsx", "app/entry.client.jsx", "src/client.tsx", "src/client.jsx"].find(files);
|
|
283
|
+
return entry ? { kind: "entry", entry, make: false } : { kind: "unknown" };
|
|
284
|
+
}
|
|
285
|
+
function withPanel(layout) {
|
|
286
|
+
const close = layout.indexOf("</body>");
|
|
287
|
+
if (close < 0 || close !== layout.lastIndexOf("</body>"))
|
|
288
|
+
return null;
|
|
289
|
+
const eol = eolOf(layout);
|
|
290
|
+
const lineStart = layout.lastIndexOf(`
|
|
291
|
+
`, close) + 1;
|
|
292
|
+
const indent = layout.slice(lineStart, close);
|
|
293
|
+
const rendered = /^[ \t]*$/.test(indent) ? `${layout.slice(0, lineStart)}${indent}${indent.includes("\t") ? "\t" : " "}${COMPONENT_RENDER}${eol}${layout.slice(lineStart)}` : `${layout.slice(0, close)}${COMPONENT_RENDER}${layout.slice(close)}`;
|
|
294
|
+
const { bare } = scan(rendered);
|
|
295
|
+
const last = lastImportEnd(rendered, bare);
|
|
296
|
+
if (last !== null)
|
|
297
|
+
return `${rendered.slice(0, last)}${eol}${COMPONENT_IMPORT}${rendered.slice(last)}`;
|
|
298
|
+
const at = directiveEnd(rendered, bare);
|
|
299
|
+
if (at === null)
|
|
300
|
+
return null;
|
|
301
|
+
return `${rendered.slice(0, at)}${COMPONENT_IMPORT}${eol}${rendered.slice(at)}`;
|
|
302
|
+
}
|
|
303
|
+
function inside(dir, path) {
|
|
304
|
+
try {
|
|
305
|
+
const root = realpathSync(dir);
|
|
306
|
+
let at = resolve(dir, path);
|
|
307
|
+
const rest = [];
|
|
308
|
+
while (!existsSync(at)) {
|
|
309
|
+
if (lstatSync(at, { throwIfNoEntry: false }))
|
|
310
|
+
return false;
|
|
311
|
+
const up = dirname(at);
|
|
312
|
+
if (up === at)
|
|
313
|
+
return false;
|
|
314
|
+
rest.unshift(basename(at));
|
|
315
|
+
at = up;
|
|
316
|
+
}
|
|
317
|
+
const from = relative(root, join(realpathSync(at), ...rest));
|
|
318
|
+
return from !== "" && from !== ".." && !from.startsWith(`..${sep}`) && !isAbsolute(from);
|
|
319
|
+
} catch {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function mountsKnobs(path, source, look) {
|
|
324
|
+
const live = scan(source).code;
|
|
325
|
+
if (MOUNTS.test(live))
|
|
326
|
+
return true;
|
|
327
|
+
for (const [, , spec = ""] of live.matchAll(RELATIVE_IMPORTS)) {
|
|
328
|
+
const base = join(dirname(path), spec);
|
|
329
|
+
const candidates = [
|
|
330
|
+
base,
|
|
331
|
+
...SCRIPT_EXTENSIONS.map((extension) => `${base}.${extension}`),
|
|
332
|
+
...SCRIPT_EXTENSIONS.map((extension) => join(base, `index.${extension}`))
|
|
333
|
+
];
|
|
334
|
+
for (const candidate of candidates) {
|
|
335
|
+
const text = look(candidate);
|
|
336
|
+
if (text === null)
|
|
337
|
+
continue;
|
|
338
|
+
if (MOUNTS.test(scan(text).code))
|
|
339
|
+
return true;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
class ReadFailed extends Error {
|
|
347
|
+
path;
|
|
348
|
+
code;
|
|
349
|
+
constructor(path, code) {
|
|
350
|
+
super(`${path} ${code}`);
|
|
351
|
+
this.path = path;
|
|
352
|
+
this.code = code;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function plan(dir) {
|
|
356
|
+
const files = (path) => existsSync(join(dir, path));
|
|
357
|
+
const read = (path) => {
|
|
358
|
+
try {
|
|
359
|
+
return readFileSync(join(dir, path), "utf8");
|
|
360
|
+
} catch (error) {
|
|
361
|
+
throw new ReadFailed(path, errorCode(error));
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
const look = (path) => {
|
|
365
|
+
try {
|
|
366
|
+
return inside(dir, path) && statSync(join(dir, path)).isFile() ? read(path) : null;
|
|
367
|
+
} catch {
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
let pkg = null;
|
|
372
|
+
if (files("package.json")) {
|
|
373
|
+
try {
|
|
374
|
+
pkg = JSON.parse(read("package.json").replace(/^/, ""));
|
|
375
|
+
} catch {
|
|
376
|
+
return { dir, edits: [], lines: [MESSAGES.packageJson], code: 1 };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const found = framework(pkg, files, read);
|
|
380
|
+
const edits = [];
|
|
381
|
+
const lines = [];
|
|
382
|
+
let code = 0;
|
|
383
|
+
const byHand = (step, missing) => {
|
|
384
|
+
if (missing)
|
|
385
|
+
lines.push(MESSAGES.unknown);
|
|
386
|
+
lines.push(step);
|
|
387
|
+
code = 1;
|
|
388
|
+
};
|
|
389
|
+
const edit = (path, kind, content) => {
|
|
390
|
+
edits.push({ path, kind, content });
|
|
391
|
+
lines.push(kind === "create" ? MESSAGES.created(path) : MESSAGES.changed(path));
|
|
392
|
+
};
|
|
393
|
+
if (found.kind !== "plain")
|
|
394
|
+
lines.push(MESSAGES.install[packageManager(files)]);
|
|
395
|
+
if (found.kind === "next-app" || found.kind === "next-pages") {
|
|
396
|
+
const beside = found.kind === "next-app" ? found.layout : found.app;
|
|
397
|
+
const typed = /\.tsx?$/.test(beside);
|
|
398
|
+
const folder = found.kind === "next-app" ? dirname(beside) : dirname(dirname(beside));
|
|
399
|
+
const component = join(folder, `${COMPONENT_NAME}.${typed ? "tsx" : "jsx"}`);
|
|
400
|
+
if (!inside(dir, beside) || !inside(dir, component))
|
|
401
|
+
byHand(MESSAGES.next, false);
|
|
402
|
+
else {
|
|
403
|
+
const source = read(beside);
|
|
404
|
+
const eol = eolOf(source);
|
|
405
|
+
const ours = source.includes(COMPONENT_IMPORT);
|
|
406
|
+
const makeComponent = () => {
|
|
407
|
+
if (files(component))
|
|
408
|
+
lines.push(MESSAGES.unchanged(component));
|
|
409
|
+
else
|
|
410
|
+
edit(component, "create", COMPONENT.replaceAll(`
|
|
411
|
+
`, eol));
|
|
412
|
+
};
|
|
413
|
+
if (ours || mountsKnobs(beside, source, look)) {
|
|
414
|
+
if (ours)
|
|
415
|
+
makeComponent();
|
|
416
|
+
lines.push(MESSAGES.unchanged(beside));
|
|
417
|
+
} else if (found.kind === "next-pages") {
|
|
418
|
+
makeComponent();
|
|
419
|
+
byHand(MESSAGES.next, false);
|
|
420
|
+
} else {
|
|
421
|
+
const next = withPanel(source);
|
|
422
|
+
makeComponent();
|
|
423
|
+
if (next === null)
|
|
424
|
+
byHand(MESSAGES.next, false);
|
|
425
|
+
else
|
|
426
|
+
edit(beside, "change", next);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
} else if (found.kind === "entry") {
|
|
430
|
+
if (!inside(dir, found.entry))
|
|
431
|
+
byHand(MESSAGES.entry, false);
|
|
432
|
+
else if (found.make)
|
|
433
|
+
edit(found.entry, "create", `${MOUNT_LINE}
|
|
434
|
+
`);
|
|
435
|
+
else {
|
|
436
|
+
const source = read(found.entry);
|
|
437
|
+
const eol = eolOf(source);
|
|
438
|
+
if (MOUNTS.test(scan(source).code))
|
|
439
|
+
lines.push(MESSAGES.unchanged(found.entry));
|
|
440
|
+
else
|
|
441
|
+
edit(found.entry, "change", `${source}${source === "" || source.endsWith(`
|
|
442
|
+
`) ? "" : eol}${MOUNT_LINE}${eol}`);
|
|
443
|
+
}
|
|
444
|
+
} else if (found.kind === "plain")
|
|
445
|
+
byHand(MESSAGES.plain, false);
|
|
446
|
+
else
|
|
447
|
+
byHand(depends(pkg, "next") ? MESSAGES.next : MESSAGES.entry, true);
|
|
448
|
+
lines.push(MESSAGES.production, MESSAGES.early, MESSAGES.open, MESSAGES.reference);
|
|
449
|
+
return { dir, edits, lines, code };
|
|
450
|
+
}
|
|
451
|
+
function apply(planned) {
|
|
452
|
+
const ordered = [...planned.edits].sort((a, b) => Number(a.kind === "create") - Number(b.kind === "create"));
|
|
453
|
+
const changed = [];
|
|
454
|
+
for (const { path, kind, content } of ordered) {
|
|
455
|
+
const file = join(planned.dir, path);
|
|
456
|
+
try {
|
|
457
|
+
const before = kind === "change" ? readFileSync(file, "utf8") : null;
|
|
458
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
459
|
+
writeFileSync(file, content, { flag: kind === "create" ? "wx" : "w" });
|
|
460
|
+
if (before !== null)
|
|
461
|
+
changed.push({ file, before });
|
|
462
|
+
} catch (error) {
|
|
463
|
+
for (const { file: back, before } of changed) {
|
|
464
|
+
try {
|
|
465
|
+
writeFileSync(back, before);
|
|
466
|
+
} catch {}
|
|
467
|
+
}
|
|
468
|
+
return MESSAGES.writeFailed(path, errorCode(error));
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
function errorCode(error) {
|
|
474
|
+
const code = error instanceof Error ? Reflect.get(error, "code") : undefined;
|
|
475
|
+
return typeof code === "string" ? code : String(error);
|
|
476
|
+
}
|
|
477
|
+
function run(args, dir, print = console.log) {
|
|
478
|
+
const [command, ...flags] = args;
|
|
479
|
+
if (command !== "init" || flags.some((flag) => flag !== "--dry-run")) {
|
|
480
|
+
print(MESSAGES.usage);
|
|
481
|
+
return 1;
|
|
482
|
+
}
|
|
483
|
+
const dry = flags.includes("--dry-run");
|
|
484
|
+
let planned;
|
|
485
|
+
try {
|
|
486
|
+
planned = plan(dir);
|
|
487
|
+
} catch (error) {
|
|
488
|
+
if (!(error instanceof ReadFailed))
|
|
489
|
+
throw error;
|
|
490
|
+
print(MESSAGES.writeFailed(error.path, error.code));
|
|
491
|
+
return 1;
|
|
492
|
+
}
|
|
493
|
+
if (dry)
|
|
494
|
+
print(MESSAGES.dryRun);
|
|
495
|
+
else {
|
|
496
|
+
const failed = apply(planned);
|
|
497
|
+
if (failed !== null) {
|
|
498
|
+
print(failed);
|
|
499
|
+
return 1;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
for (const line of planned.lines)
|
|
503
|
+
print(line);
|
|
504
|
+
return planned.code;
|
|
505
|
+
}
|
|
506
|
+
function isMain() {
|
|
507
|
+
try {
|
|
508
|
+
return realpathSync(process.argv[1] ?? "") === realpathSync(fileURLToPath(import.meta.url));
|
|
509
|
+
} catch {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (isMain())
|
|
514
|
+
process.exitCode = run(process.argv.slice(2), process.cwd());
|
|
515
|
+
export {
|
|
516
|
+
withPanel,
|
|
517
|
+
run,
|
|
518
|
+
plan,
|
|
519
|
+
packageManager,
|
|
520
|
+
moduleEntry,
|
|
521
|
+
framework,
|
|
522
|
+
apply,
|
|
523
|
+
ReadFailed,
|
|
524
|
+
MOUNT_LINE,
|
|
525
|
+
MESSAGES,
|
|
526
|
+
COMPONENT
|
|
527
|
+
};
|
package/dist/edit/keep.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare const MAX_BYTES: number;
|
|
|
52
52
|
export declare const MAX_PAGES = 20;
|
|
53
53
|
/** Why an edit was not made again. */
|
|
54
54
|
export declare const REASONS: {
|
|
55
|
-
readonly invalid: "not an edit
|
|
55
|
+
readonly invalid: "not an edit knobs reads";
|
|
56
56
|
readonly missing: "not found on the page";
|
|
57
57
|
readonly rule: "its rule is not on the page";
|
|
58
58
|
readonly changed: "the page has another value now";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HTML_MIN,
|
|
5
5
|
forcedSelector,
|
|
6
6
|
forcing
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-tqq2ygpj.js";
|
|
8
8
|
import"./index-58jdczmj.js";
|
|
9
9
|
import {
|
|
10
10
|
HIDE_ATTRIBUTE,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
rulesOf,
|
|
30
30
|
successor,
|
|
31
31
|
textEdit
|
|
32
|
-
} from "./index-
|
|
32
|
+
} from "./index-v2v4rmpe.js";
|
|
33
33
|
import {
|
|
34
34
|
compareSpecificity,
|
|
35
35
|
edits,
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
readSavedEdit,
|
|
39
39
|
specificity,
|
|
40
40
|
splitList
|
|
41
|
-
} from "./index-
|
|
41
|
+
} from "./index-q53j8wg5.js";
|
|
42
42
|
import {
|
|
43
43
|
boxValue,
|
|
44
44
|
sizeText
|
|
@@ -93,11 +93,11 @@ import {
|
|
|
93
93
|
segments,
|
|
94
94
|
toolToggle,
|
|
95
95
|
toolbar
|
|
96
|
-
} from "./index-
|
|
96
|
+
} from "./index-fjrrgd9h.js";
|
|
97
97
|
import {
|
|
98
98
|
getState,
|
|
99
99
|
subscribe
|
|
100
|
-
} from "./index-
|
|
100
|
+
} from "./index-8d1yk9d2.js";
|
|
101
101
|
import {
|
|
102
102
|
isMac
|
|
103
103
|
} from "./index-s6yzsvs4.js";
|
|
@@ -107,7 +107,7 @@ import {
|
|
|
107
107
|
letterMatches,
|
|
108
108
|
typesInField,
|
|
109
109
|
withShift
|
|
110
|
-
} from "./index-
|
|
110
|
+
} from "./index-2jc9dnta.js";
|
|
111
111
|
import {
|
|
112
112
|
SIDES,
|
|
113
113
|
boxModel,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
HTML_MIN,
|
|
6
6
|
forcedSelector,
|
|
7
7
|
forcing
|
|
8
|
-
} from "./react-
|
|
8
|
+
} from "./react-3ev6rwqz.js";
|
|
9
9
|
import"./react-97b5b8j4.js";
|
|
10
10
|
import {
|
|
11
11
|
HIDE_ATTRIBUTE,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
rulesOf,
|
|
31
31
|
successor,
|
|
32
32
|
textEdit
|
|
33
|
-
} from "./react-
|
|
33
|
+
} from "./react-0gxs9aef.js";
|
|
34
34
|
import {
|
|
35
35
|
compareSpecificity,
|
|
36
36
|
edits,
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
readSavedEdit,
|
|
40
40
|
specificity,
|
|
41
41
|
splitList
|
|
42
|
-
} from "./react-
|
|
42
|
+
} from "./react-8nmtt0ge.js";
|
|
43
43
|
import {
|
|
44
44
|
boxValue,
|
|
45
45
|
sizeText
|
|
@@ -94,11 +94,11 @@ import {
|
|
|
94
94
|
segments,
|
|
95
95
|
toolToggle,
|
|
96
96
|
toolbar
|
|
97
|
-
} from "./react-
|
|
97
|
+
} from "./react-actmnkwp.js";
|
|
98
98
|
import {
|
|
99
99
|
getState,
|
|
100
100
|
subscribe
|
|
101
|
-
} from "./react-
|
|
101
|
+
} from "./react-zp7fdw8e.js";
|
|
102
102
|
import {
|
|
103
103
|
isMac
|
|
104
104
|
} from "./react-5h7pxnax.js";
|
|
@@ -108,7 +108,7 @@ import {
|
|
|
108
108
|
letterMatches,
|
|
109
109
|
typesInField,
|
|
110
110
|
withShift
|
|
111
|
-
} from "./react-
|
|
111
|
+
} from "./react-meve34wp.js";
|
|
112
112
|
import {
|
|
113
113
|
SIDES,
|
|
114
114
|
boxModel,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
turnOf,
|
|
25
25
|
turnedPose,
|
|
26
26
|
windowRect
|
|
27
|
-
} from "./index-
|
|
27
|
+
} from "./index-cb91vcka.js";
|
|
28
28
|
import {
|
|
29
29
|
hush,
|
|
30
30
|
hushOnce,
|
|
@@ -3269,7 +3269,7 @@ async function loadAll(files) {
|
|
|
3269
3269
|
if (ok)
|
|
3270
3270
|
return image;
|
|
3271
3271
|
}
|
|
3272
|
-
throw new Error(`
|
|
3272
|
+
throw new Error(`knobs: ${file} did not load`);
|
|
3273
3273
|
};
|
|
3274
3274
|
return Promise.all(files.map(loaded));
|
|
3275
3275
|
}
|
|
@@ -9680,7 +9680,7 @@ function open(veiled, first) {
|
|
|
9680
9680
|
if (fresh())
|
|
9681
9681
|
frame3.setAttribute(FRESH_ATTRIBUTE, "");
|
|
9682
9682
|
frame3.name = FRAME_NAME;
|
|
9683
|
-
frame3.title = "
|
|
9683
|
+
frame3.title = "knobs viewport";
|
|
9684
9684
|
frame3.setAttribute("sandbox", SANDBOX);
|
|
9685
9685
|
frameUrl = window.location.href;
|
|
9686
9686
|
follow3({ page: frameDocument, locate, refresh: () => browser?.refresh() });
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
turnOf,
|
|
26
26
|
turnedPose,
|
|
27
27
|
windowRect
|
|
28
|
-
} from "./react-
|
|
28
|
+
} from "./react-6ngtb6p9.js";
|
|
29
29
|
import {
|
|
30
30
|
hush,
|
|
31
31
|
hushOnce,
|
|
@@ -3270,7 +3270,7 @@ async function loadAll(files) {
|
|
|
3270
3270
|
if (ok)
|
|
3271
3271
|
return image;
|
|
3272
3272
|
}
|
|
3273
|
-
throw new Error(`
|
|
3273
|
+
throw new Error(`knobs: ${file} did not load`);
|
|
3274
3274
|
};
|
|
3275
3275
|
return Promise.all(files.map(loaded));
|
|
3276
3276
|
}
|
|
@@ -9681,7 +9681,7 @@ function open(veiled, first) {
|
|
|
9681
9681
|
if (fresh())
|
|
9682
9682
|
frame3.setAttribute(FRESH_ATTRIBUTE, "");
|
|
9683
9683
|
frame3.name = FRAME_NAME;
|
|
9684
|
-
frame3.title = "
|
|
9684
|
+
frame3.title = "knobs viewport";
|
|
9685
9685
|
frame3.setAttribute("sandbox", SANDBOX);
|
|
9686
9686
|
frameUrl = window.location.href;
|
|
9687
9687
|
follow3({ page: frameDocument, locate, refresh: () => browser?.refresh() });
|