@donotdev/cli 0.3.6 → 0.3.8

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.
@@ -8769,6 +8769,224 @@ var init_spawn_utils = __esm({
8769
8769
  }
8770
8770
  });
8771
8771
 
8772
+ // packages/tooling/src/utils/secrets-resolver.ts
8773
+ function parseEnvFile(filePath) {
8774
+ if (!pathExists(filePath)) return {};
8775
+ const content = readSync(filePath, { format: "text" });
8776
+ if (typeof content !== "string" || !content) return {};
8777
+ const result = {};
8778
+ for (const line of content.split(/\r?\n/)) {
8779
+ const trimmed = line.trim();
8780
+ if (!trimmed || trimmed.startsWith("#")) continue;
8781
+ const eqIdx = trimmed.indexOf("=");
8782
+ if (eqIdx === -1) continue;
8783
+ const key = trimmed.slice(0, eqIdx).trim();
8784
+ let value = trimmed.slice(eqIdx + 1).trim();
8785
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
8786
+ value = value.slice(1, -1);
8787
+ }
8788
+ if (key && value) {
8789
+ result[key] = value;
8790
+ }
8791
+ }
8792
+ return result;
8793
+ }
8794
+ var init_secrets_resolver = __esm({
8795
+ "packages/tooling/src/utils/secrets-resolver.ts"() {
8796
+ "use strict";
8797
+ init_utils2();
8798
+ init_pathResolver();
8799
+ }
8800
+ });
8801
+
8802
+ // packages/tooling/src/apps/sync-secrets.ts
8803
+ import { spawnSync as spawnSync2 } from "node:child_process";
8804
+ function parseEnvFile2(filePath) {
8805
+ if (!pathExists(filePath)) {
8806
+ throw new DoNotDevError(
8807
+ `Environment file not found: ${filePath}`,
8808
+ "file-not-found",
8809
+ { context: { filePath } }
8810
+ );
8811
+ }
8812
+ const result = parseEnvFile(filePath);
8813
+ if (Object.keys(result).length === 0) {
8814
+ log2.debug(`No key-value pairs found in ${filePath}`);
8815
+ }
8816
+ return result;
8817
+ }
8818
+ function readPublicAppEnv(appDir, file = ".env") {
8819
+ const env = parseEnvFile2(joinPath(appDir, file));
8820
+ return Object.fromEntries(
8821
+ Object.entries(env).filter(
8822
+ ([key]) => PUBLIC_ENV_PREFIXES.some((prefix) => key.startsWith(prefix))
8823
+ )
8824
+ );
8825
+ }
8826
+ var PUBLIC_ENV_PREFIXES;
8827
+ var init_sync_secrets = __esm({
8828
+ "packages/tooling/src/apps/sync-secrets.ts"() {
8829
+ "use strict";
8830
+ init_utils2();
8831
+ init_cli_output();
8832
+ init_errors();
8833
+ init_pathResolver();
8834
+ init_secrets_resolver();
8835
+ PUBLIC_ENV_PREFIXES = ["NEXT_PUBLIC_", "VITE_", "EXPO_PUBLIC_"];
8836
+ }
8837
+ });
8838
+
8839
+ // packages/tooling/src/utils/supabase-management.ts
8840
+ function parseProjectRef(supabaseUrl) {
8841
+ return supabaseUrl?.match(/https?:\/\/([a-z0-9]+)\.supabase\.co/)?.[1];
8842
+ }
8843
+ var init_supabase_management = __esm({
8844
+ "packages/tooling/src/utils/supabase-management.ts"() {
8845
+ "use strict";
8846
+ init_utils2();
8847
+ }
8848
+ });
8849
+
8850
+ // packages/tooling/src/apps/uat-target.ts
8851
+ import { createHash } from "node:crypto";
8852
+ function declaredEnvKeys(filePath) {
8853
+ if (!pathExists(filePath)) return [];
8854
+ const content = readSync(filePath, { format: "text" });
8855
+ if (typeof content !== "string") return [];
8856
+ return content.split(/\r?\n/).map((line) => line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/)?.[1]).filter((key) => !!key);
8857
+ }
8858
+ function declaredPublicKeys(filePath) {
8859
+ return declaredEnvKeys(filePath).filter(
8860
+ (key) => PUBLIC_PREFIXES.some((p) => key.startsWith(p))
8861
+ );
8862
+ }
8863
+ function supabaseUrlOf(env) {
8864
+ return env["VITE_SUPABASE_URL"] || env["NEXT_PUBLIC_SUPABASE_URL"] || void 0;
8865
+ }
8866
+ function readProductionAppEnv(appDir) {
8867
+ const files = [".env", ".env.production"].filter(
8868
+ (file) => pathExists(joinPath(appDir, file))
8869
+ );
8870
+ const env = Object.assign(
8871
+ {},
8872
+ ...files.map((file) => parseEnvFile(joinPath(appDir, file)))
8873
+ );
8874
+ const publicKeys = new Set(
8875
+ files.flatMap((file) => Object.keys(readPublicAppEnv(appDir, file)))
8876
+ );
8877
+ return { files, env, publicKeys };
8878
+ }
8879
+ function normalizeUrl(url) {
8880
+ return url.trim().replace(/\/+$/, "").toLowerCase();
8881
+ }
8882
+ function readProductionIdentifiers(projectRoot, appDir) {
8883
+ const appsDir = joinPath(projectRoot, "apps");
8884
+ const dirs = pathExists(appsDir) ? readdirSync3(appsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => joinPath(appsDir, entry.name)) : [projectRoot];
8885
+ const ids = {
8886
+ vercelProjects: /* @__PURE__ */ new Map(),
8887
+ supabaseRefs: /* @__PURE__ */ new Map(),
8888
+ supabaseUrls: /* @__PURE__ */ new Map()
8889
+ };
8890
+ for (const dir of [.../* @__PURE__ */ new Set([...appDir ? [appDir] : [], ...dirs])]) {
8891
+ for (const name of readProductionAppEnv(dir).files) {
8892
+ const file = joinPath(dir, name);
8893
+ const env = parseEnvFile(file);
8894
+ const projectId = env["VERCEL_PROJECT_ID"];
8895
+ if (projectId && !ids.vercelProjects.has(projectId)) ids.vercelProjects.set(projectId, file);
8896
+ const url = supabaseUrlOf(env);
8897
+ if (!url) continue;
8898
+ const ref = parseProjectRef(url);
8899
+ if (ref && !ids.supabaseRefs.has(ref)) ids.supabaseRefs.set(ref, file);
8900
+ if (!ids.supabaseUrls.has(normalizeUrl(url))) ids.supabaseUrls.set(normalizeUrl(url), file);
8901
+ }
8902
+ }
8903
+ return ids;
8904
+ }
8905
+ function productionVercelProjectFile(ids, projectId) {
8906
+ return projectId ? ids.vercelProjects.get(projectId) : void 0;
8907
+ }
8908
+ function productionSupabaseProjectFile(ids, project) {
8909
+ const ref = project.ref ?? parseProjectRef(project.url);
8910
+ return (ref ? ids.supabaseRefs.get(ref) : void 0) ?? (project.url ? ids.supabaseUrls.get(normalizeUrl(project.url)) : void 0);
8911
+ }
8912
+ function fail(message) {
8913
+ throw new DoNotDevError(message, "configuration-error");
8914
+ }
8915
+ function resolveUatTarget(appDir, projectRoot, needs) {
8916
+ const uatEnvPath = joinPath(appDir, UAT_ENV_FILE);
8917
+ if (!pathExists(uatEnvPath)) {
8918
+ fail(
8919
+ `UAT needs ${uatEnvPath}: the public values of the UAT build (VITE_* / NEXT_PUBLIC_*) and VERCEL_PROJECT_ID / VERCEL_ORG_ID of the UAT Vercel project. Create it (dn setup uat writes it).`
8920
+ );
8921
+ }
8922
+ const uatEnv = parseEnvFile(uatEnvPath);
8923
+ const publicEnv = {
8924
+ ...Object.fromEntries(declaredPublicKeys(uatEnvPath).map((key) => [key, ""])),
8925
+ ...readPublicAppEnv(appDir, UAT_ENV_FILE)
8926
+ };
8927
+ const { files: prodFiles, publicKeys: prodPublicKeys } = readProductionAppEnv(appDir);
8928
+ const production = readProductionIdentifiers(projectRoot, appDir);
8929
+ const missingKeys = [...prodPublicKeys].filter((key) => !(key in publicEnv));
8930
+ if (missingKeys.length > 0) {
8931
+ fail(
8932
+ `${uatEnvPath} must define every public key of the production env files (${prodFiles.join(", ")}), else the production value is built in. Missing: ${missingKeys.join(", ")}. An empty value (KEY=) leaves it unset.`
8933
+ );
8934
+ }
8935
+ const uatSupabaseUrl = supabaseUrlOf(publicEnv);
8936
+ const uatRef = parseProjectRef(uatSupabaseUrl);
8937
+ const prodSupabaseFile = productionSupabaseProjectFile(production, { url: uatSupabaseUrl });
8938
+ if (prodSupabaseFile) {
8939
+ fail(
8940
+ `${uatEnvPath} points at the production Supabase project (${uatRef ?? uatSupabaseUrl}, named in ${prodSupabaseFile}). Set the UAT project URL and publishable key.`
8941
+ );
8942
+ }
8943
+ const target = { publicEnv };
8944
+ if (needs.vercel) {
8945
+ const projectId = uatEnv["VERCEL_PROJECT_ID"];
8946
+ if (!projectId) {
8947
+ fail(`UAT needs VERCEL_PROJECT_ID (UAT Vercel project) in ${uatEnvPath}. Set the id of the UAT Vercel project (dn setup uat writes it).`);
8948
+ }
8949
+ const prodVercelFile = productionVercelProjectFile(production, projectId);
8950
+ if (prodVercelFile) {
8951
+ fail(
8952
+ `${uatEnvPath} VERCEL_PROJECT_ID is the production Vercel project (${projectId}, named in ${prodVercelFile}). Set the id of the UAT Vercel project.`
8953
+ );
8954
+ }
8955
+ target.vercel = { projectId, orgId: uatEnv["VERCEL_ORG_ID"] || void 0 };
8956
+ }
8957
+ if (needs.supabaseFunctions) {
8958
+ if (!uatSupabaseUrl || !uatRef) {
8959
+ fail(
8960
+ `UAT needs the UAT Supabase URL (VITE_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_URL, https://<ref>.supabase.co) in ${uatEnvPath}.`
8961
+ );
8962
+ }
8963
+ const secretsPath = joinPath(projectRoot, UAT_SECRETS_FILE);
8964
+ const dbPassword = parseEnvFile(secretsPath)["UAT_SUPABASE_DB_PWD"];
8965
+ if (!dbPassword) {
8966
+ fail(
8967
+ `UAT needs UAT_SUPABASE_DB_PWD (database password of the UAT project ${uatRef}) in ${secretsPath}.`
8968
+ );
8969
+ }
8970
+ target.supabase = { url: uatSupabaseUrl, dbPassword };
8971
+ }
8972
+ return target;
8973
+ }
8974
+ var UAT_ENV_FILE, UAT_SECRETS_FILE, PUBLIC_PREFIXES;
8975
+ var init_uat_target = __esm({
8976
+ "packages/tooling/src/apps/uat-target.ts"() {
8977
+ "use strict";
8978
+ init_utils2();
8979
+ init_sync_secrets();
8980
+ init_errors();
8981
+ init_pathResolver();
8982
+ init_secrets_resolver();
8983
+ init_supabase_management();
8984
+ UAT_ENV_FILE = ".env.uat";
8985
+ UAT_SECRETS_FILE = ".dndev.uat.secrets";
8986
+ PUBLIC_PREFIXES = ["NEXT_PUBLIC_", "VITE_", "EXPO_PUBLIC_"];
8987
+ }
8988
+ });
8989
+
8772
8990
  // packages/cli/src/bin/commands/dev.ts
