create-gato-app 0.1.2 → 0.2.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 +67 -57
- package/dist/args.js +199 -84
- package/dist/clack-ui.js +86 -0
- package/dist/cli.js +58 -36
- package/dist/compare.js +6 -0
- package/dist/compose-ports.js +137 -0
- package/dist/delegate.js +20 -10
- package/dist/env-file.js +54 -0
- package/dist/github.js +28 -0
- package/dist/index.js +9 -0
- package/dist/kit-engines.js +39 -0
- package/dist/kit-modules.js +66 -0
- package/dist/next-steps.js +49 -0
- package/dist/node-version.js +19 -1
- package/dist/port-probe.js +31 -0
- package/dist/questions.js +176 -0
- package/dist/ui.js +1 -0
- package/dist/validate.js +39 -0
- package/dist/wizard.js +233 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,55 +8,77 @@ npx create-gato-app my-app
|
|
|
8
8
|
npm create gato-app@latest my-app
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
You need Node.js
|
|
11
|
+
You need Node.js in the range the chosen kit version declares (`engines.node`; `^22.12.0 || ^24.0.0 || ^26.0.0`
|
|
12
|
+
today), `git`, and Docker for the database.
|
|
12
13
|
|
|
13
14
|
## What it does
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
The order follows the rule "refuse before anything is written":
|
|
17
|
+
|
|
18
|
+
1. **Checks the flags, the directory and the project name.** The last segment of `<dir>` becomes the project
|
|
19
|
+
name (lowercase letters, digits and hyphens, starting with a letter, 2-50 characters); the directory must be
|
|
20
|
+
missing or empty. `--title` and `--admin-email` are validated here.
|
|
21
|
+
2. **Picks the kit version** (`--kit-version <x.y.z>`, or the highest `v<x.y.z>` tag of `webamigos/gatojs`) and
|
|
22
|
+
**checks Node** against that version's `engines.node`, read from GitHub before the download. The refusal says
|
|
23
|
+
whether Node is too old, an unsupported odd-numbered release line, or too new. `--yes` does not bypass it;
|
|
24
|
+
`--skip-install` turns it into a warning. Kit versions without `engines.node` are checked against `>=22`.
|
|
25
|
+
3. **Downloads the kit** tag tarball into a temporary directory (no clone, no history), removed at the end.
|
|
26
|
+
4. **Asks the questions** (defaults with `--yes`): modules with their descriptions from that kit version, locales,
|
|
27
|
+
display name, first admin's email, file storage when `uploads` is chosen (`local`, or `s3` with endpoint and
|
|
28
|
+
keys; the default endpoint `http://localhost:9000` is a local MinIO started with Docker), and whether to set up
|
|
29
|
+
the database now. A flag skips its question.
|
|
30
|
+
5. **Assembles the project** with the `gato-cli` version `create-gato-app` pins
|
|
31
|
+
(`node <gato-cli>/dist/gato.mjs create … --yes --no-install --no-git`). The project gets
|
|
32
|
+
`"gato-cli": "^<that version>"` in `devDependencies`.
|
|
33
|
+
6. **Writes `.env`**: every manifest variable with a `generate` field (`BETTER_AUTH_SECRET`, `API_KEY_PEPPER`, …)
|
|
34
|
+
gets a random value; `COMPOSE_PROJECT_NAME=<slug>-<6 random characters>` is written once, so two projects in
|
|
35
|
+
directories with the same name never share containers or volumes; the storage answers are filled in.
|
|
36
|
+
7. **Starts Docker** (unless `--skip-docker`, `--skip-install` or "no" to setup): probes every port
|
|
37
|
+
`docker-compose.yml` publishes for the services it starts (plus the `s3` profile for a local MinIO). A busy port
|
|
38
|
+
stops this step with the `*_PORT` variables to set in `.env` (and the URLs that use them); otherwise
|
|
39
|
+
`docker compose up -d --wait`.
|
|
40
|
+
8. **`git init`, `npm install`, `prisma migrate dev --name init`, `admin:create`** (when an email was given; the
|
|
41
|
+
generated password is printed once), then **the first commit**. The commit comes last so it holds the lockfile
|
|
42
|
+
`npm install` rewrote and the first migration: the tree is clean when the wizard ends.
|
|
43
|
+
9. **Prints the next steps**, listing only what it did not do.
|
|
44
|
+
|
|
45
|
+
Exit code 1 means a step the run wanted did not finish (busy port, Docker not running, a failed install or
|
|
46
|
+
migration); the project stays in place and the next steps say how to continue.
|
|
47
|
+
|
|
48
|
+
`--skip-install` writes files only: no `npm install`, Docker, migration or first commit (a commit before the first
|
|
49
|
+
`npm install` would be dirty right away, because npm rewrites the lockfile). `git init` still runs.
|
|
27
50
|
|
|
28
51
|
## Flags
|
|
29
52
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
| `--
|
|
35
|
-
| `--
|
|
36
|
-
| `--
|
|
37
|
-
| `--
|
|
38
|
-
| `--
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
| `--
|
|
45
|
-
| `--
|
|
46
|
-
| `--
|
|
47
|
-
| `--
|
|
48
|
-
| `--
|
|
49
|
-
| `--
|
|
50
|
-
| `--no-install` | Skip `npm install`. |
|
|
51
|
-
| `--no-git` | Skip `git init` and the first commit. |
|
|
52
|
-
| `--cli-source <tgz>` | The project's `gato-cli` from a packed tarball (`file:`), for CI. |
|
|
53
|
+
| Flag | Meaning |
|
|
54
|
+
| -------------------------------- | --------------------------------------------------------------------------------- |
|
|
55
|
+
| `--modules a,b` | Kit modules besides the core (`--modules ""` = core only). |
|
|
56
|
+
| `--locales pl\|pl,en` | App locales (`pl` is required). |
|
|
57
|
+
| `--title <text>` | Display name (1-60 characters, no quotes, backslashes, `<`, `>`, `$`, backticks). |
|
|
58
|
+
| `--admin-email <email>` | First admin's email. |
|
|
59
|
+
| `--storage local\|s3` | File storage when `uploads` is chosen. |
|
|
60
|
+
| `--s3-endpoint <url>` | S3 endpoint (default `http://localhost:9000`, local MinIO). |
|
|
61
|
+
| `--s3-access-key-id <id>` | S3 access key id (needed with `--yes` and a non-local endpoint). |
|
|
62
|
+
| `--s3-secret-access-key <key>` | S3 secret access key (same). |
|
|
63
|
+
| `--yes` | Ask nothing; defaults for everything not given (setup included). |
|
|
64
|
+
| `--setup` | Set up the database without asking. |
|
|
65
|
+
| `--skip-docker` | Do not start Docker (and so no migration or admin). |
|
|
66
|
+
| `--skip-install`, `--no-install` | Write files only; an unsupported Node only warns. |
|
|
67
|
+
| `--no-git` | No `git init` and no first commit. |
|
|
68
|
+
| `--kit-version <x.y.z>` | Kit version (tag `v<x.y.z>`). Default: the highest `v<x.y.z>` tag. |
|
|
69
|
+
| `--kit <path>` | Use a local kit checkout instead of downloading one (kit development, CI). |
|
|
70
|
+
| `--cli-source <tgz>` | The project's `gato-cli` from a packed tarball (`file:`), for CI. |
|
|
71
|
+
| `--help`, `-h` | Print usage. |
|
|
72
|
+
| `--version`, `-v` | Print the `create-gato-app` version. |
|
|
53
73
|
|
|
54
74
|
Examples:
|
|
55
75
|
|
|
56
76
|
```bash
|
|
57
|
-
npx create-gato-app my-app
|
|
58
|
-
npx create-gato-app my-app --
|
|
59
|
-
npx create-gato-app my-app --
|
|
77
|
+
npx create-gato-app my-app
|
|
78
|
+
npx create-gato-app my-app --yes --modules uploads,api-keys --admin-email you@example.com
|
|
79
|
+
npx create-gato-app my-app --yes --modules uploads --storage s3 \
|
|
80
|
+
--s3-endpoint https://s3.example.com --s3-access-key-id AKIA… --s3-secret-access-key …
|
|
81
|
+
npx create-gato-app my-app --kit ../gatojs --yes --skip-install --no-git
|
|
60
82
|
```
|
|
61
83
|
|
|
62
84
|
## GitHub token
|
|
@@ -76,23 +98,10 @@ The token is only sent to `api.github.com`; it is never printed. When GitHub rej
|
|
|
76
98
|
`create-gato-app` says so and retries once without it. On a 403 or 429 (rate limit), set a token or pass
|
|
77
99
|
`--kit-version`.
|
|
78
100
|
|
|
79
|
-
## Project name
|
|
80
|
-
|
|
81
|
-
The last segment of `<dir>` becomes the project name: lowercase letters, digits and hyphens, starting with a letter,
|
|
82
|
-
2-50 characters. `create-gato-app` checks it before it downloads anything.
|
|
83
|
-
|
|
84
101
|
## Not yet
|
|
85
102
|
|
|
86
|
-
|
|
87
|
-
`docs/superpowers/specs/2026-11-21-gato-cli-design.md` §5
|
|
88
|
-
|
|
89
|
-
- an interactive wizard (`@clack/prompts`) with module descriptions from the chosen kit version, locales, title, admin
|
|
90
|
-
email, and the storage provider for `uploads` (`local`, or `s3` with endpoint and keys);
|
|
91
|
-
- validation and escaping of `--title` and `--admin-email`;
|
|
92
|
-
- generated secrets for every manifest variable with a `generate` field (`secret-32`, `secret-64`);
|
|
93
|
-
- `COMPOSE_PROJECT_NAME=<slug>-<6 random characters>` in `.env`, port probing before `docker compose up`, `--skip-docker`;
|
|
94
|
-
- the default kit version from GitHub Releases filtered by `kitFormat`, and the `kitFormat` compatibility check;
|
|
95
|
-
- next steps that list only what the wizard did not do.
|
|
103
|
+
The default kit version still comes from the highest tag; choosing it from GitHub Releases filtered by `kitFormat`
|
|
104
|
+
(spec `docs/superpowers/specs/2026-11-21-gato-cli-design.md` §5) comes later.
|
|
96
105
|
|
|
97
106
|
## Development
|
|
98
107
|
|
|
@@ -103,9 +112,10 @@ SMOKE_INSTALL=1 bash packages/create-gato-app/scripts/smoke-pack.sh "$PWD"
|
|
|
103
112
|
```
|
|
104
113
|
|
|
105
114
|
The smoke script packs `gato-cli` and `create-gato-app`, installs both tarballs into an empty prefix, creates projects
|
|
106
|
-
from this checkout (
|
|
107
|
-
|
|
108
|
-
`
|
|
115
|
+
from this checkout (with and without `--cli-source <gato-cli tarball>`), and checks versions, the `gato-cli` tarball's
|
|
116
|
+
file list, the exact pin, generated secrets, `COMPOSE_PROJECT_NAME` and the storage answers in `.env`.
|
|
117
|
+
`SMOKE_INSTALL=1` also lets the wizard install a project with `--skip-docker` (one commit, clean tree), checks that the
|
|
118
|
+
projects' `gato` is the packed one, and runs the wizard against a busy `DB_PORT`. CI runs the same script in `.github/workflows/packages.yml`.
|
|
109
119
|
|
|
110
120
|
## Publishing
|
|
111
121
|
|
package/dist/args.js
CHANGED
|
@@ -1,50 +1,184 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { isHttpUrl, LOCAL_MINIO_ENDPOINT } from "./questions.js";
|
|
3
|
+
import { adminEmailError, envValueError, titleError } from "./validate.js";
|
|
1
4
|
export const USAGE = [
|
|
2
5
|
"Usage: create-gato-app <dir> [options]",
|
|
3
6
|
"",
|
|
4
|
-
"Creates a GatoJS project: downloads the kit
|
|
7
|
+
"Creates a GatoJS project: checks Node, downloads the kit, asks a few questions, assembles the project",
|
|
8
|
+
"with gato-cli, writes .env (secrets, COMPOSE_PROJECT_NAME), starts Docker, installs, migrates and commits.",
|
|
5
9
|
"",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
" --
|
|
9
|
-
" --
|
|
10
|
-
" -
|
|
11
|
-
"
|
|
10
|
+
"Answers (asked when missing, defaults with --yes):",
|
|
11
|
+
' --modules <a,b> kit modules besides the core ("" = core only)',
|
|
12
|
+
" --locales <pl|pl,en> app locales (pl is required)",
|
|
13
|
+
" --title <text> display name",
|
|
14
|
+
" --admin-email <email> first admin's email",
|
|
15
|
+
" --storage <local|s3> file storage when the uploads module is chosen",
|
|
16
|
+
" --s3-endpoint <url> S3 endpoint (default http://localhost:9000, local MinIO)",
|
|
17
|
+
" --s3-access-key-id <id> S3 access key id",
|
|
18
|
+
" --s3-secret-access-key <key> S3 secret access key",
|
|
12
19
|
"",
|
|
13
|
-
"
|
|
14
|
-
" --
|
|
15
|
-
" --
|
|
20
|
+
"Steps:",
|
|
21
|
+
" --yes accept defaults, ask nothing",
|
|
22
|
+
" --setup start Docker, migrate and create the admin without asking",
|
|
23
|
+
" --skip-docker do not start Docker (no migrate, no admin:create)",
|
|
24
|
+
" --skip-install write files only: no npm install, Docker or first commit;",
|
|
25
|
+
" an unsupported Node only warns (alias --no-install)",
|
|
26
|
+
" --no-git no git init and no first commit",
|
|
27
|
+
"",
|
|
28
|
+
"Kit source:",
|
|
29
|
+
" --kit-version <x.y.z> kit version (tag v<x.y.z>); default: the highest v<x.y.z> tag",
|
|
30
|
+
" --kit <path> use a local kit checkout instead of downloading one",
|
|
31
|
+
" --cli-source <tarball> the project's gato-cli from a packed tarball (CI)",
|
|
32
|
+
"",
|
|
33
|
+
" -h, --help print this help",
|
|
34
|
+
" -v, --version print the create-gato-app version",
|
|
16
35
|
"",
|
|
17
36
|
"Rate limits: set GITHUB_TOKEN or GH_TOKEN, or log in with `gh auth login`.",
|
|
18
37
|
].join("\n");
|
|
19
38
|
const KIT_VERSION_PATTERN = /^v?((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))$/;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
"--locales",
|
|
23
|
-
"--title",
|
|
24
|
-
"--admin-email",
|
|
25
|
-
"--cli-source",
|
|
26
|
-
]);
|
|
27
|
-
const UNSUPPORTED_FLAGS = new Set(["--skip-docker"]);
|
|
28
|
-
const NO_INSTALL = "--no-install";
|
|
39
|
+
const LOCALES_ERROR = "--locales: use pl or pl,en (pl is required)";
|
|
40
|
+
const ALLOWED_LOCALES = ["pl", "en"];
|
|
29
41
|
const MISSING_VALUE_MESSAGES = {
|
|
30
42
|
"--kit-version": "--kit-version needs a value, e.g. --kit-version 0.1.0",
|
|
31
43
|
"--kit": "--kit needs a path",
|
|
32
44
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
const SINGLE_USE_OPTIONS = ["kit-version", "kit"];
|
|
46
|
+
const S3_FLAGS = [
|
|
47
|
+
"s3-endpoint",
|
|
48
|
+
"s3-access-key-id",
|
|
49
|
+
"s3-secret-access-key",
|
|
50
|
+
];
|
|
51
|
+
const OPTIONS = {
|
|
52
|
+
help: { type: "boolean", short: "h" },
|
|
53
|
+
version: { type: "boolean", short: "v" },
|
|
54
|
+
modules: { type: "string" },
|
|
55
|
+
locales: { type: "string" },
|
|
56
|
+
title: { type: "string" },
|
|
57
|
+
"admin-email": { type: "string" },
|
|
58
|
+
storage: { type: "string" },
|
|
59
|
+
"s3-endpoint": { type: "string" },
|
|
60
|
+
"s3-access-key-id": { type: "string" },
|
|
61
|
+
"s3-secret-access-key": { type: "string" },
|
|
62
|
+
yes: { type: "boolean" },
|
|
63
|
+
setup: { type: "boolean" },
|
|
64
|
+
"skip-docker": { type: "boolean" },
|
|
65
|
+
"skip-install": { type: "boolean" },
|
|
66
|
+
"no-install": { type: "boolean" },
|
|
67
|
+
"no-git": { type: "boolean" },
|
|
68
|
+
"kit-version": { type: "string" },
|
|
69
|
+
kit: { type: "string" },
|
|
70
|
+
"cli-source": { type: "string" },
|
|
71
|
+
};
|
|
72
|
+
function optionNameOf(message) {
|
|
73
|
+
const match = /'(-[^' ]+)/.exec(message);
|
|
74
|
+
return match ? match[1] : message;
|
|
75
|
+
}
|
|
76
|
+
function missingValue(flag) {
|
|
77
|
+
return MISSING_VALUE_MESSAGES[flag] ?? `${flag} needs a value`;
|
|
78
|
+
}
|
|
79
|
+
function parseOptions(argv) {
|
|
80
|
+
try {
|
|
81
|
+
return parseArgs({
|
|
82
|
+
args: argv,
|
|
83
|
+
options: OPTIONS,
|
|
84
|
+
allowPositionals: true,
|
|
85
|
+
strict: true,
|
|
86
|
+
tokens: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (!(error instanceof Error) || !("code" in error)) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
const option = optionNameOf(error.message);
|
|
94
|
+
if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
95
|
+
throw new Error(`Unknown option: ${option}`, { cause: error });
|
|
37
96
|
}
|
|
97
|
+
if (error.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE") {
|
|
98
|
+
const takesValue = Object.entries(OPTIONS).some(([name, config]) => `--${name}` === option && config.type === "string");
|
|
99
|
+
throw new Error(takesValue ? missingValue(option) : `${option} does not take a value`, { cause: error });
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function listOf(value) {
|
|
105
|
+
return value
|
|
106
|
+
.split(",")
|
|
107
|
+
.map((item) => item.trim())
|
|
108
|
+
.filter((item) => item !== "");
|
|
109
|
+
}
|
|
110
|
+
function parseLocales(value) {
|
|
111
|
+
const locales = listOf(value);
|
|
112
|
+
const valid = locales.includes("pl") &&
|
|
113
|
+
new Set(locales).size === locales.length &&
|
|
114
|
+
locales.every((locale) => ALLOWED_LOCALES.includes(locale));
|
|
115
|
+
if (!valid) {
|
|
116
|
+
throw new Error(LOCALES_ERROR);
|
|
117
|
+
}
|
|
118
|
+
return locales;
|
|
119
|
+
}
|
|
120
|
+
function nonEmpty(value, flag) {
|
|
121
|
+
if (value === undefined) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (value === "") {
|
|
125
|
+
throw new Error(missingValue(flag));
|
|
38
126
|
}
|
|
39
|
-
return
|
|
127
|
+
return value;
|
|
40
128
|
}
|
|
41
129
|
function parseKitVersion(value) {
|
|
42
|
-
const
|
|
130
|
+
const text = nonEmpty(value, "--kit-version");
|
|
131
|
+
if (text === null) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const match = KIT_VERSION_PATTERN.exec(text);
|
|
43
135
|
if (!match) {
|
|
44
|
-
throw new Error(`--kit-version: expected x.y.z, got "${
|
|
136
|
+
throw new Error(`--kit-version: expected x.y.z, got "${text}"`);
|
|
45
137
|
}
|
|
46
138
|
return match[1];
|
|
47
139
|
}
|
|
140
|
+
function checked(value, flag, error) {
|
|
141
|
+
if (value === undefined) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const message = error(value);
|
|
145
|
+
if (message !== null) {
|
|
146
|
+
throw new Error(`${flag}: ${message}`);
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
function parseTitle(value) {
|
|
151
|
+
return checked(value, "--title", titleError)?.trim() ?? null;
|
|
152
|
+
}
|
|
153
|
+
function parseStorage(values) {
|
|
154
|
+
const storage = values.storage;
|
|
155
|
+
if (storage !== undefined && storage !== "local" && storage !== "s3") {
|
|
156
|
+
throw new Error("--storage: use local or s3");
|
|
157
|
+
}
|
|
158
|
+
for (const flag of S3_FLAGS) {
|
|
159
|
+
if (values[flag] !== undefined && storage !== "s3") {
|
|
160
|
+
throw new Error(`--${flag} needs --storage s3`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const endpoint = values["s3-endpoint"];
|
|
164
|
+
if (endpoint !== undefined && !isHttpUrl(endpoint)) {
|
|
165
|
+
throw new Error("--s3-endpoint: expected an http(s) URL");
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
storage: storage ?? null,
|
|
169
|
+
s3Endpoint: endpoint ?? null,
|
|
170
|
+
s3AccessKeyId: checked(values["s3-access-key-id"], "--s3-access-key-id", (value) => envValueError("S3 access key id", value)),
|
|
171
|
+
s3SecretAccessKey: checked(values["s3-secret-access-key"], "--s3-secret-access-key", (value) => envValueError("S3 secret access key", value)),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function assertExternalS3Keys(args) {
|
|
175
|
+
const external = args.s3Endpoint !== null && args.s3Endpoint !== LOCAL_MINIO_ENDPOINT;
|
|
176
|
+
if (args.yes &&
|
|
177
|
+
external &&
|
|
178
|
+
(args.s3AccessKeyId === null || args.s3SecretAccessKey === null)) {
|
|
179
|
+
throw new Error("--storage s3 with --s3-endpoint needs --s3-access-key-id and --s3-secret-access-key (or drop --yes to be asked)");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
48
182
|
export function parseCliArgs(argv) {
|
|
49
183
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
50
184
|
return { kind: "help" };
|
|
@@ -52,67 +186,48 @@ export function parseCliArgs(argv) {
|
|
|
52
186
|
if (argv.includes("--version") || argv.includes("-v")) {
|
|
53
187
|
return { kind: "version" };
|
|
54
188
|
}
|
|
55
|
-
const values =
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const arg = argv[index];
|
|
61
|
-
const ownFlag = ownValueFlagOf(arg);
|
|
62
|
-
if (ownFlag !== null) {
|
|
63
|
-
let value;
|
|
64
|
-
if (arg.includes("=")) {
|
|
65
|
-
value = arg.slice(arg.indexOf("=") + 1);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
value = argv[index + 1];
|
|
69
|
-
if (value !== undefined && !value.startsWith("-")) {
|
|
70
|
-
index += 1;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
value = undefined;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (value === undefined || value === "") {
|
|
77
|
-
throw new Error(MISSING_VALUE_MESSAGES[ownFlag]);
|
|
78
|
-
}
|
|
79
|
-
if (values.has(ownFlag)) {
|
|
80
|
-
throw new Error(`${ownFlag} given more than once`);
|
|
81
|
-
}
|
|
82
|
-
values.set(ownFlag, value);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (UNSUPPORTED_FLAGS.has(arg)) {
|
|
86
|
-
throw new Error(`${arg} is not supported yet`);
|
|
189
|
+
const { values, positionals, tokens } = parseOptions(argv);
|
|
190
|
+
for (const name of SINGLE_USE_OPTIONS) {
|
|
191
|
+
const uses = tokens.filter((token) => token.kind === "option" && token.name === name);
|
|
192
|
+
if (uses.length > 1) {
|
|
193
|
+
throw new Error(`--${name} given more than once`);
|
|
87
194
|
}
|
|
88
|
-
if (arg === "--skip-install" || arg === NO_INSTALL) {
|
|
89
|
-
if (install) {
|
|
90
|
-
passthrough.push(NO_INSTALL);
|
|
91
|
-
}
|
|
92
|
-
install = false;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
passthrough.push(arg);
|
|
96
|
-
if (GATO_CREATE_VALUE_OPTIONS.has(arg)) {
|
|
97
|
-
const value = argv[index + 1];
|
|
98
|
-
if (value !== undefined) {
|
|
99
|
-
passthrough.push(value);
|
|
100
|
-
index += 1;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (!arg.startsWith("-")) {
|
|
104
|
-
positionals.push(arg);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const kitVersionValue = values.get("--kit-version");
|
|
108
|
-
const kitPath = values.get("--kit") ?? null;
|
|
109
|
-
if (kitVersionValue !== undefined && kitPath !== null) {
|
|
110
|
-
throw new Error("--kit and --kit-version cannot be used together");
|
|
111
195
|
}
|
|
112
|
-
const
|
|
113
|
-
const [target] = positionals;
|
|
196
|
+
const [target, unexpected] = positionals;
|
|
114
197
|
if (target === undefined || target === "") {
|
|
115
198
|
throw new Error(`Missing project directory.\n${USAGE}`);
|
|
116
199
|
}
|
|
117
|
-
|
|
200
|
+
if (unexpected !== undefined) {
|
|
201
|
+
throw new Error(`Unexpected argument: ${unexpected}`);
|
|
202
|
+
}
|
|
203
|
+
const kitVersion = parseKitVersion(values["kit-version"]);
|
|
204
|
+
const kitPath = nonEmpty(values.kit, "--kit");
|
|
205
|
+
if (kitVersion !== null && kitPath !== null) {
|
|
206
|
+
throw new Error("--kit and --kit-version cannot be used together");
|
|
207
|
+
}
|
|
208
|
+
const install = !(values["skip-install"] || values["no-install"]);
|
|
209
|
+
const docker = install && !values["skip-docker"];
|
|
210
|
+
const setup = values.setup ?? false;
|
|
211
|
+
if (setup && !docker) {
|
|
212
|
+
throw new Error("--setup needs npm install and Docker; drop --skip-install/--skip-docker");
|
|
213
|
+
}
|
|
214
|
+
const args = {
|
|
215
|
+
kind: "create",
|
|
216
|
+
target,
|
|
217
|
+
kitVersion,
|
|
218
|
+
kitPath,
|
|
219
|
+
modules: values.modules === undefined ? null : listOf(values.modules),
|
|
220
|
+
locales: values.locales === undefined ? null : parseLocales(values.locales),
|
|
221
|
+
title: parseTitle(values.title),
|
|
222
|
+
adminEmail: checked(values["admin-email"], "--admin-email", adminEmailError),
|
|
223
|
+
yes: values.yes ?? false,
|
|
224
|
+
setup,
|
|
225
|
+
install,
|
|
226
|
+
docker,
|
|
227
|
+
git: !values["no-git"],
|
|
228
|
+
cliSource: nonEmpty(values["cli-source"], "--cli-source"),
|
|
229
|
+
...parseStorage(values),
|
|
230
|
+
};
|
|
231
|
+
assertExternalS3Keys(args);
|
|
232
|
+
return args;
|
|
118
233
|
}
|
package/dist/clack-ui.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as clack from "@clack/prompts";
|
|
2
|
+
import { CancelledError } from "./questions.js";
|
|
3
|
+
function answered(value) {
|
|
4
|
+
if (clack.isCancel(value)) {
|
|
5
|
+
throw new CancelledError("Cancelled");
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export const clackPrompter = {
|
|
10
|
+
async multiselect(input) {
|
|
11
|
+
return answered(await clack.multiselect({
|
|
12
|
+
message: input.message,
|
|
13
|
+
options: input.options,
|
|
14
|
+
initialValues: input.initialValues,
|
|
15
|
+
required: false,
|
|
16
|
+
}));
|
|
17
|
+
},
|
|
18
|
+
async text(input) {
|
|
19
|
+
return answered(await clack.text({
|
|
20
|
+
message: input.message,
|
|
21
|
+
defaultValue: input.defaultValue,
|
|
22
|
+
placeholder: input.placeholder,
|
|
23
|
+
validate: input.validate
|
|
24
|
+
? (value) => input.validate?.(value ?? "")
|
|
25
|
+
: undefined,
|
|
26
|
+
}));
|
|
27
|
+
},
|
|
28
|
+
async password(input) {
|
|
29
|
+
return answered(await clack.password({
|
|
30
|
+
message: input.message,
|
|
31
|
+
validate: input.validate
|
|
32
|
+
? (value) => input.validate?.(value ?? "")
|
|
33
|
+
: undefined,
|
|
34
|
+
}));
|
|
35
|
+
},
|
|
36
|
+
async select(input) {
|
|
37
|
+
return answered(await clack.select({
|
|
38
|
+
message: input.message,
|
|
39
|
+
options: input.options,
|
|
40
|
+
initialValue: input.initialValue,
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
async confirm(input) {
|
|
44
|
+
return answered(await clack.confirm({
|
|
45
|
+
message: input.message,
|
|
46
|
+
initialValue: input.initialValue,
|
|
47
|
+
}));
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
export const clackUi = {
|
|
51
|
+
intro: (title) => clack.intro(title),
|
|
52
|
+
step: (message) => clack.log.step(message),
|
|
53
|
+
info: (message) => clack.log.info(message),
|
|
54
|
+
warn: (message) => clack.log.warn(message),
|
|
55
|
+
note: (title, lines) => {
|
|
56
|
+
clack.log.step(title);
|
|
57
|
+
// WHY: a boxed clack note wraps long lines, which breaks copying a command with a long path.
|
|
58
|
+
process.stdout.write(`${lines.map((line) => ` ${line}`).join("\n")}\n`);
|
|
59
|
+
},
|
|
60
|
+
outro: (message) => clack.outro(message),
|
|
61
|
+
async task(label, work) {
|
|
62
|
+
const spinner = clack.spinner();
|
|
63
|
+
spinner.start(label);
|
|
64
|
+
try {
|
|
65
|
+
const result = await work();
|
|
66
|
+
spinner.stop(label);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
spinner.error(label);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
export const plainUi = {
|
|
76
|
+
intro: (title) => console.log(title),
|
|
77
|
+
step: (message) => console.log(message),
|
|
78
|
+
info: (message) => console.log(message),
|
|
79
|
+
warn: (message) => console.error(`Warning: ${message}`),
|
|
80
|
+
note: (title, lines) => console.log([`${title}:`, ...lines.map((line) => ` ${line}`)].join("\n")),
|
|
81
|
+
outro: (message) => console.log(message),
|
|
82
|
+
async task(label, work) {
|
|
83
|
+
console.log(`${label}…`);
|
|
84
|
+
return work();
|
|
85
|
+
},
|
|
86
|
+
};
|