create-kide-app 0.6.0 → 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 +46 -4
  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,
@@ -59,7 +60,9 @@ const pm = {
59
60
  exec: "pnpm exec",
60
61
  dlx: "pnpm dlx",
61
62
  run: "pnpm",
62
- install: "pnpm install",
63
+ // The scaffold rewrites package.json, so the template lockfile never matches; pnpm
64
+ // defaults to --frozen-lockfile when CI=true and would refuse to install.
65
+ install: "pnpm install --no-frozen-lockfile",
63
66
  };
64
67
 
65
68
  // --- Template repo ---
@@ -468,7 +471,19 @@ async function main() {
468
471
  const adaptersDir = path.join(projectDir, "adapters");
469
472
  const targetDir = path.join(adaptersDir, target);
470
473
 
474
+ // Signs admin session cookies. Production builds refuse to sign in without it.
475
+ const authSecret = randomBytes(32).toString("base64");
476
+
471
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
+
472
487
  // The Cloudflare adapter/storage/env implementations live in the tree at
473
488
  // src/cms/platform/cloudflare. We only copy the target's Astro/Drizzle/wrangler config and
474
489
  // flip the two platform selectors to point at that profile — no source files are overwritten.
@@ -649,8 +664,10 @@ async function main() {
649
664
  try {
650
665
  await runAsync(pm.install, projectDir);
651
666
  s.stop("Dependencies installed");
652
- } catch {
667
+ } catch (err) {
653
668
  s.stop(`${pm.install} failed — run it manually`);
669
+ if (err.stderr) console.error(err.stderr.slice(-1500));
670
+ if (err.stdout) console.error(err.stdout.slice(-1500));
654
671
  }
655
672
 
656
673
  // --- Initialize git repository ---
@@ -813,6 +830,7 @@ async function main() {
813
830
  r2Created: false,
814
831
  migrationsApplied: false,
815
832
  deployed: false,
833
+ secretSet: false,
816
834
  url: null,
817
835
  };
818
836
  if (target === "cloudflare") {
@@ -981,10 +999,11 @@ async function main() {
981
999
  );
982
1000
  cf.migrationsApplied = true;
983
1001
  s.stop("Migrations applied");
984
- } catch {
1002
+ } catch (err) {
985
1003
  s.stop(
986
1004
  "Migration apply failed — run manually with: wrangler d1 migrations apply --remote",
987
1005
  );
1006
+ if (err.stderr) console.error(err.stderr.toString().slice(-800));
988
1007
  }
989
1008
  }
990
1009
 
@@ -1014,6 +1033,20 @@ async function main() {
1014
1033
  if (err.stderr) console.error(err.stderr.slice(-1500));
1015
1034
  if (err.stdout) console.error(err.stdout.slice(-1500));
1016
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
+ }
1017
1050
  }
1018
1051
  }
1019
1052
  }
@@ -1023,6 +1056,9 @@ async function main() {
1023
1056
  // --- Done ---
1024
1057
 
1025
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
+ );
1026
1062
  // Without a terminal the dev server would never return control; skip it.
1027
1063
  const startDev = flags.noDev || !interactive
1028
1064
  ? false
@@ -1047,7 +1083,7 @@ async function main() {
1047
1083
  p.outro("Project created!");
1048
1084
  }
1049
1085
  } else {
1050
- if (cf.deployed && cf.url) {
1086
+ if (cf.deployed && cf.url && cf.secretSet) {
1051
1087
  const liveLines = [
1052
1088
  `Live at: ${cf.url}`,
1053
1089
  `Admin: ${cf.url}/admin`,
@@ -1084,6 +1120,12 @@ async function main() {
1084
1120
  if (!cf.deployed) {
1085
1121
  remaining.push(` ${pm.run} run deploy`);
1086
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
+ }
1087
1129
  if (remaining.length > 0) {
1088
1130
  lines.push("", "Remaining setup:", ...remaining);
1089
1131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kide-app",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Scaffold a new Kide CMS project",
5
5
  "author": "Matti Hernesniemi",
6
6
  "license": "MIT",