create-kide-app 0.5.0 → 0.6.1
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 +7 -5
- package/index.js +63 -17
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -17,21 +17,23 @@ The CLI asks for:
|
|
|
17
17
|
|
|
18
18
|
## Non-interactive use
|
|
19
19
|
|
|
20
|
-
Every prompt can be answered with a flag; supplied answers skip their prompts.
|
|
20
|
+
Every prompt can be answered with a flag; supplied answers skip their prompts. Without a terminal (CI, agents) every answer must be supplied — a missing one fails with the flags to pass, before anything is created.
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
pnpm create kide-app my-app --starter=marketing --seed --mode=embedded --target=local --no-github --no-dev
|
|
24
|
+
pnpm create kide-app my-app --starter=blank --mode=package --target=cloudflare --cloudflare-setup --deploy --no-github
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
| Flag | Values |
|
|
27
28
|
| ---- | ------ |
|
|
28
29
|
| `--starter=` | `blank` or a starter name from the template release |
|
|
29
|
-
| `--seed` / `--no-seed` | Seed example content (local target
|
|
30
|
+
| `--seed` / `--no-seed` | Seed example content (local target with a starter) |
|
|
30
31
|
| `--mode=` | `package` or `embedded` |
|
|
31
32
|
| `--target=` | `local` or `cloudflare` |
|
|
32
|
-
| `--no-
|
|
33
|
-
| `--no-
|
|
34
|
-
| `--no-
|
|
33
|
+
| `--cloudflare-setup` / `--no-cloudflare-setup` | Create the D1 database and R2 bucket and apply migrations (Cloudflare target) |
|
|
34
|
+
| `--deploy` / `--no-deploy` | Deploy after setup (Cloudflare target) |
|
|
35
|
+
| `--no-github` | Skip the GitHub repo prompt (skipped without a terminal) |
|
|
36
|
+
| `--no-dev` | Skip the dev-server prompt (skipped without a terminal) |
|
|
35
37
|
|
|
36
38
|
The template repo can be overridden with the `KIDE_TEMPLATE_REPO` env var (forks, local testing).
|
|
37
39
|
|
package/index.js
CHANGED
|
@@ -59,7 +59,9 @@ const pm = {
|
|
|
59
59
|
exec: "pnpm exec",
|
|
60
60
|
dlx: "pnpm dlx",
|
|
61
61
|
run: "pnpm",
|
|
62
|
-
|
|
62
|
+
// The scaffold rewrites package.json, so the template lockfile never matches; pnpm
|
|
63
|
+
// defaults to --frozen-lockfile when CI=true and would refuse to install.
|
|
64
|
+
install: "pnpm install --no-frozen-lockfile",
|
|
63
65
|
};
|
|
64
66
|
|
|
65
67
|
// --- Template repo ---
|
|
@@ -142,6 +144,8 @@ const resolveLatestTag = async () => {
|
|
|
142
144
|
// --- CLI flags (non-interactive use: CI, agents, testing) ---
|
|
143
145
|
// Any prompt whose answer is supplied by a flag is skipped. Example:
|
|
144
146
|
// create-kide-app my-app --starter=marketing --seed --mode=embedded --target=local --no-github --no-dev
|
|
147
|
+
// Without a terminal (CI, agents) a required answer must come from a flag; a missing one
|
|
148
|
+
// fails with the flag to pass instead of stopping at a prompt nobody can answer.
|
|
145
149
|
|
|
146
150
|
const parseArgs = (argv) => {
|
|
147
151
|
const flags = {};
|
|
@@ -151,7 +155,10 @@ const parseArgs = (argv) => {
|
|
|
151
155
|
else if (arg === "--no-seed") flags.seed = false;
|
|
152
156
|
else if (arg === "--no-github") flags.noGithub = true;
|
|
153
157
|
else if (arg === "--no-dev") flags.noDev = true;
|
|
154
|
-
else if (arg === "--
|
|
158
|
+
else if (arg === "--cloudflare-setup") flags.cloudflareSetup = true;
|
|
159
|
+
else if (arg === "--no-cloudflare-setup") flags.cloudflareSetup = false;
|
|
160
|
+
else if (arg === "--deploy") flags.deploy = true;
|
|
161
|
+
else if (arg === "--no-deploy") flags.deploy = false;
|
|
155
162
|
else if (arg.startsWith("--starter=")) flags.starter = arg.slice("--starter=".length);
|
|
156
163
|
else if (arg.startsWith("--mode=")) flags.mode = arg.slice("--mode=".length);
|
|
157
164
|
else if (arg.startsWith("--target=")) flags.target = arg.slice("--target=".length);
|
|
@@ -161,6 +168,26 @@ const parseArgs = (argv) => {
|
|
|
161
168
|
return { flags, positional };
|
|
162
169
|
};
|
|
163
170
|
|
|
171
|
+
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
172
|
+
|
|
173
|
+
// Without a terminal, every answer that would otherwise be prompted for must come from a
|
|
174
|
+
// flag. Checked before cloning so a missing flag fails fast and leaves nothing behind.
|
|
175
|
+
const missingAnswers = (flags, positional) => {
|
|
176
|
+
const missing = [];
|
|
177
|
+
if (!positional[0]) missing.push("the project name as the first argument");
|
|
178
|
+
if (flags.starter === undefined) missing.push("--starter=<blank | starter name>");
|
|
179
|
+
if (flags.mode === undefined) missing.push("--mode=package | embedded");
|
|
180
|
+
if (flags.target === undefined) missing.push("--target=local | cloudflare");
|
|
181
|
+
if (flags.target === "local" && flags.starter && flags.starter !== "blank" && flags.seed === undefined) {
|
|
182
|
+
missing.push("--seed or --no-seed");
|
|
183
|
+
}
|
|
184
|
+
if (flags.target === "cloudflare") {
|
|
185
|
+
if (flags.cloudflareSetup === undefined) missing.push("--cloudflare-setup or --no-cloudflare-setup");
|
|
186
|
+
else if (flags.cloudflareSetup && flags.deploy === undefined) missing.push("--deploy or --no-deploy");
|
|
187
|
+
}
|
|
188
|
+
return missing;
|
|
189
|
+
};
|
|
190
|
+
|
|
164
191
|
// --- Main ---
|
|
165
192
|
|
|
166
193
|
async function main() {
|
|
@@ -180,6 +207,14 @@ async function main() {
|
|
|
180
207
|
process.exit(1);
|
|
181
208
|
}
|
|
182
209
|
|
|
210
|
+
if (!interactive) {
|
|
211
|
+
const missing = missingAnswers(flags, positional);
|
|
212
|
+
if (missing.length > 0) {
|
|
213
|
+
p.cancel(`No terminal to prompt. Pass:\n ${missing.join("\n ")}`);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
183
218
|
// 1. Project name
|
|
184
219
|
const projectName =
|
|
185
220
|
positional[0] ||
|
|
@@ -616,8 +651,10 @@ async function main() {
|
|
|
616
651
|
try {
|
|
617
652
|
await runAsync(pm.install, projectDir);
|
|
618
653
|
s.stop("Dependencies installed");
|
|
619
|
-
} catch {
|
|
654
|
+
} catch (err) {
|
|
620
655
|
s.stop(`${pm.install} failed — run it manually`);
|
|
656
|
+
if (err.stderr) console.error(err.stderr.slice(-1500));
|
|
657
|
+
if (err.stdout) console.error(err.stdout.slice(-1500));
|
|
621
658
|
}
|
|
622
659
|
|
|
623
660
|
// --- Initialize git repository ---
|
|
@@ -648,7 +685,8 @@ async function main() {
|
|
|
648
685
|
// gh not installed or not authenticated — skip the prompt
|
|
649
686
|
}
|
|
650
687
|
|
|
651
|
-
|
|
688
|
+
// Creating a repo needs a name and visibility; without a terminal it is skipped.
|
|
689
|
+
if (ghAvailable && !flags.noGithub && interactive) {
|
|
652
690
|
const createRepo = await p.confirm({
|
|
653
691
|
message: "Create a GitHub repository for this project?",
|
|
654
692
|
initialValue: false,
|
|
@@ -783,8 +821,8 @@ async function main() {
|
|
|
783
821
|
};
|
|
784
822
|
if (target === "cloudflare") {
|
|
785
823
|
const setupNow =
|
|
786
|
-
flags.
|
|
787
|
-
?
|
|
824
|
+
flags.cloudflareSetup !== undefined
|
|
825
|
+
? flags.cloudflareSetup
|
|
788
826
|
: await p.confirm({
|
|
789
827
|
message:
|
|
790
828
|
"Set up Cloudflare resources now? (creates D1 database and R2 bucket)",
|
|
@@ -819,13 +857,17 @@ async function main() {
|
|
|
819
857
|
authenticated = true;
|
|
820
858
|
} catch {
|
|
821
859
|
p.note(
|
|
822
|
-
|
|
860
|
+
interactive
|
|
861
|
+
? "You need to log in to Cloudflare first."
|
|
862
|
+
: "Not logged in to Cloudflare. Run `wrangler login` (or set CLOUDFLARE_API_TOKEN), then finish the setup steps listed below.",
|
|
823
863
|
"Wrangler login required",
|
|
824
864
|
);
|
|
825
|
-
const doLogin =
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
865
|
+
const doLogin = interactive
|
|
866
|
+
? await p.confirm({
|
|
867
|
+
message: "Open browser to log in?",
|
|
868
|
+
initialValue: true,
|
|
869
|
+
})
|
|
870
|
+
: false;
|
|
829
871
|
if (!p.isCancel(doLogin) && doLogin) {
|
|
830
872
|
try {
|
|
831
873
|
execSync(`${pm.exec} wrangler login`, {
|
|
@@ -943,19 +985,22 @@ async function main() {
|
|
|
943
985
|
);
|
|
944
986
|
cf.migrationsApplied = true;
|
|
945
987
|
s.stop("Migrations applied");
|
|
946
|
-
} catch {
|
|
988
|
+
} catch (err) {
|
|
947
989
|
s.stop(
|
|
948
990
|
"Migration apply failed — run manually with: wrangler d1 migrations apply --remote",
|
|
949
991
|
);
|
|
992
|
+
if (err.stderr) console.error(err.stderr.toString().slice(-800));
|
|
950
993
|
}
|
|
951
994
|
}
|
|
952
995
|
|
|
953
996
|
// Deploy to Cloudflare
|
|
954
997
|
if (cf.migrationsApplied) {
|
|
955
|
-
const doDeploy =
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
998
|
+
const doDeploy =
|
|
999
|
+
flags.deploy ??
|
|
1000
|
+
(await p.confirm({
|
|
1001
|
+
message: "Deploy to Cloudflare now?",
|
|
1002
|
+
initialValue: true,
|
|
1003
|
+
}));
|
|
959
1004
|
if (!p.isCancel(doDeploy) && doDeploy) {
|
|
960
1005
|
s.start("Building and deploying to Cloudflare");
|
|
961
1006
|
try {
|
|
@@ -983,7 +1028,8 @@ async function main() {
|
|
|
983
1028
|
// --- Done ---
|
|
984
1029
|
|
|
985
1030
|
if (target === "local") {
|
|
986
|
-
|
|
1031
|
+
// Without a terminal the dev server would never return control; skip it.
|
|
1032
|
+
const startDev = flags.noDev || !interactive
|
|
987
1033
|
? false
|
|
988
1034
|
: await p.confirm({
|
|
989
1035
|
message: "Start the dev server now?",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-kide-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Scaffold a new Kide CMS project",
|
|
5
5
|
"author": "Matti Hernesniemi",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"bin": {
|
|
9
9
|
"create-kide-app": "./index.js"
|
|
10
10
|
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"release": "npm version patch && git push --follow-tags && npm publish",
|
|
13
|
+
"release:minor": "npm version minor && git push --follow-tags && npm publish"
|
|
14
|
+
},
|
|
11
15
|
"files": [
|
|
12
16
|
"index.js"
|
|
13
17
|
],
|
|
@@ -28,9 +32,5 @@
|
|
|
28
32
|
},
|
|
29
33
|
"dependencies": {
|
|
30
34
|
"@clack/prompts": "^1.1.0"
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"release": "npm version patch && git push --follow-tags && npm publish",
|
|
34
|
-
"release:minor": "npm version minor && git push --follow-tags && npm publish"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|