kizlo 0.9.1 → 0.10.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.
@@ -1,5 +1,6 @@
1
- import { composeStop, createStack } from "../wp/docker.js";
2
- import { ensureGitignored, envGroups, envKeysPresent, mergeEnv, pickStackPort, writeFileIfAbsent } from "../utils.js";
1
+ import { LOCAL_DIR_REL } from "../wp/constants.js";
2
+ import { composeStop, createStack, dockerHint, dockerStatus } from "../wp/docker.js";
3
+ import { DEFAULT_ENV_KEYS, ensureGitignored, envGroups, envKeysPresent, mergeEnv, pickStackPort, writeFileIfAbsent } from "../utils.js";
3
4
  import { DEFAULT_DEV_DB_PORT, DEFAULT_DEV_PORT, resolveStackName } from "../daemon/config.js";
4
5
  import { createAdminAppPassword } from "../wp/bootstrap.js";
5
6
  import { bootstrapDev } from "../wp/dev.js";
@@ -14,46 +15,67 @@ import { randomBytes } from "node:crypto";
14
15
  import getPort, { portNumbers } from "get-port";
15
16
 
16
17
  //#region src/cli/commands/_setup.ts
17
- /** Production connection keys — what a real deploy needs, and what `.env.example` always lists. */
18
- const PROD_WP_ENV_KEYS = [
19
- "KIZLO_SITE_SECRET",
20
- "KIZLO_WORDPRESS_URL",
21
- "KIZLO_WORDPRESS_USERNAME",
22
- "KIZLO_WORDPRESS_APPLICATION_PASSWORD"
23
- ];
24
18
  /**
25
- * The `.env` keys setup manages and the values to write, branched on the connection mode. A local
26
- * dev stack writes the `KIZLO_DEV_WORDPRESS_*` / `KIZLO_DEV_SITE_SECRET` set plus `KIZLO_TARGET=dev`, so it
27
- * never touches the production keys (a user can point those at a real site). A remote site writes the
28
- * bare production keys exactly as before — no `KIZLO_TARGET`, since `"production"` is the default target.
19
+ * The resolved `.env` key names the scaffold writes: the template's declared `env` when it has one,
20
+ * else the preset's built-in `envKeys` (the generic `base` preset), else the {@link DEFAULT_ENV_KEYS}
21
+ * fallback for an in-repo template before the first stamped release. Threaded into `managedEnv`,
22
+ * `writeEnv`, and `collectConnectionFromEnv` so the scaffold writes the names the pinned runtime reads.
29
23
  */