8773
8991
  init_utils2();
8774
8992
 
@@ -8780,6 +8998,7 @@ init_utils2();
8780
8998
 
8781
8999
  // packages/tooling/src/apps/dev.ts
8782
9000
  init_utils2();
9001
+ init_uat_target();
8783
9002
  init_app_selector();
8784
9003
  init_cli_output();
8785
9004
  init_errors();
@@ -8793,7 +9012,7 @@ var SIGNAL_EXIT_CODES = {
8793
9012
  SIGTERM: 143
8794
9013
  // 128 + 15
8795
9014
  };
8796
- async function main() {
9015
+ async function main(options = {}) {
8797
9016
  const args = process.argv.slice(2);
8798
9017
  const appName = args[0] && args[0] !== "dev" ? args[0] : void 0;
8799
9018
  const projectRoot = getRepoRoot();
@@ -8807,6 +9026,15 @@ async function main() {
8807
9026
  if (!app) {
8808
9027
  return 1;
8809
9028
  }
9029
+ const uatEnv = options.uat ? resolveUatTarget(app.path, projectRoot, {
9030
+ vercel: false,
9031
+ supabaseFunctions: false
9032
+ }).publicEnv : {};
9033
+ if (options.uat) {
9034
+ log2.info(
9035
+ `UAT backend: ${uatEnv["VITE_SUPABASE_URL"] || uatEnv["NEXT_PUBLIC_SUPABASE_URL"] || "(no Supabase URL in .env.uat)"}`
9036
+ );
9037
+ }
8810
9038
  log2.info(`Starting dev server for ${app.name}...
8811
9039
  `);
8812
9040
  const turboArgs = ["dev", "--filter", app.packageName];
@@ -8816,7 +9044,7 @@ async function main() {
8816
9044
  ["turbo", ...turboArgs],
8817
9045
  {
8818
9046
  stdio: "inherit",
8819
- env: createAppEnv(app.path),
9047
+ env: { ...createAppEnv(app.path), ...uatEnv },
8820
9048
  cwd: projectRoot
8821
9049
  }
8822
9050
  );
@@ -9117,7 +9117,11 @@ var init_command_registry = __esm({
9117
9117
  appCommand: true,
9118
9118
  actionPattern: "app",
9119
9119
  options: [
9120
- { flags: "-c, --concurrency <n>", description: "set concurrency" }
9120
+ { flags: "-c, --concurrency <n>", description: "set concurrency" },
9121
+ {
9122
+ flags: "--uat",
9123
+ description: "Run locally against the UAT backend (apps/<app>/.env.uat; refuses production values)"
9124
+ }
9121
9125
  ],
9122
9126
  loader: "../apps/dev.ts",
9123
9127
  exportName: "dev"
@@ -9419,7 +9423,7 @@ var init_command_registry = __esm({
9419
9423
  options: [
9420
9424
  {
9421
9425
  flags: "-y, --yes",
9422
- description: "Accept every default answer: packages and docs, no major updates, then bun install"
9426
+ description: "Accept every default answer: packages, docs, AI harness and the demo/dndev apps already present, no major updates, then bun install"
9423
9427
  }
9424
9428
  ],
9425
9429
  loader: "../maintenance/bump.ts",
@@ -9437,7 +9441,7 @@ var init_command_registry = __esm({
9437
9441
  // ---------------------------------------------------------------------------
9438
9442
  {
9439
9443
  name: "deploy [app]",
9440
- description: "Deploy app",
9444
+ description: "Deploy app to production (UAT: uat <app>)",
9441
9445
  category: "deployment",
9442
9446
  public: true,
9443
9447
  appCommand: true,
@@ -9455,10 +9459,6 @@ var init_command_registry = __esm({
9455
9459
  flags: "--force",
9456
9460
  description: "Delete deployed Firebase functions missing from the local source (default: off; the deploy aborts and names them)"
9457
9461
  },
9458
- {
9459
- flags: "--staging",
9460
- description: "Deploy to staging (uses .env.staging and staging credentials)"
9461
- },
9462
9462
  {
9463
9463
  flags: "--scope <scope>",
9464
9464
  description: "What to deploy: frontend, functions, rules, both or all. Implies --yes"
@@ -9476,43 +9476,31 @@ var init_command_registry = __esm({
9476
9476
  exportName: "deploy"
9477
9477
  },
9478
9478
  {
9479
- name: "staging [app]",
9480
- description: "Deploy to staging/UAT (shorthand for deploy --staging)",
9481
- alias: "uat",
9479
+ name: "uat [app]",
9480
+ description: "Ship the code on this machine to UAT (Supabase + Vercel apps): apps/<app>/.env.uat, .dndev.uat.secrets; never production values; history-aware migrations, noindex",
9482
9481
  category: "deployment",
9483
9482
  public: true,
9484
9483
  appCommand: true,
9485
9484
  options: [
9486
- {
9487
- flags: "-p, --project <project>",
9488
- description: "Project ID (overrides default)"
9489
- },
9490
9485
  {
9491
9486
  flags: "--skip-build",
9492
9487
  description: "Reuse existing builds (dist/, out/, .vercel/output, functions, edge .build/). Default: build"
9493
9488
  },
9494
- {
9495
- flags: "--from-git",
9496
- description: "Next.js on Vercel: let Vercel build from linked Git (default: local vercel build + upload)"
9497
- },
9498
- {
9499
- flags: "--force",
9500
- description: "Delete deployed Firebase functions missing from the local source (default: off; the deploy aborts and names them)"
9501
- },
9502
9489
  {
9503
9490
  flags: "--scope <scope>",
9504
- description: "What to deploy: frontend, functions, rules, both or all. Implies --yes"
9491
+ description: "What to deploy: frontend, functions, both or all. Implies --yes"
9505
9492
  },
9506
9493
  {
9507
9494
  flags: "-y, --yes",
9508
9495
  description: "Non-interactive: never prompt; a missing required value fails, naming its flag (also when stdin is not a TTY)"
9509
9496
  },
9510
9497
  {
9511
- flags: "--no-sync-secrets",
9512
- description: "Skip pushing the secrets functions.yaml binds to Firebase Secret Manager (default: push changed values)"
9498
+ flags: "--refresh-data",
9499
+ description: "Copy production data into UAT (anonymized; storage incremental), then deploy; overwrites UAT data; asks for confirmation unless --yes"
9513
9500
  }
9514
9501
  ],
9515
- loader: "../apps/deploy.ts"
9502
+ loader: "../apps/uat.ts",
9503
+ exportName: "uat"
9516
9504
  },
9517
9505
  {
9518
9506
  name: "sync-secrets",
@@ -9582,10 +9570,15 @@ var init_command_registry = __esm({
9582
9570
  },
9583
9571
  {
9584
9572
  name: "setup [provider]",
9585
- description: "Set up infrastructure providers (firebase, supabase, vercel)",
9573
+ description: "Set up infrastructure providers (firebase, supabase, vercel) or the UAT environment (uat)",
9586
9574
  category: "deployment",
9587
9575
  public: true,
9588
- options: [],
9576
+ options: [
9577
+ {
9578
+ flags: "-y, --yes",
9579
+ description: "dn setup uat: create missing UAT resources without prompting"
9580
+ }
9581
+ ],
9589
9582
  loader: "../cli/setup/setup.ts",
9590
9583
  exportName: "setup"
9591
9584
  },
@@ -9599,10 +9592,6 @@ var init_command_registry = __esm({
9599
9592
  {
9600
9593
  flags: "--app <app>",
9601
9594
  description: "App name (auto-detected if single app)"
9602
- },
9603
- {
9604
- flags: "--staging",
9605
- description: "Include staging workflow generation"
9606
9595
  }
9607
9596
  ],
9608
9597
  loader: "../scaffolding/setup-cicd.ts",
@@ -9774,11 +9763,19 @@ var init_command_registry = __esm({
9774
9763
  },
9775
9764
  {
9776
9765
  flags: "--output-dir <dir>",
9777
- description: "output directory for migrations (default: supabase/migrations)"
9766
+ description: "output directory for migrations (default: supabase/migrations of the app the command runs for: the nearest folder up with supabase/config.toml, or the only app with one under apps/; fails when none)"
9778
9767
  },
9779
9768
  {
9780
9769
  flags: "--no-single-file",
9781
9770
  description: "emit one migration file per entity"
9771
+ },
9772
+ {
9773
+ flags: "--only <collections...>",
9774
+ description: "emit only these collections into ONE new migration <version>_<first>[_and_more].sql (version: now, or the latest existing + 1 so it sorts last); never touches *_entity_tables.sql (for a live app adding a feature's entities; feature-owned collections accepted)"
9775
+ },
9776
+ {
9777
+ flags: "--app-dir <dir>",
9778
+ description: "app folder whose src/config/app.ts turns framework features on (their entities are included when installed; default: the app of the output dir)"
9782
9779
  }
9783
9780
  ],
9784
9781
  loader: "../generators/sql-generator.ts"