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/dist/cli.js CHANGED
@@ -1,30 +1,49 @@
1
+ import { existsSync } from "node:fs";
2
+ import { readdir } from "node:fs/promises";
1
3
  import { resolve } from "node:path";
2
4
  import { parseCliArgs, USAGE } from "./args.js";
3
- import { gatoCreateCommand } from "./delegate.js";
4
- import { GitHubTokenRejectedError, resolveKitVersion, resolveToken, } from "./github.js";
5
+ import { fetchKitPackageJson, GitHubTokenRejectedError, resolveKitVersion, resolveToken, } from "./github.js";
5
6
  import { downloadKit } from "./kit-download.js";
7
+ import { nodeRangesFromPackageJson, readKitPackageJson, } from "./kit-engines.js";
6
8
  import { checkNodeVersion } from "./node-version.js";
7
9
  import { assertProjectName } from "./project-name.js";
8
- async function delegate(deps, kitDir, passthrough) {
9
- const { command, args } = gatoCreateCommand({
10
- nodePath: deps.nodePath,
11
- gatoBin: deps.gatoBin,
12
- kitDir,
13
- passthrough,
14
- });
15
- const result = await deps.spawn(command, args, {
16
- cwd: deps.cwd,
17
- stdio: "inherit",
10
+ import { CancelledError } from "./questions.js";
11
+ import { runWizard } from "./wizard.js";
12
+ const TOKEN_RETRY_WARNING = "GitHub rejected the token (401); retrying without it.";
13
+ const NO_TERMINAL = "No terminal for questions: pass --yes to accept defaults (and flags such as --modules or --admin-email for the rest).";
14
+ const CANCELLED = "Cancelled; nothing was written.";
15
+ class StopError extends Error {
16
+ name = "StopError";
17
+ }
18
+ function checkNode(deps, args, packageJson) {
19
+ const { ranges, warning } = nodeRangesFromPackageJson(packageJson);
20
+ if (warning !== null) {
21
+ deps.error(warning);
22
+ }
23
+ const verdict = checkNodeVersion({
24
+ version: deps.nodeVersion,
25
+ willInstall: args.install,
26
+ ranges,
18
27
  });
19
- return result.code;
28
+ if (verdict.kind === "refuse") {
29
+ throw new StopError(verdict.message);
30
+ }
31
+ if (verdict.kind === "warn") {
32
+ deps.error(verdict.message);
33
+ }
20
34
  }
21
- const TOKEN_RETRY_WARNING = "GitHub rejected the token (401); retrying without it.";
22
- async function downloadAndDelegate(deps, requested, passthrough, token) {
35
+ async function assertEmptyTarget(projectDir) {
36
+ if (existsSync(projectDir) && (await readdir(projectDir)).length > 0) {
37
+ throw new StopError(`Directory ${projectDir} exists and is not empty; choose another name or empty it.`);
38
+ }
39
+ }
40
+ async function downloadAndRun(deps, args, projectDir, token) {
23
41
  const version = await resolveKitVersion({
24
- requested,
42
+ requested: args.kitVersion,
25
43
  fetch: deps.fetch,
26
44
  token,
27
45
  });
46
+ checkNode(deps, args, await fetchKitPackageJson({ fetch: deps.fetch, token, version }));
28
47
  deps.log(`Downloading GatoJS kit v${version}…`);
29
48
  const workDir = await deps.makeTempDir();
30
49
  try {
@@ -35,19 +54,19 @@ async function downloadAndDelegate(deps, requested, passthrough, token) {
35
54
  spawn: deps.spawn,
36
55
  workDir,
37
56
  });
38
- return await delegate(deps, kitDir, passthrough);
57
+ return await runWizard(deps, args, kitDir, projectDir);
39
58
  }
40
59
  finally {
41
60
  await deps.removeDir(workDir);
42
61
  }
43
62
  }
44
- async function createFromDownload(deps, requested, passthrough) {
63
+ async function createFromDownload(deps, args, projectDir) {
45
64
  const token = await resolveToken({
46
65
  env: deps.env,
47
66
  ghAuthToken: deps.ghAuthToken,
48
67
  });
49
68
  try {
50
- return await downloadAndDelegate(deps, requested, passthrough, token);
69
+ return await downloadAndRun(deps, args, projectDir, token);
51
70
  }
52
71
  catch (error) {
53
72
  if (!(error instanceof GitHubTokenRejectedError)) {
@@ -55,9 +74,23 @@ async function createFromDownload(deps, requested, passthrough) {
55
74
  }
56
75
  // WHY: the kit repository is public, so a stale or wrong token should not block the download.
57
76
  deps.error(TOKEN_RETRY_WARNING);
58
- return await downloadAndDelegate(deps, requested, passthrough, null);
77
+ return await downloadAndRun(deps, args, projectDir, null);
59
78
  }
60
79
  }
80
+ async function create(deps, args) {
81
+ assertProjectName(deps.cwd, args.target);
82
+ const projectDir = resolve(deps.cwd, args.target);
83
+ await assertEmptyTarget(projectDir);
84
+ if (!args.yes && !deps.interactive) {
85
+ throw new StopError(NO_TERMINAL);
86
+ }
87
+ if (args.kitPath === null) {
88
+ return createFromDownload(deps, args, projectDir);
89
+ }
90
+ const kitDir = resolve(deps.cwd, args.kitPath);
91
+ checkNode(deps, args, await readKitPackageJson(kitDir));
92
+ return runWizard(deps, args, kitDir, projectDir);
93
+ }
61
94
  export async function run(argv, deps) {
62
95
  try {
63
96
  const args = parseCliArgs(argv);
@@ -69,24 +102,13 @@ export async function run(argv, deps) {
69
102
  deps.log(deps.packageVersion);
70
103
  return 0;
71
104
  }
72
- assertProjectName(deps.cwd, args.target);
73
- const verdict = checkNodeVersion({
74
- version: deps.nodeVersion,
75
- willInstall: args.install,
76
- });
77
- if (verdict.kind === "refuse") {
78
- deps.error(verdict.message);
79
- return 1;
80
- }
81
- if (verdict.kind === "warn") {
82
- deps.error(verdict.message);
83
- }
84
- if (args.kitPath !== null) {
85
- return await delegate(deps, resolve(deps.cwd, args.kitPath), args.passthrough);
86
- }
87
- return await createFromDownload(deps, args.kitVersion, args.passthrough);
105
+ return await create(deps, args);
88
106
  }
89
107
  catch (error) {
108
+ if (error instanceof CancelledError) {
109
+ deps.error(CANCELLED);
110
+ return 1;
111
+ }
90
112
  deps.error(error instanceof Error ? error.message : String(error));
91
113
  return 1;
92
114
  }
@@ -0,0 +1,6 @@
1
+ export function compareNames(a, b) {
2
+ if (a < b) {
3
+ return -1;
4
+ }
5
+ return a > b ? 1 : 0;
6
+ }
@@ -0,0 +1,137 @@
1
+ export const FREE_PORT_SEARCH_LIMIT = 100;
2
+ const MAX_PORT = 65535;
3
+ const SERVICE_LINE = /^ {2}([A-Za-z0-9_.-]+):\s*$/;
4
+ const TOP_LEVEL_LINE = /^\S/;
5
+ const PROFILES_LINE = /^ {4}profiles:\s*\[(.*)\]\s*$/;
6
+ const PORTS_LINE = /^ {4}ports:\s*$/;
7
+ const KEY_LINE = /^ {4}\S/;
8
+ const PORT_ITEM = /^\s+-\s*["']?(?:\$\{([A-Za-z0-9_]+):-(\d+)\}|(\d+)):\d+(?:\/\w+)?["']?\s*$/;
9
+ const DIGITS = /^\d+$/;
10
+ function parseProfiles(list) {
11
+ return list
12
+ .split(",")
13
+ .map((item) => item.trim().replace(/^["']|["']$/g, ""))
14
+ .filter((item) => item !== "");
15
+ }
16
+ function portFor(variable, fallback, env) {
17
+ const override = env[variable];
18
+ if (override !== undefined && DIGITS.test(override)) {
19
+ return Number(override);
20
+ }
21
+ return Number(fallback);
22
+ }
23
+ function parseServices(composeText, env) {
24
+ const services = [];
25
+ let inServices = false;
26
+ let current = null;
27
+ let inPorts = false;
28
+ for (const line of composeText.split(/\r?\n/)) {
29
+ if (TOP_LEVEL_LINE.test(line)) {
30
+ inServices = line.startsWith("services:");
31
+ current = null;
32
+ inPorts = false;
33
+ continue;
34
+ }
35
+ if (!inServices) {
36
+ continue;
37
+ }
38
+ const service = SERVICE_LINE.exec(line);
39
+ if (service) {
40
+ current = { name: service[1], profiles: [], ports: [] };
41
+ services.push(current);
42
+ inPorts = false;
43
+ continue;
44
+ }
45
+ if (current === null) {
46
+ continue;
47
+ }
48
+ const profiles = PROFILES_LINE.exec(line);
49
+ if (profiles) {
50
+ current.profiles = parseProfiles(profiles[1]);
51
+ inPorts = false;
52
+ continue;
53
+ }
54
+ if (PORTS_LINE.test(line)) {
55
+ inPorts = true;
56
+ continue;
57
+ }
58
+ if (KEY_LINE.test(line)) {
59
+ inPorts = false;
60
+ continue;
61
+ }
62
+ const item = inPorts ? PORT_ITEM.exec(line) : null;
63
+ if (item) {
64
+ const [, variable, fallback, literal] = item;
65
+ current.ports.push(variable === undefined
66
+ ? { service: current.name, variable: null, port: Number(literal) }
67
+ : {
68
+ service: current.name,
69
+ variable,
70
+ port: portFor(variable, fallback, env),
71
+ });
72
+ }
73
+ }
74
+ return services;
75
+ }
76
+ export function publishedPorts(composeText, input) {
77
+ return parseServices(composeText, input.env)
78
+ .filter((service) => service.profiles.length === 0 ||
79
+ service.profiles.some((profile) => input.profiles.includes(profile)))
80
+ .flatMap((service) => service.ports);
81
+ }
82
+ export async function suggestFreePort(port, isPortBusy, taken) {
83
+ const last = Math.min(port + FREE_PORT_SEARCH_LIMIT, MAX_PORT);
84
+ for (let candidate = port + 1; candidate <= last; candidate += 1) {
85
+ if (!taken.includes(candidate) && !(await isPortBusy(candidate))) {
86
+ return candidate;
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ function hostPortPattern(port) {
92
+ return new RegExp(`((?:localhost|127\\.0\\.0\\.1):)${port}(?!\\d)`, "g");
93
+ }
94
+ function dependentLines(envText, from, to) {
95
+ const lines = [];
96
+ for (const line of envText.split(/\r?\n/)) {
97
+ const separator = line.indexOf("=");
98
+ if (separator <= 0 || line.startsWith("#")) {
99
+ continue;
100
+ }
101
+ const pattern = hostPortPattern(from);
102
+ if (pattern.test(line.slice(separator + 1))) {
103
+ const value = line
104
+ .slice(separator + 1)
105
+ .replace(hostPortPattern(from), `$1${to}`);
106
+ lines.push(`${line.slice(0, separator)}=${value}`);
107
+ }
108
+ }
109
+ return lines;
110
+ }
111
+ export function portSettings(input) {
112
+ const settings = [];
113
+ for (const { variable, port } of input.busy) {
114
+ if (variable === null) {
115
+ continue;
116
+ }
117
+ const free = input.free.get(port) ?? null;
118
+ if (free === null) {
119
+ settings.push(`${variable}=<free port>`);
120
+ continue;
121
+ }
122
+ settings.push(`${variable}=${free}`, ...dependentLines(input.envText, port, free));
123
+ }
124
+ return settings;
125
+ }
126
+ export function busyPortsReport(busy, settings) {
127
+ const lines = busy.map(({ service, variable, port }) => {
128
+ const owner = variable === null
129
+ ? `service ${service}`
130
+ : `${variable}, service ${service}`;
131
+ return `Port ${port} (${owner}) is already in use, so the Docker services were not started.`;
132
+ });
133
+ if (settings.length > 0) {
134
+ lines.push("Set free ports in .env, then run the remaining steps below:", ...settings.map((setting) => ` ${setting}`));
135
+ }
136
+ return lines;
137
+ }
package/dist/delegate.js CHANGED
@@ -1,12 +1,22 @@
1
1
  export function gatoCreateCommand(input) {
2
- return {
3
- command: input.nodePath,
4
- args: [
5
- input.gatoBin,
6
- "create",
7
- ...input.passthrough,
8
- "--kit",
9
- input.kitDir,
10
- ],
11
- };
2
+ const { answers } = input;
3
+ const args = [
4
+ input.gatoBin,
5
+ "create",
6
+ input.projectDir,
7
+ "--yes",
8
+ "--no-install",
9
+ "--no-git",
10
+ `--modules=${answers.modules.join(",")}`,
11
+ `--locales=${answers.locales.join(",")}`,
12
+ `--title=${answers.title}`,
13
+ ];
14
+ if (answers.adminEmail !== null) {
15
+ args.push(`--admin-email=${answers.adminEmail}`);
16
+ }
17
+ if (input.cliSource !== null) {
18
+ args.push(`--cli-source=${input.cliSource}`);
19
+ }
20
+ args.push(`--kit=${input.kitDir}`);
21
+ return { command: input.nodePath, args };
12
22
  }
@@ -0,0 +1,83 @@
1
+ export const SUFFIX_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
2
+ export const SUFFIX_LENGTH = 6;
3
+ const COMPOSE_PROJECT_NAME = "COMPOSE_PROJECT_NAME";
4
+ function escapeRegExp(text) {
5
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6
+ }
7
+ function linePattern(key) {
8
+ return new RegExp(`^${escapeRegExp(key)}=.*$`, "m");
9
+ }
10
+ export function setEnvValues(text, values) {
11
+ let result = text;
12
+ for (const [key, value] of Object.entries(values)) {
13
+ const line = `${key}=${value}`;
14
+ const pattern = linePattern(key);
15
+ if (pattern.test(result)) {
16
+ result = result.replace(pattern, () => line);
17
+ continue;
18
+ }
19
+ const separator = result === "" || result.endsWith("\n") ? "" : "\n";
20
+ result = `${result}${separator}${line}\n`;
21
+ }
22
+ return result;
23
+ }
24
+ export function readEnvValue(text, key) {
25
+ const match = linePattern(key).exec(text);
26
+ return match === null ? null : match[0].slice(key.length + 1);
27
+ }
28
+ export function randomSuffix(bytes) {
29
+ return Array.from(bytes.slice(0, SUFFIX_LENGTH), (byte) => SUFFIX_ALPHABET.charAt(byte % SUFFIX_ALPHABET.length)).join("");
30
+ }
31
+ export function composeProjectName(slug, suffix) {
32
+ return `${slug}-${suffix}`;
33
+ }
34
+ function storageValues(storage) {
35
+ if (storage === null) {
36
+ return {};
37
+ }
38
+ if (storage.provider === "local") {
39
+ return { STORAGE_PROVIDER: "local" };
40
+ }
41
+ return {
42
+ STORAGE_PROVIDER: "s3",
43
+ S3_ENDPOINT: storage.endpoint,
44
+ S3_ACCESS_KEY_ID: storage.accessKeyId,
45
+ S3_SECRET_ACCESS_KEY: storage.secretAccessKey,
46
+ };
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
+ }
73
+ export function wizardEnvValues(input) {
74
+ const values = {};
75
+ if (readEnvValue(input.existing, COMPOSE_PROJECT_NAME) === null) {
76
+ values[COMPOSE_PROJECT_NAME] = composeProjectName(input.slug, input.suffix);
77
+ }
78
+ return {
79
+ ...values,
80
+ ...storageValues(input.storage),
81
+ ...mailValues(input.mail),
82
+ };
83
+ }
package/dist/github.js CHANGED
@@ -111,3 +111,31 @@ export async function fetchKitTarball(input) {
111
111
  const response = await request(input.fetch, tarballUrl(input.version, input.token), input.token, `kit v${input.version}`);
112
112
  return new Uint8Array(await response.arrayBuffer());
113
113
  }
114
+ export function packageJsonUrl(version) {
115
+ return `https://api.github.com/repos/${KIT_REPO}/contents/package.json?ref=v${version}`;
116
+ }
117
+ function decodedContent(payload) {
118
+ if (typeof payload !== "object" || payload === null) {
119
+ return null;
120
+ }
121
+ const { encoding, content } = payload;
122
+ if (encoding !== "base64" || typeof content !== "string") {
123
+ return null;
124
+ }
125
+ return Buffer.from(content.replace(/\s/g, ""), "base64").toString("utf8");
126
+ }
127
+ export async function fetchKitPackageJson(input) {
128
+ const what = `package.json of kit v${input.version}`;
129
+ const response = await request(input.fetch, packageJsonUrl(input.version), input.token, what);
130
+ const text = decodedContent(await response.json());
131
+ const unexpected = `GitHub returned an unexpected package.json for kit v${input.version}`;
132
+ if (text === null) {
133
+ throw new Error(unexpected);
134
+ }
135
+ try {
136
+ return JSON.parse(text);
137
+ }
138
+ catch (error) {
139
+ throw new Error(unexpected, { cause: error });
140
+ }
141
+ }
package/dist/index.js CHANGED
@@ -1,15 +1,20 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console -- the CLI entry point: the console is its output */
3
+ import { randomBytes } from "node:crypto";
2
4
  import { readFileSync } from "node:fs";
3
5
  import { createRequire } from "node:module";
4
6
  import { mkdtemp, rm } from "node:fs/promises";
5
7
  import { tmpdir } from "node:os";
6
8
  import { join } from "node:path";
9
+ import { clackPrompter, clackUi, plainUi } from "./clack-ui.js";
7
10
  import { run } from "./cli.js";
8
11
  import { gatoBinPath } from "./gato-bin.js";
12
+ import { isPortBusy } from "./port-probe.js";
9
13
  import { ghAuthToken, spawnProcess } from "./process.js";
10
14
  const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
11
15
  const gatoPackageJsonPath = createRequire(import.meta.url).resolve("gato-cli/package.json");
12
16
  const gatoBin = gatoBinPath(gatoPackageJsonPath, JSON.parse(readFileSync(gatoPackageJsonPath, "utf8")));
17
+ const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
13
18
  run(process.argv.slice(2), {
14
19
  nodeVersion: process.version,
15
20
  nodePath: process.execPath,
@@ -22,6 +27,11 @@ run(process.argv.slice(2), {
22
27
  ghAuthToken,
23
28
  makeTempDir: () => mkdtemp(join(tmpdir(), "create-gato-app-")),
24
29
  removeDir: (dir) => rm(dir, { recursive: true, force: true }),
30
+ interactive,
31
+ prompter: clackPrompter,
32
+ ui: process.stdout.isTTY ? clackUi : plainUi,
33
+ isPortBusy,
34
+ randomBytes: (size) => randomBytes(size),
25
35
  log: (line) => console.log(line),
26
36
  error: (line) => console.error(line),
27
37
  }).then((code) => {
@@ -0,0 +1,39 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { enginesRange, parseEnginesRange, SUPPORTED_NODE_RANGES, } from "./node-version.js";
4
+ function enginesNodeOf(packageJson) {
5
+ if (typeof packageJson !== "object" || packageJson === null) {
6
+ return undefined;
7
+ }
8
+ const engines = packageJson.engines;
9
+ if (typeof engines !== "object" || engines === null) {
10
+ return undefined;
11
+ }
12
+ return engines.node;
13
+ }
14
+ export function nodeRangesFromPackageJson(packageJson) {
15
+ const node = enginesNodeOf(packageJson);
16
+ if (typeof node !== "string") {
17
+ return { ranges: SUPPORTED_NODE_RANGES, warning: null };
18
+ }
19
+ const ranges = parseEnginesRange(node);
20
+ if (ranges === null) {
21
+ return {
22
+ ranges: SUPPORTED_NODE_RANGES,
23
+ warning: `The kit's Node range "${node}" is not one create-gato-app understands; checking against ${enginesRange(SUPPORTED_NODE_RANGES)} instead.`,
24
+ };
25
+ }
26
+ return { ranges, warning: null };
27
+ }
28
+ export async function readKitPackageJson(kitDir) {
29
+ let text;
30
+ try {
31
+ text = await readFile(join(kitDir, "package.json"), "utf8");
32
+ }
33
+ catch (error) {
34
+ throw new Error(`${kitDir} is not a GatoJS checkout (no package.json)`, {
35
+ cause: error,
36
+ });
37
+ }
38
+ return JSON.parse(text);
39
+ }
@@ -0,0 +1,66 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { compareNames } from "./compare.js";
4
+ const CORE = "core";
5
+ function isStringArray(value) {
6
+ return (Array.isArray(value) && value.every((item) => typeof item === "string"));
7
+ }
8
+ export function parseKitModule(raw, file) {
9
+ const invalid = new Error(`${file} is not a valid module manifest`);
10
+ if (typeof raw !== "object" || raw === null) {
11
+ throw invalid;
12
+ }
13
+ const { name, description, requires } = raw;
14
+ if (typeof name !== "string" || name === "") {
15
+ throw invalid;
16
+ }
17
+ if (description !== undefined && typeof description !== "string") {
18
+ throw invalid;
19
+ }
20
+ if (requires !== undefined && !isStringArray(requires)) {
21
+ throw invalid;
22
+ }
23
+ return { name, description: description ?? "", requires: requires ?? [] };
24
+ }
25
+ export async function readKitModules(kitDir) {
26
+ const dir = join(kitDir, "kit/modules");
27
+ const files = (await readdir(dir)).filter((file) => file.endsWith(".json"));
28
+ const modules = [];
29
+ for (const file of files) {
30
+ const relative = `kit/modules/${file}`;
31
+ let raw;
32
+ try {
33
+ raw = JSON.parse(await readFile(join(dir, file), "utf8"));
34
+ }
35
+ catch (error) {
36
+ throw new Error(`${relative} is not a valid module manifest`, {
37
+ cause: error,
38
+ });
39
+ }
40
+ const module = parseKitModule(raw, relative);
41
+ if (module.name !== CORE) {
42
+ modules.push(module);
43
+ }
44
+ }
45
+ return modules.sort((a, b) => compareNames(a.name, b.name));
46
+ }
47
+ export function withRequired(selected, modules) {
48
+ const byName = new Map(modules.map((module) => [module.name, module]));
49
+ const chosen = new Set();
50
+ const pending = selected.filter((name) => name !== CORE);
51
+ while (pending.length > 0) {
52
+ const name = pending.pop();
53
+ const module = byName.get(name);
54
+ if (module === undefined) {
55
+ const available = modules.map((item) => item.name).join(", ");
56
+ throw new Error(`Unknown module "${name}". Available: ${available}.`);
57
+ }
58
+ if (!chosen.has(name)) {
59
+ chosen.add(name);
60
+ pending.push(...module.requires.filter((required) => required !== CORE));
61
+ }
62
+ }
63
+ return modules
64
+ .map((module) => module.name)
65
+ .filter((name) => chosen.has(name));
66
+ }
@@ -0,0 +1,49 @@
1
+ import { isAbsolute, relative } from "node:path";
2
+ const SAFE_WORD = /^[A-Za-z0-9_./@%+=:,-]+$/;
3
+ const ADMIN_EMAIL_PLACEHOLDER = "<your-email>";
4
+ export const MANUAL_COMMIT = 'git add -A && git commit -m "chore: initial commit"';
5
+ export function shellQuote(value) {
6
+ if (SAFE_WORD.test(value)) {
7
+ return value;
8
+ }
9
+ return `'${value.replaceAll("'", "'\\''")}'`;
10
+ }
11
+ export function displayDir(cwd, projectDir) {
12
+ const path = relative(cwd, projectDir);
13
+ if (path === "") {
14
+ return ".";
15
+ }
16
+ return path.startsWith("..") || isAbsolute(path) ? projectDir : path;
17
+ }
18
+ function composeUp(profiles) {
19
+ const flags = profiles
20
+ .map((profile) => `--profile ${shellQuote(profile)} `)
21
+ .join("");
22
+ return `docker compose ${flags}up -d`;
23
+ }
24
+ export function nextSteps(outcome) {
25
+ const steps = [];
26
+ if (outcome.dir !== ".") {
27
+ steps.push(`cd ${shellQuote(outcome.dir)}`);
28
+ }
29
+ if (!outcome.installed) {
30
+ steps.push("npm install");
31
+ }
32
+ if (!outcome.dockerUp) {
33
+ steps.push(composeUp(outcome.profiles));
34
+ }
35
+ if (!outcome.migrated) {
36
+ steps.push("npx prisma migrate dev --name init");
37
+ }
38
+ if (outcome.git && !outcome.committed) {
39
+ steps.push(MANUAL_COMMIT);
40
+ }
41
+ if (!outcome.adminCreated) {
42
+ const email = outcome.adminEmail === null
43
+ ? ADMIN_EMAIL_PLACEHOLDER
44
+ : shellQuote(outcome.adminEmail);
45
+ steps.push(`npm run admin:create -- --email ${email}`);
46
+ }
47
+ steps.push("npm run dev");
48
+ return steps;
49
+ }
@@ -61,6 +61,9 @@ function headline(version, ranges) {
61
61
  if (isAboveAll) {
62
62
  return `Node ${current} is too new: GatoJS supports Node ${supported}.`;
63
63
  }
64
+ if (version.major % 2 === 1) {
65
+ return `Node ${current} is an unsupported odd-numbered release line: GatoJS supports Node ${supported}.`;
66
+ }
64
67
  return `Node ${current} is an unsupported release line: GatoJS supports Node ${supported}.`;
65
68
  }
66
69
  export function checkNodeVersion(input) {
@@ -83,7 +86,7 @@ export function checkNodeVersion(input) {
83
86
  message: [
84
87
  summary,
85
88
  "",
86
- "Stopping before anything is downloaded: `gato create` runs npm install under this Node.",
89
+ "Stopping before anything is downloaded: create-gato-app runs npm install under this Node.",
87
90
  "",
88
91
  ` nvm install ${recommendedMajor} # or fnm, volta, asdf, …`,
89
92
  "",
@@ -91,3 +94,18 @@ export function checkNodeVersion(input) {
91
94
  ].join("\n"),
92
95
  };
93
96
  }
97
+ const ENGINES_PART = /^(\^|>=\s*)(\d+)(?:\.(\d+))?(?:\.(\d+))?$/;
98
+ export function parseEnginesRange(range) {
99
+ const parts = range.split("||").map((part) => part.trim());
100
+ const ranges = [];
101
+ for (const part of parts) {
102
+ const match = ENGINES_PART.exec(part);
103
+ if (!match) {
104
+ return null;
105
+ }
106
+ const major = Number(match[2]);
107
+ const from = `${major}.${Number(match[3] ?? 0)}.${Number(match[4] ?? 0)}`;
108
+ ranges.push(match[1] === "^" ? { from, belowMajor: major + 1 } : { from });
109
+ }
110
+ return ranges.sort((a, b) => compareWithRangeStart(rangeStart(a), rangeStart(b)));
111
+ }