@vinena/knobs 0.6.6 → 0.7.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/CHANGELOG.md +26 -0
- package/README.md +13 -7
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/dist/cli.d.ts +95 -0
- package/dist/cli.js +527 -0
- package/dist/{context-eawqn680.js → context-2r76ext7.js} +3 -3
- package/dist/{context-vd2xep5t.js → context-h1bdt8w3.js} +3 -3
- package/dist/early.global.js +7 -8
- package/dist/edit/html.d.ts +7 -3
- package/dist/edit/keep.d.ts +2 -2
- package/dist/{elementsview-n26sp8m7.js → elementsview-mcg6d5zp.js} +21 -19
- package/dist/{elementsview-dpm0xmb2.js → elementsview-mwr1s17z.js} +21 -19
- package/dist/engine/bezels.d.ts +2 -2
- package/dist/engine/check.d.ts +2 -2
- package/dist/engine/describe.d.ts +2 -2
- package/dist/engine/devices.d.ts +3 -3
- package/dist/engine/fit.d.ts +4 -4
- package/dist/engine/foldhand.d.ts +2 -2
- package/dist/engine/frame.d.ts +6 -6
- package/dist/engine/frames.d.ts +4 -4
- package/dist/engine/fresh.d.ts +12 -5
- package/dist/engine/header.d.ts +3 -1
- package/dist/engine/identity.d.ts +4 -4
- package/dist/engine/index.d.ts +7 -7
- package/dist/engine/locale.d.ts +2 -2
- package/dist/engine/morph.d.ts +2 -2
- package/dist/engine/native.d.ts +8 -8
- package/dist/engine/placeholder.d.ts +3 -3
- package/dist/engine/reload.d.ts +2 -2
- package/dist/engine/screen.d.ts +2 -2
- package/dist/engine/scrollkeep.d.ts +1 -1
- package/dist/engine/store.d.ts +11 -11
- package/dist/engine/storekeys.d.ts +34 -0
- package/dist/engine/style.d.ts +1 -1
- package/dist/engine/tabicon.d.ts +2 -2
- package/dist/engine/underneath.d.ts +1 -0
- package/dist/engine/width.d.ts +3 -3
- package/dist/{framekit-0as9t6a7.js → framekit-4v7nc3ea.js} +25 -20
- package/dist/{framekit-dknq662p.js → framekit-wyppj1se.js} +25 -20
- package/dist/grab/clipboard.d.ts +2 -0
- package/dist/{index-jfv7vavj.js → index-311fys81.js} +93 -29
- package/dist/index-3dcgysws.js +77 -0
- package/dist/{index-7vb2ct4s.js → index-3s4v7gw5.js} +11 -10
- package/dist/{index-ztnjefrh.js → index-585hs9tp.js} +5 -1
- package/dist/{index-za4ppxay.js → index-6t0w5s7p.js} +1 -1
- package/dist/{index-r1rdj05c.js → index-82y8x8vv.js} +14 -11
- package/dist/{index-dxga6h10.js → index-9targr2f.js} +26 -16
- package/dist/{index-x3sxssbs.js → index-a23nv5j4.js} +65 -45
- package/dist/{index-t4kssacm.js → index-abwqw8jh.js} +6 -1
- package/dist/{index-s6yzsvs4.js → index-bgzyc7rz.js} +22 -15
- package/dist/{index-t4wrs2a3.js → index-c1t6knbf.js} +20 -14
- package/dist/{index-7w0nm76e.js → index-cqymjce4.js} +20 -14
- package/dist/{index-69fvtkcm.js → index-dvtbh3c8.js} +24 -18
- package/dist/{index-ajs4na3f.js → index-k4w5v53q.js} +2 -2
- package/dist/{index-df35z48z.js → index-n31pn4ax.js} +20 -16
- package/dist/{index-ymqm185m.js → index-rps0bdq9.js} +1 -1
- package/dist/{index-a8ffw5ft.js → index-szd9bddn.js} +1 -1
- package/dist/{index-whehz74d.js → index-vhda420r.js} +32 -6
- package/dist/{index-xs29b55n.js → index-vmprrfwe.js} +5 -2
- package/dist/{index-20bc9yrj.js → index-vmz7htwn.js} +1 -1
- package/dist/index.d.ts +14 -8
- package/dist/index.global.js +176 -159
- package/dist/index.js +108 -43
- package/dist/instance.d.ts +7 -1
- package/dist/mark.d.ts +50 -0
- package/dist/{react-msn10fjb.js → react-4ezjf7mq.js} +24 -18
- package/dist/react-4qn9vsjw.js +78 -0
- package/dist/{react-73reavv4.js → react-4tcwpama.js} +1 -1
- package/dist/{react-k4pkm1p5.js → react-7eyps0cg.js} +2 -2
- package/dist/{react-10r2rczp.js → react-7tzwahsm.js} +14 -11
- package/dist/{react-yx3g9k55.js → react-amvrbng8.js} +5 -2
- package/dist/{react-5rq7bnsy.js → react-atw9y8ny.js} +5 -1
- package/dist/{react-4phtr2nd.js → react-dg4bjv3j.js} +1 -1
- package/dist/{react-vbk58f9m.js → react-hdneb4v3.js} +32 -6
- package/dist/{react-h9w04skh.js → react-j87bdhhe.js} +4 -1
- package/dist/{react-wtgvkf6g.js → react-mkafgzqf.js} +1 -1
- package/dist/{react-a1r0nr0g.js → react-ppyj3fg2.js} +65 -45
- package/dist/{react-0r5418av.js → react-rbmk30xk.js} +92 -29
- package/dist/{react-y9gr8yt2.js → react-rxw73n04.js} +1 -1
- package/dist/{react-5h7pxnax.js → react-tet7swk2.js} +22 -15
- package/dist/{react-5ekfj7g3.js → react-w94cfn87.js} +20 -16
- package/dist/{react-v08ywmtw.js → react-wzd3cfg8.js} +11 -10
- package/dist/{react-2b7725je.js → react-x209et38.js} +26 -16
- package/dist/react.d.ts +3 -1
- package/dist/react.js +111 -44
- package/dist/{replay-ehgxp9py.js → replay-3xqgt3xg.js} +8 -8
- package/dist/{replay-461gcdh1.js → replay-48gn27bj.js} +8 -8
- package/dist/storage/onload.d.ts +1 -1
- package/dist/{storageview-5p1y11b5.js → storageview-2rvwk0v7.js} +20 -17
- package/dist/{storageview-kxzpnfvr.js → storageview-6vq7nz02.js} +20 -17
- package/dist/styles/force.d.ts +3 -1
- package/dist/types.d.ts +4 -4
- package/dist/ui/actions.d.ts +3 -3
- package/dist/ui/bindings.d.ts +1 -1
- package/dist/ui/catalog.d.ts +14 -14
- package/dist/ui/changes.d.ts +1 -1
- package/dist/ui/colors.d.ts +1 -1
- package/dist/ui/deviceknobs.d.ts +2 -2
- package/dist/ui/editors.d.ts +3 -3
- package/dist/ui/foldslider.d.ts +2 -2
- package/dist/ui/icons.d.ts +5 -2
- package/dist/ui/keys.d.ts +1 -1
- package/dist/ui/list.d.ts +10 -10
- package/dist/ui/palette.d.ts +2 -2
- package/dist/ui/panel.d.ts +2 -0
- package/dist/ui/pin.d.ts +2 -2
- package/dist/ui/prefs.d.ts +1 -1
- package/dist/ui/rows.d.ts +3 -3
- package/dist/ui/settings.d.ts +11 -1
- package/dist/ui/storageview.d.ts +2 -2
- package/dist/ui/stylesview.d.ts +3 -3
- package/dist/ui/swatches.d.ts +2 -2
- package/package.json +5 -2
- package/skills/{devknobs → knobs}/SKILL.md +52 -51
- package/dist/index-5tv6sr74.js +0 -23
- package/dist/react-t2qnewz2.js +0 -24
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 Knobs = process.env.NODE_ENV === "development" ? dynamic(() => import("@vinena/knobs/react").then((m) => m.Knobs), { ssr: false }) : null;',
|
|
215
|
+
"",
|
|
216
|
+
"export function DevPanel() {",
|
|
217
|
+
" return <>{Knobs && <Knobs />}</>;",
|
|
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
|
+
};
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
grabEntry,
|
|
8
8
|
joinEntries,
|
|
9
9
|
quickEntry
|
|
10
|
-
} from "./react-
|
|
10
|
+
} from "./react-amvrbng8.js";
|
|
11
11
|
import"./react-1gqwa2yw.js";
|
|
12
|
-
import"./react-
|
|
12
|
+
import"./react-atw9y8ny.js";
|
|
13
13
|
import"./react-fp73vhyd.js";
|
|
14
|
-
import"./react-
|
|
14
|
+
import"./react-4qn9vsjw.js";
|
|
15
15
|
export {
|
|
16
16
|
quickEntry,
|
|
17
17
|
joinEntries,
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
grabEntry,
|
|
7
7
|
joinEntries,
|
|
8
8
|
quickEntry
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-vmprrfwe.js";
|
|
10
10
|
import"./index-aymfvd8s.js";
|
|
11
|
-
import"./index-
|
|
11
|
+
import"./index-abwqw8jh.js";
|
|
12
12
|
import"./index-a974q3aa.js";
|
|
13
|
-
import"./index-
|
|
13
|
+
import"./index-3dcgysws.js";
|
|
14
14
|
export {
|
|
15
15
|
quickEntry,
|
|
16
16
|
joinEntries,
|