@snowyroad/braid 0.79.5 → 0.80.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/dist/cli.js +69 -28
- package/npm-shrinkwrap.json +2541 -2
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -6959,6 +6959,7 @@ function startUpdateNotifier(opts) {
|
|
|
6959
6959
|
|
|
6960
6960
|
// src/cli.ts
|
|
6961
6961
|
import { readFileSync as readFileSync9 } from "fs";
|
|
6962
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6962
6963
|
|
|
6963
6964
|
// src/cliArgs.ts
|
|
6964
6965
|
var USAGE = `Usage: braid <command>
|
|
@@ -7189,10 +7190,42 @@ function parseCliArgs(argv) {
|
|
|
7189
7190
|
if (!parsed.ok) return { kind: "usage", error: parsed.error };
|
|
7190
7191
|
return { kind: "run", argv };
|
|
7191
7192
|
}
|
|
7192
|
-
if (first ===
|
|
7193
|
+
if (first === "tui") {
|
|
7194
|
+
return { kind: "tui", bare: false, args: argv.slice(1) };
|
|
7195
|
+
}
|
|
7196
|
+
if (first === void 0) return { kind: "tui", bare: true, args: [] };
|
|
7193
7197
|
return { kind: "usage", error: `Unknown command: ${first}` };
|
|
7194
7198
|
}
|
|
7195
7199
|
|
|
7200
|
+
// src/launchTui.ts
|
|
7201
|
+
import { spawn as spawn2 } from "child_process";
|
|
7202
|
+
import { createRequire } from "module";
|
|
7203
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
7204
|
+
function resolveTuiEntry() {
|
|
7205
|
+
try {
|
|
7206
|
+
const require2 = createRequire(import.meta.url);
|
|
7207
|
+
const pkgPath = require2.resolve("arp-tui/package.json");
|
|
7208
|
+
const pkg = require2("arp-tui/package.json");
|
|
7209
|
+
const rel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.["arp-tui"];
|
|
7210
|
+
return rel ? join8(dirname6(pkgPath), rel) : null;
|
|
7211
|
+
} catch {
|
|
7212
|
+
return null;
|
|
7213
|
+
}
|
|
7214
|
+
}
|
|
7215
|
+
function runTui(args, env, selfCliPath) {
|
|
7216
|
+
const entry = resolveTuiEntry();
|
|
7217
|
+
if (!entry) {
|
|
7218
|
+
console.error("[braid] the interactive UI is not installed \u2014 reinstall @snowyroad/braid");
|
|
7219
|
+
return Promise.resolve(1);
|
|
7220
|
+
}
|
|
7221
|
+
const childEnv = { ...env, ARP_TUI_BRIDGE_CMD: `${process.execPath} ${selfCliPath}` };
|
|
7222
|
+
return new Promise((resolve2) => {
|
|
7223
|
+
const child = spawn2(process.execPath, [entry, ...args], { stdio: "inherit", env: childEnv });
|
|
7224
|
+
child.on("error", () => resolve2(1));
|
|
7225
|
+
child.on("close", (code) => resolve2(code ?? 1));
|
|
7226
|
+
});
|
|
7227
|
+
}
|
|
7228
|
+
|
|
7196
7229
|
// src/enroll.ts
|
|
7197
7230
|
var ENROLL_STDIN_MAX_BYTES = 16 * 1024;
|
|
7198
7231
|
function readBoundedStdin(stream, maxBytes) {
|
|
@@ -8477,7 +8510,7 @@ import { homedir as homedir6 } from "os";
|
|
|
8477
8510
|
|
|
8478
8511
|
// src/service/manager.ts
|
|
8479
8512
|
import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync7, rmSync as rmSync2, existsSync as existsSync6 } from "fs";
|
|
8480
|
-
import { join as
|
|
8513
|
+
import { join as join10 } from "path";
|
|
8481
8514
|
|
|
8482
8515
|
// src/service/templates.ts
|
|
8483
8516
|
function escapeXml(s) {
|
|
@@ -8649,17 +8682,17 @@ function schtasksXml(p) {
|
|
|
8649
8682
|
|
|
8650
8683
|
// src/service/win32.ts
|
|
8651
8684
|
import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync6, readdirSync as readdirSync4, readFileSync as readFileSync7, unlinkSync as unlinkSync3 } from "fs";
|
|
8652
|
-
import { join as
|
|
8685
|
+
import { join as join9 } from "path";
|
|
8653
8686
|
function win32LogDir(homeDir) {
|
|
8654
|
-
return
|
|
8687
|
+
return join9(homeDir, "AppData", "Local", "braid", "logs");
|
|
8655
8688
|
}
|
|
8656
8689
|
function win32Manager(ctx) {
|
|
8657
|
-
const serviceDir =
|
|
8690
|
+
const serviceDir = join9(ctx.braidDir, "service");
|
|
8658
8691
|
const task = (name) => schtasksLabel(name);
|
|
8659
8692
|
const legacyTask = (name) => legacySchtasksLabel(name);
|
|
8660
|
-
const xmlPath = (name) =>
|
|
8661
|
-
const wrapperPath = (name) =>
|
|
8662
|
-
const launcherPath = (name) =>
|
|
8693
|
+
const xmlPath = (name) => join9(serviceDir, `${task(name)}.xml`);
|
|
8694
|
+
const wrapperPath = (name) => join9(serviceDir, `${task(name)}.cmd`);
|
|
8695
|
+
const launcherPath = (name) => join9(serviceDir, `${task(name)}.vbs`);
|
|
8663
8696
|
const st = (...args) => ctx.exec("schtasks", args);
|
|
8664
8697
|
const stx = async (...args) => {
|
|
8665
8698
|
const res = await st(...args);
|
|
@@ -8670,18 +8703,18 @@ function win32Manager(ctx) {
|
|
|
8670
8703
|
};
|
|
8671
8704
|
const killBridgeProcess = async (name) => {
|
|
8672
8705
|
const legacyAgents = legacyTwinPath(ctx.braidDir, ["agents"]);
|
|
8673
|
-
const agentDirs = [
|
|
8706
|
+
const agentDirs = [join9(ctx.braidDir, "agents"), ...legacyAgents ? [legacyAgents] : []];
|
|
8674
8707
|
const hostDirs = [];
|
|
8675
8708
|
for (const agentsDir of agentDirs) {
|
|
8676
8709
|
try {
|
|
8677
|
-
for (const host of readdirSync4(agentsDir)) hostDirs.push(
|
|
8710
|
+
for (const host of readdirSync4(agentsDir)) hostDirs.push(join9(agentsDir, host));
|
|
8678
8711
|
} catch {
|
|
8679
8712
|
}
|
|
8680
8713
|
}
|
|
8681
8714
|
for (const hostDir of hostDirs) {
|
|
8682
8715
|
let pid = NaN;
|
|
8683
8716
|
try {
|
|
8684
|
-
pid = Number(readFileSync7(
|
|
8717
|
+
pid = Number(readFileSync7(join9(hostDir, `${name}.json.lock`), "utf8").trim());
|
|
8685
8718
|
} catch {
|
|
8686
8719
|
continue;
|
|
8687
8720
|
}
|
|
@@ -8725,7 +8758,7 @@ function win32Manager(ctx) {
|
|
|
8725
8758
|
await st("/delete", "/tn", task(name), "/f");
|
|
8726
8759
|
await st("/delete", "/tn", legacyTask(name), "/f");
|
|
8727
8760
|
try {
|
|
8728
|
-
unlinkSync3(
|
|
8761
|
+
unlinkSync3(join9(runDir(ctx.braidDir), `${name}.token`));
|
|
8729
8762
|
} catch {
|
|
8730
8763
|
}
|
|
8731
8764
|
const legacyToken = legacyTwinPath(ctx.braidDir, ["run", `${name}.token`]);
|
|
@@ -8763,7 +8796,7 @@ function win32Manager(ctx) {
|
|
|
8763
8796
|
return { installed, loaded, running };
|
|
8764
8797
|
},
|
|
8765
8798
|
logsPath(name) {
|
|
8766
|
-
return
|
|
8799
|
+
return join9(win32LogDir(ctx.homeDir), `${name}.err.log`);
|
|
8767
8800
|
}
|
|
8768
8801
|
};
|
|
8769
8802
|
}
|
|
@@ -8777,7 +8810,7 @@ var NotSupportedError = class extends Error {
|
|
|
8777
8810
|
};
|
|
8778
8811
|
function makeServiceManager(platform, exec, deps = {}) {
|
|
8779
8812
|
const homeDir = deps.homeDir ?? process.env.HOME ?? "";
|
|
8780
|
-
const braidDir = deps.braidDir ??
|
|
8813
|
+
const braidDir = deps.braidDir ?? join10(homeDir, ".braid");
|
|
8781
8814
|
const uid = deps.uid ?? (typeof process.getuid === "function" ? process.getuid() : 0);
|
|
8782
8815
|
const nodePath = deps.nodePath ?? process.execPath;
|
|
8783
8816
|
const entryPath = pinnedEntryPath({ braidDir });
|
|
@@ -8802,11 +8835,11 @@ function notSupportedManager(platform) {
|
|
|
8802
8835
|
};
|
|
8803
8836
|
}
|
|
8804
8837
|
function darwinManager(ctx) {
|
|
8805
|
-
const launchAgentsDir =
|
|
8806
|
-
const logDir =
|
|
8807
|
-
const legacyLogDir =
|
|
8808
|
-
const plistPath = (name) =>
|
|
8809
|
-
const legacyPlistPath = (name) =>
|
|
8838
|
+
const launchAgentsDir = join10(ctx.homeDir, "Library", "LaunchAgents");
|
|
8839
|
+
const logDir = join10(ctx.homeDir, "Library", "Logs", "braid");
|
|
8840
|
+
const legacyLogDir = join10(ctx.homeDir, "Library", "Logs", "arp-bridge");
|
|
8841
|
+
const plistPath = (name) => join10(launchAgentsDir, `${launchdLabel(name)}.plist`);
|
|
8842
|
+
const legacyPlistPath = (name) => join10(launchAgentsDir, `${legacyLaunchdLabel(name)}.plist`);
|
|
8810
8843
|
const legacyInstalled = (name) => !existsSync6(plistPath(name)) && existsSync6(legacyPlistPath(name));
|
|
8811
8844
|
const domainTarget = `gui/${ctx.uid}`;
|
|
8812
8845
|
const serviceTarget = (name) => `${domainTarget}/${legacyInstalled(name) ? legacyLaunchdLabel(name) : launchdLabel(name)}`;
|
|
@@ -8871,16 +8904,16 @@ function darwinManager(ctx) {
|
|
|
8871
8904
|
};
|
|
8872
8905
|
},
|
|
8873
8906
|
logsPath(name) {
|
|
8874
|
-
return
|
|
8907
|
+
return join10(legacyInstalled(name) ? legacyLogDir : logDir, `${name}.err.log`);
|
|
8875
8908
|
}
|
|
8876
8909
|
};
|
|
8877
8910
|
}
|
|
8878
8911
|
function linuxManager(ctx) {
|
|
8879
|
-
const unitDir =
|
|
8912
|
+
const unitDir = join10(ctx.homeDir, ".config", "systemd", "user");
|
|
8880
8913
|
const newUnitName = (name) => `braid-${name}.service`;
|
|
8881
8914
|
const legacyUnitName = (name) => `arp-bridge-${name}.service`;
|
|
8882
|
-
const newUnitPath = (name) =>
|
|
8883
|
-
const legacyUnitPath = (name) =>
|
|
8915
|
+
const newUnitPath = (name) => join10(unitDir, newUnitName(name));
|
|
8916
|
+
const legacyUnitPath = (name) => join10(unitDir, legacyUnitName(name));
|
|
8884
8917
|
const legacyInstalled = (name) => !existsSync6(newUnitPath(name)) && existsSync6(legacyUnitPath(name));
|
|
8885
8918
|
const unitName = (name) => legacyInstalled(name) ? legacyUnitName(name) : newUnitName(name);
|
|
8886
8919
|
const unitPath = (name) => legacyInstalled(name) ? legacyUnitPath(name) : newUnitPath(name);
|
|
@@ -9162,7 +9195,7 @@ function printStatusHuman(name, st, logsPath) {
|
|
|
9162
9195
|
|
|
9163
9196
|
// src/service/serviceLog.ts
|
|
9164
9197
|
import { createWriteStream, mkdirSync as mkdirSync8 } from "fs";
|
|
9165
|
-
import { dirname as
|
|
9198
|
+
import { dirname as dirname7, join as join11 } from "path";
|
|
9166
9199
|
|
|
9167
9200
|
// src/service/logRotation.ts
|
|
9168
9201
|
import {
|
|
@@ -9215,16 +9248,16 @@ function rotateLogFileIfNeeded(logPath, opts = {}) {
|
|
|
9215
9248
|
|
|
9216
9249
|
// src/service/serviceLog.ts
|
|
9217
9250
|
function darwinLogDir(homeDir) {
|
|
9218
|
-
return
|
|
9251
|
+
return join11(homeDir, "Library", "Logs", "braid");
|
|
9219
9252
|
}
|
|
9220
9253
|
function serviceLogTargets(name, platform, homeDir) {
|
|
9221
9254
|
if (platform === "darwin") {
|
|
9222
9255
|
const d = darwinLogDir(homeDir);
|
|
9223
|
-
return [
|
|
9256
|
+
return [join11(d, `${name}.out.log`), join11(d, `${name}.err.log`)];
|
|
9224
9257
|
}
|
|
9225
9258
|
if (platform === "win32") {
|
|
9226
9259
|
const d = win32LogDir(homeDir);
|
|
9227
|
-
return [
|
|
9260
|
+
return [join11(d, `${name}.out.log`), join11(d, `${name}.err.log`)];
|
|
9228
9261
|
}
|
|
9229
9262
|
return [];
|
|
9230
9263
|
}
|
|
@@ -9274,7 +9307,7 @@ function initServiceLogging(opts) {
|
|
|
9274
9307
|
};
|
|
9275
9308
|
}
|
|
9276
9309
|
function defaultTeeStream(path4) {
|
|
9277
|
-
mkdirSync8(
|
|
9310
|
+
mkdirSync8(dirname7(path4), { recursive: true });
|
|
9278
9311
|
const stream = createWriteStream(path4, { flags: "a" });
|
|
9279
9312
|
stream.on("error", () => {
|
|
9280
9313
|
});
|
|
@@ -9486,6 +9519,14 @@ async function main() {
|
|
|
9486
9519
|
applyEnvAliases();
|
|
9487
9520
|
installCrashGuard();
|
|
9488
9521
|
const invocation = parseCliArgs(process.argv.slice(2));
|
|
9522
|
+
if (invocation.kind === "tui") {
|
|
9523
|
+
if (invocation.bare && !process.stdout.isTTY) {
|
|
9524
|
+
console.error(USAGE);
|
|
9525
|
+
process.exit(1);
|
|
9526
|
+
}
|
|
9527
|
+
const selfCli = fileURLToPath3(import.meta.url);
|
|
9528
|
+
process.exit(await runTui(invocation.args, process.env, selfCli));
|
|
9529
|
+
}
|
|
9489
9530
|
if (invocation.kind === "usage") {
|
|
9490
9531
|
if (invocation.error) console.error(`[braid] ${invocation.error}`);
|
|
9491
9532
|
console.error(USAGE);
|