create-gato-app 0.1.2 → 0.3.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 +81 -57
- package/dist/args.js +270 -84
- package/dist/clack-ui.js +87 -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 +83 -0
- package/dist/github.js +28 -0
- package/dist/index.js +10 -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 +286 -0
- package/dist/ui.js +1 -0
- package/dist/validate.js +49 -0
- package/dist/wizard.js +234 -0
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -8,55 +8,89 @@ 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), how the app sends mail
|
|
29
|
+
(`smtp`, `resend` or `console`), and whether to set up 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 and mail answers are filled in.
|
|
36
|
+
Mail: `smtp` with the default host `127.0.0.1` keeps the local mailpit `SMTP_URL` from `.env.example`; another
|
|
37
|
+
SMTP host writes `MAIL_PROVIDER=smtp`, `SMTP_HOST`, `SMTP_PORT` (and `SMTP_USER`/`SMTP_PASS` when a user is
|
|
38
|
+
given); `resend` writes `MAIL_PROVIDER=resend` and `RESEND_API_KEY`; `console` writes `MAIL_PROVIDER=console`
|
|
39
|
+
(no mail is sent). Every answer except the local mailpit empties `SMTP_URL`, so only one SMTP source is set.
|
|
40
|
+
7. **Starts Docker** (unless `--skip-docker`, `--skip-install` or "no" to setup): probes every port
|
|
41
|
+
`docker-compose.yml` publishes for the services it starts (plus the `s3` profile for a local MinIO). A busy port
|
|
42
|
+
stops this step with the `*_PORT` variables to set in `.env` (and the URLs that use them); otherwise
|
|
43
|
+
`docker compose up -d --wait`.
|
|
44
|
+
8. **`git init`, `npm install`, `prisma migrate dev --name init`, `admin:create`** (when an email was given; the
|
|
45
|
+
generated password is printed once), then **the first commit**. The commit comes last so it holds the lockfile
|
|
46
|
+
`npm install` rewrote and the first migration: the tree is clean when the wizard ends.
|
|
47
|
+
9. **Prints the next steps**, listing only what it did not do.
|
|
48
|
+
|
|
49
|
+
Exit code 1 means a step the run wanted did not finish (busy port, Docker not running, a failed install or
|
|
50
|
+
migration); the project stays in place and the next steps say how to continue.
|
|
51
|
+
|
|
52
|
+
`--skip-install` writes files only: no `npm install`, Docker, migration or first commit (a commit before the first
|
|
53
|
+
`npm install` would be dirty right away, because npm rewrites the lockfile). `git init` still runs.
|
|
27
54
|
|
|
28
55
|
## Flags
|
|
29
56
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
| `--
|
|
35
|
-
| `--
|
|
36
|
-
| `--
|
|
37
|
-
| `--
|
|
38
|
-
| `--
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
| `--
|
|
45
|
-
| `--
|
|
46
|
-
| `--
|
|
47
|
-
| `--
|
|
48
|
-
| `--
|
|
49
|
-
| `--
|
|
50
|
-
| `--no-
|
|
51
|
-
| `--
|
|
52
|
-
| `--
|
|
57
|
+
| Flag | Meaning |
|
|
58
|
+
| -------------------------------- | --------------------------------------------------------------------------------- |
|
|
59
|
+
| `--modules a,b` | Kit modules besides the core (`--modules ""` = core only). |
|
|
60
|
+
| `--locales pl\|pl,en` | App locales (`pl` is required). |
|
|
61
|
+
| `--title <text>` | Display name (1-60 characters, no quotes, backslashes, `<`, `>`, `$`, backticks). |
|
|
62
|
+
| `--admin-email <email>` | First admin's email. |
|
|
63
|
+
| `--storage local\|s3` | File storage when `uploads` is chosen. |
|
|
64
|
+
| `--s3-endpoint <url>` | S3 endpoint (default `http://localhost:9000`, local MinIO). |
|
|
65
|
+
| `--s3-access-key-id <id>` | S3 access key id (needed with `--yes` and a non-local endpoint). |
|
|
66
|
+
| `--s3-secret-access-key <key>` | S3 secret access key (same). |
|
|
67
|
+
| `--mail-provider <smtp\|resend\|console>` | How the app sends mail (default `smtp` with the local mailpit). |
|
|
68
|
+
| `--smtp-host <host>` | SMTP relay host (default `127.0.0.1`, local mailpit); needs `--mail-provider smtp`. |
|
|
69
|
+
| `--smtp-port <port>` | SMTP relay port, 1-65535 (default 587). |
|
|
70
|
+
| `--smtp-user <user>` | SMTP user; none means no authentication. |
|
|
71
|
+
| `--smtp-pass <pass>` | SMTP password (needed with `--yes` and `--smtp-user`). |
|
|
72
|
+
| `--resend-api-key <key>` | Resend API key (needed with `--yes` and `--mail-provider resend`). |
|
|
73
|
+
| `--yes` | Ask nothing; defaults for everything not given (setup included). |
|
|
74
|
+
| `--setup` | Set up the database without asking. |
|
|
75
|
+
| `--skip-docker` | Do not start Docker (and so no migration or admin). |
|
|
76
|
+
| `--skip-install`, `--no-install` | Write files only; an unsupported Node only warns. |
|
|
77
|
+
| `--no-git` | No `git init` and no first commit. |
|
|
78
|
+
| `--kit-version <x.y.z>` | Kit version (tag `v<x.y.z>`). Default: the highest `v<x.y.z>` tag. |
|
|
79
|
+
| `--kit <path>` | Use a local kit checkout instead of downloading one (kit development, CI). |
|
|
80
|
+
| `--cli-source <tgz>` | The project's `gato-cli` from a packed tarball (`file:`), for CI. |
|
|
81
|
+
| `--help`, `-h` | Print usage. |
|
|
82
|
+
| `--version`, `-v` | Print the `create-gato-app` version. |
|
|
53
83
|
|
|
54
84
|
Examples:
|
|
55
85
|
|
|
56
86
|
```bash
|
|
57
|
-
npx create-gato-app my-app
|
|
58
|
-
npx create-gato-app my-app --
|
|
59
|
-
npx create-gato-app my-app --
|
|
87
|
+
npx create-gato-app my-app
|
|
88
|
+
npx create-gato-app my-app --yes --modules uploads,api-keys --admin-email you@example.com
|
|
89
|
+
npx create-gato-app my-app --yes --modules uploads --storage s3 \
|
|
90
|
+
--s3-endpoint https://s3.example.com --s3-access-key-id AKIA… --s3-secret-access-key …
|
|
91
|
+
npx create-gato-app my-app --yes --mail-provider smtp --smtp-host smtp.example.com \
|
|
92
|
+
--smtp-user app --smtp-pass …
|
|
93
|
+
npx create-gato-app my-app --kit ../gatojs --yes --skip-install --no-git
|
|
60
94
|
```
|
|
61
95
|
|
|
62
96
|
## GitHub token
|
|
@@ -76,23 +110,10 @@ The token is only sent to `api.github.com`; it is never printed. When GitHub rej
|
|
|
76
110
|
`create-gato-app` says so and retries once without it. On a 403 or 429 (rate limit), set a token or pass
|
|
77
111
|
`--kit-version`.
|
|
78
112
|
|
|
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
113
|
## Not yet
|
|
85
114
|
|
|
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.
|
|
115
|
+
The default kit version still comes from the highest tag; choosing it from GitHub Releases filtered by `kitFormat`
|
|
116
|
+
(spec `docs/superpowers/specs/2026-11-21-gato-cli-design.md` §5) comes later.
|
|
96
117
|
|
|
97
118
|
## Development
|
|
98
119
|
|
|
@@ -103,9 +124,12 @@ SMOKE_INSTALL=1 bash packages/create-gato-app/scripts/smoke-pack.sh "$PWD"
|
|
|
103
124
|
```
|
|
104
125
|
|
|
105
126
|
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
|
-
`
|
|
127
|
+
from this checkout (with and without `--cli-source <gato-cli tarball>`), and checks versions, the `gato-cli` tarball's
|
|
128
|
+
file list, the exact pin, generated secrets, `COMPOSE_PROJECT_NAME`, the storage answers and the mail answer in
|
|
129
|
+
`.env`. With `SMOKE_INSTALL=1` it also creates a project with `--mail-provider console` and checks its `.env` with
|
|
130
|
+
`checkEnv` from `@gatojs/env` inside the project.
|
|
131
|
+
`SMOKE_INSTALL=1` also lets the wizard install a project with `--skip-docker` (one commit, clean tree), checks that the
|
|
132
|
+
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
133
|
|
|
110
134
|
## Publishing
|
|
111
135
|
|
package/dist/args.js
CHANGED
|
@@ -1,50 +1,253 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { isHttpUrl, LOCAL_MINIO_ENDPOINT } from "./questions.js";
|
|
3
|
+
import { adminEmailError, envValueError, parsePort, PORT_ERROR, 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",
|
|
19
|
+
" --mail-provider <smtp|resend|console>",
|
|
20
|
+
" how the app sends mail (default smtp: local mailpit)",
|
|
21
|
+
" --smtp-host <host> SMTP relay host (default 127.0.0.1, local mailpit)",
|
|
22
|
+
" --smtp-port <port> SMTP relay port (default 587)",
|
|
23
|
+
" --smtp-user <user> SMTP user (none = no authentication)",
|
|
24
|
+
" --smtp-pass <pass> SMTP password",
|
|
25
|
+
" --resend-api-key <key> Resend API key",
|
|
12
26
|
"",
|
|
13
|
-
"
|
|
14
|
-
" --
|
|
15
|
-
" --
|
|
27
|
+
"Steps:",
|
|
28
|
+
" --yes accept defaults, ask nothing",
|
|
29
|
+
" --setup start Docker, migrate and create the admin without asking",
|
|
30
|
+
" --skip-docker do not start Docker (no migrate, no admin:create)",
|
|
31
|
+
" --skip-install write files only: no npm install, Docker or first commit;",
|
|
32
|
+
" an unsupported Node only warns (alias --no-install)",
|
|
33
|
+
" --no-git no git init and no first commit",
|
|
34
|
+
"",
|
|
35
|
+
"Kit source:",
|
|
36
|
+
" --kit-version <x.y.z> kit version (tag v<x.y.z>); default: the highest v<x.y.z> tag",
|
|
37
|
+
" --kit <path> use a local kit checkout instead of downloading one",
|
|
38
|
+
" --cli-source <tarball> the project's gato-cli from a packed tarball (CI)",
|
|
39
|
+
"",
|
|
40
|
+
" -h, --help print this help",
|
|
41
|
+
" -v, --version print the create-gato-app version",
|
|
16
42
|
"",
|
|
17
43
|
"Rate limits: set GITHUB_TOKEN or GH_TOKEN, or log in with `gh auth login`.",
|
|
18
44
|
].join("\n");
|
|
19
45
|
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";
|
|
46
|
+
const LOCALES_ERROR = "--locales: use pl or pl,en (pl is required)";
|
|
47
|
+
const ALLOWED_LOCALES = ["pl", "en"];
|
|
29
48
|
const MISSING_VALUE_MESSAGES = {
|
|
30
49
|
"--kit-version": "--kit-version needs a value, e.g. --kit-version 0.1.0",
|
|
31
50
|
"--kit": "--kit needs a path",
|
|
32
51
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
const SINGLE_USE_OPTIONS = ["kit-version", "kit"];
|
|
53
|
+
const S3_FLAGS = [
|
|
54
|
+
"s3-endpoint",
|
|
55
|
+
"s3-access-key-id",
|
|
56
|
+
"s3-secret-access-key",
|
|
57
|
+
];
|
|
58
|
+
const SMTP_FLAGS = [
|
|
59
|
+
"smtp-host",
|
|
60
|
+
"smtp-port",
|
|
61
|
+
"smtp-user",
|
|
62
|
+
"smtp-pass",
|
|
63
|
+
];
|
|
64
|
+
const MAIL_PROVIDERS = ["smtp", "resend", "console"];
|
|
65
|
+
const OPTIONS = {
|
|
66
|
+
help: { type: "boolean", short: "h" },
|
|
67
|
+
version: { type: "boolean", short: "v" },
|
|
68
|
+
modules: { type: "string" },
|
|
69
|
+
locales: { type: "string" },
|
|
70
|
+
title: { type: "string" },
|
|
71
|
+
"admin-email": { type: "string" },
|
|
72
|
+
storage: { type: "string" },
|
|
73
|
+
"s3-endpoint": { type: "string" },
|
|
74
|
+
"s3-access-key-id": { type: "string" },
|
|
75
|
+
"s3-secret-access-key": { type: "string" },
|
|
76
|
+
"mail-provider": { type: "string" },
|
|
77
|
+
"smtp-host": { type: "string" },
|
|
78
|
+
"smtp-port": { type: "string" },
|
|
79
|
+
"smtp-user": { type: "string" },
|
|
80
|
+
"smtp-pass": { type: "string" },
|
|
81
|
+
"resend-api-key": { type: "string" },
|
|
82
|
+
yes: { type: "boolean" },
|
|
83
|
+
setup: { type: "boolean" },
|
|
84
|
+
"skip-docker": { type: "boolean" },
|
|
85
|
+
"skip-install": { type: "boolean" },
|
|
86
|
+
"no-install": { type: "boolean" },
|
|
87
|
+
"no-git": { type: "boolean" },
|
|
88
|
+
"kit-version": { type: "string" },
|
|
89
|
+
kit: { type: "string" },
|
|
90
|
+
"cli-source": { type: "string" },
|
|
91
|
+
};
|
|
92
|
+
function optionNameOf(message) {
|
|
93
|
+
const match = /'(-[^' ]+)/.exec(message);
|
|
94
|
+
return match ? match[1] : message;
|
|
95
|
+
}
|
|
96
|
+
function missingValue(flag) {
|
|
97
|
+
return MISSING_VALUE_MESSAGES[flag] ?? `${flag} needs a value`;
|
|
98
|
+
}
|
|
99
|
+
function parseOptions(argv) {
|
|
100
|
+
try {
|
|
101
|
+
return parseArgs({
|
|
102
|
+
args: argv,
|
|
103
|
+
options: OPTIONS,
|
|
104
|
+
allowPositionals: true,
|
|
105
|
+
strict: true,
|
|
106
|
+
tokens: true,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (!(error instanceof Error) || !("code" in error)) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
const option = optionNameOf(error.message);
|
|
114
|
+
if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
115
|
+
throw new Error(`Unknown option: ${option}`, { cause: error });
|
|
37
116
|
}
|
|
117
|
+
if (error.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE") {
|
|
118
|
+
const takesValue = Object.entries(OPTIONS).some(([name, config]) => `--${name}` === option && config.type === "string");
|
|
119
|
+
throw new Error(takesValue ? missingValue(option) : `${option} does not take a value`, { cause: error });
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function listOf(value) {
|
|
125
|
+
return value
|
|
126
|
+
.split(",")
|
|
127
|
+
.map((item) => item.trim())
|
|
128
|
+
.filter((item) => item !== "");
|
|
129
|
+
}
|
|
130
|
+
function parseLocales(value) {
|
|
131
|
+
const locales = listOf(value);
|
|
132
|
+
const valid = locales.includes("pl") &&
|
|
133
|
+
new Set(locales).size === locales.length &&
|
|
134
|
+
locales.every((locale) => ALLOWED_LOCALES.includes(locale));
|
|
135
|
+
if (!valid) {
|
|
136
|
+
throw new Error(LOCALES_ERROR);
|
|
38
137
|
}
|
|
39
|
-
return
|
|
138
|
+
return locales;
|
|
139
|
+
}
|
|
140
|
+
function nonEmpty(value, flag) {
|
|
141
|
+
if (value === undefined) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (value === "") {
|
|
145
|
+
throw new Error(missingValue(flag));
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
40
148
|
}
|
|
41
149
|
function parseKitVersion(value) {
|
|
42
|
-
const
|
|
150
|
+
const text = nonEmpty(value, "--kit-version");
|
|
151
|
+
if (text === null) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const match = KIT_VERSION_PATTERN.exec(text);
|
|
43
155
|
if (!match) {
|
|
44
|
-
throw new Error(`--kit-version: expected x.y.z, got "${
|
|
156
|
+
throw new Error(`--kit-version: expected x.y.z, got "${text}"`);
|
|
45
157
|
}
|
|
46
158
|
return match[1];
|
|
47
159
|
}
|
|
160
|
+
function checked(value, flag, error) {
|
|
161
|
+
if (value === undefined) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const message = error(value);
|
|
165
|
+
if (message !== null) {
|
|
166
|
+
throw new Error(`${flag}: ${message}`);
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
function parseTitle(value) {
|
|
171
|
+
return checked(value, "--title", titleError)?.trim() ?? null;
|
|
172
|
+
}
|
|
173
|
+
function parseStorage(values) {
|
|
174
|
+
const storage = values.storage;
|
|
175
|
+
if (storage !== undefined && storage !== "local" && storage !== "s3") {
|
|
176
|
+
throw new Error("--storage: use local or s3");
|
|
177
|
+
}
|
|
178
|
+
for (const flag of S3_FLAGS) {
|
|
179
|
+
if (values[flag] !== undefined && storage !== "s3") {
|
|
180
|
+
throw new Error(`--${flag} needs --storage s3`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const endpoint = values["s3-endpoint"];
|
|
184
|
+
if (endpoint !== undefined && !isHttpUrl(endpoint)) {
|
|
185
|
+
throw new Error("--s3-endpoint: expected an http(s) URL");
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
storage: storage ?? null,
|
|
189
|
+
s3Endpoint: endpoint ?? null,
|
|
190
|
+
s3AccessKeyId: checked(values["s3-access-key-id"], "--s3-access-key-id", (value) => envValueError("S3 access key id", value)),
|
|
191
|
+
s3SecretAccessKey: checked(values["s3-secret-access-key"], "--s3-secret-access-key", (value) => envValueError("S3 secret access key", value)),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function isMailProvider(value) {
|
|
195
|
+
return MAIL_PROVIDERS.includes(value);
|
|
196
|
+
}
|
|
197
|
+
function envValue(values, flag, label) {
|
|
198
|
+
return checked(values[flag], `--${flag}`, (value) => envValueError(label, value));
|
|
199
|
+
}
|
|
200
|
+
function parseSmtpPort(value) {
|
|
201
|
+
if (value === undefined) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const port = parsePort(value);
|
|
205
|
+
if (port === null) {
|
|
206
|
+
throw new Error(`--smtp-port: ${PORT_ERROR}`);
|
|
207
|
+
}
|
|
208
|
+
return port;
|
|
209
|
+
}
|
|
210
|
+
function parseMail(values) {
|
|
211
|
+
const provider = values["mail-provider"];
|
|
212
|
+
if (provider !== undefined && !isMailProvider(provider)) {
|
|
213
|
+
throw new Error("--mail-provider: use smtp, resend or console");
|
|
214
|
+
}
|
|
215
|
+
for (const flag of SMTP_FLAGS) {
|
|
216
|
+
if (values[flag] !== undefined && provider !== "smtp") {
|
|
217
|
+
throw new Error(`--${flag} needs --mail-provider smtp`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (values["resend-api-key"] !== undefined && provider !== "resend") {
|
|
221
|
+
throw new Error("--resend-api-key needs --mail-provider resend");
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
mailProvider: provider ?? null,
|
|
225
|
+
smtpHost: envValue(values, "smtp-host", "SMTP host"),
|
|
226
|
+
smtpPort: parseSmtpPort(values["smtp-port"]),
|
|
227
|
+
smtpUser: envValue(values, "smtp-user", "SMTP user"),
|
|
228
|
+
smtpPass: envValue(values, "smtp-pass", "SMTP password"),
|
|
229
|
+
resendApiKey: envValue(values, "resend-api-key", "Resend API key"),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function assertMailCredentials(args) {
|
|
233
|
+
if (!args.yes) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (args.mailProvider === "resend" && args.resendApiKey === null) {
|
|
237
|
+
throw new Error("--mail-provider resend needs --resend-api-key (or drop --yes to be asked)");
|
|
238
|
+
}
|
|
239
|
+
if (args.smtpUser !== null && args.smtpPass === null) {
|
|
240
|
+
throw new Error("--smtp-user needs --smtp-pass (or drop --yes to be asked)");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function assertExternalS3Keys(args) {
|
|
244
|
+
const external = args.s3Endpoint !== null && args.s3Endpoint !== LOCAL_MINIO_ENDPOINT;
|
|
245
|
+
if (args.yes &&
|
|
246
|
+
external &&
|
|
247
|
+
(args.s3AccessKeyId === null || args.s3SecretAccessKey === null)) {
|
|
248
|
+
throw new Error("--storage s3 with --s3-endpoint needs --s3-access-key-id and --s3-secret-access-key (or drop --yes to be asked)");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
48
251
|
export function parseCliArgs(argv) {
|
|
49
252
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
50
253
|
return { kind: "help" };
|
|
@@ -52,67 +255,50 @@ export function parseCliArgs(argv) {
|
|
|
52
255
|
if (argv.includes("--version") || argv.includes("-v")) {
|
|
53
256
|
return { kind: "version" };
|
|
54
257
|
}
|
|
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`);
|
|
87
|
-
}
|
|
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);
|
|
258
|
+
const { values, positionals, tokens } = parseOptions(argv);
|
|
259
|
+
for (const name of SINGLE_USE_OPTIONS) {
|
|
260
|
+
const uses = tokens.filter((token) => token.kind === "option" && token.name === name);
|
|
261
|
+
if (uses.length > 1) {
|
|
262
|
+
throw new Error(`--${name} given more than once`);
|
|
105
263
|
}
|
|
106
264
|
}
|
|
107
|
-
const
|
|
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
|
-
}
|
|
112
|
-
const kitVersion = kitVersionValue === undefined ? null : parseKitVersion(kitVersionValue);
|
|
113
|
-
const [target] = positionals;
|
|
265
|
+
const [target, unexpected] = positionals;
|
|
114
266
|
if (target === undefined || target === "") {
|
|
115
267
|
throw new Error(`Missing project directory.\n${USAGE}`);
|
|
116
268
|
}
|
|
117
|
-
|
|
269
|
+
if (unexpected !== undefined) {
|
|
270
|
+
throw new Error(`Unexpected argument: ${unexpected}`);
|
|
271
|
+
}
|
|
272
|
+
const kitVersion = parseKitVersion(values["kit-version"]);
|
|
273
|
+
const kitPath = nonEmpty(values.kit, "--kit");
|
|
274
|
+
if (kitVersion !== null && kitPath !== null) {
|
|
275
|
+
throw new Error("--kit and --kit-version cannot be used together");
|
|
276
|
+
}
|
|
277
|
+
const install = !(values["skip-install"] || values["no-install"]);
|
|
278
|
+
const docker = install && !values["skip-docker"];
|
|
279
|
+
const setup = values.setup ?? false;
|
|
280
|
+
if (setup && !docker) {
|
|
281
|
+
throw new Error("--setup needs npm install and Docker; drop --skip-install/--skip-docker");
|
|
282
|
+
}
|
|
283
|
+
const args = {
|
|
284
|
+
kind: "create",
|
|
285
|
+
target,
|
|
286
|
+
kitVersion,
|
|
287
|
+
kitPath,
|
|
288
|
+
modules: values.modules === undefined ? null : listOf(values.modules),
|
|
289
|
+
locales: values.locales === undefined ? null : parseLocales(values.locales),
|
|
290
|
+
title: parseTitle(values.title),
|
|
291
|
+
adminEmail: checked(values["admin-email"], "--admin-email", adminEmailError),
|
|
292
|
+
yes: values.yes ?? false,
|
|
293
|
+
setup,
|
|
294
|
+
install,
|
|
295
|
+
docker,
|
|
296
|
+
git: !values["no-git"],
|
|
297
|
+
cliSource: nonEmpty(values["cli-source"], "--cli-source"),
|
|
298
|
+
...parseStorage(values),
|
|
299
|
+
...parseMail(values),
|
|
300
|
+
};
|
|
301
|
+
assertExternalS3Keys(args);
|
|
302
|
+
assertMailCredentials(args);
|
|
303
|
+
return args;
|
|
118
304
|
}
|
package/dist/clack-ui.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable no-console -- the terminal UI: the console is its output */
|
|
2
|
+
import * as clack from "@clack/prompts";
|
|
3
|
+
import { CancelledError } from "./questions.js";
|
|
4
|
+
function answered(value) {
|
|
5
|
+
if (clack.isCancel(value)) {
|
|
6
|
+
throw new CancelledError("Cancelled");
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export const clackPrompter = {
|
|
11
|
+
async multiselect(input) {
|
|
12
|
+
return answered(await clack.multiselect({
|
|
13
|
+
message: input.message,
|
|
14
|
+
options: input.options,
|
|
15
|
+
initialValues: input.initialValues,
|
|
16
|
+
required: false,
|
|
17
|
+
}));
|
|
18
|
+
},
|
|
19
|
+
async text(input) {
|
|
20
|
+
return answered(await clack.text({
|
|
21
|
+
message: input.message,
|
|
22
|
+
defaultValue: input.defaultValue,
|
|
23
|
+
placeholder: input.placeholder,
|
|
24
|
+
validate: input.validate
|
|
25
|
+
? (value) => input.validate?.(value ?? "")
|
|
26
|
+
: undefined,
|
|
27
|
+
}));
|
|
28
|
+
},
|
|
29
|
+
async password(input) {
|
|
30
|
+
return answered(await clack.password({
|
|
31
|
+
message: input.message,
|
|
32
|
+
validate: input.validate
|
|
33
|
+
? (value) => input.validate?.(value ?? "")
|
|
34
|
+
: undefined,
|
|
35
|
+
}));
|
|
36
|
+
},
|
|
37
|
+
async select(input) {
|
|
38
|
+
return answered(await clack.select({
|
|
39
|
+
message: input.message,
|
|
40
|
+
options: input.options,
|
|
41
|
+
initialValue: input.initialValue,
|
|
42
|
+
}));
|
|
43
|
+
},
|
|
44
|
+
async confirm(input) {
|
|
45
|
+
return answered(await clack.confirm({
|
|
46
|
+
message: input.message,
|
|
47
|
+
initialValue: input.initialValue,
|
|
48
|
+
}));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export const clackUi = {
|
|
52
|
+
intro: (title) => clack.intro(title),
|
|
53
|
+
step: (message) => clack.log.step(message),
|
|
54
|
+
info: (message) => clack.log.info(message),
|
|
55
|
+
warn: (message) => clack.log.warn(message),
|
|
56
|
+
note: (title, lines) => {
|
|
57
|
+
clack.log.step(title);
|
|
58
|
+
// WHY: a boxed clack note wraps long lines, which breaks copying a command with a long path.
|
|
59
|
+
process.stdout.write(`${lines.map((line) => ` ${line}`).join("\n")}\n`);
|
|
60
|
+
},
|
|
61
|
+
outro: (message) => clack.outro(message),
|
|
62
|
+
async task(label, work) {
|
|
63
|
+
const spinner = clack.spinner();
|
|
64
|
+
spinner.start(label);
|
|
65
|
+
try {
|
|
66
|
+
const result = await work();
|
|
67
|
+
spinner.stop(label);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
spinner.error(label);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
export const plainUi = {
|
|
77
|
+
intro: (title) => console.log(title),
|
|
78
|
+
step: (message) => console.log(message),
|
|
79
|
+
info: (message) => console.log(message),
|
|
80
|
+
warn: (message) => console.error(`Warning: ${message}`),
|
|
81
|
+
note: (title, lines) => console.log([`${title}:`, ...lines.map((line) => ` ${line}`)].join("\n")),
|
|
82
|
+
outro: (message) => console.log(message),
|
|
83
|
+
async task(label, work) {
|
|
84
|
+
console.log(`${label}…`);
|
|
85
|
+
return work();
|
|
86
|
+
},
|
|
87
|
+
};
|