norc-cli 0.4.0 → 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 +2 -0
- package/dist/index.js +86 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,8 @@ 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`, ...). 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
|
+
|
|
25
27
|
## Setup
|
|
26
28
|
|
|
27
29
|
`norc login` / `norc pair` / `norc bridge` talk to the norc.app project by
|
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");
|
|
@@ -46346,13 +46359,16 @@ async function installService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
46346
46359
|
await deps.mkdir((0, import_node_path8.join)(deps.home, ".config", "systemd", "user"), { recursive: true });
|
|
46347
46360
|
await deps.writeFile(path, systemdUnit(deps.binaryPath));
|
|
46348
46361
|
await deps.exec("systemctl", ["--user", "daemon-reload"]);
|
|
46349
|
-
await deps.exec("systemctl", ["--user", "enable", "
|
|
46362
|
+
await deps.exec("systemctl", ["--user", "enable", "norc.service"]);
|
|
46363
|
+
await deps.exec("systemctl", ["--user", "restart", "norc.service"]);
|
|
46350
46364
|
return;
|
|
46351
46365
|
}
|
|
46352
46366
|
case "darwin": {
|
|
46353
46367
|
const path = launchdPlistPath(deps.home);
|
|
46354
46368
|
await deps.mkdir((0, import_node_path8.join)(deps.home, "Library", "LaunchAgents"), { recursive: true });
|
|
46355
46369
|
await deps.writeFile(path, launchdPlist(deps.binaryPath));
|
|
46370
|
+
await deps.exec("launchctl", ["unload", path]).catch(() => {
|
|
46371
|
+
});
|
|
46356
46372
|
await deps.exec("launchctl", ["load", "-w", path]);
|
|
46357
46373
|
return;
|
|
46358
46374
|
}
|
|
@@ -46369,6 +46385,8 @@ async function installService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
46369
46385
|
"LIMITED",
|
|
46370
46386
|
"/F"
|
|
46371
46387
|
]);
|
|
46388
|
+
await deps.exec("schtasks", ["/End", "/TN", SCHEDULED_TASK_NAME]).catch(() => {
|
|
46389
|
+
});
|
|
46372
46390
|
await deps.exec("schtasks", ["/Run", "/TN", SCHEDULED_TASK_NAME]);
|
|
46373
46391
|
return;
|
|
46374
46392
|
}
|
|
@@ -46402,6 +46420,39 @@ async function uninstallService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
46402
46420
|
}
|
|
46403
46421
|
}
|
|
46404
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
|
+
|
|
46405
46456
|
// src/index.ts
|
|
46406
46457
|
var HELP = `norc \u2014 headless job scheduler CLI
|
|
46407
46458
|
|
|
@@ -46471,6 +46522,7 @@ async function cmdLogin(args) {
|
|
|
46471
46522
|
if (!result2.ok) throw new Error(result2.message);
|
|
46472
46523
|
await savePairedDevice({ machineId: result2.machineId, deviceToken: result2.deviceToken });
|
|
46473
46524
|
console.log(`logged in. machine id: ${result2.machineId}`);
|
|
46525
|
+
await ensureBackgroundService();
|
|
46474
46526
|
return;
|
|
46475
46527
|
}
|
|
46476
46528
|
debugLog("login: falling through to email OTP path \u2014 no API key ended up set");
|
|
@@ -46499,6 +46551,7 @@ async function cmdPair() {
|
|
|
46499
46551
|
} else if (p.phase === "paired") {
|
|
46500
46552
|
await savePairedDevice({ machineId: p.machineId, deviceToken: p.deviceToken });
|
|
46501
46553
|
console.log(`paired. machine id: ${p.machineId}`);
|
|
46554
|
+
await ensureBackgroundService();
|
|
46502
46555
|
} else if (p.phase === "expired") {
|
|
46503
46556
|
console.log("pairing code expired \u2014 run `norc pair` again.");
|
|
46504
46557
|
} else {
|
|
@@ -46638,7 +46691,38 @@ async function cmdJobs(args) {
|
|
|
46638
46691
|
throw new Error("usage: norc jobs <list|add|rm|enable|disable>");
|
|
46639
46692
|
}
|
|
46640
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
|
+
}
|
|
46641
46724
|
async function cmdBridge() {
|
|
46725
|
+
restartOnUpgrade();
|
|
46642
46726
|
const url = supabaseUrl();
|
|
46643
46727
|
const anonKey = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
46644
46728
|
await runBridge({ supabaseUrl: url, anonKey }, systemCrontabIo);
|