create-op-node 0.12.1 → 0.12.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/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ import { Octokit } from '@octokit/rest';
7
7
  import _sodium from 'libsodium-wrappers';
8
8
  import { randomBytes, createHmac } from 'crypto';
9
9
  import { join, resolve, dirname } from 'path';
10
- import { mkdir, writeFile, access, chmod, rename, rm } from 'fs/promises';
10
+ import { readFile, mkdir, writeFile, access, chmod, rename, rm } from 'fs/promises';
11
11
  import { homedir } from 'os';
12
12
  import { readFileSync } from 'fs';
13
13
  import * as tls from 'tls';
@@ -3259,6 +3259,9 @@ async function resetStopStackPhase(input, deps) {
3259
3259
  files: input.stack.composeFiles,
3260
3260
  cwd: input.stack.repoPath,
3261
3261
  ...input.stack.envFile ? { envFile: input.stack.envFile } : {},
3262
+ // Hydrate placeholder values for the template's `${VAR:?…}` required vars
3263
+ // so interpolation succeeds; `down` doesn't use the values. (#85)
3264
+ ...input.stack.env ? { env: input.stack.env } : {},
3262
3265
  wipeVolumes: input.stack.wipeVolumes,
3263
3266
  removeOrphans: input.stack.removeOrphans,
3264
3267
  ...input.stack.wipeImages ? { removeImages: "all" } : {}
@@ -3398,6 +3401,7 @@ var resetCommand = new Command("reset").description(
3398
3401
  wipeImages
3399
3402
  });
3400
3403
  await confirmReset({ opts, region, wipeData });
3404
+ const teardownEnv = repoPath ? await computeTeardownEnv(resolveComposeFiles(repoPath, opts.composeFile)) : void 0;
3401
3405
  const input = buildResetInput({
3402
3406
  opts,
3403
3407
  repoPath,
@@ -3405,7 +3409,8 @@ var resetCommand = new Command("reset").description(
3405
3409
  launchAgentPaths,
3406
3410
  wipeData,
3407
3411
  wipeImages,
3408
- removeOrphans
3412
+ removeOrphans,
3413
+ ...teardownEnv ? { teardownEnv } : {}
3409
3414
  });
3410
3415
  await runResetWithSpinners({ opts, region, wipeData, input });
3411
3416
  });
@@ -3514,15 +3519,41 @@ async function confirmReset(args) {
3514
3519
  }
3515
3520
  }
3516
3521
  }
3522
+ var TEARDOWN_PLACEHOLDER = "reset-teardown-placeholder";
3523
+ var REQUIRED_VAR_RE = /\$\{([A-Za-z_]\w*):?\?/g;
3524
+ function buildTeardownEnv(composeFileContents, baseEnv = process.env) {
3525
+ const overlay = {};
3526
+ for (const text6 of composeFileContents) {
3527
+ for (const match of text6.matchAll(REQUIRED_VAR_RE)) {
3528
+ const name = match[1];
3529
+ const existing = baseEnv[name];
3530
+ if (existing === void 0 || existing === "") {
3531
+ overlay[name] = TEARDOWN_PLACEHOLDER;
3532
+ }
3533
+ }
3534
+ }
3535
+ return overlay;
3536
+ }
3537
+ async function computeTeardownEnv(composeFiles) {
3538
+ const contents = [];
3539
+ for (const file of composeFiles) {
3540
+ try {
3541
+ contents.push(await readFile(file, "utf8"));
3542
+ } catch {
3543
+ }
3544
+ }
3545
+ return buildTeardownEnv(contents);
3546
+ }
3517
3547
  function buildResetInput(args) {
3518
- const { opts, repoPath, plistExists, launchAgentPaths, wipeData, wipeImages, removeOrphans } = args;
3548
+ const { opts, repoPath, plistExists, launchAgentPaths, wipeData, wipeImages, removeOrphans, teardownEnv } = args;
3519
3549
  const stack = repoPath ? {
3520
3550
  repoPath,
3521
3551
  composeFiles: resolveComposeFiles(repoPath, opts.composeFile),
3522
3552
  wipeVolumes: wipeData,
3523
3553
  wipeImages,
3524
3554
  removeOrphans,
3525
- ...opts.envFile ? { envFile: opts.envFile } : {}
3555
+ ...opts.envFile ? { envFile: opts.envFile } : {},
3556
+ ...teardownEnv ? { env: teardownEnv } : {}
3526
3557
  } : void 0;
3527
3558
  const launchAgent = plistExists && !opts.skipLaunchAgent ? {
3528
3559
  paths: launchAgentPaths,
@@ -5090,7 +5121,7 @@ function withDefaultSubcommand(argv, known) {
5090
5121
  }
5091
5122
 
5092
5123
  // src/cli.ts
5093
- var VERSION = "0.12.1";
5124
+ var VERSION = "0.12.2";
5094
5125
  var program = new Command();
5095
5126
  program.name("create-op-node").description(
5096
5127
  "Interactive bootstrap for an Opus Populi federation node.\nCloudflare infrastructure \u2192 Mac Studio \u2192 live public API."