create-op-node 0.12.0 → 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';
@@ -2271,7 +2271,7 @@ var bootstrapCommand = new Command("bootstrap").description(
2271
2271
  new Option(
2272
2272
  "--compose-file <path>",
2273
2273
  "Repeatable. Compose file relative to repo root. Default: prod + backup (production), prod only (--local-only)."
2274
- )
2274
+ ).argParser(collectComposeFile)
2275
2275
  ).addOption(new Option("--env-file <path>", "Compose --env-file. Default: .env.production")).addOption(new Option("--skip-brew", "Skip the Homebrew package install pass").default(false)).addOption(
2276
2276
  new Option(
2277
2277
  "--skip-launch-agent",
@@ -3011,6 +3011,9 @@ function resolveComposeFiles(repoPath, composeFile) {
3011
3011
  const inputs = composeFile ?? ["docker-compose-prod.yml"];
3012
3012
  return inputs.map((f) => f.startsWith("/") ? f : join(repoPath, f));
3013
3013
  }
3014
+ function collectComposeFile(value, previous) {
3015
+ return [...previous ?? [], value];
3016
+ }
3014
3017
  function resolveModels(opts) {
3015
3018
  return [
3016
3019
  opts.embeddingModel ?? DEFAULT_EMBEDDING_MODEL,
@@ -3256,6 +3259,9 @@ async function resetStopStackPhase(input, deps) {
3256
3259
  files: input.stack.composeFiles,
3257
3260
  cwd: input.stack.repoPath,
3258
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 } : {},
3259
3265
  wipeVolumes: input.stack.wipeVolumes,
3260
3266
  removeOrphans: input.stack.removeOrphans,
3261
3267
  ...input.stack.wipeImages ? { removeImages: "all" } : {}
@@ -3344,7 +3350,7 @@ var resetCommand = new Command("reset").description(
3344
3350
  new Option(
3345
3351
  "--compose-file <path>",
3346
3352
  "Repeatable. Compose file relative to repo root. Default: docker-compose-prod.yml"
3347
- ).default(["docker-compose-prod.yml"])
3353
+ ).argParser(collectComposeFile)
3348
3354
  ).addOption(new Option("--env-file <path>", "Compose --env-file. Default: .env.production")).addOption(
3349
3355
  new Option(
3350
3356
  "--wipe-data",
@@ -3395,6 +3401,7 @@ var resetCommand = new Command("reset").description(
3395
3401
  wipeImages
3396
3402
  });
3397
3403
  await confirmReset({ opts, region, wipeData });
3404
+ const teardownEnv = repoPath ? await computeTeardownEnv(resolveComposeFiles(repoPath, opts.composeFile)) : void 0;
3398
3405
  const input = buildResetInput({
3399
3406
  opts,
3400
3407
  repoPath,
@@ -3402,7 +3409,8 @@ var resetCommand = new Command("reset").description(
3402
3409
  launchAgentPaths,
3403
3410
  wipeData,
3404
3411
  wipeImages,
3405
- removeOrphans
3412
+ removeOrphans,
3413
+ ...teardownEnv ? { teardownEnv } : {}
3406
3414
  });
3407
3415
  await runResetWithSpinners({ opts, region, wipeData, input });
3408
3416
  });
@@ -3511,15 +3519,41 @@ async function confirmReset(args) {
3511
3519
  }
3512
3520
  }
3513
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
+ }
3514
3547
  function buildResetInput(args) {
3515
- const { opts, repoPath, plistExists, launchAgentPaths, wipeData, wipeImages, removeOrphans } = args;
3548
+ const { opts, repoPath, plistExists, launchAgentPaths, wipeData, wipeImages, removeOrphans, teardownEnv } = args;
3516
3549
  const stack = repoPath ? {
3517
3550
  repoPath,
3518
3551
  composeFiles: resolveComposeFiles(repoPath, opts.composeFile),
3519
3552
  wipeVolumes: wipeData,
3520
3553
  wipeImages,
3521
3554
  removeOrphans,
3522
- ...opts.envFile ? { envFile: opts.envFile } : {}
3555
+ ...opts.envFile ? { envFile: opts.envFile } : {},
3556
+ ...teardownEnv ? { env: teardownEnv } : {}
3523
3557
  } : void 0;
3524
3558
  const launchAgent = plistExists && !opts.skipLaunchAgent ? {
3525
3559
  paths: launchAgentPaths,
@@ -5087,7 +5121,7 @@ function withDefaultSubcommand(argv, known) {
5087
5121
  }
5088
5122
 
5089
5123
  // src/cli.ts
5090
- var VERSION = "0.12.0";
5124
+ var VERSION = "0.12.2";
5091
5125
  var program = new Command();
5092
5126
  program.name("create-op-node").description(
5093
5127
  "Interactive bootstrap for an Opus Populi federation node.\nCloudflare infrastructure \u2192 Mac Studio \u2192 live public API."