querysub 0.676.0 → 0.677.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.676.0",
3
+ "version": "0.677.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -372,6 +372,13 @@ async function main() {
372
372
  await runPromise(`ssh ${sshRemote} "grep -qxF 'set-option -g history-limit 100000' ~/.tmux.conf 2>/dev/null || echo 'set-option -g history-limit 100000' >> ~/.tmux.conf"`);
373
373
  console.log("āœ… Tmux scrollback history set to 100000");
374
374
 
375
+ // Before anything clones or installs, so an application that needs credentials on the machine (a private dependency it cannot yarn install without) can put them there first. As early as it can be: git is what the hook has to work with, and it is only installed above.
376
+ await runApplicationHook({
377
+ sshRemote,
378
+ hookName: "machineSetupStart",
379
+ onFailure: "Anything it was meant to set up on the machine is missing, so the clone and install below may fail.",
380
+ });
381
+
375
382
  // 5. Clone current repo into ~/machine-alwaysup with SSH key handling for private repos
376
383
  console.log("Setting up repository...");
377
384
  let gitURLLive = await getGitURLLive();
@@ -484,13 +491,18 @@ sudo systemctl start ${SERVICE_UNIT_NAME}
484
491
  console.log(` Screen: ssh ${sshRemote} -t "tmux attach -t ${SERVICE_NAME}"`);
485
492
  console.log(` Status: ssh ${sshRemote} "systemctl status ${SERVICE_UNIT_NAME}"`);
486
493
 
487
- await runMachineDeployHook(sshRemote);
494
+ await runApplicationHook({
495
+ sshRemote,
496
+ hookName: "machineDeploy",
497
+ onFailure: "This is fine if the synchronization database hasn't been set up yet, or isn't running.",
498
+ });
488
499
 
489
500
  console.log("\nšŸŽ‰ Machine setup complete!");
490
501
  }
491
502
 
492
- async function runMachineDeployHook(sshRemote: string) {
493
- let hookPathBase = path.resolve("./machineDeploy");
503
+ async function runApplicationHook(config: { sshRemote: string; hookName: string; onFailure: string }) {
504
+ let { sshRemote, hookName, onFailure } = config;
505
+ let hookPathBase = path.resolve(`./${hookName}`);
494
506
  let hookExists = false;
495
507
  for (let extension of [".ts", ".tsx", ".js"]) {
496
508
  if (await fsExistsAsync(hookPathBase + extension)) {
@@ -499,20 +511,21 @@ async function runMachineDeployHook(sshRemote: string) {
499
511
  }
500
512
  }
501
513
  if (!hookExists) {
502
- console.log(`No machineDeploy file at ${hookPathBase}, skipping the application deploy hook`);
514
+ console.log(`No ${hookName} file at ${hookPathBase}, skipping that application hook`);
503
515
  return;
504
516
  }
505
- console.log(`Running the machineDeploy hook at ${hookPathBase}`);
517
+ console.log(`Running the ${hookName} hook at ${hookPathBase}`);
506
518
  try {
507
- let hookModule = await import(hookPathBase) as { machineDeploy?: (config: { sshRemote: string }) => Promise<void> };
508
- if (!hookModule.machineDeploy) {
509
- throw new Error(`Expected ${hookPathBase} to export machineDeploy, exports are: ${Object.keys(hookModule).join(", ") || "(none)"}`);
519
+ let hookModule = await import(hookPathBase) as { [exportName: string]: ((config: { sshRemote: string }) => Promise<void>) | undefined };
520
+ let hook = hookModule[hookName];
521
+ if (!hook) {
522
+ throw new Error(`Expected ${hookPathBase} to export ${hookName}, exports are: ${Object.keys(hookModule).join(", ") || "(none)"}`);
510
523
  }
511
- await hookModule.machineDeploy({ sshRemote });
512
- console.log("āœ… machineDeploy hook finished");
524
+ await hook({ sshRemote });
525
+ console.log(`āœ… ${hookName} hook finished`);
513
526
  } catch (e) {
514
527
  console.error((e as Error).stack || String(e));
515
- console.error(`āš ļø The machineDeploy hook failed (see the error above). This is fine if the synchronization database hasn't been set up yet, or isn't running.`);
528
+ console.error(`āš ļø The ${hookName} hook failed (see the error above). ${onFailure}`);
516
529
  }
517
530
  }
518
531