30
- function managedEnv(preset, conn) {
31
- if (conn.mode === "local") return {
24
+ function resolveEnvKeys(preset, manifest) {
25
+ return manifest?.env ?? preset.envKeys ?? DEFAULT_ENV_KEYS;
26
+ }
27
+ /** Remote connection keys — what a real deploy needs, and what `.env.example` always lists. */
28
+ function remoteKeys(envKeys) {
29
+ return [
30
+ envKeys.remote.siteSecret,
31
+ envKeys.remote.wpUrl,
32
+ envKeys.remote.wpUsername,
33
+ envKeys.remote.wpPassword
34
+ ];
35
+ }
36
+ /**
37
+ * The `.env` keys setup manages and the values to write, branched on the connection mode. Local
38
+ * WordPress writes the `KIZLO_LOCAL_WP_*` / `KIZLO_LOCAL_WP_SECRET` set plus `KIZLO_CONNECT=local`,
39
+ * so it never touches the remote keys (a user can point those at a real site). A remote site writes
40
+ * the bare remote keys exactly as before — no `KIZLO_CONNECT`, since `"remote"` is the default.
41
+ */
42
+ function managedEnv(envKeys, conn) {
43
+ if (conn.mode === "local") {
44
+ const { connect, siteSecret: siteSecret$1, wpUrl: wpUrl$1, wpUsername: wpUsername$1, wpPassword: wpPassword$1 } = envKeys.local;
45
+ return {
46
+ keys: [
47
+ envKeys.baseUrl,
48
+ connect,
49
+ siteSecret$1,
50
+ wpUrl$1,
51
+ wpUsername$1,
52
+ wpPassword$1
53
+ ],
54
+ values: {
55
+ [envKeys.baseUrl]: conn.baseUrl,
56
+ [connect]: "local",
57
+ [siteSecret$1]: conn.siteSecret,
58
+ [wpUrl$1]: conn.wpUrl,
59
+ [wpUsername$1]: conn.wpUsername,
60
+ [wpPassword$1]: conn.wpPassword
61
+ }
62
+ };
63
+ }
64
+ const { siteSecret, wpUrl, wpUsername, wpPassword } = envKeys.remote;
65
+ return {
32
66
  keys: [
33
- preset.baseUrlEnvKey,
34
- "KIZLO_TARGET",
35
- "KIZLO_DEV_SITE_SECRET",
36
- "KIZLO_DEV_WORDPRESS_URL",
37
- "KIZLO_DEV_WORDPRESS_USERNAME",
38
- "KIZLO_DEV_WORDPRESS_APPLICATION_PASSWORD"
67
+ envKeys.baseUrl,
68
+ siteSecret,
69
+ wpUrl,
70
+ wpUsername,
71
+ wpPassword
39
72
  ],
40
73
  values: {
41
- [preset.baseUrlEnvKey]: conn.baseUrl,
42
- KIZLO_TARGET: "dev",
43
- KIZLO_DEV_SITE_SECRET: conn.siteSecret,
44
- KIZLO_DEV_WORDPRESS_URL: conn.wpUrl,
45
- KIZLO_DEV_WORDPRESS_USERNAME: conn.wpUsername,
46
- KIZLO_DEV_WORDPRESS_APPLICATION_PASSWORD: conn.wpPassword
47
- }
48
- };
49
- return {
50
- keys: [preset.baseUrlEnvKey, ...PROD_WP_ENV_KEYS],
51
- values: {
52
- [preset.baseUrlEnvKey]: conn.baseUrl,
53
- KIZLO_SITE_SECRET: conn.siteSecret,
54
- KIZLO_WORDPRESS_URL: conn.wpUrl,
55
- KIZLO_WORDPRESS_USERNAME: conn.wpUsername,
56
- KIZLO_WORDPRESS_APPLICATION_PASSWORD: conn.wpPassword
74
+ [envKeys.baseUrl]: conn.baseUrl,
75
+ [siteSecret]: conn.siteSecret,
76
+ [wpUrl]: conn.wpUrl,
77
+ [wpUsername]: conn.wpUsername,
78
+ [wpPassword]: conn.wpPassword
57
79
  }
58
80
  };
59
81
  }
@@ -149,18 +171,24 @@ async function collectConnectionInteractively(preset, opts = {}) {
149
171
  initialValue: "local",
150
172
  options: [{
151
173
  value: "local",
152
- label: "Set up a local dev environment",
153
- hint: "runs WordPress in Docker"
174
+ label: "Set up local WordPress",
175
+ hint: "runs in Docker, for dev and test"
154
176
  }, {
155
177
  value: "remote",
156
178
  label: "Use my own WordPress",
157
- hint: "connect to an existing site"
179
+ hint: "connect to your existing WordPress"
158
180
  }]
159
181
  }));
182
+ if (mode === "local") {
183
+ const status = await dockerStatus();
184
+ if (status !== "running") {
185
+ p.cancel(dockerHint(status));
186
+ process.exit(1);
187
+ }
188
+ }
160
189
  let wpUrl = "";
161
190
  let wpUsername = "";
162
191
  let wpPassword = "";
163
- let devPath;
164
192
  if (mode === "remote") {
165
193
  wpUrl = orCancel(await p.text({
166
194
  message: "WordPress URL",
@@ -175,11 +203,7 @@ async function collectConnectionInteractively(preset, opts = {}) {
175
203
  message: "WordPress application password",
176
204
  validate: validate(requiredString)
177
205
  }));
178
- } else devPath = orCancel(await p.text({
179
- message: "Local WordPress folder",
180
- initialValue: "wordpress",
181
- validate: validate(dirPath)
182
- }));
206
+ }
183
207
  return {
184
208
  mode,
185
209
  baseUrl,
@@ -187,27 +211,26 @@ async function collectConnectionInteractively(preset, opts = {}) {
187
211
  siteSecret,
188
212
  wpUrl,
189
213
  wpUsername,
190
- wpPassword,
191
- devPath
214
+ wpPassword
192
215
  };
193
216
  }
