create-gato-app 0.2.0 → 0.3.4

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
@@ -25,14 +25,18 @@ The order follows the rule "refuse before anything is written":
25
25
  3. **Downloads the kit** tag tarball into a temporary directory (no clone, no history), removed at the end.
26
26
  4. **Asks the questions** (defaults with `--yes`): modules with their descriptions from that kit version, locales,
27
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.
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
30
  5. **Assembles the project** with the `gato-cli` version `create-gato-app` pins
31
31
  (`node <gato-cli>/dist/gato.mjs create … --yes --no-install --no-git`). The project gets
32
32
  `"gato-cli": "^<that version>"` in `devDependencies`.
33
33
  6. **Writes `.env`**: every manifest variable with a `generate` field (`BETTER_AUTH_SECRET`, `API_KEY_PEPPER`, …)
34
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.
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.
36
40
  7. **Starts Docker** (unless `--skip-docker`, `--skip-install` or "no" to setup): probes every port
37
41
  `docker-compose.yml` publishes for the services it starts (plus the `s3` profile for a local MinIO). A busy port
38
42
  stops this step with the `*_PORT` variables to set in `.env` (and the URLs that use them); otherwise
@@ -60,6 +64,12 @@ migration); the project stays in place and the next steps say how to continue.
60
64
  | `--s3-endpoint <url>` | S3 endpoint (default `http://localhost:9000`, local MinIO). |
61
65
  | `--s3-access-key-id <id>` | S3 access key id (needed with `--yes` and a non-local endpoint). |
62
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`). |
63
73
  | `--yes` | Ask nothing; defaults for everything not given (setup included). |
64
74
  | `--setup` | Set up the database without asking. |
65
75
  | `--skip-docker` | Do not start Docker (and so no migration or admin). |
@@ -78,6 +88,8 @@ npx create-gato-app my-app
78
88
  npx create-gato-app my-app --yes --modules uploads,api-keys --admin-email you@example.com
79
89
  npx create-gato-app my-app --yes --modules uploads --storage s3 \
80
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 …
81
93
  npx create-gato-app my-app --kit ../gatojs --yes --skip-install --no-git
82
94
  ```
83
95
 
@@ -113,7 +125,9 @@ SMOKE_INSTALL=1 bash packages/create-gato-app/scripts/smoke-pack.sh "$PWD"
113
125
 
114
126
  The smoke script packs `gato-cli` and `create-gato-app`, installs both tarballs into an empty prefix, creates projects
115
127
  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`.
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.
117
131
  `SMOKE_INSTALL=1` also lets the wizard install a project with `--skip-docker` (one commit, clean tree), checks that the
118
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`.
119
133
 
