@muhkoo/cli 0.14.0-alpha.7 → 0.14.0-alpha.9
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 +106 -5
- package/bin/muhkoo.js +8 -1
- package/package.json +2 -2
- package/src/commands/domains.js +1 -1
- package/src/commands/functions.js +2 -2
- package/src/commands/login.js +2 -1
- package/src/commands/promote.js +2 -2
- package/src/commands/provision.js +2 -2
- package/src/commands/tokens.js +1 -1
- package/src/commands/vcs.js +89 -6
- package/src/commands/vfs.js +264 -51
- package/src/index.js +11 -6
- package/src/lib/auth.js +3 -3
- package/src/lib/ignore.js +900 -94
- package/src/lib/mount.js +2049 -164
- package/src/lib/syncPlan.js +105 -2
- package/src/lib/ui.js +92 -23
- package/src/lib/vfs.js +39 -16
- package/src/lib/webLogin.js +1 -1
package/src/commands/vfs.js
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* keep byte-exact — and the first one to drift would corrupt real files.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
10
|
+
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
11
11
|
import { basename, resolve } from "node:path";
|
|
12
12
|
import { openClient, explainWriteFailure } from "../lib/vfs.js";
|
|
13
|
-
import { mount as mountDir, importOnce } from "../lib/mount.js";
|
|
14
|
-
import { draftIgnores } from "../lib/ignore.js";
|
|
13
|
+
import { mount as mountDir, importOnce, previewMount, heldBack, acceptIgnores, diskIgnoreTexts, assertMountable } from "../lib/mount.js";
|
|
14
|
+
import { draftIgnores, ignoreFileProblem } from "../lib/ignore.js";
|
|
15
15
|
import { loadConfig, saveConfig } from "../lib/config.js";
|
|
16
|
-
import { table, json, ok, info, warn, die } from "../lib/ui.js";
|
|
16
|
+
import { table, json, ok, info, warn, die, writeText, prompt } from "../lib/ui.js";
|
|
17
17
|
|
|
18
18
|
export const help = `muhkoo vfs — your encrypted filesystem
|
|
19
19
|
|
|
@@ -33,17 +33,64 @@ Usage:
|
|
|
33
33
|
muhkoo vfs find <glob> e.g. '/apps/**/*.ts'
|
|
34
34
|
muhkoo vfs history <path> prior versions, newest first
|
|
35
35
|
muhkoo vfs restore <path> [index] restore a version (default 0)
|
|
36
|
-
muhkoo vfs ignore [dir]
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
muhkoo vfs ignore [dir] show whether ignore rules this directory
|
|
37
|
+
used earlier still hold files back, which
|
|
38
|
+
ignore files changed, and which local
|
|
39
|
+
files they hold
|
|
40
|
+
muhkoo vfs ignore [dir] --accept show what accepting would let through,
|
|
41
|
+
and a digest of the ignore files as they
|
|
42
|
+
now stand (on a terminal, asks y/N)
|
|
43
|
+
muhkoo vfs ignore [dir] --accept <d> make exactly the files with digest <d> the
|
|
44
|
+
only rules; refused if they changed since
|
|
45
|
+
(a running mount acts on it at once)
|
|
46
|
+
muhkoo vfs ignore [dir] --draft print a .vcsignore drafted from the Node
|
|
47
|
+
defaults + every .gitignore and
|
|
48
|
+
.git/info/exclude on disk (it replaces them
|
|
49
|
+
all); --write saves it (--force to replace),
|
|
50
|
+
unless it is past an ignore file's limits
|
|
51
|
+
muhkoo vfs import <dir…> [--path <p>] upload whole projects, once. Upload only:
|
|
52
|
+
never writes or deletes anything here
|
|
39
53
|
muhkoo vfs mount <dir> [--path <p>] sync a subtree to disk and keep it live
|
|
40
|
-
(dot-files skipped; deletes need --allow-delete
|
|
54
|
+
(dot-files skipped; deletes need --allow-delete;
|
|
55
|
+
Ctrl-C or closing the terminal stops it after
|
|
56
|
+
the current file; a second Ctrl-C quits now)
|
|
41
57
|
muhkoo vfs sweep [--force] reclaim orphaned records
|
|
42
58
|
muhkoo vfs use-app <domain> use an app, by the domain you use it at
|
|
43
59
|
muhkoo vfs app show which app you are writing as
|
|
44
60
|
|
|
45
|
-
What gets synced is decided by .vcsignore
|
|
46
|
-
|
|
61
|
+
What gets synced is decided by .vcsignore if there is one. Otherwise git's
|
|
62
|
+
rules apply: every .gitignore, each scoped to its own directory, and
|
|
63
|
+
.git/info/exclude. Built-in Node defaults sit underneath either way (they
|
|
64
|
+
exclude .env and .env.*, but not .env.example).
|
|
65
|
+
|
|
66
|
+
Once a path has been kept home, no edit to an ignore file lets it sync —
|
|
67
|
+
pulled or local, a rule removed or a blank line added. Each directory keeps
|
|
68
|
+
every set of ignore rules it has used since the last accept
|
|
69
|
+
(.muhkoo/ignore-rules.json, never synced, with a copy under ~/.muhkoo), and a
|
|
70
|
+
path is ignored if any of them, or the files as they now stand, ignore it.
|
|
71
|
+
New exclusions apply at once; a loosening waits until you accept it:
|
|
72
|
+
\`muhkoo vfs ignore <dir> --accept\` shows what that lets through, which ignore
|
|
73
|
+
files changed, and the digest that accepts exactly those files. Check them
|
|
74
|
+
first — one that came from your filesystem may not be yours. Comments, blank
|
|
75
|
+
lines and line endings change nothing, and neither does going back to rules
|
|
76
|
+
already kept; any other change to the ignore files — a rule added, removed or
|
|
77
|
+
reworded, a file added or removed, here or from your filesystem — is kept as
|
|
78
|
+
another set of rules, up to 64 or 2 MB. Past that, or if the stored rules
|
|
79
|
+
cannot be read, nothing syncs until you accept. An ignore file from your
|
|
80
|
+
filesystem too large to read as rules is not pulled. Until every ignore file
|
|
81
|
+
due has come down, nothing uploads. A path too costly to match against the
|
|
82
|
+
rules is left alone — neither synced nor deleted — and named.
|
|
83
|
+
|
|
84
|
+
Some paths never sync in either direction, whatever the rules say: .git,
|
|
85
|
+
.ssh, node_modules, .muhkoo, editor and agent config (.vscode, .idea, .claude,
|
|
86
|
+
.cursor, .zed, .fleet), .husky, and shell and credential files (.npmrc,
|
|
87
|
+
.netrc, .zshrc, .zshenv, …). Neither import nor mount will run on your home
|
|
88
|
+
directory, or on anything that contains it. One pass of mount pulls at most
|
|
89
|
+
2 GiB or 10,000 files, and reads at most as much to compare, carrying on at
|
|
90
|
+
once in another pass; what it has read before it does not read again. A pull
|
|
91
|
+
leaves the disk 5% of its space free, at least 1 GiB and at most 10 GiB —
|
|
92
|
+
judged by the bytes that arrive, not the sizes your filesystem reports.
|
|
93
|
+
Ignore files are held to these limits like any other file.
|
|
47
94
|
|
|
48
95
|
Reading your files is free. WRITING stores bytes, which are metered to an
|
|
49
96
|
app — so put, rm, cp, mv and restore need an app signed in first.
|
|
@@ -52,11 +99,19 @@ Options:
|
|
|
52
99
|
--app <name> write as this app for one command
|
|
53
100
|
--key <k> supply the app key yourself (apps that publish their public
|
|
54
101
|
config at /.well-known/muhkoo.json need no key)
|
|
55
|
-
--allow-delete propagate
|
|
56
|
-
the file's history too, so unlike an
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
102
|
+
--allow-delete propagate deletions (import: only to your filesystem). OFF by
|
|
103
|
+
default: a delete removes the file's history too, so unlike an
|
|
104
|
+
overwrite it cannot be undone. It trusts the remote side. A pass
|
|
105
|
+
that would leave fewer than half the files this run has tracked,
|
|
106
|
+
or delete anything when one side is empty, deletes nothing in
|
|
107
|
+
that direction and says why — a guard against a broken or
|
|
108
|
+
missing root, not against whatever can write your filesystem
|
|
109
|
+
--hidden also sync dot-files and dot-directories (never the ones above)
|
|
110
|
+
--dry-run import: list what would be uploaded, the total size, and what
|
|
111
|
+
import skips. mount: list what mounting would download,
|
|
112
|
+
upload and delete, then stop. Neither writes anything, here,
|
|
113
|
+
in your filesystem or under ~/.muhkoo, and neither pairs this
|
|
114
|
+
machine (it signs in for the one command if it must)
|
|
60
115
|
--no-pair unlock for this command only; pair nothing to this machine`;
|
|
61
116
|
|
|
62
117
|
export default async function vfs(args) {
|
|
@@ -67,18 +122,22 @@ export default async function vfs(args) {
|
|
|
67
122
|
// to write a file on this disk is both pointless and expensive: each unlock
|
|
68
123
|
// is a vault read, and a loop over a dozen projects trips the auth rate
|
|
69
124
|
// limiter long before it finishes.
|
|
70
|
-
if (sub === "ignore") return
|
|
71
|
-
|
|
72
|
-
|
|
125
|
+
if (sub === "ignore") return ignoreCommand(args);
|
|
126
|
+
|
|
127
|
+
// A dry run writes nothing, and that includes ~/.muhkoo: unlocking would
|
|
128
|
+
// otherwise pair a machine not paired yet (a device enrolled on the server,
|
|
129
|
+
// its key saved) and reset a stale working directory. It unlocks for this
|
|
130
|
+
// command only. A swallowed directory (`--dry-run <dir>`) still counts.
|
|
131
|
+
const dryRun = (sub === "import" || sub === "push" || sub === "mount") && Boolean(args["dry-run"]);
|
|
132
|
+
const client = await openClient(dryRun ? { ...args, pair: false, readOnly: true } : args);
|
|
73
133
|
const fs = client.vfs;
|
|
74
134
|
const a = (n, dflt) => args._[n] ?? dflt;
|
|
75
135
|
|
|
76
136
|
try {
|
|
77
137
|
return await run();
|
|
78
138
|
} catch (err) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
if (explained !== (err?.message ?? String(err))) die(explained);
|
|
139
|
+
const explained = explainWriteFailure(err, await loadConfig());
|
|
140
|
+
if (explained) die(...explained);
|
|
82
141
|
throw err;
|
|
83
142
|
}
|
|
84
143
|
|
|
@@ -128,7 +187,7 @@ export default async function vfs(args) {
|
|
|
128
187
|
|
|
129
188
|
case "cat": {
|
|
130
189
|
const path = required(a(2), "cat <path>");
|
|
131
|
-
|
|
190
|
+
writeText(await fs.readText(path));
|
|
132
191
|
return;
|
|
133
192
|
}
|
|
134
193
|
|
|
@@ -217,7 +276,7 @@ export default async function vfs(args) {
|
|
|
217
276
|
if (args.json) return json({ app: slug ?? null, known: Object.keys(current.vfsApps ?? {}) });
|
|
218
277
|
if (!slug) {
|
|
219
278
|
return info(
|
|
220
|
-
"Not writing as any app — reads work, writes will not
|
|
279
|
+
"Not writing as any app — reads work, writes will not.",
|
|
221
280
|
"Sign one in with: muhkoo vfs use-app <slug> --key <appKey>",
|
|
222
281
|
);
|
|
223
282
|
}
|
|
@@ -226,7 +285,7 @@ export default async function vfs(args) {
|
|
|
226
285
|
|
|
227
286
|
case "import":
|
|
228
287
|
case "push": {
|
|
229
|
-
const dirs = args
|
|
288
|
+
const { flags, positionals: dirs } = booleanFlags(args, ["hidden", "allow-delete", "dry-run", "no-pair"]);
|
|
230
289
|
if (!dirs.length) return die("Usage: muhkoo vfs import <dir…> [--path /apps/<slug>]");
|
|
231
290
|
// `--path` names ONE destination, so it cannot mean anything sensible for
|
|
232
291
|
// several directories at once.
|
|
@@ -237,11 +296,8 @@ export default async function vfs(args) {
|
|
|
237
296
|
// Several directories in ONE process, on purpose: every invocation of the
|
|
238
297
|
// CLI unlocks the vault, and a shell loop over a dozen projects trips the
|
|
239
298
|
// auth rate limiter before it finishes.
|
|
240
|
-
const opts = {
|
|
241
|
-
|
|
242
|
-
allowDelete: Boolean(args["allow-delete"]),
|
|
243
|
-
dryRun: Boolean(args["dry-run"]),
|
|
244
|
-
};
|
|
299
|
+
const opts = { hidden: flags.hidden, allowDelete: flags["allow-delete"], dryRun: flags["dry-run"] };
|
|
300
|
+
let failed = 0;
|
|
245
301
|
for (const d of dirs) {
|
|
246
302
|
const root = normalizeRoot(args.path ?? `/apps/${await slugFor(resolve(d))}`);
|
|
247
303
|
try {
|
|
@@ -249,24 +305,40 @@ export default async function vfs(args) {
|
|
|
249
305
|
} catch (err) {
|
|
250
306
|
// One unreadable project must not abandon the other twelve.
|
|
251
307
|
warn(`${d}: ${err?.message ?? err}`);
|
|
308
|
+
failed++;
|
|
252
309
|
}
|
|
253
310
|
}
|
|
311
|
+
// ...but it must still fail the command, or `import ~ && deploy` carries
|
|
312
|
+
// on as if it had worked. `die`, not `process.exitCode`: the launcher
|
|
313
|
+
// exits 0 explicitly once a command returns.
|
|
314
|
+
if (failed) return die(`${failed} of ${dirs.length} director${dirs.length === 1 ? "y was" : "ies were"} not imported — see above.`);
|
|
254
315
|
return;
|
|
255
316
|
}
|
|
256
317
|
|
|
257
318
|
case "mount": {
|
|
258
|
-
const
|
|
319
|
+
const { flags, positionals } = booleanFlags(args, ["hidden", "allow-delete", "dry-run", "no-pair"]);
|
|
320
|
+
if (positionals.length > 1) return die(`vfs mount takes one directory, not ${positionals.length}: ${positionals.join(", ")}`);
|
|
321
|
+
const dir = required(positionals[0], "mount <dir> [--path /apps]");
|
|
259
322
|
const root = normalizeRoot(args.path ?? "/");
|
|
323
|
+
if (flags["dry-run"]) {
|
|
324
|
+
return previewMount({ client, dir: resolve(dir), root, opts: { allowDelete: flags["allow-delete"], hidden: flags.hidden } });
|
|
325
|
+
}
|
|
260
326
|
// Ctrl-C is the way out of a foreground watcher, so it has to be a clean
|
|
261
327
|
// stop that flushes state — not a process kill mid-write.
|
|
328
|
+
// A closed terminal (SIGHUP) is the same request: killed outright, a
|
|
329
|
+
// pass could stop between writing a pulled file and recording it.
|
|
262
330
|
const controller = new AbortController();
|
|
263
|
-
const stop = (
|
|
264
|
-
|
|
265
|
-
process.on(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
331
|
+
const stop = stopOnSignals(controller);
|
|
332
|
+
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
333
|
+
for (const sig of signals) process.on(sig, stop);
|
|
334
|
+
try {
|
|
335
|
+
await mountDir({
|
|
336
|
+
client, dir: resolve(dir), root, signal: controller.signal,
|
|
337
|
+
opts: { allowDelete: flags["allow-delete"], hidden: flags.hidden },
|
|
338
|
+
});
|
|
339
|
+
} finally {
|
|
340
|
+
for (const sig of signals) process.off(sig, stop);
|
|
341
|
+
}
|
|
270
342
|
return ok("Unmounted.");
|
|
271
343
|
}
|
|
272
344
|
|
|
@@ -285,22 +357,143 @@ export default async function vfs(args) {
|
|
|
285
357
|
}
|
|
286
358
|
|
|
287
359
|
/**
|
|
288
|
-
*
|
|
360
|
+
* `vfs ignore`: what the ignore ratchet holds back, accepting the ignore files
|
|
361
|
+
* as they now stand, and drafting a `.vcsignore`. Local only — no session, no
|
|
362
|
+
* network.
|
|
289
363
|
*/
|
|
290
|
-
async function
|
|
291
|
-
|
|
364
|
+
async function ignoreCommand(args) {
|
|
365
|
+
// `--accept <digest>`: the shared parser hands the flag the next word, which
|
|
366
|
+
// is either the digest a preview printed or — `--accept ~/proj` — the
|
|
367
|
+
// directory, taken as one below.
|
|
368
|
+
const digest = typeof args.accept === "string" && DIGEST.test(args.accept) ? args.accept : undefined;
|
|
369
|
+
const { flags, positionals: named } = booleanFlags(digest ? { ...args, accept: true } : args, ["accept", "draft", "write", "force", "hidden"]);
|
|
370
|
+
if (named.length > 1) return die(`vfs ignore takes one directory, not ${named.length}: ${named.join(", ")}`);
|
|
371
|
+
const on = (flag) => flags[flag];
|
|
372
|
+
const dir = resolve(named[0] ?? ".");
|
|
373
|
+
// Accepting, or writing a draft, would otherwise create the directory.
|
|
374
|
+
if (!(await stat(dir).then((s) => s.isDirectory(), () => false))) return die(`${dir} does not exist, or is not a directory.`);
|
|
375
|
+
if (on("write") || on("draft")) return draftIgnoreFile(dir, { write: on("write"), force: on("force") });
|
|
376
|
+
if (on("accept")) return acceptCommand(dir, digest);
|
|
377
|
+
|
|
378
|
+
const shown = await heldBack(dir);
|
|
379
|
+
if (shown.unreadable) return die(shown.unreadable.message);
|
|
380
|
+
if (!shown.mounted) return info(`${dir} has no stored ignore rules: it has not been mounted or imported here.`);
|
|
381
|
+
if (!shown.inForce) {
|
|
382
|
+
return info(
|
|
383
|
+
`Nothing in ${dir} is held back: the ignore files as they now stand are the ones last accepted.`,
|
|
384
|
+
"(`--draft` prints a .vcsignore drafted from them; `--write` saves it.)",
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
showHeld(dir, shown);
|
|
388
|
+
return info("", `To see what accepting the ignore files as they now stand would let through: muhkoo vfs ignore ${dir} --accept`);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** A digest `--accept` prints, and takes back. */
|
|
392
|
+
const DIGEST = /^[0-9a-f]{16}$/;
|
|
393
|
+
|
|
394
|
+
/** What the older rules still hold, as `vfs ignore` and `--accept` both show it. */
|
|
395
|
+
function showHeld(dir, { changed, held }) {
|
|
396
|
+
info(`Ignore rules ${dir} used earlier — when they were last accepted, or since — still apply here, beside the files as they now stand.`);
|
|
397
|
+
if (changed.length) info("Changed since they were last accepted — check them, since one that came from your filesystem may not be yours:", ...changed.map((c) => ` ${c}`));
|
|
398
|
+
if (held.length) info("Local files they hold back, which accepting lets through:", ...held.map((p) => ` ${p}`));
|
|
399
|
+
else info("No local file is held back by them; accepting only tidies the stored rules.");
|
|
400
|
+
info("Files arriving from your filesystem that they keep out may be held too, and would then come down.");
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* `--accept`: show what accepting lets through, with a digest of the ignore
|
|
405
|
+
* files as they now stand; `--accept <digest>` accepts exactly those, and
|
|
406
|
+
* refuses when they have changed since. On a terminal it asks instead, and
|
|
407
|
+
* accepts the files it showed — the same digest, checked the same way.
|
|
408
|
+
*
|
|
409
|
+
* Bound to what was shown, because an accept adopts whatever ignore files are
|
|
410
|
+
* on disk, one that arrived from elsewhere included: `--accept --yes` re-read
|
|
411
|
+
* the disk, so a file that landed after the preview was adopted unseen.
|
|
412
|
+
*/
|
|
413
|
+
async function acceptCommand(dir, digest) {
|
|
414
|
+
try {
|
|
415
|
+
await assertMountable(dir);
|
|
416
|
+
} catch (err) {
|
|
417
|
+
return die(err?.message ?? String(err));
|
|
418
|
+
}
|
|
419
|
+
const shown = await heldBack(dir);
|
|
420
|
+
if (!shown.mounted) return die(`${dir} has never been mounted or imported, so it has no ignore rules to accept.`);
|
|
421
|
+
if (digest) return accept(dir, digest);
|
|
422
|
+
if (shown.unreadable) warn(shown.unreadable.message, " So what accepting lets through cannot be listed.");
|
|
423
|
+
else if (!shown.inForce) return info(`Nothing to accept: the ignore files in ${dir} as they now stand are the ones last accepted.`);
|
|
424
|
+
else showHeld(dir, shown);
|
|
425
|
+
info("", `Those are the ignore files as they now stand (digest ${shown.digest}). To accept exactly them: muhkoo vfs ignore ${dir} --accept ${shown.digest}`);
|
|
426
|
+
if (!(process.stdin.isTTY && process.stdout.isTTY)) return;
|
|
427
|
+
if (!/^y(es)?$/i.test(await prompt("Accept them now? [y/N] "))) return info("Not accepted — nothing has changed.");
|
|
428
|
+
return accept(dir, shown.digest);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async function accept(dir, digest) {
|
|
432
|
+
let eligible;
|
|
433
|
+
try {
|
|
434
|
+
({ eligible } = await acceptIgnores(dir, digest));
|
|
435
|
+
} catch (err) {
|
|
436
|
+
return die(err?.message ?? String(err));
|
|
437
|
+
}
|
|
438
|
+
return ok(
|
|
439
|
+
`Accepted the ignore files in ${dir} as they now stand: only they decide what syncs from now on.`,
|
|
440
|
+
...(eligible?.length ? [` Now eligible to sync: ${eligible.join(", ")}`] : []),
|
|
441
|
+
" A running `muhkoo vfs mount` acts on this at once.",
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Draft a `.vcsignore` from every ignore file git reads, as it stands on disk,
|
|
447
|
+
* and print it — or with --write, save it.
|
|
448
|
+
*
|
|
449
|
+
* From every file, not the root `.gitignore` alone: a `.vcsignore` replaces
|
|
450
|
+
* them all, so leaving the nested ones out switched them off. From the files
|
|
451
|
+
* ON DISK: the draft is what the directory says now. Writing a looser
|
|
452
|
+
* `.vcsignore` than the rules it replaces lets nothing new through until it is
|
|
453
|
+
* accepted — the ignore ratchet holds whatever the older rules excluded.
|
|
454
|
+
*/
|
|
455
|
+
async function draftIgnoreFile(dir, { write, force }) {
|
|
292
456
|
const target = `${dir}/.vcsignore`;
|
|
293
457
|
const existing = await readFile(target, "utf8").catch(() => null);
|
|
294
|
-
if (existing && !
|
|
458
|
+
if (write && existing && !force) {
|
|
295
459
|
return die(`${target} already exists. Pass --force to replace it.`);
|
|
296
460
|
}
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
461
|
+
const texts = await diskIgnoreTexts(dir);
|
|
462
|
+
const draft = draftIgnores(texts);
|
|
463
|
+
const carried = [...texts.keys()].filter((file) => file !== ".gitignore");
|
|
464
|
+
const note = carried.length ? [` Carried over: ${carried.join(", ")} — a .vcsignore replaces them all.`] : [];
|
|
465
|
+
// One flat file of what several said can be past what one ignore file may
|
|
466
|
+
// hold. Written, it would stop every pass that read it.
|
|
467
|
+
const problem = ignoreFileProblem(draft);
|
|
468
|
+
const refusal = problem && [
|
|
469
|
+
`A .vcsignore drafted from them would not be read: ${problem}.`,
|
|
470
|
+
" Without a .vcsignore the mount reads every .gitignore as git does, so there is no need for one to keep them.",
|
|
471
|
+
];
|
|
472
|
+
if (!write) {
|
|
473
|
+
info(...draft.replace(/\n$/, "").split("\n"));
|
|
474
|
+
if (refusal) warn(...refusal);
|
|
475
|
+
return info("", `(nothing written — pass --write to save this to ${target})`, ...note);
|
|
301
476
|
}
|
|
477
|
+
if (refusal) return die(`Not written. ${refusal[0]}`, ...refusal.slice(1));
|
|
302
478
|
await writeFile(target, draft);
|
|
303
|
-
return ok(`Wrote ${target}
|
|
479
|
+
return ok(`Wrote ${target}`, ...note);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* The signal handler for a running mount: the first Ctrl-C stops it after the
|
|
484
|
+
* step under way, the second quits at once.
|
|
485
|
+
*
|
|
486
|
+
* A step can be a 100MB file on a slow link, and waiting on it in silence
|
|
487
|
+
* read as a hang — and a second Ctrl-C did nothing, leaving kill as the way
|
|
488
|
+
* out. Quitting mid-step is safe: every file lands by rename, so a hard exit
|
|
489
|
+
* leaves the old file or the new one, and the next pass sorts out the rest.
|
|
490
|
+
*/
|
|
491
|
+
export function stopOnSignals(controller, { exit = (code) => process.exit(code) } = {}) {
|
|
492
|
+
return () => {
|
|
493
|
+
if (controller.signal.aborted) return exit(130);
|
|
494
|
+
info("Stopping after the current file — press Ctrl-C again to quit now.");
|
|
495
|
+
controller.abort();
|
|
496
|
+
};
|
|
304
497
|
}
|
|
305
498
|
|
|
306
499
|
/**
|
|
@@ -322,6 +515,24 @@ async function slugFor(dir) {
|
|
|
322
515
|
return declared || basename(dir);
|
|
323
516
|
}
|
|
324
517
|
|
|
518
|
+
/**
|
|
519
|
+
* `names` read as on/off switches, and the positionals from index 2 on.
|
|
520
|
+
*
|
|
521
|
+
* The shared parser gives a flag the next word as its value, so a flag given
|
|
522
|
+
* before a directory swallowed it: `vfs import ~/a --dry-run ~/b` dry-ran
|
|
523
|
+
* ~/a and skipped ~/b without a word, and `vfs mount --allow-delete ~/proj`
|
|
524
|
+
* died asking for a directory. A string value of a switch is a positional.
|
|
525
|
+
*/
|
|
526
|
+
function booleanFlags(args, names) {
|
|
527
|
+
const flags = {};
|
|
528
|
+
const positionals = args._.slice(2);
|
|
529
|
+
for (const name of names) {
|
|
530
|
+
flags[name] = Boolean(args[name]);
|
|
531
|
+
if (typeof args[name] === "string") positionals.push(args[name]);
|
|
532
|
+
}
|
|
533
|
+
return { flags, positionals };
|
|
534
|
+
}
|
|
535
|
+
|
|
325
536
|
function required(value, usage) {
|
|
326
537
|
if (!value) die(`Missing argument. Usage: muhkoo vfs ${usage}`);
|
|
327
538
|
return value;
|
|
@@ -366,11 +577,13 @@ async function useApp(nameOrDomain, key) {
|
|
|
366
577
|
|
|
367
578
|
if (!key && !known[nameOrDomain]) {
|
|
368
579
|
die(
|
|
369
|
-
`Could not work out the app key for "${nameOrDomain}"
|
|
370
|
-
(looksLikeDomain
|
|
371
|
-
? `That app does not publish ${WELL_KNOWN} yet. Pass it once with --key <appKey>.`
|
|
372
|
-
:
|
|
373
|
-
|
|
580
|
+
`Could not work out the app key for "${nameOrDomain}".`,
|
|
581
|
+
...(looksLikeDomain
|
|
582
|
+
? [`That app does not publish ${WELL_KNOWN} yet. Pass it once with --key <appKey>.`]
|
|
583
|
+
: [
|
|
584
|
+
`Pass it once with --key <appKey>, or use the domain you access the app at.`,
|
|
585
|
+
`App keys are shown when an app is created (muhkoo apps create).`,
|
|
586
|
+
]),
|
|
374
587
|
);
|
|
375
588
|
}
|
|
376
589
|
const next = key ? { ...known, [nameOrDomain]: key } : known;
|
package/src/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { readFile } from "node:fs/promises";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import { parseArgs } from "./lib/args.js";
|
|
11
|
-
import { c, die } from "./lib/ui.js";
|
|
11
|
+
import { c, die, info } from "./lib/ui.js";
|
|
12
12
|
|
|
13
13
|
const COMMANDS = {
|
|
14
14
|
login: () => import("./commands/login.js"),
|
|
@@ -55,9 +55,14 @@ Backend
|
|
|
55
55
|
functions ls|get|code|deploy|rm|enable|disable
|
|
56
56
|
|
|
57
57
|
Files
|
|
58
|
-
vfs ls|cat|put|get|rm|cp|mv|find|history|restore
|
|
59
|
-
vcs status|commit|log|diff|branch|switch|merge
|
|
58
|
+
vfs cd|pwd|ls|stat|tree|cat|put|get|mkdir|rm|cp|mv|find|history|restore
|
|
60
59
|
your encrypted filesystem
|
|
60
|
+
vfs import|mount|ignore
|
|
61
|
+
upload a project, keep a directory in sync, and
|
|
62
|
+
choose what syncs
|
|
63
|
+
vfs sweep|use-app|app reclaim records; pick the app writes are made as
|
|
64
|
+
vcs status|commit|log|show|diff|branch|switch|checkout|merge|restore
|
|
65
|
+
version control over it
|
|
61
66
|
|
|
62
67
|
Hosting
|
|
63
68
|
deploy deploy a built client to Muhkoo hosting (test env)
|
|
@@ -91,8 +96,8 @@ export async function run(argv) {
|
|
|
91
96
|
const args = parseArgs(argv.map((a) => (a === "-h" ? "--help" : a === "-v" ? "--version" : a)));
|
|
92
97
|
const name = args._[0];
|
|
93
98
|
|
|
94
|
-
if (wantsVersion) return
|
|
95
|
-
if (!name || name === "help") return
|
|
99
|
+
if (wantsVersion) return info(await version());
|
|
100
|
+
if (!name || name === "help") return info(...TOP_HELP.split("\n"));
|
|
96
101
|
|
|
97
102
|
const loader = COMMANDS[name];
|
|
98
103
|
if (!loader) {
|
|
@@ -104,7 +109,7 @@ export async function run(argv) {
|
|
|
104
109
|
// Per-command help.
|
|
105
110
|
if (wantsHelp) {
|
|
106
111
|
// `keys` reuses apps.js, which documents `keys rotate` in its own help.
|
|
107
|
-
|
|
112
|
+
info(...(mod.help || TOP_HELP).split("\n"));
|
|
108
113
|
return;
|
|
109
114
|
}
|
|
110
115
|
|
package/src/lib/auth.js
CHANGED
|
@@ -38,9 +38,9 @@ export async function loadClient() {
|
|
|
38
38
|
return mod.Client;
|
|
39
39
|
} catch (e) {
|
|
40
40
|
die(
|
|
41
|
-
"Couldn't load @muhkoo/connect for programmatic login
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
"Couldn't load @muhkoo/connect for programmatic login.",
|
|
42
|
+
" Reinstall the CLI, or sign in via the portal and pass --token instead.",
|
|
43
|
+
` Underlying error: ${e?.message || e}`,
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
}
|