194
217
  /**
195
218
  * Non-interactive connection: skip prompts and use env values where present. Missing ones are
196
219
  * left empty for the user to fill in later. Never fails — always yields a fillable project.
197
220
  */
198
- function collectConnectionFromEnv(preset) {
221
+ function collectConnectionFromEnv(envKeys) {
199
222
  return {
200
223
  mode: "remote",
201
- baseUrl: process.env[preset.baseUrlEnvKey]?.trim() ?? "",
202
- siteSecret: process.env.KIZLO_SITE_SECRET?.trim() || randomBytes(32).toString("hex"),
203
- wpUrl: process.env.KIZLO_WORDPRESS_URL?.trim() ?? "",
204
- wpUsername: process.env.KIZLO_WORDPRESS_USERNAME?.trim() ?? "",
205
- wpPassword: process.env.KIZLO_WORDPRESS_APPLICATION_PASSWORD?.trim() ?? ""
224
+ baseUrl: process.env[envKeys.baseUrl]?.trim() ?? "",
225
+ siteSecret: process.env[envKeys.remote.siteSecret]?.trim() || randomBytes(32).toString("hex"),
226
+ wpUrl: process.env[envKeys.remote.wpUrl]?.trim() ?? "",
227
+ wpUsername: process.env[envKeys.remote.wpUsername]?.trim() ?? "",
228
+ wpPassword: process.env[envKeys.remote.wpPassword]?.trim() ?? ""
206
229
  };
207
230
  }
208
- /** Build a {@link ResolvedDevConfig} from the chosen install folder, matching `resolveDevConfig`'s
231
+ /** Build a {@link ResolvedDevConfig} for the fixed `.kizlo/local` install, matching `resolveDevConfig`'s
209
232
  * defaults — built directly so setup never has to round-trip through the config file it's writing. */
210
- function devConfigFor(cwd, devPath) {
233
+ function devConfigFor(cwd) {
211
234
  return {
212
235
  configDir: cwd,
213
236
  project: `${resolveStackName(cwd)}-dev`,
@@ -216,15 +239,15 @@ function devConfigFor(cwd, devPath) {
216
239
  dbPort: DEFAULT_DEV_DB_PORT,
217
240
  dbPortExplicit: false,
218
241
  fixtures: [],
219
- wordpressPath: devPath,
220
- wordpressDir: path.resolve(cwd, devPath)
242
+ wordpressPath: LOCAL_DIR_REL,
243
+ wordpressDir: path.resolve(cwd, LOCAL_DIR_REL)
221
244
  };
222
245
  }
223
246
  /**
224
- * Boot the local dev stack once to produce working credentials, then stop it (volumes
225
- * persist, so a later `kizlo dev` resumes instantly). The dev stack mints no application
226
- * password — that's a test-stack concern — so we create one here for REST auth in `.env`.
227
- * While the stack is still up, push the dev site settings (`siteSecret` plus the Kizlo server's
247
+ * Boot local WordPress once to produce working credentials, then stop it (volumes
248
+ * persist, so a later `kizlo dev` resumes instantly). Local WordPress mints no application
249
+ * password — that's a test concern — so we create one here for REST auth in `.env`.
250
+ * While it's still up, push the site settings (`siteSecret` plus the Kizlo server's
228
251
  * `url`/`backend_url`, derived from `baseUrl`) into the plugin so webhook signing and event delivery
229
252
  * work.
230
253
  */
@@ -266,23 +289,24 @@ async function provisionLocalStack(cfg, siteSecret, baseUrl) {
266
289
  };
267
290
  }
268
291
  /**
269
- * Provision the local WordPress dev stack and fill the connection's WP credentials from it, then
270
- * report the outcome. Mutates `conn` in place (wpUrl / wpUsername / wpPassword). Exits on failure,
271
- * matching the previous inline behavior. No-op for a remote connection.
292
+ * Provision local WordPress and fill the connection's WP credentials from it, then report the
293
+ * outcome. Mutates `conn` in place (wpUrl / wpUsername / wpPassword). Writing the `local` flags into
294
+ * `kizlo.config.ts` is the caller's job (the generated config for `create`/`init`). Exits on failure.
295
+ * No-op for a remote connection.
272
296
  */
273
297
  async function setupLocalWordPress(cwd, conn) {
274
- if (conn.mode !== "local" || !conn.devPath) return;
275
- ensureGitignored(cwd, conn.devPath);
298
+ if (conn.mode !== "local") return;
299
+ ensureGitignored(cwd, ".kizlo/");
276
300
  const s = p.spinner();
277
301
  s.start("Setting up local WordPress (first run downloads images, this can take a while)");
278
302
  try {
279
- const local = await provisionLocalStack(devConfigFor(cwd, conn.devPath), conn.siteSecret, conn.baseUrl);
303
+ const local = await provisionLocalStack(devConfigFor(cwd), conn.siteSecret, conn.baseUrl);
280
304
  conn.wpUrl = local.url;
281
305
  conn.wpUsername = local.username;
282
306
  conn.wpPassword = local.appPassword;
283
307
  conn.adminPassword = local.adminPassword;
284
308
  s.stop("Local WordPress ready");
285
- if (local.secretSyncError) p.log.warn(`Could not sync KIZLO_DEV_SITE_SECRET to the local plugin (${local.secretSyncError})`);
309
+ if (local.secretSyncError) p.log.warn(`Could not sync KIZLO_LOCAL_WP_SECRET to the local plugin (${local.secretSyncError})`);
286
310
  } catch (error) {
287
311
  s.stop("Local WordPress setup failed");
288
312
  p.cancel(error instanceof Error ? error.message : String(error));
@@ -290,12 +314,34 @@ async function setupLocalWordPress(cwd, conn) {
290
314
  }
291
315
  }
292
316
  /**
317
+ * The template's own `.env.example`, when it ships one. Templates own the framework-specific key names
318
+ * (e.g. `NEXT_PUBLIC_KIZLO_API_URL`) and the shared section layout, so their file is the source of the
319
+ * scaffold's `.env.example` — see {@link writeEnv}. Undefined for the base preset (no template dir).
320
+ */
321
+ function readEnvExample(templateDir) {
322
+ const file = path.join(templateDir, ".env.example");
323
+ return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : void 0;
324
+ }
325
+ /**
326
+ * The `.env.example` body for the base preset, which ships no template file. Lists the API URL and the
327
+ * remote connection keys, then the commented `KIZLO_CONNECT=local` toggle for the local-dev path. Real
328
+ * templates carry their own `.env.example` (passed to {@link writeEnv}) so its structure and comments
329
+ * stay consistent with the `.env` the scaffold writes.
330
+ */
331
+ function generatedEnvExample(envKeys) {
332
+ const exampleKeys = [envKeys.baseUrl, ...remoteKeys(envKeys)];
333
+ const { content } = mergeEnv("", Object.fromEntries(exampleKeys.map((key) => [key, ""])), new Set(exampleKeys), envGroups(envKeys));
334
+ return `${content}\n# Point the app at local WordPress (managed by \`kizlo dev\`) instead of the keys above:\n# ${envKeys.local.connect}=local\n`;
335
+ }
336
+ /**
293
337
  * Write (or update) `.env` and `.env.example` for the managed keys and report the outcome.
294
338
  * Existing conflicting `.env` values are preserved unless `force`; interactively the user is asked,
295
- * and under `--yes` they are kept. `.env.example` is only written when absent.
339
+ * and under `--yes` they are kept. `.env.example` is only written when absent, and is sourced from the
340
+ * template's own file (`opts.exampleTemplate`) so it matches the `.env` structure, falling back to a
341
+ * generated block for the base preset.
296
342
  */
297
- async function writeEnv(cwd, preset, conn, opts) {
298
- const { keys, values: envValues } = managedEnv(preset, conn);
343
+ async function writeEnv(cwd, envKeys, conn, opts) {
344
+ const { keys, values: envValues } = managedEnv(envKeys, conn);
299
345
  const envPath = path.join(cwd, ".env");
300
346
  const envExisted = fs.existsSync(envPath);
301
347
  const existingEnv = envExisted ? fs.readFileSync(envPath, "utf8") : "";
@@ -311,11 +357,9 @@ async function writeEnv(cwd, preset, conn, opts) {
311
357
  initialValue: true
312
358
  }))) overwriteKeys = /* @__PURE__ */ new Set();
313
359
  }
314
- const merge = mergeEnv(existingEnv, envValues, overwriteKeys, envGroups(preset.baseUrlEnvKey));
360
+ const merge = mergeEnv(existingEnv, envValues, overwriteKeys, envGroups(envKeys));
315
361
  fs.writeFileSync(envPath, merge.content);
316
- const exampleKeys = [preset.baseUrlEnvKey, ...PROD_WP_ENV_KEYS];
317
- const { content: exampleEnv } = mergeEnv("", Object.fromEntries(exampleKeys.map((key) => [key, ""])), new Set(exampleKeys), envGroups(preset.baseUrlEnvKey));
318
- const exampleBody = `${exampleEnv}\n# Point the app at a local dev stack (managed by \`kizlo dev\`) instead of the keys above:\n# KIZLO_TARGET=dev\n`;
362
+ const exampleBody = opts.exampleTemplate ?? generatedEnvExample(envKeys);
319
363
  const exampleCreated = writeFileIfAbsent(path.join(cwd, ".env.example"), exampleBody);
320
364
  if (!envExisted) p.log.success("Created .env");
321
365
  else if (merge.updated.length || merge.added.length) p.log.success("Updated .env");
@@ -359,4 +403,4 @@ function nextStepsNote(conn, prefix = "") {
359
403
  }
360
404
 
361
405
  //#endregion
362
- export { collectConnectionFromEnv, collectConnectionInteractively, dirPath, nextStepsLines, nextStepsNote, orCancel, pickAppPort, setupLocalWordPress, syncRemote, validate, withApiPath, writeEnv };
406
+ export { collectConnectionFromEnv, collectConnectionInteractively, dirPath, nextStepsLines, nextStepsNote, orCancel, pickAppPort, readEnvExample, resolveEnvKeys, setupLocalWordPress, syncRemote, validate, withApiPath, writeEnv };
@@ -8,13 +8,14 @@ import fs from "node:fs";
8
8
  import * as p from "@clack/prompts";
9
9
 
10
10
  //#region src/cli/commands/_wiring.ts
11
- /** The kizlo.config.ts a scaffolded project gets: the Kizlo directory, optional import alias, and —
12
- * for a local dev setup — the WordPress install folder so `kizlo dev` knows where it lives. */
13
- function kizloConfigTemplate(dir, alias, devPath) {
11
+ /** The kizlo.config.ts a scaffolded project gets: the Kizlo directory, an optional import alias, and —
12
+ * when local WordPress is chosen — `dev.local` + `test.local` so `kizlo dev` and `kizlo test` boot the
13
+ * fixed `.kizlo/local` install. */
14
+ function kizloConfigTemplate(dir, alias, localWordPress = false) {
14
15
  return `import { defineConfig } from "kizlo/config"
15
16
 
16
17
  export default defineConfig({
17
- dir: "${dir}",${alias ? `\n\talias: "${alias}",` : ""}${devPath ? `\n\tdev: { path: "${devPath}" },` : ""}
18
+ dir: "${dir}",${alias ? `\n\talias: "${alias}",` : ""}${localWordPress ? `\n\tdev: { local: true },\n\ttest: { local: true },` : ""}
18
19
  })
19
20
  `;
20
21
  }
@@ -1,9 +1,8 @@
1
- import { dockerAvailable } from "../wp/docker.js";
2
- import { availablePackageManagers, detectInvokingPackageManager, ensureGitignored, frameworkCreateArgs, getVersion, installArgs, runCommandAsync, runCommandCaptured } from "../utils.js";
1
+ import { availablePackageManagers, detectInvokingPackageManager, ensureGitignored, frameworkCreateArgs, installArgs, runCommandAsync, runCommandCaptured } from "../utils.js";
3
2
  import { getPreset } from "../presets/index.js";
4
3
  import { fetchTemplate } from "../presets/source.js";
5
- import { adaptFile, changesFor, fileEntries, isExample, patchEntries, readManifest } from "../presets/template.js";
6
- import { collectConnectionInteractively, nextStepsLines, orCancel, pickAppPort, setupLocalWordPress, syncRemote, validate, withApiPath, writeEnv } from "./_setup.js";
4
+ import { adaptFile, changesFor, fileEntries, isExample, minCliError, patchEntries, readManifest, resolveDependencies } from "../presets/template.js";
5
+ import { collectConnectionInteractively, nextStepsLines, orCancel, pickAppPort, readEnvExample, resolveEnvKeys, setupLocalWordPress, syncRemote, validate, withApiPath, writeEnv } from "./_setup.js";
7
6
  import { applyLayoutPatches, buildScaffoldContext, kizloConfigTemplate, reportScaffold, scaffoldFile, writeGeneratedContract } from "./_wiring.js";
8
7
  import z from "zod/v4";
9
8
  import path from "node:path";
@@ -29,16 +28,23 @@ const PACKAGE_MANAGERS = [
29
28
  "bun"
30
29
  ];
31
30
  /**
32
- * Pin the `kizlo` dependency in the freshly bootstrapped `package.json`. The template is
33
- * authoritative for the version (`kizloVersion` in its manifest, stamped at release), falling back to
34
- * the running CLI's version in-repo before the first stamp. The dependency is only recorded, not
35
- * installed — the getting-started note tells the user to run install.
31
+ * Pin Kizlo's dependencies in the freshly bootstrapped `package.json`. The template is authoritative
32
+ * for the versions (its manifest's `dependencies`/`devDependencies`, stamped at release), falling back
33
+ * to the running CLI's version for `kizlo` in-repo before the first stamp. The deps are only recorded,
34
+ * not installed — the getting-started note tells the user to run install.
36
35
  */
37
- function recordKizloDependency(dir, manifest) {
36
+ function recordDependencies(dir, manifest) {
38
37
  const pkgPath = path.join(dir, "package.json");
39
38
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
40
- pkg.dependencies ??= {};
41
- pkg.dependencies.kizlo = manifest.kizloVersion ?? `^${getVersion()}`;
39
+ const { dependencies, devDependencies } = resolveDependencies(manifest);
40
+ pkg.dependencies = {
41
+ ...pkg.dependencies,
42
+ ...dependencies
43
+ };
44
+ if (Object.keys(devDependencies).length) pkg.devDependencies = {
45
+ ...pkg.devDependencies,
46
+ ...devDependencies
47
+ };
42
48
  fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, " ")}\n`);
43
49
  }
44
50
  /**
@@ -59,7 +65,7 @@ function bootstrapArgs(manifest, pm, name) {
59
65
  * tsconfig, the root layout); this drives the manifest — the same engine `init` uses — to record the
60
66
  * `kizlo` dependency, write `kizlo.config.ts`, scaffold the manifest's files (the `base` plumbing and
61
67
  * the `create` layout/styles always, the `example`-flagged demo pages only when `includeExamples`),
62
- * seed the generated contract, and ignore `.env`. On a fresh app Kizlo owns the layout, so `create`
68
+ * seed the generated contract, and ignore `.env` and the `.kizlo/` working dir (which holds the local WordPress install). On a fresh app Kizlo owns the layout, so `create`
63
69
  * writes it whole (already SEO-wired) rather than patching — `applyLayoutPatches` runs over `create`'s
64
70
  * patches, which are none today. The target directory layout comes straight from the manifest's
65
71
  * conventions, which the bootstrap flags are chosen to match, so files land where they expect. Fresh
@@ -73,12 +79,12 @@ async function applyManifestWiring(dir, templateDir, manifest, opts) {
73
79
  alias,
74
80
  clientUrl: void 0
75
81
  });
76
- recordKizloDependency(dir, manifest);
82
+ recordDependencies(dir, manifest);
77
83
  const changes = changesFor(manifest, "create").filter((change) => opts.includeExamples || !isExample(change));
78
84
  const files = [{
79
85
  label: "Kizlo config",
80
86
  relPath: "kizlo.config.ts",
81
- contents: kizloConfigTemplate(kizloDir, alias, opts.devPath)
87
+ contents: kizloConfigTemplate(kizloDir, alias, opts.localDev)
82
88
  }, ...fileEntries(changes).map((entry) => adaptFile(templateDir, entry, manifest.conventions, scaffold))];
83
89
  for (const file of files) reportScaffold(file, await scaffoldFile(dir, file, {
84
90
  force: true,
@@ -86,6 +92,7 @@ async function applyManifestWiring(dir, templateDir, manifest, opts) {
86
92
  }), false);
87
93
  writeGeneratedContract(dir, path.join(kizloDir, "server"));
88
94
  ensureGitignored(dir, ".env");
95
+ ensureGitignored(dir, ".kizlo/");
89
96
  applyLayoutPatches(dir, patchEntries(changes), manifest.conventions, scaffold);
90
97
  }
91
98
  const create = defineCommand({
@@ -156,16 +163,12 @@ const create = defineCommand({
156
163
  })),
157
164
  initialValue: defaultPm
158
165
  }));
166
+ const conn = await collectConnectionInteractively(preset, { baseUrl: `http://localhost:${await pickAppPort()}` });
167
+ if (preset.apiPath && conn.baseUrl) conn.baseUrl = withApiPath(conn.baseUrl, preset.apiPath);
159
168
  const includeExamples = orCancel(await p.confirm({
160
- message: "Add example pages?",
169
+ message: "Add examples?",
161
170
  initialValue: true
162
171
  }));
163
- const conn = await collectConnectionInteractively(preset, { baseUrl: `http://localhost:${await pickAppPort()}` });
164
- if (preset.apiPath && conn.baseUrl) conn.baseUrl = withApiPath(conn.baseUrl, preset.apiPath);
165
- if (conn.mode === "local" && !await dockerAvailable()) {
166
- p.cancel("Docker isn't available — start Docker (or install it) and re-run, or choose “Use my own WordPress”.");
167
- process.exit(1);
168
- }
169
172
  const fetched = await fetchTemplate(template);
170
173
  const fail = (message) => {
171
174
  fetched.cleanup();
@@ -173,6 +176,8 @@ const create = defineCommand({
173
176
  process.exit(1);
174
177
  };
175
178
  const manifest = readManifest(fetched.dir);
179
+ const minErr = minCliError(manifest);
180
+ if (minErr) fail(minErr);
176
181
  const bootstrap = bootstrapArgs(manifest, pm, name);
177
182
  if (!bootstrap) {
178
183
  fetched.cleanup();
@@ -187,10 +192,11 @@ const create = defineCommand({
187
192
  if (scaffold.output) p.log.error(scaffold.output);
188
193
  fail(`${preset.label} setup failed — see the output above and try again.`);
189
194
  }
195
+ const exampleTemplate = readEnvExample(fetched.dir);
190
196
  try {
191
197
  await applyManifestWiring(dir, fetched.dir, manifest, {
192
- devPath: conn.devPath,
193
- includeExamples
198
+ includeExamples,
199
+ localDev: conn.mode === "local"
194
200
  });
195
201
  } catch (error) {
196
202
  fail(error instanceof Error ? error.message : String(error));
@@ -208,9 +214,10 @@ const create = defineCommand({
208
214
  if (!depsInstalled) p.log.warn(`Install them yourself: cd ${name} && ${installArgs(pm).join(" ")}`);
209
215
  }
210
216
  await setupLocalWordPress(dir, conn);
211
- await writeEnv(dir, preset, conn, {
217
+ await writeEnv(dir, resolveEnvKeys(preset, manifest), conn, {
212
218
  force: true,
213
- yes: false
219
+ yes: false,
220
+ exampleTemplate
214
221
  });
215
222
  await syncRemote(conn);
216
223
  p.note([