waygraph 0.12.21 → 0.12.22
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/bin/waygraph +48 -13
- package/dist/auto-explore-run.js +13 -17
- package/package.json +1 -1
package/bin/waygraph
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
#!/bin/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Cross-platform CLI launcher.
|
|
4
|
+
*
|
|
5
|
+
* Why Node (not #!/bin/sh + readlink -f):
|
|
6
|
+
* - macOS BSD `readlink` has no `-f` (GNU) -> "illegal option -- f" / broken bin
|
|
7
|
+
* - Windows npm expects a Node shebang for `.cmd` shims
|
|
8
|
+
*
|
|
9
|
+
* Still registers `tsx/esm` before `dist/cli.js` so consumer `.block.ts` /
|
|
10
|
+
* `.flow.ts` dynamic imports resolve the same as the old shell wrapper.
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
|
|
17
|
+
const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
18
|
+
const require = createRequire(join(pkgRoot, "package.json"));
|
|
19
|
+
let tsxEsm;
|
|
20
|
+
try {
|
|
21
|
+
tsxEsm = require.resolve("tsx/esm");
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error(
|
|
24
|
+
"waygraph: cannot resolve dependency \"tsx\" (required to load .ts Blocks).\n" +
|
|
25
|
+
" Reinstall: npm install waygraph\n" +
|
|
26
|
+
` Detail: ${err instanceof Error ? err.message : String(err)}`,
|
|
27
|
+
);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const cli = join(pkgRoot, "dist", "cli.js");
|
|
32
|
+
const child = spawn(
|
|
33
|
+
process.execPath,
|
|
34
|
+
["--import", tsxEsm, cli, ...process.argv.slice(2)],
|
|
35
|
+
{ stdio: "inherit", env: process.env, windowsHide: true },
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
child.on("error", (err) => {
|
|
39
|
+
console.error(`waygraph: failed to start CLI: ${err.message}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
42
|
+
child.on("exit", (code, signal) => {
|
|
43
|
+
if (signal) {
|
|
44
|
+
process.kill(process.pid, signal);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
process.exit(code ?? 1);
|
|
48
|
+
});
|
package/dist/auto-explore-run.js
CHANGED
|
@@ -468,22 +468,16 @@ function printCliMenu(menu, library) {
|
|
|
468
468
|
console.log(" [q] quit");
|
|
469
469
|
console.log("");
|
|
470
470
|
}
|
|
471
|
-
async function cliPick(menu) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (Number.isInteger(n) && n >= 1 && n <= menu.flat.length) {
|
|
480
|
-
return { type: "pick", index: n - 1 };
|
|
481
|
-
}
|
|
482
|
-
console.log("Enter a number from the list, or q to quit.");
|
|
471
|
+
async function cliPick(menu, rl) {
|
|
472
|
+
while (true) {
|
|
473
|
+
const ans = (await rl.question("Choose: ")).trim().toLowerCase();
|
|
474
|
+
if (ans === "q" || ans === "quit")
|
|
475
|
+
return { type: "quit" };
|
|
476
|
+
const n = Number(ans);
|
|
477
|
+
if (Number.isInteger(n) && n >= 1 && n <= menu.flat.length) {
|
|
478
|
+
return { type: "pick", index: n - 1 };
|
|
483
479
|
}
|
|
484
|
-
|
|
485
|
-
finally {
|
|
486
|
-
rl.close();
|
|
480
|
+
console.log("Enter a number from the list, or q to quit.");
|
|
487
481
|
}
|
|
488
482
|
}
|
|
489
483
|
/**
|
|
@@ -544,6 +538,7 @@ export async function runAutoExplore(projectDir, options = {}) {
|
|
|
544
538
|
wiredPage = target;
|
|
545
539
|
}
|
|
546
540
|
let here = null;
|
|
541
|
+
const cliRl = cli ? createInterface({ input, output }) : null;
|
|
547
542
|
try {
|
|
548
543
|
for (;;) {
|
|
549
544
|
page = await ensureLivePage(context, page, startUrl);
|
|
@@ -572,9 +567,9 @@ export async function runAutoExplore(projectDir, options = {}) {
|
|
|
572
567
|
break;
|
|
573
568
|
}
|
|
574
569
|
let pick;
|
|
575
|
-
if (cli) {
|
|
570
|
+
if (cli && cliRl) {
|
|
576
571
|
printCliMenu(menu, library.byName);
|
|
577
|
-
pick = await cliPick(menu);
|
|
572
|
+
pick = await cliPick(menu, cliRl);
|
|
578
573
|
}
|
|
579
574
|
else {
|
|
580
575
|
pick = await headfulPick(page, menu, library.byName, mem, () => pickWait.promise);
|
|
@@ -614,6 +609,7 @@ export async function runAutoExplore(projectDir, options = {}) {
|
|
|
614
609
|
}
|
|
615
610
|
}
|
|
616
611
|
finally {
|
|
612
|
+
cliRl?.close();
|
|
617
613
|
await context.close();
|
|
618
614
|
await browser.close();
|
|
619
615
|
}
|