create-gato-app 0.1.1 → 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 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 22 or newer and `git` (`gato create` lists the kit files with `git ls-files`).
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
- 1. **Checks Node** against the supported range (`>=22`). An unsupported Node stops the command before
16
- anything is downloaded, with a message saying whether it is too old or too new. `--skip-install` (or `--no-install`)
17
- turns the refusal into a warning, because nothing is installed then. `--yes` does not bypass the check.
18
- 2. **Picks the kit version:** `--kit-version <x.y.z>`, or the highest `v<x.y.z>` tag of `webamigos/gatojs`
19
- (GitHub tags API; prerelease and other tags are ignored).
20
- 3. **Downloads the kit** tag tarball into a temporary directory and extracts it with the system `tar`. No clone, no git
21
- history.
22
- 4. **Runs `gato create`** from the `gato-cli` package that `create-gato-app` depends on at an exact version
23
- (`node <gato-cli>/dist/gato.mjs create <dir> … --kit <kit>`), with your terminal attached, so its prompts and flags
24
- work exactly as documented for `gato create`. The exit code is `gato create`'s. The new project gets
25
- `"gato-cli": "^<that version>"` in `devDependencies`. The kit's own `.wa/bin/wa.mjs` is not used.
26
- 5. **Removes the temporary directory**, also when something fails.
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
- Flags of `create-gato-app` itself:
31
-
32
- | Flag | Meaning |
33
- | ----------------------- | ------------------------------------------------------------------------------------------------------------------- |
34
- | `--kit-version <x.y.z>` | Kit version (tag `v<x.y.z>`). Default: the highest `v<x.y.z>` tag. |
35
- | `--kit <path>` | Use a local kit checkout instead of downloading one (kit development, CI). Cannot be combined with `--kit-version`. |
36
- | `--skip-install` | Write files only: passes `--no-install` to `gato create` and turns the Node refusal into a warning. |
37
- | `--help`, `-h` | Print usage. |
38
- | `--version`, `-v` | Print the `create-gato-app` version. |
39
-
40
- Every other argument goes to `gato create` unchanged, for example:
41
-
42
- | Flag | Meaning |
43
- | ----------------------- | ------------------------------------------------------------- |
44
- | `--modules a,b` | Kit modules besides the core (`--modules ""` = core only). |
45
- | `--locales pl,en` | App locales (`pl` required). |
46
- | `--title <text>` | Display name. |
47
- | `--admin-email <email>` | First admin's email. |
48
- | `--yes` | No questions; defaults for everything not given. |
49
- | `--setup` | After install: start the database, migrate, create the admin. |
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 --yes --modules uploads,api-keys
58
- npx create-gato-app my-app --kit-version 0.1.0 --skip-install
59
- npx create-gato-app my-app --kit ../gatojs --yes --no-install --no-git
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
- This version installs a project; it is not the full wizard yet. Planned (spec
87
- `docs/superpowers/specs/2026-11-21-gato-cli-design.md` §5–§7 in the GatoJS repository):
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 (one with `--cli-source <gato-cli tarball>`, one without), and checks versions, the `gato-cli`
107
- tarball's file list and the exact pin. `SMOKE_INSTALL=1` also runs `npm install` in the project and checks that its
108
- `gato` is the packed one. CI runs the same script in `.github/workflows/packages.yml`.
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 and runs `gato create` from gato-cli.",
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
- "Options of create-gato-app:",
7
- " --kit-version <x.y.z> kit version (tag v<x.y.z>); default: the highest v<x.y.z> tag",
8
- " --kit <path> use a local kit checkout instead of downloading one",
9
- " --skip-install write files only (passes --no-install); Node check only warns",
10
- " -h, --help print this help",
11
- " -v, --version print the create-gato-app version",
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
- "Other options go to `gato create`: --modules a,b --locales pl,en --title <text>",
14
- " --admin-email <email> --yes --setup --no-install --no-git",
15
- " --cli-source <tarball> (the project's gato-cli from a packed tarball, for CI)",
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 GATO_CREATE_VALUE_OPTIONS = new Set([
21
- "--modules",
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
- function ownValueFlagOf(arg) {
34
- for (const flag of ["--kit-version", "--kit"]) {
35
- if (arg === flag || arg.startsWith(`${flag}=`)) {
36
- return flag;
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 null;
127
+ return value;
40
128
  }
41
129
  function parseKitVersion(value) {
42
- const match = KIT_VERSION_PATTERN.exec(value);
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 "${value}"`);
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 = new Map();
56
- const passthrough = [];
57
- const positionals = [];
58
- let install = true;
59
- for (let index = 0; index < argv.length; index += 1) {
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 kitVersion = kitVersionValue === undefined ? null : parseKitVersion(kitVersionValue);
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
- return { kind: "create", target, kitVersion, kitPath, install, passthrough };
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
  }
@@ -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
+ };