kizlo 0.9.0 → 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.
- package/LICENSE +201 -21
- package/dist/cli/commands/_setup.js +121 -77
- package/dist/cli/commands/_wiring.js +5 -4
- package/dist/cli/commands/create.js +32 -25
- package/dist/cli/commands/dev.js +63 -71
- package/dist/cli/commands/init.js +93 -103
- package/dist/cli/commands/test.js +34 -34
- package/dist/cli/daemon/config.js +18 -24
- package/dist/cli/presets/base.js +4 -2
- package/dist/cli/presets/nextjs.js +0 -1
- package/dist/cli/presets/template.js +76 -2
- 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 +1 -1
- package/dist/cli/wp/setup.js +1 -1
- package/dist/cli/wp/stack.js +4 -4
- package/dist/config.d.ts +20 -23
- package/dist/index.d.ts +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/router.d.ts +5 -5
- package/dist/test/server.js +1 -1
- package/dist/test.d.ts +3 -3
- package/dist/test.js +3 -3
- package/package.json +3 -3
- package/dist/cli/wp/byo.js +0 -113
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kizlo
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
@@ -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`
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"KIZLO_DEV_WORDPRESS_APPLICATION_PASSWORD"
|
|
67
|
+
envKeys.baseUrl,
|
|
68
|
+
siteSecret,
|
|
69
|
+
wpUrl,
|
|
70
|
+
wpUsername,
|
|
71
|
+
wpPassword
|
|
39
72
|
],
|
|
40
73
|
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
|
|
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
|
|
153
|
-
hint: "runs
|
|
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
|
|
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
|
-
}
|
|
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(
|
|
221
|
+
function collectConnectionFromEnv(envKeys) {
|
|
199
222
|
return {
|
|
200
223
|
mode: "remote",
|
|
201
|
-
baseUrl: process.env[
|
|
202
|
-
siteSecret: process.env.
|
|
203
|
-
wpUrl: process.env.
|
|
204
|
-
wpUsername: process.env.
|
|
205
|
-
wpPassword: process.env.
|
|
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}
|
|
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
|
|
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:
|
|
220
|
-
wordpressDir: path.resolve(cwd,
|
|
242
|
+
wordpressPath: LOCAL_DIR_REL,
|
|
243
|
+
wordpressDir: path.resolve(cwd, LOCAL_DIR_REL)
|
|
221
244
|
};
|
|
222
245
|
}
|
|
223
246
|
/**
|
|
224
|
-
* Boot
|
|
225
|
-
* persist, so a later `kizlo dev` resumes instantly).
|
|
226
|
-
* password — that's a test
|
|
227
|
-
* While
|
|
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
|
|
270
|
-
*
|
|
271
|
-
*
|
|
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"
|
|
275
|
-
ensureGitignored(cwd,
|
|
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
|
|
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
|
|
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,
|
|
298
|
-
const { keys, values: envValues } = managedEnv(
|
|
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(
|
|
360
|
+
const merge = mergeEnv(existingEnv, envValues, overwriteKeys, envGroups(envKeys));
|
|
315
361
|
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`;
|
|
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
|
-
*
|
|
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
|
}
|