create-kide-app 0.6.1 → 0.7.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.
Files changed (2) hide show
  1. package/index.js +38 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import * as p from "@clack/prompts";
4
4
  import { execSync, spawn } from "node:child_process";
5
+ import { randomBytes } from "node:crypto";
5
6
  import {
6
7
  cpSync,
7
8
  existsSync,
@@ -470,7 +471,19 @@ async function main() {
470
471
  const adaptersDir = path.join(projectDir, "adapters");
471
472
  const targetDir = path.join(adaptersDir, target);
472
473
 
474
+ // Signs admin session cookies. Production builds refuse to sign in without it.
475
+ const authSecret = randomBytes(32).toString("base64");
476
+
473
477
  if (target === "cloudflare") {
478
+ // `pnpm preview` runs a production build in wrangler, which reads local secrets
479
+ // from .dev.vars — keep it out of git.
480
+ writeFileSync(path.join(projectDir, ".dev.vars"), `KIDE_AUTH_SECRET=${authSecret}\n`);
481
+ const gitignorePath = path.join(projectDir, ".gitignore");
482
+ const gitignore = existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf-8") : "";
483
+ if (!/^\.dev\.vars$/m.test(gitignore)) {
484
+ writeFileSync(gitignorePath, `${gitignore.replace(/\n?$/, "\n")}.dev.vars\n`);
485
+ }
486
+
474
487
  // The Cloudflare adapter/storage/env implementations live in the tree at
475
488
  // src/cms/platform/cloudflare. We only copy the target's Astro/Drizzle/wrangler config and
476
489
  // flip the two platform selectors to point at that profile — no source files are overwritten.
@@ -817,6 +830,7 @@ async function main() {
817
830
  r2Created: false,
818
831
  migrationsApplied: false,
819
832
  deployed: false,
833
+ secretSet: false,
820
834
  url: null,
821
835
  };
822
836
  if (target === "cloudflare") {
@@ -1019,6 +1033,20 @@ async function main() {
1019
1033
  if (err.stderr) console.error(err.stderr.slice(-1500));
1020
1034
  if (err.stdout) console.error(err.stdout.slice(-1500));
1021
1035
  }
1036
+ if (cf.deployed) {
1037
+ s.start("Setting the admin sign-in secret");
1038
+ try {
1039
+ execSync(
1040
+ `${pm.exec} wrangler secret put KIDE_AUTH_SECRET --config dist/server/wrangler.json`,
1041
+ { cwd: projectDir, input: authSecret, stdio: ["pipe", "pipe", "pipe"] },
1042
+ );
1043
+ cf.secretSet = true;
1044
+ s.stop("Admin sign-in secret set");
1045
+ } catch (err) {
1046
+ s.stop("Could not set KIDE_AUTH_SECRET — set it manually (see below)");
1047
+ if (err.stderr) console.error(err.stderr.toString().slice(-800));
1048
+ }
1049
+ }
1022
1050
  }
1023
1051
  }
1024
1052
  }
@@ -1028,6 +1056,9 @@ async function main() {
1028
1056
  // --- Done ---
1029
1057
 
1030
1058
  if (target === "local") {
1059
+ p.log.info(
1060
+ "Production deploys need KIDE_AUTH_SECRET in the environment — generate one with `openssl rand -base64 32`.",
1061
+ );
1031
1062
  // Without a terminal the dev server would never return control; skip it.
1032
1063
  const startDev = flags.noDev || !interactive
1033
1064
  ? false
@@ -1052,7 +1083,7 @@ async function main() {
1052
1083
  p.outro("Project created!");
1053
1084
  }
1054
1085
  } else {
1055
- if (cf.deployed && cf.url) {
1086
+ if (cf.deployed && cf.url && cf.secretSet) {
1056
1087
  const liveLines = [
1057
1088
  `Live at: ${cf.url}`,
1058
1089
  `Admin: ${cf.url}/admin`,
@@ -1089,6 +1120,12 @@ async function main() {
1089
1120
  if (!cf.deployed) {
1090
1121
  remaining.push(` ${pm.run} run deploy`);
1091
1122
  }
1123
+ if (!cf.secretSet) {
1124
+ remaining.push(
1125
+ ` ${pm.dlx} wrangler secret put KIDE_AUTH_SECRET`,
1126
+ " # paste the value from .dev.vars — admin sign-in needs it",
1127
+ );
1128
+ }
1092
1129
  if (remaining.length > 0) {
1093
1130
  lines.push("", "Remaining setup:", ...remaining);
1094
1131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kide-app",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Scaffold a new Kide CMS project",
5
5
  "author": "Matti Hernesniemi",
6
6
  "license": "MIT",