norc-cli 0.4.1 → 0.4.2
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 +1 -1
- package/dist/index.js +80 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ brew install norcapp/norc/norc-cli
|
|
|
22
22
|
|
|
23
23
|
Requires Node.js >= 24 (via npm — brew/apt/scoop bundle their own runtime, no system Node needed).
|
|
24
24
|
|
|
25
|
-
To update, use the same channel (`npm install -g norc-cli@latest`, `brew upgrade norc-cli`, ...).
|
|
25
|
+
To update, use the same channel (`npm install -g norc-cli@latest`, `brew upgrade norc-cli`, ...). You don't need to restart anything: the background service notices the new version within about 10 minutes and restarts on it (apt and scoop restart it straight away). `norc pair` and `norc login --key` start the service the first time. Upgrading from 0.4.1 or earlier through npm or Homebrew: run `norc service install` once after this update, since the older bridge can't restart itself. On Windows the service doesn't restart itself: after an npm update there, run `norc service install` each time (scoop does it for you).
|
|
26
26
|
|
|
27
27
|
## Setup
|
|
28
28
|
|
package/dist/index.js
CHANGED
|
@@ -44401,7 +44401,7 @@ var import_node_os5 = require("node:os");
|
|
|
44401
44401
|
var import_node_path3 = require("node:path");
|
|
44402
44402
|
|
|
44403
44403
|
// src/version.ts
|
|
44404
|
-
var VERSION2 = "0.4.
|
|
44404
|
+
var VERSION2 = "0.4.2";
|
|
44405
44405
|
|
|
44406
44406
|
// src/host-details.ts
|
|
44407
44407
|
var ARCH = { x64: "x86_64", arm64: "arm64", ia32: "x86", arm: "arm" };
|
|
@@ -46293,11 +46293,24 @@ function defaultServiceDeps(binaryPath) {
|
|
|
46293
46293
|
mkdir: import_promises7.mkdir,
|
|
46294
46294
|
writeFile: import_promises7.writeFile,
|
|
46295
46295
|
rm: import_promises7.rm,
|
|
46296
|
+
exists: async (path) => (0, import_promises7.access)(path).then(() => true, () => false),
|
|
46296
46297
|
exec: async (cmd, args) => {
|
|
46297
46298
|
await execFileAsync2(cmd, args);
|
|
46298
46299
|
}
|
|
46299
46300
|
};
|
|
46300
46301
|
}
|
|
46302
|
+
async function isServiceInstalled(deps) {
|
|
46303
|
+
switch (deps.platform) {
|
|
46304
|
+
case "linux":
|
|
46305
|
+
return deps.exists(systemdUnitPath(deps.home));
|
|
46306
|
+
case "darwin":
|
|
46307
|
+
return deps.exists(launchdPlistPath(deps.home));
|
|
46308
|
+
case "win32":
|
|
46309
|
+
return deps.exec("schtasks", ["/Query", "/TN", SCHEDULED_TASK_NAME]).then(() => true, () => false);
|
|
46310
|
+
default:
|
|
46311
|
+
return false;
|
|
46312
|
+
}
|
|
46313
|
+
}
|
|
46301
46314
|
var SCHEDULED_TASK_NAME = "norc-cli-bridge";
|
|
46302
46315
|
function systemdUnitPath(home) {
|
|
46303
46316
|
return (0, import_node_path8.join)(home, ".config", "systemd", "user", "norc.service");
|
|
@@ -46407,6 +46420,39 @@ async function uninstallService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
46407
46420
|
}
|
|
46408
46421
|
}
|
|
46409
46422
|
|
|
46423
|
+
// src/upgrade-watch.ts
|
|
46424
|
+
var import_node_child_process9 = require("node:child_process");
|
|
46425
|
+
var import_node_util3 = require("node:util");
|
|
46426
|
+
var execFileAsync3 = (0, import_node_util3.promisify)(import_node_child_process9.execFile);
|
|
46427
|
+
var SEMVER = /^\d+\.\d+\.\d+$/;
|
|
46428
|
+
async function installedVersion(cmd, run2 = async (f, a) => (await execFileAsync3(f, a, { timeout: 15e3 })).stdout) {
|
|
46429
|
+
const [file, ...args] = cmd;
|
|
46430
|
+
if (!file) return null;
|
|
46431
|
+
try {
|
|
46432
|
+
const out = (await run2(file, [...args, "--version"])).trim();
|
|
46433
|
+
return SEMVER.test(out) ? out : null;
|
|
46434
|
+
} catch {
|
|
46435
|
+
return null;
|
|
46436
|
+
}
|
|
46437
|
+
}
|
|
46438
|
+
function watchForUpgrade(opts) {
|
|
46439
|
+
let busy = false;
|
|
46440
|
+
const timer = setInterval(() => {
|
|
46441
|
+
if (busy) return;
|
|
46442
|
+
busy = true;
|
|
46443
|
+
void opts.check().then((v) => {
|
|
46444
|
+
if (v && v !== opts.current) {
|
|
46445
|
+
clearInterval(timer);
|
|
46446
|
+
opts.onUpgrade(v);
|
|
46447
|
+
}
|
|
46448
|
+
}).finally(() => {
|
|
46449
|
+
busy = false;
|
|
46450
|
+
});
|
|
46451
|
+
}, opts.intervalMs);
|
|
46452
|
+
timer.unref?.();
|
|
46453
|
+
return () => clearInterval(timer);
|
|
46454
|
+
}
|
|
46455
|
+
|
|
46410
46456
|
// src/index.ts
|
|
46411
46457
|
var HELP = `norc \u2014 headless job scheduler CLI
|
|
46412
46458
|
|
|
@@ -46476,6 +46522,7 @@ async function cmdLogin(args) {
|
|
|
46476
46522
|
if (!result2.ok) throw new Error(result2.message);
|
|
46477
46523
|
await savePairedDevice({ machineId: result2.machineId, deviceToken: result2.deviceToken });
|
|
46478
46524
|
console.log(`logged in. machine id: ${result2.machineId}`);
|
|
46525
|
+
await ensureBackgroundService();
|
|
46479
46526
|
return;
|
|
46480
46527
|
}
|
|
46481
46528
|
debugLog("login: falling through to email OTP path \u2014 no API key ended up set");
|
|
@@ -46504,6 +46551,7 @@ async function cmdPair() {
|
|
|
46504
46551
|
} else if (p.phase === "paired") {
|
|
46505
46552
|
await savePairedDevice({ machineId: p.machineId, deviceToken: p.deviceToken });
|
|
46506
46553
|
console.log(`paired. machine id: ${p.machineId}`);
|
|
46554
|
+
await ensureBackgroundService();
|
|
46507
46555
|
} else if (p.phase === "expired") {
|
|
46508
46556
|
console.log("pairing code expired \u2014 run `norc pair` again.");
|
|
46509
46557
|
} else {
|
|
@@ -46643,7 +46691,38 @@ async function cmdJobs(args) {
|
|
|
46643
46691
|
throw new Error("usage: norc jobs <list|add|rm|enable|disable>");
|
|
46644
46692
|
}
|
|
46645
46693
|
}
|
|
46694
|
+
async function ensureBackgroundService() {
|
|
46695
|
+
const deps = defaultServiceDeps(resolveBinaryPath());
|
|
46696
|
+
try {
|
|
46697
|
+
if (await isServiceInstalled(deps)) return;
|
|
46698
|
+
await installService(deps);
|
|
46699
|
+
console.log("started the norc background service (norc bridge); it starts again at every login.");
|
|
46700
|
+
} catch (e) {
|
|
46701
|
+
console.error(`could not start the background service automatically (${e.message}). Run \`norc service install\`.`);
|
|
46702
|
+
}
|
|
46703
|
+
}
|
|
46704
|
+
var UPGRADE_EXIT_CODE = 75;
|
|
46705
|
+
function restartOnUpgrade() {
|
|
46706
|
+
if (process.platform === "win32") return;
|
|
46707
|
+
const supervised = Boolean(process.env.INVOCATION_ID) || process.env.XPC_SERVICE_NAME === "dev.norc.cli";
|
|
46708
|
+
watchForUpgrade({
|
|
46709
|
+
current: VERSION2,
|
|
46710
|
+
intervalMs: 10 * 6e4,
|
|
46711
|
+
// The launcher path, not process.execPath: Node resolves execPath to a versioned runtime
|
|
46712
|
+
// (e.g. Homebrew's Cellar node) that an upgrade deletes; the launcher's path stays put.
|
|
46713
|
+
check: () => installedVersion([resolveBinaryPath()]),
|
|
46714
|
+
onUpgrade: (installed) => {
|
|
46715
|
+
if (!supervised) {
|
|
46716
|
+
console.error(`norc-cli ${installed} is installed; this bridge still runs ${VERSION2}. Restart \`norc bridge\` to use it.`);
|
|
46717
|
+
return;
|
|
46718
|
+
}
|
|
46719
|
+
console.error(`norc-cli ${installed} is installed (this bridge runs ${VERSION2}); exiting so the service restarts on the new version.`);
|
|
46720
|
+
process.exit(UPGRADE_EXIT_CODE);
|
|
46721
|
+
}
|
|
46722
|
+
});
|
|
46723
|
+
}
|
|
46646
46724
|
async function cmdBridge() {
|
|
46725
|
+
restartOnUpgrade();
|
|
46647
46726
|
const url = supabaseUrl();
|
|
46648
46727
|
const anonKey = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
46649
46728
|
await runBridge({ supabaseUrl: url, anonKey }, systemCrontabIo);
|