package/dist/args.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { isHttpUrl, LOCAL_MINIO_ENDPOINT } from "./questions.js";
3
- import { adminEmailError, envValueError, titleError } from "./validate.js";
3
+ import { adminEmailError, envValueError, parsePort, PORT_ERROR, titleError, } from "./validate.js";
4
4
  export const USAGE = [
5
5
  "Usage: create-gato-app <dir> [options]",
6
6
  "",
@@ -16,6 +16,13 @@ export const USAGE = [
16
16
  " --s3-endpoint <url> S3 endpoint (default http://localhost:9000, local MinIO)",
17
17
  " --s3-access-key-id <id> S3 access key id",
18
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",
19
26
  "",
20
27
  "Steps:",
21
28
  " --yes accept defaults, ask nothing",
@@ -48,6 +55,13 @@ const S3_FLAGS = [
48
55
  "s3-access-key-id",
49
56
  "s3-secret-access-key",
50
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"];
51
65
  const OPTIONS = {
52
66
  help: { type: "boolean", short: "h" },
53
67
  version: { type: "boolean", short: "v" },
@@ -59,6 +73,12 @@ const OPTIONS = {
59
73
  "s3-endpoint": { type: "string" },
60
74
  "s3-access-key-id": { type: "string" },
61
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" },
62
82
  yes: { type: "boolean" },
63
83
  setup: { type: "boolean" },
64
84
  "skip-docker": { type: "boolean" },
@@ -171,6 +191,55 @@ function parseStorage(values) {
171
191
  s3SecretAccessKey: checked(values["s3-secret-access-key"], "--s3-secret-access-key", (value) => envValueError("S3 secret access key", value)),
172
192
  };
173
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
+ }
174
243
  function assertExternalS3Keys(args) {
175
244
  const external = args.s3Endpoint !== null && args.s3Endpoint !== LOCAL_MINIO_ENDPOINT;
176
245
  if (args.yes &&
@@ -227,7 +296,9 @@ export function parseCliArgs(argv) {
227
296
  git: !values["no-git"],
228
297
  cliSource: nonEmpty(values["cli-source"], "--cli-source"),
229
298
  ...parseStorage(values),
299
+ ...parseMail(values),
230
300
  };
231
301
  assertExternalS3Keys(args);
302
+ assertMailCredentials(args);
232
303
  return args;
233
304
  }
package/dist/clack-ui.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console -- the terminal UI: the console is its output */
1
2
  import * as clack from "@clack/prompts";
2
3
  import { CancelledError } from "./questions.js";
3
4
  function answered(value) {
package/dist/env-file.js CHANGED
@@ -45,10 +45,39 @@ function storageValues(storage) {
45
45
  S3_SECRET_ACCESS_KEY: storage.secretAccessKey,
46
46
  };
47
47
  }
48
+ function smtpAuthValues(user, pass) {
49
+ return user === null ? {} : { SMTP_USER: user, SMTP_PASS: pass ?? "" };
50
+ }
51
+ function mailValues(mail) {
52
+ if (mail.provider === "console") {
53
+ return { MAIL_PROVIDER: "console", SMTP_URL: "" };
54
+ }
55
+ if (mail.provider === "resend") {
56
+ return {
57
+ MAIL_PROVIDER: "resend",
58
+ RESEND_API_KEY: mail.apiKey,
59
+ SMTP_URL: "",
60
+ };
61
+ }
62
+ if (mail.localMailpit) {
63
+ return {};
64
+ }
65
+ return {
66
+ MAIL_PROVIDER: "smtp",
67
+ SMTP_URL: "",
68
+ SMTP_HOST: mail.host,
69
+ SMTP_PORT: String(mail.port),
70
+ ...smtpAuthValues(mail.user, mail.pass),
71
+ };
72
+ }
48
73
  export function wizardEnvValues(input) {
49
74
  const values = {};
50
75
  if (readEnvValue(input.existing, COMPOSE_PROJECT_NAME) === null) {
51
76
  values[COMPOSE_PROJECT_NAME] = composeProjectName(input.slug, input.suffix);
52
77
  }
53
- return { ...values, ...storageValues(input.storage) };
78
+ return {
79
+ ...values,
80
+ ...storageValues(input.storage),
81
+ ...mailValues(input.mail),
82
+ };
54
83
  }
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console -- the CLI entry point: the console is its output */
2
3
  import { randomBytes } from "node:crypto";
3
4
  import { readFileSync } from "node:fs";
4
5
  import { createRequire } from "node:module";
package/dist/questions.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { withRequired } from "./kit-modules.js";
2
- import { adminEmailError, envValueError, titleError } from "./validate.js";
2
+ import { adminEmailError, envValueError, parsePort, PORT_ERROR, titleError, } from "./validate.js";
3
3
  export const LOCAL_MINIO_ENDPOINT = "http://localhost:9000";
4
4
  export const LOCAL_MINIO_KEY = "minioadmin";
5
5
  export const HTTP_URL_ERROR = "expected an http(s) URL";
6
+ export const LOCAL_MAILPIT_HOST = "127.0.0.1";
7
+ export const DEFAULT_SMTP_PORT = 587;
6
8
  export class CancelledError extends Error {
7
9
  name = "CancelledError";
8
10
  }
@@ -148,6 +150,113 @@ async function askStorage(context, modules) {
148
150
  }
149
151
  return provider === "s3" ? askS3(context) : { provider: "local" };
150
152
  }
153
+ function optionalEnvValue(label, value) {
154
+ return value.trim() === ""
155
+ ? undefined
156
+ : orUndefined(envValueError(label, value.trim()));
157
+ }
158
+ async function askMailProvider({ args, prompter, ask, }) {
159
+ if (args.mailProvider !== null) {
160
+ return args.mailProvider;
161
+ }
162
+ if (!ask) {
163
+ return "smtp";
164
+ }
165
+ return prompter.select({
166
+ message: "How should the app send mail?",
167
+ options: [
168
+ {
169
+ value: "smtp",
170
+ label: "smtp",
171
+ hint: "local mailpit in development, or your own relay",
172
+ },
173
+ { value: "resend", label: "resend", hint: "Resend API key" },
174
+ {
175
+ value: "console",
176
+ label: "console",
177
+ hint: "send nothing, log emails to the console",
178
+ },
179
+ ],
180
+ initialValue: "smtp",
181
+ });
182
+ }
183
+ async function askSmtpHost({ args, prompter, ask }) {
184
+ if (args.smtpHost !== null) {
185
+ return args.smtpHost;
186
+ }
187
+ if (!ask) {
188
+ return LOCAL_MAILPIT_HOST;
189
+ }
190
+ const host = await prompter.text({
191
+ message: `SMTP host (${LOCAL_MAILPIT_HOST} = local mailpit started with Docker)`,
192
+ defaultValue: LOCAL_MAILPIT_HOST,
193
+ placeholder: LOCAL_MAILPIT_HOST,
194
+ validate: (value) => optionalEnvValue("SMTP host", value),
195
+ });
196
+ return host.trim() || LOCAL_MAILPIT_HOST;
197
+ }
198
+ async function askSmtpPort({ args, prompter, ask }) {
199
+ if (args.smtpPort !== null) {
200
+ return args.smtpPort;
201
+ }
202
+ if (!ask) {
203
+ return DEFAULT_SMTP_PORT;
204
+ }
205
+ const port = await prompter.text({
206
+ message: "SMTP port",
207
+ defaultValue: String(DEFAULT_SMTP_PORT),
208
+ placeholder: String(DEFAULT_SMTP_PORT),
209
+ validate: (value) => value.trim() === "" || parsePort(value.trim()) !== null
210
+ ? undefined
211
+ : `SMTP port: ${PORT_ERROR}`,
212
+ });
213
+ return parsePort(port.trim()) ?? DEFAULT_SMTP_PORT;
214
+ }
215
+ async function askSmtpUser({ args, prompter, ask, }) {
216
+ if (args.smtpUser !== null) {
217
+ return args.smtpUser;
218
+ }
219
+ if (!ask) {
220
+ return null;
221
+ }
222
+ const user = (await prompter.text({
223
+ message: "SMTP user (empty = no authentication)",
224
+ defaultValue: "",
225
+ validate: (value) => optionalEnvValue("SMTP user", value),
226
+ })).trim();
227
+ return user === "" ? null : user;
228
+ }
229
+ async function askSmtp(context) {
230
+ const host = await askSmtpHost(context);
231
+ if (host === LOCAL_MAILPIT_HOST) {
232
+ return { provider: "smtp", localMailpit: true };
233
+ }
234
+ const port = await askSmtpPort(context);
235
+ const user = await askSmtpUser(context);
236
+ const pass = user === null
237
+ ? null
238
+ : (context.args.smtpPass ??
239
+ (await context.prompter.password({
240
+ message: "SMTP password",
241
+ validate: (value) => orUndefined(envValueError("SMTP password", value)),
242
+ })));
243
+ return { provider: "smtp", localMailpit: false, host, port, user, pass };
244
+ }
245
+ async function askMail(context) {
246
+ const provider = await askMailProvider(context);
247
+ if (provider === "console") {
248
+ return { provider: "console" };
249
+ }
250
+ if (provider === "smtp") {
251
+ return askSmtp(context);
252
+ }
253
+ const apiKey = context.args.resendApiKey ??
254
+ (await context.prompter.password({
255
+ message: "Resend API key",
256
+ validate: (value) => orUndefined(envValueError("Resend API key", value)),
257
+ }));
258
+ return { provider: "resend", apiKey };
259
+ }
151
260
  async function askSetup({ args, prompter, ask }) {
152
261
  if (!args.install || !args.docker) {
153
262
  return false;
@@ -171,6 +280,7 @@ export async function collectAnswers(input) {
171
280
  const title = await askTitle(context, input.slug);
172
281
  const adminEmail = await askAdminEmail(context);
173
282
  const storage = await askStorage(context, modules);
283
+ const mail = await askMail(context);
174
284
  const setup = await askSetup(context);
175
- return { modules, locales, title, adminEmail, storage, setup };
285
+ return { modules, locales, title, adminEmail, storage, mail, setup };
176
286
  }
package/dist/validate.js CHANGED
@@ -37,3 +37,13 @@ export function envValueError(label, value) {
37
37
  }
38
38
  return null;
39
39
  }
40
+ export const PORT_ERROR = "expected a port 1-65535";
41
+ const MAX_PORT = 65535;
42
+ const DIGITS = /^\d+$/;
43
+ export function parsePort(value) {
44
+ if (!DIGITS.test(value)) {
45
+ return null;
46
+ }
47
+ const port = Number(value);
48
+ return port >= 1 && port <= MAX_PORT ? port : null;
49
+ }
package/dist/wizard.js CHANGED
@@ -55,6 +55,7 @@ async function writeWizardEnv(context, answers) {
55
55
  slug: basename(context.projectDir),
56
56
  suffix: randomSuffix(context.deps.randomBytes(SUFFIX_LENGTH)),
57
57
  storage: answers.storage,
58
+ mail: answers.mail,
58
59
  }));
59
60
  await writeFile(envPath, text, { mode: 0o600 });
60
61
  await chmod(envPath, 0o600);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-gato-app",
3
- "version": "0.2.0",
3
+ "version": "0.3.4",
4
4
  "description": "Create a GatoJS project (Next.js kit) with one command",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -49,20 +49,18 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@clack/prompts": "^1.9.0",
52
- "gato-cli": "0.3.0"
52
+ "gato-cli": "0.7.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@eslint/js": "^9.39.5",
56
55
  "@fast-check/vitest": "^0.5.0",
56
+ "@gatojs/eslint-config": "*",
57
57
  "@stryker-mutator/core": "^10.1.1",
58
58
  "@stryker-mutator/typescript-checker": "^10.1.1",
59
59
  "@stryker-mutator/vitest-runner": "^10.1.1",
60
60
  "@types/node": "^22",
61
61
  "eslint": "^9.39.5",
62
62
  "fast-check": "^4.10.3",
63
- "globals": "^17.14.0",
64
63
  "typescript": "^5",
65
- "typescript-eslint": "^8.73.0",
66
64
  "vitest": "^4.1.2"
67
65
  }
68
66
  }