kizlo 0.9.1 → 0.11.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.
- package/README.md +4 -4
- package/dist/cli/commands/_setup.js +132 -79
- package/dist/cli/commands/_wiring.js +5 -4
- package/dist/cli/commands/create.js +35 -28
- package/dist/cli/commands/dev.js +172 -87
- package/dist/cli/commands/init.js +97 -103
- package/dist/cli/commands/test.js +34 -34
- package/dist/cli/daemon/config.js +18 -24
- package/dist/cli/daemon/logger.js +1 -1
- package/dist/cli/daemon/reload.js +66 -0
- package/dist/cli/daemon/watch.js +0 -1
- package/dist/cli/presets/base.js +4 -2
- package/dist/cli/presets/nextjs.js +0 -1
- package/dist/cli/presets/template.js +104 -18
- package/dist/cli/utils.js +41 -19
- package/dist/cli/wp/compose/override.js +3 -3
- package/dist/cli/wp/compose/override.test.ts +2 -2
- package/dist/cli/wp/compose/override.ts +3 -3
- package/dist/cli/wp/constants.d.ts +10 -4
- package/dist/cli/wp/constants.js +10 -4
- package/dist/cli/wp/dev.js +13 -58
- package/dist/cli/wp/docker.d.ts +16 -4
- package/dist/cli/wp/docker.js +20 -7
- package/dist/cli/wp/settings.js +9 -3
- package/dist/cli/wp/setup.js +1 -1
- package/dist/cli/wp/stack.js +4 -4
- package/dist/comment/schema.js +2 -2
- package/dist/config.d.ts +20 -23
- package/dist/context.d.ts +9 -0
- package/dist/context.js +20 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/integrations/nextjs/kizlo.server.js +1 -1
- package/dist/integrations/nextjs/utils.js +2 -2
- package/dist/kizlo.d.ts +16 -16
- package/dist/kizlo.js +19 -15
- package/dist/package.js +1 -1
- package/dist/page/schema.js +2 -2
- package/dist/post/schema.js +2 -2
- package/dist/router.d.ts +9 -9
- package/dist/shared/schema.d.ts +1 -2
- package/dist/shared/schema.js +2 -2
- package/dist/test/server.js +1 -1
- package/dist/test.d.ts +3 -3
- package/dist/test.js +3 -3
- package/dist/wordpress/service.d.ts +4 -0
- package/dist/wordpress/service.js +5 -0
- package/package.json +2 -2
- package/dist/cli/wp/byo.js +0 -113
package/README.md
CHANGED
|
@@ -23,16 +23,16 @@ Kizlo is an open-source framework for building content-driven applications with
|
|
|
23
23
|
|
|
24
24
|
## Quick start
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Scaffold a new project with Kizlo already wired:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
npx kizlo@latest
|
|
29
|
+
npx kizlo@latest create
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Or add Kizlo to an existing project:
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
npx kizlo
|
|
35
|
+
npx kizlo@latest init
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
See the [docs](https://kizlo.io/docs) for the full guide.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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";
|
|
6
7
|
import { removeProjectContainers } from "../wp/session.js";
|
|
7
8
|
import { syncSiteSettings } from "../wp/settings.js";
|
|
8
9
|
import { devStack } from "../wp/stack.js";
|
|
10
|
+
import { isPluginVersionSupported, pluginUpdateMessage } from "@kizlo/shared";
|
|
9
11
|
import z from "zod/v4";
|
|
10
12
|
import path from "node:path";
|
|
11
13
|
import fs from "node:fs";
|
|
@@ -14,51 +16,76 @@ import { randomBytes } from "node:crypto";
|
|
|
14
16
|
import getPort, { portNumbers } from "get-port";
|
|
15
17
|
|
|
16
18
|
//#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
19
|
/**
|
|
25
|
-
* The `.env`
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
20
|
+
* The resolved `.env` key names the scaffold writes: the template's declared `env` when it has one,
|
|
21
|
+
* else the preset's built-in `envKeys` (the generic `base` preset), else the {@link DEFAULT_ENV_KEYS}
|
|
22
|
+
* fallback for an in-repo template before the first stamped release. Threaded into `managedEnv`,
|
|
23
|
+
* `writeEnv`, and `collectConnectionFromEnv` so the scaffold writes the names the pinned runtime reads.
|
|
29
24
|
*/
|
|
30
|
-
function
|
|
31
|
-
|
|
25
|
+
function resolveEnvKeys(preset, manifest) {
|
|
26
|
+
return manifest?.env ?? preset.envKeys ?? DEFAULT_ENV_KEYS;
|
|
27
|
+
}
|
|
28
|
+
/** Remote connection keys — what a real deploy needs, and what `.env.example` always lists. */
|
|
29
|
+
function remoteKeys(envKeys) {
|
|
30
|
+
return [
|
|
31
|
+
envKeys.remote.siteSecret,
|
|
32
|
+
envKeys.remote.wpUrl,
|
|
33
|
+
envKeys.remote.wpUsername,
|
|
34
|
+
envKeys.remote.wpPassword
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The `.env` keys setup manages and the values to write, branched on the connection mode. Local
|
|
39
|
+
* WordPress writes the `KIZLO_LOCAL_WP_*` / `KIZLO_LOCAL_WP_SECRET` set plus `KIZLO_CONNECT=local`,
|
|
40
|
+
* so it never touches the remote keys (a user can point those at a real site). A remote site writes
|
|
41
|
+
* the bare remote keys exactly as before — no `KIZLO_CONNECT`, since `"remote"` is the default.
|
|
42
|
+
*/
|
|
43
|
+
function managedEnv(envKeys, conn) {
|
|
44
|
+
if (conn.mode === "local") {
|
|
45
|
+
const { connect, siteSecret: siteSecret$1, wpUrl: wpUrl$1, wpUsername: wpUsername$1, wpPassword: wpPassword$1 } = envKeys.local;
|
|
46
|
+
return {
|
|
47
|
+
keys: [
|
|
48
|
+
envKeys.baseUrl,
|
|
49
|
+
connect,
|
|
50
|
+
siteSecret$1,
|
|
51
|
+
wpUrl$1,
|
|
52
|
+
wpUsername$1,
|
|
53
|
+
wpPassword$1
|
|
54
|
+
],
|
|
55
|
+
values: {
|
|
56
|
+
[envKeys.baseUrl]: conn.baseUrl,
|
|
57
|
+
[connect]: "local",
|
|
58
|
+
[siteSecret$1]: conn.siteSecret,
|
|
59
|
+
[wpUrl$1]: conn.wpUrl,
|
|
60
|
+
[wpUsername$1]: conn.wpUsername,
|
|
61
|
+
[wpPassword$1]: conn.wpPassword
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const { siteSecret, wpUrl, wpUsername, wpPassword } = envKeys.remote;
|
|
66
|
+
return {
|
|
32
67
|
keys: [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"KIZLO_DEV_WORDPRESS_APPLICATION_PASSWORD"
|
|
68
|
+
envKeys.baseUrl,
|
|
69
|
+
siteSecret,
|
|
70
|
+
wpUrl,
|
|
71
|
+
wpUsername,
|
|
72
|
+
wpPassword
|
|
39
73
|
],
|
|
40
74
|
values: {
|
|
41
|
-
[
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
75
|
+
[envKeys.baseUrl]: conn.baseUrl,
|
|
76
|
+
[siteSecret]: conn.siteSecret,
|
|
77
|
+
[wpUrl]: conn.wpUrl,
|
|
78
|
+
[wpUsername]: conn.wpUsername,
|
|
79
|
+
[wpPassword]: conn.wpPassword
|
|
57
80
|
}
|
|
58
81
|
};
|
|
59
82
|
}
|
|
60
83
|
const requiredString = z.string().trim().min(1, "Required");
|
|
61
|
-
const urlString = requiredString.pipe(z.url(
|
|
84
|
+
const urlString = requiredString.pipe(z.url({
|
|
85
|
+
protocol: /^https?$/,
|
|
86
|
+
hostname: /^(localhost|(\d{1,3}\.){3}\d{1,3}|([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})$/,
|
|
87
|
+
error: "Must be a valid http(s) URL with a real host (e.g. https://example.com)"
|
|
88
|
+
}));
|
|
62
89
|
const dirPath = requiredString.refine((value) => !value.endsWith(".ts"), "Enter a directory, not a file");
|
|
63
90
|
function validate(schema) {
|
|
64
91
|
return (value) => {
|
|
@@ -149,18 +176,24 @@ async function collectConnectionInteractively(preset, opts = {}) {
|
|
|
149
176
|
initialValue: "local",
|
|
150
177
|
options: [{
|
|
151
178
|
value: "local",
|
|
152
|
-
label: "Set up
|
|
153
|
-
hint: "runs
|
|
179
|
+
label: "Set up local WordPress",
|
|
180
|
+
hint: "runs in Docker, for dev and test"
|
|
154
181
|
}, {
|
|
155
182
|
value: "remote",
|
|
156
183
|
label: "Use my own WordPress",
|
|
157
|
-
hint: "connect to
|
|
184
|
+
hint: "connect to your existing WordPress"
|
|
158
185
|
}]
|
|
159
186
|
}));
|
|
187
|
+
if (mode === "local") {
|
|
188
|
+
const status = await dockerStatus();
|
|
189
|
+
if (status !== "running") {
|
|
190
|
+
p.cancel(dockerHint(status));
|
|
191
|
+
process.exit(1);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
160
194
|
let wpUrl = "";
|
|
161
195
|
let wpUsername = "";
|
|
162
196
|
let wpPassword = "";
|
|
163
|
-
let devPath;
|
|
164
197
|
if (mode === "remote") {
|
|
165
198
|
wpUrl = orCancel(await p.text({
|
|
166
199
|
message: "WordPress URL",
|
|
@@ -175,11 +208,7 @@ async function collectConnectionInteractively(preset, opts = {}) {
|
|
|
175
208
|
message: "WordPress application password",
|
|
176
209
|
validate: validate(requiredString)
|
|
177
210
|
}));
|
|
178
|
-
}
|
|
179
|
-
message: "Local WordPress folder",
|
|
180
|
-
initialValue: "wordpress",
|
|
181
|
-
validate: validate(dirPath)
|
|
182
|
-
}));
|
|
211
|
+
}
|
|
183
212
|
return {
|
|
184
213
|
mode,
|
|
185
214
|
baseUrl,
|
|
@@ -187,27 +216,26 @@ async function collectConnectionInteractively(preset, opts = {}) {
|
|
|
187
216
|
siteSecret,
|
|
188
217
|
wpUrl,
|
|
189
218
|
wpUsername,
|
|
190
|
-
wpPassword
|
|
191
|
-
devPath
|
|
219
|
+
wpPassword
|
|
192
220
|
};
|
|
193
221
|
}
|
|
194
222
|
/**
|
|
195
223
|
* Non-interactive connection: skip prompts and use env values where present. Missing ones are
|
|
196
224
|
* left empty for the user to fill in later. Never fails — always yields a fillable project.
|
|
197
225
|
*/
|
|
198
|
-
function collectConnectionFromEnv(
|
|
226
|
+
function collectConnectionFromEnv(envKeys) {
|
|
199
227
|
return {
|
|
200
228
|
mode: "remote",
|
|
201
|
-
baseUrl: process.env[
|
|
202
|
-
siteSecret: process.env.
|
|
203
|
-
wpUrl: process.env.
|
|
204
|
-
wpUsername: process.env.
|
|
205
|
-
wpPassword: process.env.
|
|
229
|
+
baseUrl: process.env[envKeys.baseUrl]?.trim() ?? "",
|
|
230
|
+
siteSecret: process.env[envKeys.remote.siteSecret]?.trim() || randomBytes(32).toString("hex"),
|
|
231
|
+
wpUrl: process.env[envKeys.remote.wpUrl]?.trim() ?? "",
|
|
232
|
+
wpUsername: process.env[envKeys.remote.wpUsername]?.trim() ?? "",
|
|
233
|
+
wpPassword: process.env[envKeys.remote.wpPassword]?.trim() ?? ""
|
|
206
234
|
};
|
|
207
235
|
}
|
|
208
|
-
/** Build a {@link ResolvedDevConfig}
|
|
236
|
+
/** Build a {@link ResolvedDevConfig} for the fixed `.kizlo/local` install, matching `resolveDevConfig`'s
|
|
209
237
|
* defaults — built directly so setup never has to round-trip through the config file it's writing. */
|
|
210
|
-
function devConfigFor(cwd
|
|
238
|
+
function devConfigFor(cwd) {
|
|
211
239
|
return {
|
|
212
240
|
configDir: cwd,
|
|
213
241
|
project: `${resolveStackName(cwd)}-dev`,
|
|
@@ -216,15 +244,15 @@ function devConfigFor(cwd, devPath) {
|
|
|
216
244
|
dbPort: DEFAULT_DEV_DB_PORT,
|
|
217
245
|
dbPortExplicit: false,
|
|
218
246
|
fixtures: [],
|
|
219
|
-
wordpressPath:
|
|
220
|
-
wordpressDir: path.resolve(cwd,
|
|
247
|
+
wordpressPath: LOCAL_DIR_REL,
|
|
248
|
+
wordpressDir: path.resolve(cwd, LOCAL_DIR_REL)
|
|
221
249
|
};
|
|
222
250
|
}
|
|
223
251
|
/**
|
|
224
|
-
* Boot
|
|
225
|
-
* persist, so a later `kizlo dev` resumes instantly).
|
|
226
|
-
* password — that's a test
|
|
227
|
-
* While
|
|
252
|
+
* Boot local WordPress once to produce working credentials, then stop it (volumes
|
|
253
|
+
* persist, so a later `kizlo dev` resumes instantly). Local WordPress mints no application
|
|
254
|
+
* password — that's a test concern — so we create one here for REST auth in `.env`.
|
|
255
|
+
* While it's still up, push the site settings (`siteSecret` plus the Kizlo server's
|
|
228
256
|
* `url`/`backend_url`, derived from `baseUrl`) into the plugin so webhook signing and event delivery
|
|
229
257
|
* work.
|
|
230
258
|
*/
|
|
@@ -266,23 +294,24 @@ async function provisionLocalStack(cfg, siteSecret, baseUrl) {
|
|
|
266
294
|
};
|
|
267
295
|
}
|
|
268
296
|
/**
|
|
269
|
-
* Provision
|
|
270
|
-
*
|
|
271
|
-
*
|
|
297
|
+
* Provision local WordPress and fill the connection's WP credentials from it, then report the
|
|
298
|
+
* outcome. Mutates `conn` in place (wpUrl / wpUsername / wpPassword). Writing the `local` flags into
|
|
299
|
+
* `kizlo.config.ts` is the caller's job (the generated config for `create`/`init`). Exits on failure.
|
|
300
|
+
* No-op for a remote connection.
|
|
272
301
|
*/
|
|
273
302
|
async function setupLocalWordPress(cwd, conn) {
|
|
274
|
-
if (conn.mode !== "local"
|
|
275
|
-
ensureGitignored(cwd,
|
|
303
|
+
if (conn.mode !== "local") return;
|
|
304
|
+
ensureGitignored(cwd, ".kizlo/");
|
|
276
305
|
const s = p.spinner();
|
|
277
306
|
s.start("Setting up local WordPress (first run downloads images, this can take a while)");
|
|
278
307
|
try {
|
|
279
|
-
const local = await provisionLocalStack(devConfigFor(cwd
|
|
308
|
+
const local = await provisionLocalStack(devConfigFor(cwd), conn.siteSecret, conn.baseUrl);
|
|
280
309
|
conn.wpUrl = local.url;
|
|
281
310
|
conn.wpUsername = local.username;
|
|
282
311
|
conn.wpPassword = local.appPassword;
|
|
283
312
|
conn.adminPassword = local.adminPassword;
|
|
284
313
|
s.stop("Local WordPress ready");
|
|
285
|
-
if (local.secretSyncError) p.log.warn(`Could not sync
|
|
314
|
+
if (local.secretSyncError) p.log.warn(`Could not sync KIZLO_LOCAL_WP_SECRET to the local plugin (${local.secretSyncError})`);
|
|
286
315
|
} catch (error) {
|
|
287
316
|
s.stop("Local WordPress setup failed");
|
|
288
317
|
p.cancel(error instanceof Error ? error.message : String(error));
|
|
@@ -290,12 +319,34 @@ async function setupLocalWordPress(cwd, conn) {
|
|
|
290
319
|
}
|
|
291
320
|
}
|
|
292
321
|
/**
|
|
322
|
+
* The template's own `.env.example`, when it ships one. Templates own the framework-specific key names
|
|
323
|
+
* (e.g. `NEXT_PUBLIC_KIZLO_API_URL`) and the shared section layout, so their file is the source of the
|
|
324
|
+
* scaffold's `.env.example` — see {@link writeEnv}. Undefined for the base preset (no template dir).
|
|
325
|
+
*/
|
|
326
|
+
function readEnvExample(templateDir) {
|
|
327
|
+
const file = path.join(templateDir, ".env.example");
|
|
328
|
+
return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : void 0;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The `.env.example` body for the base preset, which ships no template file. Lists the API URL and the
|
|
332
|
+
* remote connection keys, then the commented `KIZLO_CONNECT=local` toggle for the local-dev path. Real
|
|
333
|
+
* templates carry their own `.env.example` (passed to {@link writeEnv}) so its structure and comments
|
|
334
|
+
* stay consistent with the `.env` the scaffold writes.
|
|
335
|
+
*/
|
|
336
|
+
function generatedEnvExample(envKeys) {
|
|
337
|
+
const exampleKeys = [envKeys.baseUrl, ...remoteKeys(envKeys)];
|
|
338
|
+
const { content } = mergeEnv("", Object.fromEntries(exampleKeys.map((key) => [key, ""])), new Set(exampleKeys), envGroups(envKeys));
|
|
339
|
+
return `${content}\n# Point the app at local WordPress (managed by \`kizlo dev\`) instead of the keys above:\n# ${envKeys.local.connect}=local\n`;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
293
342
|
* Write (or update) `.env` and `.env.example` for the managed keys and report the outcome.
|
|
294
343
|
* 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
|
|
344
|
+
* and under `--yes` they are kept. `.env.example` is only written when absent, and is sourced from the
|
|
345
|
+
* template's own file (`opts.exampleTemplate`) so it matches the `.env` structure, falling back to a
|
|
346
|
+
* generated block for the base preset.
|
|
296
347
|
*/
|
|
297
|
-
async function writeEnv(cwd,
|
|
298
|
-
const { keys, values: envValues } = managedEnv(
|
|
348
|
+
async function writeEnv(cwd, envKeys, conn, opts) {
|
|
349
|
+
const { keys, values: envValues } = managedEnv(envKeys, conn);
|
|
299
350
|
const envPath = path.join(cwd, ".env");
|
|
300
351
|
const envExisted = fs.existsSync(envPath);
|
|
301
352
|
const existingEnv = envExisted ? fs.readFileSync(envPath, "utf8") : "";
|
|
@@ -311,11 +362,9 @@ async function writeEnv(cwd, preset, conn, opts) {
|
|
|
311
362
|
initialValue: true
|
|
312
363
|
}))) overwriteKeys = /* @__PURE__ */ new Set();
|
|
313
364
|
}
|
|
314
|
-
const merge = mergeEnv(existingEnv, envValues, overwriteKeys, envGroups(
|
|
365
|
+
const merge = mergeEnv(existingEnv, envValues, overwriteKeys, envGroups(envKeys));
|
|
315
366
|
fs.writeFileSync(envPath, merge.content);
|
|
316
|
-
const
|
|
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`;
|
|
367
|
+
const exampleBody = opts.exampleTemplate ?? generatedEnvExample(envKeys);
|
|
319
368
|
const exampleCreated = writeFileIfAbsent(path.join(cwd, ".env.example"), exampleBody);
|
|
320
369
|
if (!envExisted) p.log.success("Created .env");
|
|
321
370
|
else if (merge.updated.length || merge.added.length) p.log.success("Updated .env");
|
|
@@ -338,7 +387,11 @@ async function syncRemote(conn) {
|
|
|
338
387
|
siteUrl: conn.siteUrl,
|
|
339
388
|
backendUrl: conn.baseUrl
|
|
340
389
|
});
|
|
341
|
-
if (!sync.ok)
|
|
390
|
+
if (!sync.ok) {
|
|
391
|
+
p.log.warn(`Could not sync the site settings to WordPress (${sync.error}) — make sure the kizlo plugin is active, then set them from the Kizlo settings.`);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (!isPluginVersionSupported(sync.pluginVersion)) p.log.warn(pluginUpdateMessage(sync.pluginVersion));
|
|
342
395
|
}
|
|
343
396
|
/** The "Next steps" lines. `kizlo dev` is the single entry point for development. */
|
|
344
397
|
function nextStepsLines(conn, prefix = "") {
|
|
@@ -359,4 +412,4 @@ function nextStepsNote(conn, prefix = "") {
|
|
|
359
412
|
}
|
|
360
413
|
|
|
361
414
|
//#endregion
|
|
362
|
-
export { collectConnectionFromEnv, collectConnectionInteractively, dirPath, nextStepsLines, nextStepsNote, orCancel, pickAppPort, setupLocalWordPress, syncRemote, validate, withApiPath, writeEnv };
|
|
415
|
+
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
|
-
*
|
|
13
|
-
|
|
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}",` : ""}${
|
|
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 {
|
|
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,
|
|
6
|
-
import { collectConnectionInteractively, nextStepsLines, orCancel, pickAppPort, setupLocalWordPress, syncRemote, validate, withApiPath, writeEnv } from "./_setup.js";
|
|
4
|
+
import { adaptFile, changesFor, fileEntries, 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
|
|
33
|
-
*
|
|
34
|
-
* the running CLI's version in-repo before the first stamp. The
|
|
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
|
|
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
|
-
|
|
41
|
-
pkg.dependencies
|
|
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
|
/**
|
|
@@ -57,9 +63,9 @@ function bootstrapArgs(manifest, pm, name) {
|
|
|
57
63
|
* Layer Kizlo's wiring onto a freshly bootstrapped app in `dir`, from an already-fetched template
|
|
58
64
|
* directory + manifest. The framework CLI has produced the base project (package.json, config,
|
|
59
65
|
* tsconfig, the root layout); this drives the manifest — the same engine `init` uses — to record the
|
|
60
|
-
* `kizlo` dependency, write `kizlo.config.ts`, scaffold the manifest's files (
|
|
61
|
-
*
|
|
62
|
-
* seed the generated contract, and ignore `.env`. On a fresh app Kizlo owns the layout, so `create`
|
|
66
|
+
* `kizlo` dependency, write `kizlo.config.ts`, scaffold the manifest's files (core wiring from `base`
|
|
67
|
+
* and `create` always, the `example`-flagged demo pages only when `includeExamples`),
|
|
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
|
-
|
|
77
|
-
const changes = changesFor(manifest, "create"
|
|
82
|
+
recordDependencies(dir, manifest);
|
|
83
|
+
const changes = changesFor(manifest, "create", { includeExamples: opts.includeExamples });
|
|
78
84
|
const files = [{
|
|
79
85
|
label: "Kizlo config",
|
|
80
86
|
relPath: "kizlo.config.ts",
|
|
81
|
-
contents: kizloConfigTemplate(kizloDir, alias, opts.
|
|
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
|
|
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
|
-
|
|
193
|
-
|
|
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([
|