busy-barback-ui 0.1.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/README.md +49 -0
- package/dist/index.js +819 -0
- package/package.json +41 -0
- package/schema.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# barback
|
|
2
|
+
|
|
3
|
+
The busy-barback/ui CLI. Like the barback who keeps a bar stocked, it makes a BUSY Bar app, brings components into it, and restocks them when there are new versions. The components become your code.
|
|
4
|
+
|
|
5
|
+
Run it with `npx`, nothing to set up. Installed with `npm install -g busy-barback-ui`, it is also `barback`.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx busy-barback-ui@latest new my-app # a new app with the kit and a starter screen
|
|
11
|
+
npx busy-barback-ui@latest open # set up the app you have
|
|
12
|
+
npx busy-barback-ui@latest fetch picture tag # bring components and what they need
|
|
13
|
+
npx busy-barback-ui@latest inventory # what differs from the registry
|
|
14
|
+
npx busy-barback-ui@latest inventory picture # the lines
|
|
15
|
+
npx busy-barback-ui@latest restock # the registry's version of what you have, asks first
|
|
16
|
+
npx busy-barback-ui@latest menu chart # what there is
|
|
17
|
+
npx busy-barback-ui@latest sample sparkline # an item's files, without bringing them
|
|
18
|
+
npx busy-barback-ui@latest toss marquee # delete a component
|
|
19
|
+
npx busy-barback-ui@latest info # the project and its config
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- `new` runs the official generator (`@busy-app/cli create`), moves the app to busy-lib 1.1, brings the core and the app kit, and writes a starter `src/main.ts`. `--pm`, `--id`, `--name`, `--author`, `--description`, `--api-version`, `--no-git` and `--no-install` go to the generator.
|
|
23
|
+
- `fetch` asks before it replaces a file you changed; `--overwrite` takes the registry's, `--dry-run` only shows, `--all` brings everything.
|
|
24
|
+
- `restock` replaces your edits in the files it updates, so it shows them and asks; `--diff` prints the lines, `--yes` skips the question.
|
|
25
|
+
- `toss` won't delete what other components still need unless you pass `--force`, and asks first.
|
|
26
|
+
- Every command takes `--cwd`, `--ref` (a branch or tag) and `--registry` (a URL or a local checkout).
|
|
27
|
+
|
|
28
|
+
## barback.json
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"$schema": "https://raw.githubusercontent.com/nezdemkovski/busy-barback-ui/master/cli/schema.json",
|
|
33
|
+
"registry": "https://raw.githubusercontent.com/nezdemkovski/busy-barback-ui/{ref}",
|
|
34
|
+
"ref": "master",
|
|
35
|
+
"paths": { "ui": "src/ui", "kit": "src/kit" }
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Pin `ref` to a tag to restock on your own schedule. `paths` moves components and the kit; imports between the files are rewritten to match. Animations always go to `src/animations`, where the app loads them from.
|
|
40
|
+
|
|
41
|
+
## Development
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bun run build # dist/index.js
|
|
45
|
+
bun test tests
|
|
46
|
+
node dist/index.js fetch tag --registry .. --cwd ../../my-app # try against this checkout
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Publishing: bump `version`, then push a `cli-v<version>` tag. The workflow checks the tag against the version, tests, builds and publishes to npm.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// package.json
|
|
3
|
+
var package_default = {
|
|
4
|
+
name: "busy-barback-ui",
|
|
5
|
+
version: "0.1.0",
|
|
6
|
+
description: "barback: brings busy-barback/ui components to your BUSY Bar app, keeps them up to date, and makes new apps.",
|
|
7
|
+
keywords: [
|
|
8
|
+
"barback",
|
|
9
|
+
"busy-bar",
|
|
10
|
+
"busybar",
|
|
11
|
+
"cli",
|
|
12
|
+
"components"
|
|
13
|
+
],
|
|
14
|
+
homepage: "https://github.com/nezdemkovski/busy-barback-ui/tree/master/cli#readme",
|
|
15
|
+
author: "nezdemkovski",
|
|
16
|
+
repository: {
|
|
17
|
+
type: "git",
|
|
18
|
+
url: "git+https://github.com/nezdemkovski/busy-barback-ui.git",
|
|
19
|
+
directory: "cli"
|
|
20
|
+
},
|
|
21
|
+
bin: {
|
|
22
|
+
barback: "dist/index.js",
|
|
23
|
+
"busy-barback-ui": "dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
files: [
|
|
26
|
+
"dist",
|
|
27
|
+
"schema.json"
|
|
28
|
+
],
|
|
29
|
+
type: "module",
|
|
30
|
+
publishConfig: {
|
|
31
|
+
access: "public",
|
|
32
|
+
provenance: true
|
|
33
|
+
},
|
|
34
|
+
scripts: {
|
|
35
|
+
build: "bun build src/index.ts --target node --outfile dist/index.js",
|
|
36
|
+
typecheck: "tsc",
|
|
37
|
+
test: "bun test tests",
|
|
38
|
+
prepublishOnly: "bun run build"
|
|
39
|
+
},
|
|
40
|
+
engines: {
|
|
41
|
+
node: ">=20"
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/args.ts
|
|
46
|
+
var SHORT = {
|
|
47
|
+
y: "yes",
|
|
48
|
+
o: "overwrite",
|
|
49
|
+
c: "cwd",
|
|
50
|
+
a: "all",
|
|
51
|
+
s: "silent",
|
|
52
|
+
f: "force",
|
|
53
|
+
h: "help",
|
|
54
|
+
v: "version"
|
|
55
|
+
};
|
|
56
|
+
var VALUED = new Set([
|
|
57
|
+
"cwd",
|
|
58
|
+
"ref",
|
|
59
|
+
"registry",
|
|
60
|
+
"ui",
|
|
61
|
+
"kit",
|
|
62
|
+
"pm",
|
|
63
|
+
"author",
|
|
64
|
+
"id",
|
|
65
|
+
"name",
|
|
66
|
+
"description",
|
|
67
|
+
"api-version"
|
|
68
|
+
]);
|
|
69
|
+
function parseArgs(argv) {
|
|
70
|
+
const positionals = [];
|
|
71
|
+
const flags = {};
|
|
72
|
+
for (let i = 0;i < argv.length; i++) {
|
|
73
|
+
const a = argv[i];
|
|
74
|
+
if (a === "--") {
|
|
75
|
+
positionals.push(...argv.slice(i + 1));
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (a.startsWith("--")) {
|
|
79
|
+
const [rawKey, inline] = a.slice(2).split("=", 2);
|
|
80
|
+
if (rawKey.startsWith("no-")) {
|
|
81
|
+
flags[rawKey.slice(3)] = false;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (inline !== undefined)
|
|
85
|
+
flags[rawKey] = inline;
|
|
86
|
+
else if (VALUED.has(rawKey) && i + 1 < argv.length)
|
|
87
|
+
flags[rawKey] = argv[++i];
|
|
88
|
+
else
|
|
89
|
+
flags[rawKey] = true;
|
|
90
|
+
} else if (a.startsWith("-") && a.length > 1) {
|
|
91
|
+
for (const ch of a.slice(1)) {
|
|
92
|
+
const key = SHORT[ch] ?? ch;
|
|
93
|
+
flags[key] = VALUED.has(key) && i + 1 < argv.length ? argv[++i] : true;
|
|
94
|
+
}
|
|
95
|
+
} else
|
|
96
|
+
positionals.push(a);
|
|
97
|
+
}
|
|
98
|
+
return { command: positionals.shift() ?? "", positionals, flags };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/commands.ts
|
|
102
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
103
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
104
|
+
import { readFile as readFile4, rm, writeFile as writeFile3 } from "node:fs/promises";
|
|
105
|
+
import { join as join4, resolve as resolve2 } from "node:path";
|
|
106
|
+
|
|
107
|
+
// src/create.ts
|
|
108
|
+
var STARTER_ITEMS = ["kit-app", "text-run"];
|
|
109
|
+
var STARTER_MAIN = `import { BusyBarAppClient } from "@busy-app/busy-lib";
|
|
110
|
+
import manifest from "./appmeta/manifest.json";
|
|
111
|
+
import { createApp, Key, Press } from "./kit/app";
|
|
112
|
+
import { Align } from "./ui/lib/elements";
|
|
113
|
+
import { color, typography } from "./ui/lib/theme";
|
|
114
|
+
import { textRun } from "./ui/text-run";
|
|
115
|
+
|
|
116
|
+
const app = createApp({ id: manifest.id, client: new BusyBarAppClient({ addr: __BUSY_ADDR__ }) });
|
|
117
|
+
|
|
118
|
+
let count = 0;
|
|
119
|
+
|
|
120
|
+
function draw() {
|
|
121
|
+
return app.screen.draw(
|
|
122
|
+
textRun({
|
|
123
|
+
parts: [
|
|
124
|
+
{ text: "Hello", font: typography.title },
|
|
125
|
+
{ text: String(count), color: color.muted },
|
|
126
|
+
],
|
|
127
|
+
x: 36,
|
|
128
|
+
baseline: 11,
|
|
129
|
+
gap: 4,
|
|
130
|
+
align: Align.center,
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
app.onWheel((delta) => {
|
|
136
|
+
count += delta;
|
|
137
|
+
void draw();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
app.on(Key.ok, Press.short, () => {
|
|
141
|
+
count = 0;
|
|
142
|
+
void draw();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
void draw();
|
|
146
|
+
`;
|
|
147
|
+
function generatorArgs(dir, pm, flags) {
|
|
148
|
+
const pass = ["author", "id", "name", "description", "api-version"];
|
|
149
|
+
const args = ["--yes", "@busy-app/cli@latest", "create", dir, "--package-manager", pm];
|
|
150
|
+
for (const k of pass)
|
|
151
|
+
if (typeof flags[k] === "string")
|
|
152
|
+
args.push(`--${k}`, flags[k]);
|
|
153
|
+
if (flags.git === false)
|
|
154
|
+
args.push("--no-git");
|
|
155
|
+
if (flags.install === false)
|
|
156
|
+
args.push("--no-install");
|
|
157
|
+
return args;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/diff.ts
|
|
161
|
+
function diffLines(before, after) {
|
|
162
|
+
const a = before.split(`
|
|
163
|
+
`), b = after.split(`
|
|
164
|
+
`);
|
|
165
|
+
const n = a.length, m = b.length;
|
|
166
|
+
const lcs = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
167
|
+
for (let i = n - 1;i >= 0; i--)
|
|
168
|
+
for (let j = m - 1;j >= 0; j--)
|
|
169
|
+
lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
170
|
+
const out = [];
|
|
171
|
+
let i = 0, j = 0;
|
|
172
|
+
while (i < n && j < m) {
|
|
173
|
+
if (a[i] === b[j]) {
|
|
174
|
+
out.push({ kind: " ", text: a[i] });
|
|
175
|
+
i++;
|
|
176
|
+
j++;
|
|
177
|
+
} else if (lcs[i + 1][j] >= lcs[i][j + 1])
|
|
178
|
+
out.push({ kind: "-", text: a[i++] });
|
|
179
|
+
else
|
|
180
|
+
out.push({ kind: "+", text: b[j++] });
|
|
181
|
+
}
|
|
182
|
+
while (i < n)
|
|
183
|
+
out.push({ kind: "-", text: a[i++] });
|
|
184
|
+
while (j < m)
|
|
185
|
+
out.push({ kind: "+", text: b[j++] });
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
function unified(before, after, context = 3) {
|
|
189
|
+
const lines = diffLines(before, after);
|
|
190
|
+
const changed = lines.map((l, i) => l.kind === " " ? -1 : i).filter((i) => i >= 0);
|
|
191
|
+
if (!changed.length)
|
|
192
|
+
return [];
|
|
193
|
+
const show = new Set;
|
|
194
|
+
for (const c of changed)
|
|
195
|
+
for (let k = Math.max(0, c - context);k <= Math.min(lines.length - 1, c + context); k++)
|
|
196
|
+
show.add(k);
|
|
197
|
+
const out = [];
|
|
198
|
+
let last = -1;
|
|
199
|
+
[...show].toSorted((x, y) => x - y).forEach((k) => {
|
|
200
|
+
if (last >= 0 && k > last + 1)
|
|
201
|
+
out.push("@@");
|
|
202
|
+
out.push(`${lines[k].kind}${lines[k].text}`);
|
|
203
|
+
last = k;
|
|
204
|
+
});
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
var changes = (before, after) => {
|
|
208
|
+
let added = 0, removed = 0;
|
|
209
|
+
for (const l of diffLines(before, after))
|
|
210
|
+
if (l.kind === "+")
|
|
211
|
+
added++;
|
|
212
|
+
else if (l.kind === "-")
|
|
213
|
+
removed++;
|
|
214
|
+
return { added, removed };
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/io.ts
|
|
218
|
+
import { createInterface } from "node:readline/promises";
|
|
219
|
+
var tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
220
|
+
var paint = (code) => (s) => tty ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
221
|
+
var c = {
|
|
222
|
+
dim: paint(2),
|
|
223
|
+
bold: paint(1),
|
|
224
|
+
red: paint(31),
|
|
225
|
+
green: paint(32),
|
|
226
|
+
yellow: paint(33),
|
|
227
|
+
cyan: paint(36)
|
|
228
|
+
};
|
|
229
|
+
var silent = false;
|
|
230
|
+
var setSilent = (v) => silent = v;
|
|
231
|
+
var log = (...parts) => {
|
|
232
|
+
if (!silent)
|
|
233
|
+
console.log(...parts);
|
|
234
|
+
};
|
|
235
|
+
var warn = (msg) => console.error(c.yellow(msg));
|
|
236
|
+
var interactive = () => Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
237
|
+
async function confirm(question, fallback = false) {
|
|
238
|
+
if (!interactive())
|
|
239
|
+
return fallback;
|
|
240
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
241
|
+
try {
|
|
242
|
+
const answer = (await rl.question(`${question} ${fallback ? "(Y/n)" : "(y/N)"} `)).trim().toLowerCase();
|
|
243
|
+
return answer ? answer === "y" || answer === "yes" : fallback;
|
|
244
|
+
} finally {
|
|
245
|
+
rl.close();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function printDiff(lines) {
|
|
249
|
+
for (const l of lines)
|
|
250
|
+
log(l === "@@" ? c.cyan("@@") : l[0] === "+" ? c.green(l) : l[0] === "-" ? c.red(l) : c.dim(l));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/ops.ts
|
|
254
|
+
import { existsSync } from "node:fs";
|
|
255
|
+
import { mkdir, readFile as readFile2, writeFile } from "node:fs/promises";
|
|
256
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
257
|
+
|
|
258
|
+
// src/paths.ts
|
|
259
|
+
import { dirname, posix } from "node:path";
|
|
260
|
+
var DEFAULT_PATHS = { ui: "src/ui", kit: "src/kit" };
|
|
261
|
+
var clean = (p) => posix.normalize(p.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
262
|
+
function targetOf(file, paths) {
|
|
263
|
+
const t = clean(file.target);
|
|
264
|
+
if (t.startsWith("src/ui/"))
|
|
265
|
+
return `${clean(paths.ui)}/${t.slice("src/ui/".length)}`;
|
|
266
|
+
if (t.startsWith("src/kit/"))
|
|
267
|
+
return `${clean(paths.kit)}/${t.slice("src/kit/".length)}`;
|
|
268
|
+
return t;
|
|
269
|
+
}
|
|
270
|
+
var IMPORT = /(\bfrom\s*|\bimport\s*\(?\s*)(["'])(\.{1,2}\/[^"']+)\2/g;
|
|
271
|
+
function rewriteImports(code, registryPath, targetPath, paths, known) {
|
|
272
|
+
const fromDir = posix.dirname(registryPath);
|
|
273
|
+
const toDir = posix.dirname(clean(targetPath));
|
|
274
|
+
return code.replace(IMPORT, (whole, lead, quote, spec) => {
|
|
275
|
+
const resolved = posix.normalize(posix.join(fromDir, spec));
|
|
276
|
+
const file = [resolved, `${resolved}.ts`].find(known);
|
|
277
|
+
if (!file)
|
|
278
|
+
return whole;
|
|
279
|
+
const target = targetOf({ path: file, type: "", target: file }, paths);
|
|
280
|
+
const ext = file === resolved ? "" : ".ts";
|
|
281
|
+
let rel = posix.relative(toDir, target.slice(0, target.length - ext.length));
|
|
282
|
+
if (!rel.startsWith("."))
|
|
283
|
+
rel = `./${rel}`;
|
|
284
|
+
return `${lead}${quote}${rel}${quote}`;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/registry.ts
|
|
289
|
+
import { readFile } from "node:fs/promises";
|
|
290
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
291
|
+
var DEFAULT_REGISTRY = "https://raw.githubusercontent.com/nezdemkovski/busy-barback-ui/{ref}";
|
|
292
|
+
var DEFAULT_REF = "master";
|
|
293
|
+
var isRemote = (base) => /^https?:\/\//.test(base);
|
|
294
|
+
function registryBase(registry, ref, cwd) {
|
|
295
|
+
const base = registry.replace("{ref}", ref).replace(/\/+$/, "");
|
|
296
|
+
return isRemote(base) || isAbsolute(base) ? base : resolve(cwd, base);
|
|
297
|
+
}
|
|
298
|
+
function source(base) {
|
|
299
|
+
const cache = new Map;
|
|
300
|
+
const load = (path) => {
|
|
301
|
+
let pending = cache.get(path);
|
|
302
|
+
if (!pending) {
|
|
303
|
+
pending = isRemote(base) ? fetch(`${base}/${path}`).then(async (res) => {
|
|
304
|
+
if (!res.ok)
|
|
305
|
+
throw new Error(`${base}/${path}: ${res.status} ${res.statusText}`);
|
|
306
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
307
|
+
}) : readFile(join(base, path)).then((b) => new Uint8Array(b));
|
|
308
|
+
cache.set(path, pending);
|
|
309
|
+
}
|
|
310
|
+
return pending;
|
|
311
|
+
};
|
|
312
|
+
const decoder = new TextDecoder;
|
|
313
|
+
return {
|
|
314
|
+
base,
|
|
315
|
+
async registry() {
|
|
316
|
+
return JSON.parse(decoder.decode(await load("registry.json")));
|
|
317
|
+
},
|
|
318
|
+
async text(path) {
|
|
319
|
+
return decoder.decode(await load(path));
|
|
320
|
+
},
|
|
321
|
+
bytes: load
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function findItem(registry, name) {
|
|
325
|
+
const wanted = name.replace(/^kit\//, "kit-");
|
|
326
|
+
return registry.items.find((i) => i.name === wanted);
|
|
327
|
+
}
|
|
328
|
+
function resolveItems(registry, names) {
|
|
329
|
+
const out = [];
|
|
330
|
+
const seen = new Set;
|
|
331
|
+
const visit = (name, from) => {
|
|
332
|
+
const item = findItem(registry, name);
|
|
333
|
+
if (!item)
|
|
334
|
+
throw new Error(from ? `${from} needs ${name}, which the registry doesn't have` : `No item named ${name}. Run \`barback menu\` to see them.`);
|
|
335
|
+
if (seen.has(item.name))
|
|
336
|
+
return;
|
|
337
|
+
seen.add(item.name);
|
|
338
|
+
for (const dep of item.registryDependencies ?? [])
|
|
339
|
+
visit(dep, item.name);
|
|
340
|
+
out.push(item);
|
|
341
|
+
};
|
|
342
|
+
for (const n of names)
|
|
343
|
+
visit(n);
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
var isCore = (item) => item.type === "registry:lib" && !item.name.startsWith("kit-");
|
|
347
|
+
var isText = (path) => /\.(ts|js|json|md)$/.test(path);
|
|
348
|
+
|
|
349
|
+
// src/ops.ts
|
|
350
|
+
var encoder = new TextEncoder;
|
|
351
|
+
var sameBytes = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
352
|
+
async function planFiles(cwd, src, registry, items, paths) {
|
|
353
|
+
const known = new Set(registry.items.flatMap((i) => i.files.map((f) => f.path)));
|
|
354
|
+
const plans = await Promise.all(items.flatMap((item) => item.files.map(async (file) => {
|
|
355
|
+
const target = targetOf(file, paths);
|
|
356
|
+
const abs = join2(cwd, target);
|
|
357
|
+
const exists = existsSync(abs);
|
|
358
|
+
if (isText(file.path)) {
|
|
359
|
+
const text = rewriteImports(await src.text(file.path), file.path, target, paths, (p) => known.has(p));
|
|
360
|
+
const local = exists ? await readFile2(abs, "utf8") : null;
|
|
361
|
+
return {
|
|
362
|
+
item: item.name,
|
|
363
|
+
path: file.path,
|
|
364
|
+
target,
|
|
365
|
+
content: encoder.encode(text),
|
|
366
|
+
text,
|
|
367
|
+
local,
|
|
368
|
+
status: local === null ? "new" : local === text ? "same" : "changed"
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const content = await src.bytes(file.path);
|
|
372
|
+
const local = exists ? new Uint8Array(await readFile2(abs)) : null;
|
|
373
|
+
return {
|
|
374
|
+
item: item.name,
|
|
375
|
+
path: file.path,
|
|
376
|
+
target,
|
|
377
|
+
content,
|
|
378
|
+
text: null,
|
|
379
|
+
local: null,
|
|
380
|
+
status: local === null ? "new" : sameBytes(local, content) ? "same" : "changed"
|
|
381
|
+
};
|
|
382
|
+
})));
|
|
383
|
+
return plans;
|
|
384
|
+
}
|
|
385
|
+
async function writePlan(cwd, plan) {
|
|
386
|
+
const abs = join2(cwd, plan.target);
|
|
387
|
+
await mkdir(dirname2(abs), { recursive: true });
|
|
388
|
+
await writeFile(abs, plan.content);
|
|
389
|
+
}
|
|
390
|
+
var installedItems = (cwd, registry, paths) => registry.items.filter((item) => {
|
|
391
|
+
const main = item.files.find((f) => isText(f.path)) ?? item.files[0];
|
|
392
|
+
return main ? existsSync(join2(cwd, targetOf(main, paths))) : false;
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// src/project.ts
|
|
396
|
+
import { spawnSync } from "node:child_process";
|
|
397
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
398
|
+
import { readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
|
|
399
|
+
import { join as join3 } from "node:path";
|
|
400
|
+
var CONFIG = "barback.json";
|
|
401
|
+
var SCHEMA = "https://raw.githubusercontent.com/nezdemkovski/busy-barback-ui/master/cli/schema.json";
|
|
402
|
+
var defaultConfig = () => ({
|
|
403
|
+
$schema: SCHEMA,
|
|
404
|
+
registry: DEFAULT_REGISTRY,
|
|
405
|
+
ref: DEFAULT_REF,
|
|
406
|
+
paths: { ...DEFAULT_PATHS }
|
|
407
|
+
});
|
|
408
|
+
async function readConfig(cwd) {
|
|
409
|
+
const file = join3(cwd, CONFIG);
|
|
410
|
+
if (!existsSync2(file))
|
|
411
|
+
return null;
|
|
412
|
+
const raw = JSON.parse(await readFile3(file, "utf8"));
|
|
413
|
+
const d = defaultConfig();
|
|
414
|
+
return {
|
|
415
|
+
...d,
|
|
416
|
+
...raw,
|
|
417
|
+
paths: { ...d.paths, ...raw.paths }
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
var writeConfig = (cwd, config) => writeFile2(join3(cwd, CONFIG), `${JSON.stringify(config, null, 2)}
|
|
421
|
+
`);
|
|
422
|
+
async function readPackage(cwd) {
|
|
423
|
+
const file = join3(cwd, "package.json");
|
|
424
|
+
return existsSync2(file) ? JSON.parse(await readFile3(file, "utf8")) : null;
|
|
425
|
+
}
|
|
426
|
+
function packageManager(cwd) {
|
|
427
|
+
if (existsSync2(join3(cwd, "bun.lock")) || existsSync2(join3(cwd, "bun.lockb")))
|
|
428
|
+
return "bun";
|
|
429
|
+
if (existsSync2(join3(cwd, "pnpm-lock.yaml")))
|
|
430
|
+
return "pnpm";
|
|
431
|
+
if (existsSync2(join3(cwd, "yarn.lock")))
|
|
432
|
+
return "yarn";
|
|
433
|
+
const agent = process.env.npm_config_user_agent ?? "";
|
|
434
|
+
if (agent.startsWith("bun"))
|
|
435
|
+
return "bun";
|
|
436
|
+
if (agent.startsWith("pnpm"))
|
|
437
|
+
return "pnpm";
|
|
438
|
+
if (agent.startsWith("yarn"))
|
|
439
|
+
return "yarn";
|
|
440
|
+
return "npm";
|
|
441
|
+
}
|
|
442
|
+
var splitSpec = (spec) => {
|
|
443
|
+
const at = spec.lastIndexOf("@");
|
|
444
|
+
return at > 0 ? { name: spec.slice(0, at), range: spec.slice(at + 1) } : { name: spec, range: "" };
|
|
445
|
+
};
|
|
446
|
+
var major = (range) => {
|
|
447
|
+
const m = /(\d+)\.(\d+)/.exec(range);
|
|
448
|
+
return m ? [Number(m[1]), Number(m[2])] : null;
|
|
449
|
+
};
|
|
450
|
+
function missingDependencies(pkg, specs) {
|
|
451
|
+
const have = { ...pkg?.devDependencies, ...pkg?.dependencies };
|
|
452
|
+
return [...new Set(specs)].filter((spec) => {
|
|
453
|
+
const { name, range } = splitSpec(spec);
|
|
454
|
+
const current = have[name];
|
|
455
|
+
if (!current)
|
|
456
|
+
return true;
|
|
457
|
+
const want = major(range), got = major(current);
|
|
458
|
+
if (!want || !got)
|
|
459
|
+
return false;
|
|
460
|
+
return got[0] < want[0] || got[0] === want[0] && got[1] < want[1];
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
function install(cwd, specs) {
|
|
464
|
+
if (!specs.length)
|
|
465
|
+
return true;
|
|
466
|
+
const pm = packageManager(cwd);
|
|
467
|
+
const args = pm === "npm" ? ["install", ...specs] : ["add", ...specs];
|
|
468
|
+
const res = spawnSync(pm, args, { cwd, stdio: "inherit", shell: process.platform === "win32" });
|
|
469
|
+
return res.status === 0;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/commands.ts
|
|
473
|
+
var RUN = "npx busy-barback-ui@latest";
|
|
474
|
+
|
|
475
|
+
class CliError extends Error {
|
|
476
|
+
}
|
|
477
|
+
var str = (v) => typeof v === "string" ? v : undefined;
|
|
478
|
+
async function context(flags, needConfig) {
|
|
479
|
+
const cwd = resolve2(str(flags.cwd) ?? process.cwd());
|
|
480
|
+
const saved = await readConfig(cwd);
|
|
481
|
+
if (needConfig && !saved)
|
|
482
|
+
throw new CliError(`No ${CONFIG} in ${cwd}. Run \`${RUN} open\` first.`);
|
|
483
|
+
const config = saved ?? defaultConfig();
|
|
484
|
+
const base = registryBase(str(flags.registry) ?? config.registry, str(flags.ref) ?? config.ref, cwd);
|
|
485
|
+
const src = source(base);
|
|
486
|
+
return { cwd, config, saved, src, registry: await src.registry() };
|
|
487
|
+
}
|
|
488
|
+
var rel = (p) => p.target;
|
|
489
|
+
async function installDependencies(cwd, items, flags) {
|
|
490
|
+
const pkg = await readPackage(cwd);
|
|
491
|
+
const missing = missingDependencies(pkg, items.flatMap((i) => i.dependencies ?? []));
|
|
492
|
+
if (!missing.length)
|
|
493
|
+
return;
|
|
494
|
+
if (flags.install === false || flags["dry-run"]) {
|
|
495
|
+
if (!flags["dry-run"] && pkg) {
|
|
496
|
+
const file = join4(cwd, "package.json");
|
|
497
|
+
const json = JSON.parse(await readFile4(file, "utf8"));
|
|
498
|
+
json.dependencies ??= {};
|
|
499
|
+
for (const spec of missing) {
|
|
500
|
+
const { name, range } = splitSpec(spec);
|
|
501
|
+
json.dependencies[name] = range ? `^${range.replace(/^\^/, "")}` : "*";
|
|
502
|
+
}
|
|
503
|
+
await writeFile3(file, `${JSON.stringify(json, null, 2)}
|
|
504
|
+
`);
|
|
505
|
+
log(c.dim(`Added to package.json, not installed: ${missing.join(", ")}`));
|
|
506
|
+
} else
|
|
507
|
+
log(c.dim(`Would install ${missing.join(", ")}`));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
log(`Installing ${missing.join(", ")} with ${packageManager(cwd)}…`);
|
|
511
|
+
if (!install(cwd, missing))
|
|
512
|
+
warn(`Couldn't install ${missing.join(", ")}. Install them yourself.`);
|
|
513
|
+
}
|
|
514
|
+
async function add(names, flags) {
|
|
515
|
+
const ctx = await context(flags, true);
|
|
516
|
+
const wanted = flags.all ? ctx.registry.items.map((i) => i.name) : names;
|
|
517
|
+
if (!wanted.length)
|
|
518
|
+
throw new CliError(`Name what to add, e.g. \`${RUN} fetch picture\`, or pass --all.`);
|
|
519
|
+
const items = resolveItems(ctx.registry, wanted);
|
|
520
|
+
const plans = await planFiles(ctx.cwd, ctx.src, ctx.registry, items, ctx.config.paths);
|
|
521
|
+
const created = [], updated = [], skipped = [];
|
|
522
|
+
for (const p of plans) {
|
|
523
|
+
if (p.status === "same")
|
|
524
|
+
continue;
|
|
525
|
+
if (p.status === "new")
|
|
526
|
+
created.push(p);
|
|
527
|
+
else if (flags.overwrite)
|
|
528
|
+
updated.push(p);
|
|
529
|
+
else if (!flags.yes && interactive() && await confirm(`${rel(p)} differs from the registry. Overwrite it?`))
|
|
530
|
+
updated.push(p);
|
|
531
|
+
else
|
|
532
|
+
skipped.push(p);
|
|
533
|
+
}
|
|
534
|
+
if (flags["dry-run"]) {
|
|
535
|
+
for (const p of created)
|
|
536
|
+
log(`${c.green("create")} ${rel(p)}`);
|
|
537
|
+
for (const p of updated)
|
|
538
|
+
log(`${c.yellow("update")} ${rel(p)}`);
|
|
539
|
+
for (const p of skipped)
|
|
540
|
+
log(`${c.dim("skip ")} ${rel(p)}`);
|
|
541
|
+
} else
|
|
542
|
+
for (const p of [...created, ...updated])
|
|
543
|
+
await writePlan(ctx.cwd, p);
|
|
544
|
+
await installDependencies(ctx.cwd, items, flags);
|
|
545
|
+
const verb = flags["dry-run"] ? "Would write" : "Wrote";
|
|
546
|
+
log(`${verb} ${created.length + updated.length} file(s) for ${items.map((i) => i.name).join(", ")}.`);
|
|
547
|
+
if (skipped.length)
|
|
548
|
+
log(c.yellow(`Kept your version of ${skipped.map(rel).join(", ")}. See what changed: ${RUN} inventory; take the registry's: --overwrite.`));
|
|
549
|
+
}
|
|
550
|
+
async function init(names, flags) {
|
|
551
|
+
const cwd = resolve2(str(flags.cwd) ?? process.cwd());
|
|
552
|
+
if (!await readPackage(cwd))
|
|
553
|
+
throw new CliError(`No package.json in ${cwd}. Make an app first: ${RUN} new my-app`);
|
|
554
|
+
const existing = await readConfig(cwd);
|
|
555
|
+
if (existing && !flags.force) {
|
|
556
|
+
log(`${CONFIG} is already here. Pass --force to write it again.`);
|
|
557
|
+
} else {
|
|
558
|
+
const config = existing ?? defaultConfig();
|
|
559
|
+
if (str(flags.ref))
|
|
560
|
+
config.ref = str(flags.ref);
|
|
561
|
+
if (str(flags.registry))
|
|
562
|
+
config.registry = str(flags.registry);
|
|
563
|
+
if (str(flags.ui))
|
|
564
|
+
config.paths.ui = str(flags.ui);
|
|
565
|
+
if (str(flags.kit))
|
|
566
|
+
config.paths.kit = str(flags.kit);
|
|
567
|
+
await writeConfig(cwd, config);
|
|
568
|
+
log(`${c.green("create")} ${CONFIG}`);
|
|
569
|
+
}
|
|
570
|
+
const { registry } = await context(flags, true);
|
|
571
|
+
const core = registry.items.filter(isCore).map((i) => i.name);
|
|
572
|
+
await add([...core, ...names], { ...flags, cwd });
|
|
573
|
+
}
|
|
574
|
+
async function changedPlans(flags, names) {
|
|
575
|
+
const ctx = await context(flags, true);
|
|
576
|
+
const installed = installedItems(ctx.cwd, ctx.registry, ctx.config.paths);
|
|
577
|
+
const items = names.length ? resolveItems(ctx.registry, names) : resolveItems(ctx.registry, installed.map((i) => i.name));
|
|
578
|
+
const plans = await planFiles(ctx.cwd, ctx.src, ctx.registry, items, ctx.config.paths);
|
|
579
|
+
return { ctx, items, plans, installed };
|
|
580
|
+
}
|
|
581
|
+
async function update(names, flags) {
|
|
582
|
+
const { ctx, items, plans, installed } = await changedPlans(flags, names);
|
|
583
|
+
if (!installed.length && !names.length)
|
|
584
|
+
throw new CliError("Nothing from barback is installed here yet.");
|
|
585
|
+
const todo = plans.filter((p) => p.status !== "same");
|
|
586
|
+
if (!todo.length) {
|
|
587
|
+
log(`Up to date with ${ctx.src.base}.`);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
for (const p of todo) {
|
|
591
|
+
if (p.status === "new")
|
|
592
|
+
log(`${c.green("create")} ${rel(p)}`);
|
|
593
|
+
else if (p.text !== null && p.local !== null) {
|
|
594
|
+
const { added, removed } = changes(p.local, p.text);
|
|
595
|
+
log(`${c.yellow("update")} ${rel(p)} ${c.green(`+${added}`)} ${c.red(`-${removed}`)}`);
|
|
596
|
+
if (flags.diff)
|
|
597
|
+
printDiff(unified(p.local, p.text));
|
|
598
|
+
} else
|
|
599
|
+
log(`${c.yellow("update")} ${rel(p)}`);
|
|
600
|
+
}
|
|
601
|
+
if (flags["dry-run"])
|
|
602
|
+
return;
|
|
603
|
+
const changed = todo.filter((p) => p.status === "changed").length;
|
|
604
|
+
if (changed && !flags.yes) {
|
|
605
|
+
if (!interactive())
|
|
606
|
+
throw new CliError("Updating replaces your edits in these files. Pass --yes to go ahead.");
|
|
607
|
+
if (!await confirm(`Replace ${changed} file(s) with the registry's? Your edits in them will be lost.`))
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
for (const p of todo)
|
|
611
|
+
await writePlan(ctx.cwd, p);
|
|
612
|
+
await installDependencies(ctx.cwd, items, flags);
|
|
613
|
+
log(`Updated ${todo.length} file(s).`);
|
|
614
|
+
}
|
|
615
|
+
async function diff(names, flags) {
|
|
616
|
+
const { ctx, plans } = await changedPlans(flags, names);
|
|
617
|
+
const changed = plans.filter((p) => p.status === "changed");
|
|
618
|
+
const missing = plans.filter((p) => p.status === "new");
|
|
619
|
+
if (!changed.length && !missing.length) {
|
|
620
|
+
log(`Everything matches ${ctx.src.base}.`);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
for (const p of changed) {
|
|
624
|
+
if (p.text === null || p.local === null) {
|
|
625
|
+
log(`${c.yellow("changed")} ${rel(p)} ${c.dim("(binary)")}`);
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (names.length) {
|
|
629
|
+
log(c.bold(`${rel(p)}`) + c.dim(` ← ${p.path}`));
|
|
630
|
+
printDiff(unified(p.local, p.text));
|
|
631
|
+
log("");
|
|
632
|
+
} else {
|
|
633
|
+
const { added, removed } = changes(p.local, p.text);
|
|
634
|
+
log(`${c.yellow("changed")} ${rel(p)} ${c.dim(p.item)} ${c.green(`+${added}`)} ${c.red(`-${removed}`)}`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
for (const p of missing)
|
|
638
|
+
log(`${c.green("missing")} ${rel(p)} ${c.dim(p.item)}`);
|
|
639
|
+
if (!names.length)
|
|
640
|
+
log(c.dim(`
|
|
641
|
+
Show the lines: ${RUN} inventory <name>. Take the registry's: ${RUN} restock <name>.`));
|
|
642
|
+
}
|
|
643
|
+
var GROUPS = [
|
|
644
|
+
["Core", isCore],
|
|
645
|
+
["Components", (i) => i.type === "registry:ui"],
|
|
646
|
+
["Kit", (i) => i.name.startsWith("kit-")]
|
|
647
|
+
];
|
|
648
|
+
async function list(names, flags) {
|
|
649
|
+
const ctx = await context(flags, false);
|
|
650
|
+
const query = names.join(" ").toLowerCase();
|
|
651
|
+
const installed = ctx.saved ? new Set(installedItems(ctx.cwd, ctx.registry, ctx.config.paths).map((i) => i.name)) : new Set;
|
|
652
|
+
const width = Math.max(...ctx.registry.items.map((i) => i.name.length));
|
|
653
|
+
for (const [title, test] of GROUPS) {
|
|
654
|
+
const items = ctx.registry.items.filter((i) => test(i) && (!query || `${i.name} ${i.description}`.toLowerCase().includes(query)));
|
|
655
|
+
if (!items.length)
|
|
656
|
+
continue;
|
|
657
|
+
log(c.bold(title));
|
|
658
|
+
for (const i of items)
|
|
659
|
+
log(` ${installed.has(i.name) ? c.green("✓") : " "} ${i.name.padEnd(width)} ${c.dim(i.description)}`);
|
|
660
|
+
log("");
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
async function view(names, flags) {
|
|
664
|
+
if (!names.length)
|
|
665
|
+
throw new CliError(`Name what to view, e.g. \`${RUN} sample picture\`.`);
|
|
666
|
+
const ctx = await context(flags, false);
|
|
667
|
+
const items = names.map((n) => resolveItems(ctx.registry, [n]).at(-1));
|
|
668
|
+
const plans = await planFiles(ctx.cwd, ctx.src, ctx.registry, items, ctx.config.paths);
|
|
669
|
+
for (const item of items) {
|
|
670
|
+
log(c.bold(item.name) + c.dim(` ${item.description}`));
|
|
671
|
+
if (item.registryDependencies?.length)
|
|
672
|
+
log(c.dim(`needs: ${item.registryDependencies.join(", ")}`));
|
|
673
|
+
for (const p of plans.filter((x) => x.item === item.name)) {
|
|
674
|
+
log(c.cyan(`
|
|
675
|
+
${p.target}`));
|
|
676
|
+
log(p.text ?? c.dim(`(binary, ${p.content.length} bytes)`));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
async function info(_, flags) {
|
|
681
|
+
const ctx = await context(flags, false);
|
|
682
|
+
log(`${c.bold("project")} ${ctx.cwd}`);
|
|
683
|
+
log(`${c.bold("config")} ${ctx.saved ? CONFIG : c.dim(`none, run ${RUN} open`)}`);
|
|
684
|
+
log(`${c.bold("registry")} ${ctx.src.base}`);
|
|
685
|
+
log(`${c.bold("paths")} ui ${ctx.config.paths.ui}, kit ${ctx.config.paths.kit}`);
|
|
686
|
+
log(`${c.bold("installer")} ${packageManager(ctx.cwd)}`);
|
|
687
|
+
if (ctx.saved)
|
|
688
|
+
log(`${c.bold("installed")} ${installedItems(ctx.cwd, ctx.registry, ctx.config.paths).map((i) => i.name).join(", ")}`);
|
|
689
|
+
}
|
|
690
|
+
async function create(names, flags) {
|
|
691
|
+
const dir = names[0];
|
|
692
|
+
if (!dir)
|
|
693
|
+
throw new CliError(`Name the app's folder: ${RUN} new my-app`);
|
|
694
|
+
const cwd = resolve2(str(flags.cwd) ?? process.cwd());
|
|
695
|
+
const target = resolve2(cwd, dir);
|
|
696
|
+
if (existsSync3(target))
|
|
697
|
+
throw new CliError(`${target} already exists.`);
|
|
698
|
+
const pm = str(flags.pm) ?? packageManager(cwd);
|
|
699
|
+
log(`Creating a BUSY Bar app in ${target} with @busy-app/cli…`);
|
|
700
|
+
const res = spawnSync2("npx", generatorArgs(dir, pm, flags), {
|
|
701
|
+
cwd,
|
|
702
|
+
stdio: "inherit",
|
|
703
|
+
shell: process.platform === "win32"
|
|
704
|
+
});
|
|
705
|
+
if (res.status !== 0 || !existsSync3(join4(target, "package.json")))
|
|
706
|
+
throw new CliError("The BUSY Bar app generator didn't finish.");
|
|
707
|
+
await init(STARTER_ITEMS, { ...flags, cwd: target, yes: true });
|
|
708
|
+
await writeFile3(join4(target, "src/main.ts"), STARTER_MAIN);
|
|
709
|
+
log(`${c.green("update")} src/main.ts`);
|
|
710
|
+
log(`
|
|
711
|
+
${c.bold("Done.")} Next:
|
|
712
|
+
cd ${dir}
|
|
713
|
+
${RUN} fetch picture marquee
|
|
714
|
+
${pm} run build`);
|
|
715
|
+
}
|
|
716
|
+
async function remove(names, flags) {
|
|
717
|
+
if (!names.length)
|
|
718
|
+
throw new CliError(`Name what to toss, e.g. \`${RUN} toss picture\`.`);
|
|
719
|
+
const ctx = await context(flags, true);
|
|
720
|
+
const installed = installedItems(ctx.cwd, ctx.registry, ctx.config.paths);
|
|
721
|
+
const items = names.map((n) => {
|
|
722
|
+
const item = installed.find((i) => i.name === n.replace(/^kit\//, "kit-"));
|
|
723
|
+
if (!item)
|
|
724
|
+
throw new CliError(`${n} isn't in this app.`);
|
|
725
|
+
return item;
|
|
726
|
+
});
|
|
727
|
+
const going = new Set(items.map((i) => i.name));
|
|
728
|
+
const needed = installed.filter((i) => !going.has(i.name) && (i.registryDependencies ?? []).some((d) => going.has(d)));
|
|
729
|
+
if (needed.length && !flags.force)
|
|
730
|
+
throw new CliError(`${needed.map((i) => i.name).join(", ")} still need ${[...going].join(", ")}. Toss them too, or pass --force.`);
|
|
731
|
+
const plans = (await planFiles(ctx.cwd, ctx.src, ctx.registry, items, ctx.config.paths)).filter((p) => p.status !== "new");
|
|
732
|
+
const edited = plans.filter((p) => p.status === "changed");
|
|
733
|
+
for (const p of plans)
|
|
734
|
+
log(`${c.red("delete")} ${rel(p)}${p.status === "changed" ? c.yellow(" (edited)") : ""}`);
|
|
735
|
+
if (flags["dry-run"])
|
|
736
|
+
return;
|
|
737
|
+
if (!flags.yes) {
|
|
738
|
+
if (!interactive())
|
|
739
|
+
throw new CliError("Pass --yes to delete these files.");
|
|
740
|
+
const ask = edited.length ? `Delete ${plans.length} file(s)? ${edited.length} of them have your edits.` : `Delete ${plans.length} file(s)?`;
|
|
741
|
+
if (!await confirm(ask))
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
for (const p of plans)
|
|
745
|
+
await rm(join4(ctx.cwd, p.target), { force: true });
|
|
746
|
+
log(`Tossed ${items.map((i) => i.name).join(", ")}.`);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// src/index.ts
|
|
750
|
+
var HELP = `${c.bold("barback")} ${package_default.version}: brings busy-barback/ui components to your BUSY Bar app.
|
|
751
|
+
|
|
752
|
+
${c.bold("Usage")}
|
|
753
|
+
barback <command> [options]
|
|
754
|
+
|
|
755
|
+
${c.bold("Commands")}
|
|
756
|
+
new <dir> a BUSY Bar app with the kit and a starter screen ${c.dim("alias: create")}
|
|
757
|
+
open [items...] set up barback.json and bring the core ${c.dim("alias: init")}
|
|
758
|
+
fetch <items...> bring components and everything they need ${c.dim("alias: add")}
|
|
759
|
+
restock [items...] the registry's version of what you have (all of it) ${c.dim("alias: update")}
|
|
760
|
+
inventory [items...] what differs from the registry; line by line if named ${c.dim("alias: diff")}
|
|
761
|
+
menu [query] everything there is, ✓ for what you have ${c.dim("alias: list, search")}
|
|
762
|
+
sample <items...> show an item's files without bringing them ${c.dim("alias: view")}
|
|
763
|
+
toss <items...> delete components from this app ${c.dim("alias: remove")}
|
|
764
|
+
info the project, its config and the registry it uses
|
|
765
|
+
|
|
766
|
+
${c.bold("Options")}
|
|
767
|
+
-c, --cwd <dir> the app's folder (default: here)
|
|
768
|
+
-y, --yes don't ask
|
|
769
|
+
-o, --overwrite fetch: replace files that differ from the registry
|
|
770
|
+
-a, --all fetch: everything
|
|
771
|
+
-f, --force open: write barback.json again; toss: even if others need it
|
|
772
|
+
--dry-run show what would change, change nothing
|
|
773
|
+
--diff restock: print the lines that change
|
|
774
|
+
--ref <ref> a git branch or tag of the registry (default: barback.json's ref)
|
|
775
|
+
--registry <url> a registry URL or a local busy-barback-ui checkout
|
|
776
|
+
--ui <dir> open: where components go (default: src/ui)
|
|
777
|
+
--kit <dir> open: where the app kit goes (default: src/kit)
|
|
778
|
+
--no-install add packages to package.json without installing them
|
|
779
|
+
--pm <name> new: npm, pnpm, yarn or bun
|
|
780
|
+
-s, --silent print nothing but errors
|
|
781
|
+
-h, --help this help
|
|
782
|
+
-v, --version the version
|
|
783
|
+
`;
|
|
784
|
+
var COMMANDS = {
|
|
785
|
+
new: create,
|
|
786
|
+
create,
|
|
787
|
+
open: init,
|
|
788
|
+
init,
|
|
789
|
+
fetch: add,
|
|
790
|
+
add,
|
|
791
|
+
restock: update,
|
|
792
|
+
update,
|
|
793
|
+
inventory: diff,
|
|
794
|
+
diff,
|
|
795
|
+
menu: list,
|
|
796
|
+
list,
|
|
797
|
+
search: list,
|
|
798
|
+
sample: view,
|
|
799
|
+
view,
|
|
800
|
+
toss: remove,
|
|
801
|
+
remove,
|
|
802
|
+
info
|
|
803
|
+
};
|
|
804
|
+
async function main() {
|
|
805
|
+
const { command, positionals, flags } = parseArgs(process.argv.slice(2));
|
|
806
|
+
if (flags.version)
|
|
807
|
+
return console.log(package_default.version);
|
|
808
|
+
if (!command || flags.help)
|
|
809
|
+
return console.log(HELP);
|
|
810
|
+
const run = COMMANDS[command];
|
|
811
|
+
if (!run)
|
|
812
|
+
throw new CliError(`Unknown command ${command}. Run barback --help.`);
|
|
813
|
+
setSilent(flags.silent === true);
|
|
814
|
+
await run(positionals, flags);
|
|
815
|
+
}
|
|
816
|
+
main().catch((err) => {
|
|
817
|
+
console.error(c.red(err instanceof CliError ? err.message : err instanceof Error ? process.env.BARBACK_DEBUG ? err.stack ?? err.message : err.message : String(err)));
|
|
818
|
+
process.exit(1);
|
|
819
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "busy-barback-ui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "barback: brings busy-barback/ui components to your BUSY Bar app, keeps them up to date, and makes new apps.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"barback",
|
|
7
|
+
"busy-bar",
|
|
8
|
+
"busybar",
|
|
9
|
+
"cli",
|
|
10
|
+
"components"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/nezdemkovski/busy-barback-ui/tree/master/cli#readme",
|
|
13
|
+
"author": "nezdemkovski",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/nezdemkovski/busy-barback-ui.git",
|
|
17
|
+
"directory": "cli"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"barback": "dist/index.js",
|
|
21
|
+
"busy-barback-ui": "dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"schema.json"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"provenance": true
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "bun build src/index.ts --target node --outfile dist/index.js",
|
|
34
|
+
"typecheck": "tsc",
|
|
35
|
+
"test": "bun test tests",
|
|
36
|
+
"prepublishOnly": "bun run build"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/schema.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "barback.json",
|
|
4
|
+
"description": "Where barback brings components from, and where they go in your BUSY Bar app.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"$schema": { "type": "string" },
|
|
8
|
+
"registry": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The registry: a URL or a local busy-barback-ui checkout, with {ref} where the git ref goes.",
|
|
11
|
+
"default": "https://raw.githubusercontent.com/nezdemkovski/busy-barback-ui/{ref}"
|
|
12
|
+
},
|
|
13
|
+
"ref": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "The git branch or tag to copy from. Pin a tag to update on your own schedule.",
|
|
16
|
+
"default": "master"
|
|
17
|
+
},
|
|
18
|
+
"paths": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"ui": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Where components and the core go.",
|
|
24
|
+
"default": "src/ui"
|
|
25
|
+
},
|
|
26
|
+
"kit": { "type": "string", "description": "Where the app kit goes.", "default": "src/kit" }
|
|
27
|
+
},
|
|
28
|
+
"additionalProperties": false
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"required": ["registry", "ref"],
|
|
32
|
+
"additionalProperties": false
|
|
33
|
+
}
|