@supatype/cli 0.8.0 → 0.9.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.
Files changed (209) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/bin/supatype.js +16 -1
  3. package/dist/after-hooks-health.d.ts +19 -0
  4. package/dist/after-hooks-health.d.ts.map +1 -0
  5. package/dist/after-hooks-health.js +69 -0
  6. package/dist/after-hooks-health.js.map +1 -0
  7. package/dist/app-vite-env.d.ts +5 -1
  8. package/dist/app-vite-env.d.ts.map +1 -1
  9. package/dist/app-vite-env.js +9 -15
  10. package/dist/app-vite-env.js.map +1 -1
  11. package/dist/augmentation-generator.d.ts +5 -0
  12. package/dist/augmentation-generator.d.ts.map +1 -1
  13. package/dist/augmentation-generator.js +13 -4
  14. package/dist/augmentation-generator.js.map +1 -1
  15. package/dist/binary-cache.d.ts +2 -1
  16. package/dist/binary-cache.d.ts.map +1 -1
  17. package/dist/binary-cache.js +2 -4
  18. package/dist/binary-cache.js.map +1 -1
  19. package/dist/byte-size.d.ts +9 -0
  20. package/dist/byte-size.d.ts.map +1 -0
  21. package/dist/byte-size.js +36 -0
  22. package/dist/byte-size.js.map +1 -0
  23. package/dist/cache-clean.d.ts +0 -2
  24. package/dist/cache-clean.d.ts.map +1 -1
  25. package/dist/cache-clean.js +1 -27
  26. package/dist/cache-clean.js.map +1 -1
  27. package/dist/cache-pins.d.ts.map +1 -1
  28. package/dist/cache-pins.js +1 -18
  29. package/dist/cache-pins.js.map +1 -1
  30. package/dist/cache-root.d.ts +7 -0
  31. package/dist/cache-root.d.ts.map +1 -0
  32. package/dist/cache-root.js +11 -0
  33. package/dist/cache-root.js.map +1 -0
  34. package/dist/cli-artifacts.d.ts.map +1 -1
  35. package/dist/cli-artifacts.js +2 -1
  36. package/dist/cli-artifacts.js.map +1 -1
  37. package/dist/cli-install-method.d.ts.map +1 -1
  38. package/dist/cli-install-method.js +7 -1
  39. package/dist/cli-install-method.js.map +1 -1
  40. package/dist/cli-launcher.d.ts +21 -0
  41. package/dist/cli-launcher.d.ts.map +1 -0
  42. package/dist/cli-launcher.js +112 -0
  43. package/dist/cli-launcher.js.map +1 -0
  44. package/dist/cli-old-versions.d.ts +44 -0
  45. package/dist/cli-old-versions.d.ts.map +1 -0
  46. package/dist/cli-old-versions.js +83 -0
  47. package/dist/cli-old-versions.js.map +1 -0
  48. package/dist/cli-program-path.d.ts +20 -0
  49. package/dist/cli-program-path.d.ts.map +1 -0
  50. package/dist/cli-program-path.js +41 -0
  51. package/dist/cli-program-path.js.map +1 -0
  52. package/dist/cli-standalone.d.ts +2 -3
  53. package/dist/cli-standalone.d.ts.map +1 -1
  54. package/dist/cli-standalone.js +51 -24
  55. package/dist/cli-standalone.js.map +1 -1
  56. package/dist/cli-version-embedded.js +1 -1
  57. package/dist/commands/cache.d.ts.map +1 -1
  58. package/dist/commands/cache.js +32 -7
  59. package/dist/commands/cache.js.map +1 -1
  60. package/dist/commands/deploy.js +1 -1
  61. package/dist/commands/deploy.js.map +1 -1
  62. package/dist/commands/dev.d.ts.map +1 -1
  63. package/dist/commands/dev.js +14 -1
  64. package/dist/commands/dev.js.map +1 -1
  65. package/dist/commands/doctor.d.ts +32 -0
  66. package/dist/commands/doctor.d.ts.map +1 -1
  67. package/dist/commands/doctor.js +66 -1
  68. package/dist/commands/doctor.js.map +1 -1
  69. package/dist/commands/hooks.d.ts.map +1 -1
  70. package/dist/commands/hooks.js +23 -15
  71. package/dist/commands/hooks.js.map +1 -1
  72. package/dist/commands/init.d.ts +25 -6
  73. package/dist/commands/init.d.ts.map +1 -1
  74. package/dist/commands/init.js +315 -286
  75. package/dist/commands/init.js.map +1 -1
  76. package/dist/commands/keys.d.ts +10 -10
  77. package/dist/commands/keys.d.ts.map +1 -1
  78. package/dist/commands/keys.js +32 -32
  79. package/dist/commands/keys.js.map +1 -1
  80. package/dist/commands/link-helpers.d.ts.map +1 -1
  81. package/dist/commands/link-helpers.js +0 -2
  82. package/dist/commands/link-helpers.js.map +1 -1
  83. package/dist/commands/push.d.ts +2 -0
  84. package/dist/commands/push.d.ts.map +1 -1
  85. package/dist/commands/push.js +38 -9
  86. package/dist/commands/push.js.map +1 -1
  87. package/dist/commands/self-host.d.ts.map +1 -1
  88. package/dist/commands/self-host.js +14 -17
  89. package/dist/commands/self-host.js.map +1 -1
  90. package/dist/commands/self-update.d.ts.map +1 -1
  91. package/dist/commands/self-update.js +9 -3
  92. package/dist/commands/self-update.js.map +1 -1
  93. package/dist/compose-kong.d.ts +4 -0
  94. package/dist/compose-kong.d.ts.map +1 -1
  95. package/dist/compose-kong.js +13 -3
  96. package/dist/compose-kong.js.map +1 -1
  97. package/dist/config.d.ts +9 -1
  98. package/dist/config.d.ts.map +1 -1
  99. package/dist/config.js +18 -3
  100. package/dist/config.js.map +1 -1
  101. package/dist/database-url-owner.d.ts +5 -3
  102. package/dist/database-url-owner.d.ts.map +1 -1
  103. package/dist/database-url-owner.js +7 -4
  104. package/dist/database-url-owner.js.map +1 -1
  105. package/dist/db-port.d.ts +2 -0
  106. package/dist/db-port.d.ts.map +1 -1
  107. package/dist/db-port.js +1 -1
  108. package/dist/db-port.js.map +1 -1
  109. package/dist/db-preflight.d.ts +32 -3
  110. package/dist/db-preflight.d.ts.map +1 -1
  111. package/dist/db-preflight.js +211 -86
  112. package/dist/db-preflight.js.map +1 -1
  113. package/dist/dev-compose.d.ts +5 -0
  114. package/dist/dev-compose.d.ts.map +1 -1
  115. package/dist/dev-compose.js +101 -45
  116. package/dist/dev-compose.js.map +1 -1
  117. package/dist/dev-log-bus.d.ts +8 -0
  118. package/dist/dev-log-bus.d.ts.map +1 -1
  119. package/dist/dev-log-bus.js +13 -0
  120. package/dist/dev-log-bus.js.map +1 -1
  121. package/dist/dev-ports.d.ts +5 -0
  122. package/dist/dev-ports.d.ts.map +1 -1
  123. package/dist/dev-ports.js +7 -3
  124. package/dist/dev-ports.js.map +1 -1
  125. package/dist/dev-session.d.ts +15 -0
  126. package/dist/dev-session.d.ts.map +1 -1
  127. package/dist/dev-session.js +24 -1
  128. package/dist/dev-session.js.map +1 -1
  129. package/dist/dev-shutdown.d.ts.map +1 -1
  130. package/dist/dev-shutdown.js +15 -2
  131. package/dist/dev-shutdown.js.map +1 -1
  132. package/dist/diff-output.d.ts +7 -1
  133. package/dist/diff-output.d.ts.map +1 -1
  134. package/dist/diff-output.js +91 -2
  135. package/dist/diff-output.js.map +1 -1
  136. package/dist/docker-runtime.d.ts +2 -0
  137. package/dist/docker-runtime.d.ts.map +1 -1
  138. package/dist/docker-runtime.js +7 -1
  139. package/dist/docker-runtime.js.map +1 -1
  140. package/dist/engine-client.d.ts.map +1 -1
  141. package/dist/engine-client.js +3 -0
  142. package/dist/engine-client.js.map +1 -1
  143. package/dist/engine-ownership-gate.d.ts +3 -1
  144. package/dist/engine-ownership-gate.d.ts.map +1 -1
  145. package/dist/engine-ownership-gate.js +5 -0
  146. package/dist/engine-ownership-gate.js.map +1 -1
  147. package/dist/env-file.d.ts +4 -2
  148. package/dist/env-file.d.ts.map +1 -1
  149. package/dist/env-file.js +6 -6
  150. package/dist/env-file.js.map +1 -1
  151. package/dist/frontend-env.d.ts +43 -0
  152. package/dist/frontend-env.d.ts.map +1 -0
  153. package/dist/frontend-env.js +81 -0
  154. package/dist/frontend-env.js.map +1 -0
  155. package/dist/hook-actor.d.ts +17 -0
  156. package/dist/hook-actor.d.ts.map +1 -0
  157. package/dist/hook-actor.js +37 -0
  158. package/dist/hook-actor.js.map +1 -0
  159. package/dist/hook-columns.d.ts +30 -0
  160. package/dist/hook-columns.d.ts.map +1 -0
  161. package/dist/hook-columns.js +77 -0
  162. package/dist/hook-columns.js.map +1 -0
  163. package/dist/hook-events.d.ts +11 -0
  164. package/dist/hook-events.d.ts.map +1 -0
  165. package/dist/hook-events.js +11 -0
  166. package/dist/hook-events.js.map +1 -0
  167. package/dist/hooks-generator.d.ts.map +1 -1
  168. package/dist/hooks-generator.js +87 -21
  169. package/dist/hooks-generator.js.map +1 -1
  170. package/dist/init-dependency-versions.d.ts.map +1 -1
  171. package/dist/init-dependency-versions.js +11 -1
  172. package/dist/init-dependency-versions.js.map +1 -1
  173. package/dist/init-package-json.d.ts +38 -1
  174. package/dist/init-package-json.d.ts.map +1 -1
  175. package/dist/init-package-json.js +150 -39
  176. package/dist/init-package-json.js.map +1 -1
  177. package/dist/model-hooks.d.ts +5 -1
  178. package/dist/model-hooks.d.ts.map +1 -1
  179. package/dist/model-hooks.js +12 -2
  180. package/dist/model-hooks.js.map +1 -1
  181. package/dist/project-config.d.ts +4 -0
  182. package/dist/project-config.d.ts.map +1 -1
  183. package/dist/project-config.js +6 -0
  184. package/dist/project-config.js.map +1 -1
  185. package/dist/resolve-target.d.ts +2 -0
  186. package/dist/resolve-target.d.ts.map +1 -1
  187. package/dist/resolve-target.js +8 -5
  188. package/dist/resolve-target.js.map +1 -1
  189. package/dist/self-host-compose.d.ts +16 -3
  190. package/dist/self-host-compose.d.ts.map +1 -1
  191. package/dist/self-host-compose.js +62 -10
  192. package/dist/self-host-compose.js.map +1 -1
  193. package/dist/shell-ports.d.ts.map +1 -1
  194. package/dist/shell-ports.js +2 -8
  195. package/dist/shell-ports.js.map +1 -1
  196. package/dist/tsx-runner.d.ts.map +1 -1
  197. package/dist/tsx-runner.js +2 -1
  198. package/dist/tsx-runner.js.map +1 -1
  199. package/dist/type-extractor.d.ts.map +1 -1
  200. package/dist/type-extractor.js +20 -11
  201. package/dist/type-extractor.js.map +1 -1
  202. package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
  203. package/dist/ui/dev/DevDashboard.js +9 -3
  204. package/dist/ui/dev/DevDashboard.js.map +1 -1
  205. package/dist/ui/flows/prompt-fields.d.ts +11 -6
  206. package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
  207. package/dist/ui/flows/prompt-fields.js +11 -8
  208. package/dist/ui/flows/prompt-fields.js.map +1 -1
  209. package/package.json +16 -13
@@ -14,16 +14,17 @@ import { loadConfig } from "../config.js";
14
14
  import { ensureComponentBinaries, reportComponentBinaryFailures, } from "../ensure-component-binaries.js";
15
15
  import { ensureFunctionsDenoTypes, sharedFunctionsReadmeSource, } from "../functions-deno-types.js";
16
16
  import { functionTemplateSource } from "../functions-template.js";
17
- import { mergeSupatypePackageJson } from "../init-package-json.js";
17
+ import { mergeSupatypePackageJson, PREPARE_COMMAND, scaffoldPackageJson, supatypeDevScript, } from "../init-package-json.js";
18
18
  import { downloadRelease, initFromExample } from "../init-example.js";
19
19
  import { errorMessage } from "../error-message.js";
20
- import { parseJsonObject } from "@supatype/shared";
20
+ import { isJsonObject, parseJsonObject } from "@supatype/shared";
21
21
  import { cliPackageVersion } from "../cli-package-version.js";
22
22
  import { initDependencyVersionsFallback, resolveInitDependencyVersions, } from "../init-dependency-versions.js";
23
23
  import { detectProjectSetup } from "../init-project-detect.js";
24
24
  import { SUPATYPE_GITIGNORE_PATHS } from "../gitignore.js";
25
+ import { DEV_FRONTEND_ENV_FILE, writeFrontendEnv } from "../frontend-env.js";
25
26
  import { DEFAULT_CLIENT_PATH, DEFAULT_TYPES_PATH } from "../type-generation.js";
26
- import { COMPOSE_DEV_KONG_PORT, NATIVE_DB_PORT, NATIVE_SERVER_PORT, nativeDatabaseUrl } from "../project-config.js";
27
+ import { COMPOSE_DEV_KONG_PORT, defaultAppStaticDir, NATIVE_DB_PORT, NATIVE_SERVER_PORT, nativeDatabaseUrl, VITE_BUILD_DIR, } from "../project-config.js";
27
28
  import { cliDatabaseUrlLines } from "../database-url-owner.js";
28
29
  const STORAGE_PROVIDER_OPTIONS = [
29
30
  { value: "local", label: "Local", hint: "storage you host yourself (SeaweedFS)" },
@@ -119,35 +120,45 @@ export function registerInit(program) {
119
120
  const asked = startInitQuestions(result.provider);
120
121
  if (asked.kongPort)
121
122
  result.kongPort = await asked.kongPort;
122
- if (opts.admin === false) {
123
- delete result.adminEmail;
124
- delete result.adminPassword;
125
- }
126
- else if (opts.adminEmail && opts.adminPassword) {
127
- result.adminEmail = opts.adminEmail;
128
- result.adminPassword = opts.adminPassword;
129
- }
130
- // CLI flags override wizard / default action choices.
131
- const doInstall = opts.install !== false && result.install;
132
- const doKeys = opts.keys !== false && result.generateKeys;
133
- if (name)
134
- mkdirSync(dir, { recursive: true });
135
- const deps = await asked.deps;
136
- scaffold(dir, result, deps);
137
- const wants = { install: doInstall, keys: doKeys };
138
- const outcome = await withStepView((view) => runSetupSteps(dir, result.packageManager, wants, view));
139
- exitOnFailedSetup(outcome, wants, result.packageManager);
140
- const { installOk, keysGenerated, binariesReady } = outcome;
141
- await warnDockerUnavailableForProvider(result.provider, asked.daemon);
142
- printNextSteps({
143
- name,
144
- result,
145
- installed: doInstall && installOk,
146
- keysGenerated,
147
- binariesReady,
148
- });
123
+ await createProject({ name, dir, result, opts, deps: asked.deps, ...(asked.daemon !== undefined && { daemon: asked.daemon }) });
124
+ });
125
+ }
126
+ /**
127
+ * Write the project, run its setup steps and print what is left, the same for the interactive init
128
+ * and `init -y`. They were two copies, and had come to disagree about whether keys nobody generated
129
+ * were a step left to do.
130
+ */
131
+ async function createProject(args) {
132
+ const { name, dir, result, opts } = args;
133
+ applyAdminFlags(result, opts);
134
+ // CLI flags override wizard / default action choices.
135
+ const wants = { install: opts.install !== false && result.install, keys: opts.keys !== false && result.generateKeys };
136
+ if (name)
137
+ mkdirSync(dir, { recursive: true });
138
+ scaffold(dir, result, await args.deps);
139
+ const outcome = await withStepView((view) => runSetupSteps(dir, result.packageManager, wants, view));
140
+ exitOnFailedSetup(outcome, wants, result.packageManager);
141
+ await warnDockerUnavailableForProvider(result.provider, args.daemon);
142
+ printNextSteps({
143
+ name,
144
+ result,
145
+ installed: wants.install && outcome.installOk,
146
+ keysGenerated: outcome.keysGenerated,
147
+ binariesReady: outcome.binariesReady,
148
+ devScript: projectDevScript(dir),
149
149
  });
150
150
  }
151
+ /** `--no-admin`, or `--admin-email` with `--admin-password`, over the answers. */
152
+ function applyAdminFlags(result, opts) {
153
+ if (opts.admin === false) {
154
+ delete result.adminEmail;
155
+ delete result.adminPassword;
156
+ }
157
+ else if (opts.adminEmail && opts.adminPassword) {
158
+ result.adminEmail = opts.adminEmail;
159
+ result.adminPassword = opts.adminPassword;
160
+ }
161
+ }
151
162
  /** Interactive init: one Ink session for wizard + scaffold + install + finish. */
152
163
  async function runInteractiveInit(args) {
153
164
  const { name, dir, defaultName, modeTarget, opts } = args;
@@ -157,47 +168,18 @@ async function runInteractiveInit(args) {
157
168
  if (detected.hasExistingFiles && detected.summaryLines.length > 0) {
158
169
  p.note(["Existing project detected:", ...detected.summaryLines.map((line) => ` • ${line}`)].join("\n"));
159
170
  }
160
- let result = await collectWizardAnswers({
171
+ const result = await collectWizardAnswers({
161
172
  defaultName,
162
173
  defaultTarget: modeTarget,
163
- dir,
164
174
  detected,
165
175
  askName: name === undefined,
166
176
  });
167
- if (opts.admin === false) {
168
- delete result.adminEmail;
169
- delete result.adminPassword;
170
- }
171
- else if (opts.adminEmail && opts.adminPassword) {
172
- result.adminEmail = opts.adminEmail;
173
- result.adminPassword = opts.adminPassword;
174
- }
175
- const doInstall = opts.install !== false && result.install;
176
- const doKeys = opts.keys !== false && result.generateKeys;
177
- if (name)
178
- mkdirSync(dir, { recursive: true });
179
- const deps = await resolveDependencyVersions();
180
- scaffold(dir, result, deps);
181
- const wants = { install: doInstall, keys: doKeys };
182
- const outcome = await withStepView((view) => runSetupSteps(dir, result.packageManager, wants, view));
183
- exitOnFailedSetup(outcome, wants, result.packageManager);
184
- const { installOk, binariesReady } = outcome;
185
- // Keys nobody asked for are not a step left to do.
186
- const keysGenerated = outcome.keysGenerated || !doKeys;
187
- await warnDockerUnavailableForProvider(result.provider);
188
- p.outro(`Supatype project ready${name ? ` in ${name}/` : ""}.`);
189
- printNextSteps({
190
- name,
191
- result,
192
- installed: doInstall && installOk,
193
- keysGenerated,
194
- binariesReady,
195
- });
177
+ await createProject({ name, dir, result, opts, deps: resolveDependencyVersions() });
196
178
  });
197
179
  process.exit(0);
198
180
  }
199
181
  export async function collectWizardAnswers(context) {
200
- const { defaultName, defaultTarget, dir, detected } = context;
182
+ const { defaultName, defaultTarget, detected } = context;
201
183
  const projectName = context.askName ? await promptProjectName(defaultName) : defaultName;
202
184
  const admin = await promptAdminUser();
203
185
  const packageManager = ensureNotCancelled(await p.select({
@@ -249,14 +231,7 @@ export async function collectWizardAnswers(context) {
249
231
  const { promptKongPortChoice } = await import("../dev-ports.js");
250
232
  kongPort = await promptKongPortChoice();
251
233
  }
252
- const defaultSchemaPath = existsSync(join(dir, "schema/index.ts"))
253
- ? "schema/index.ts"
254
- : "schema/index.ts";
255
- const schemaPath = ensureNotCancelled(await p.text({
256
- message: "Where should your schema live?",
257
- defaultValue: defaultSchemaPath,
258
- placeholder: "schema/index.ts",
259
- })).trim() || defaultSchemaPath;
234
+ const schemaPath = await askWithDefault("Where should your schema live?", "schema/index.ts");
260
235
  const app = await promptApp(detected, productionTarget);
261
236
  const email = ensureNotCancelled(await p.select({
262
237
  message: "Email provider",
@@ -299,8 +274,11 @@ export async function collectWizardAnswers(context) {
299
274
  };
300
275
  }
301
276
  async function promptProjectName(defaultName) {
302
- const answer = ensureNotCancelled(await p.text({ message: "Project name", defaultValue: defaultName, placeholder: defaultName }));
303
- return answer.trim() || defaultName;
277
+ return askWithDefault("Project name", defaultName);
278
+ }
279
+ /** A text answer, trimmed, or `defaultValue` when it was left empty. */
280
+ async function askWithDefault(message, defaultValue) {
281
+ return ensureNotCancelled(await p.text({ message, defaultValue })).trim() || defaultValue;
304
282
  }
305
283
  async function promptProductionStorage() {
306
284
  return ensureNotCancelled(await p.select({
@@ -322,14 +300,24 @@ async function promptAdminUser() {
322
300
  placeholder: "you@example.com",
323
301
  validate: (value) => (value.trim() ? undefined : "Email is required"),
324
302
  })).trim();
325
- let adminPassword = "";
303
+ return { adminEmail, adminPassword: await promptAdminPassword() };
304
+ }
305
+ /**
306
+ * The admin password, typed twice: asked once, a typo became the Studio password with nothing to
307
+ * show it. Both are asked again when they differ.
308
+ */
309
+ async function promptAdminPassword() {
326
310
  while (true) {
327
- adminPassword = ensureNotCancelled(await p.password({ message: "Admin password (min 8 characters)" })).trim();
328
- if (adminPassword.length >= 8)
329
- break;
330
- p.log.warn("Password must be at least 8 characters.");
311
+ const password = ensureNotCancelled(await p.password({ message: "Admin password (min 8 characters)" })).trim();
312
+ if (password.length < 8) {
313
+ p.log.warn("Password must be at least 8 characters.");
314
+ continue;
315
+ }
316
+ const confirmed = ensureNotCancelled(await p.password({ message: "Confirm admin password" })).trim();
317
+ if (confirmed === password)
318
+ return password;
319
+ p.log.warn("Passwords do not match.");
331
320
  }
332
- return { adminEmail, adminPassword };
333
321
  }
334
322
  async function promptApp(detected, productionTarget) {
335
323
  const initialMode = detected.hasVite && productionTarget !== "later"
@@ -347,30 +335,31 @@ async function promptApp(detected, productionTarget) {
347
335
  ],
348
336
  }));
349
337
  if (mode === "static") {
350
- const staticDir = ensureNotCancelled(await p.text({
351
- message: "Directory to serve",
352
- defaultValue: detected.staticDir,
353
- placeholder: detected.staticDir,
354
- })).trim() || detected.staticDir;
355
338
  const viteDevUrl = await promptViteDevUrl(detected, productionTarget);
356
- return { mode, staticDir, ...(viteDevUrl ? { viteDevUrl } : {}) };
339
+ return { mode, staticDir: await promptStaticDir(detected, viteDevUrl !== undefined), ...(viteDevUrl ? { viteDevUrl } : {}) };
357
340
  }
358
341
  if (mode === "proxy") {
359
- const upstream = ensureNotCancelled(await p.text({
360
- message: "URL of your running dev server",
361
- defaultValue: detected.hasVite ? detected.viteDevUrl : "http://localhost:3000",
362
- placeholder: detected.hasVite ? detected.viteDevUrl : "http://localhost:3000",
363
- })).trim() || (detected.hasVite ? detected.viteDevUrl : "http://localhost:3000");
364
- const start = ensureNotCancelled(await p.text({
365
- message: "package.json script that starts your dev server",
366
- defaultValue: detected.hasVite ? "vite" : "dev",
367
- placeholder: detected.hasVite ? "vite" : "dev",
368
- })).trim() || (detected.hasVite ? "vite" : "dev");
342
+ const upstream = await askWithDefault("URL of your running dev server", detected.hasVite ? detected.viteDevUrl : "http://localhost:3000");
343
+ const start = await askWithDefault("package.json script that starts your dev server", detected.hasVite ? "vite" : "dev");
369
344
  const viteDevUrl = await promptViteDevUrl(detected, productionTarget);
370
345
  return { mode, upstream, start, ...(viteDevUrl ? { viteDevUrl } : {}) };
371
346
  }
372
347
  return { mode: "none" };
373
348
  }
349
+ /**
350
+ * The directory a static site is served from, asked after Vite: it was asked before, so a new Vite
351
+ * project was offered ./public. A Vite project is offered its build output, ./dist; a site with no
352
+ * build is offered what detection found, ./public when it found nothing. ./public for Vite is
353
+ * warned about and kept: it is Vite's folder of assets copied into the build, not the build.
354
+ */
355
+ async function promptStaticDir(detected, vite) {
356
+ const staticDir = await askWithDefault("Directory to serve", vite ? VITE_BUILD_DIR : detected.staticDir);
357
+ if (vite && staticDirRelative(staticDir) === "public") {
358
+ p.log.warn("./public is Vite's folder for static assets it copies into the build, so serving it skips the build. " +
359
+ "Vite builds into ./dist unless vite.config.ts says otherwise.");
360
+ }
361
+ return staticDir;
362
+ }
374
363
  async function promptViteDevUrl(detected, productionTarget) {
375
364
  const defaultYes = detected.hasVite || productionTarget !== "later";
376
365
  const useVite = ensureNotCancelled(await p.confirm({
@@ -381,12 +370,7 @@ async function promptViteDevUrl(detected, productionTarget) {
381
370
  }));
382
371
  if (!useVite)
383
372
  return undefined;
384
- p.note(`Press Enter for ${detected.viteDevUrl}, or type a custom URL.`);
385
- return (ensureNotCancelled(await p.text({
386
- message: "Vite dev server URL",
387
- defaultValue: detected.viteDevUrl,
388
- placeholder: detected.viteDevUrl,
389
- })).trim() || detected.viteDevUrl);
373
+ return askWithDefault("Vite dev server URL", detected.viteDevUrl);
390
374
  }
391
375
  // ─── Package manager ───────────────────────────────────────────────────────--
392
376
  function detectInvokingPackageManager() {
@@ -497,51 +481,92 @@ export function scaffold(dir, optsOrName, deps = initDependencyVersionsFallback(
497
481
  };
498
482
  const pkgPath = join(dir, "package.json");
499
483
  if (!existsSync(pkgPath)) {
500
- write("package.json", packageJsonTemplate(opts, deps));
484
+ write("package.json", scaffoldPackageJson(opts, deps));
501
485
  }
502
486
  else {
503
- try {
504
- const existing = parseJsonObject(readFileSync(pkgPath, "utf8"));
505
- if (!existing.ok)
506
- throw new Error("package.json is not a JSON object");
507
- const merged = mergeSupatypePackageJson(existing.value, opts, deps);
508
- writeFileSync(pkgPath, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
509
- file("updated", "package.json (added Supatype dependencies)");
510
- }
511
- catch {
512
- warn("Could not merge into package.json, add @supatype/cli and @supatype/types manually.");
513
- file("skipped", "package.json (invalid JSON)");
514
- }
487
+ mergeIntoPackageJson(pkgPath, opts, deps);
515
488
  }
516
489
  write("supatype.config.ts", tsConfigTemplate(opts));
517
- if (opts.productionTarget !== "later") {
490
+ if (writesLocalOverride(opts)) {
518
491
  write("supatype.local.config.ts", localConfigTemplate(opts.app));
519
492
  }
520
493
  write(opts.schemaPath, schemaTemplate());
521
494
  write(".env", envTemplate(opts));
495
+ scaffoldDevFrontendEnv(dir, opts);
522
496
  write("seed.ts", seedTemplate(opts.projectName));
523
497
  write("seeds/.gitkeep", "");
524
498
  scaffoldAppAssets(dir, opts, write);
525
499
  if (opts.helloFunction)
526
500
  scaffoldHelloFunction(dir, write);
527
- const gitignorePath = join(dir, ".gitignore");
528
- if (existsSync(gitignorePath)) {
529
- const merged = mergeGitignoreTemplate(readFileSync(gitignorePath, "utf8"));
530
- if (merged !== readFileSync(gitignorePath, "utf8")) {
531
- writeFileSync(gitignorePath, merged, "utf8");
532
- file("updated", ".gitignore (added .supatype/)");
533
- }
534
- else {
535
- file("skipped", ".gitignore (already exists)");
501
+ scaffoldGitignore(dir, write);
502
+ }
503
+ /**
504
+ * Supatype's scripts and packages merged into the project's own package.json, saying so when its
505
+ * `prepare` changed: a project's own (husky, say) gets `supatype-prepare` after it, and the one
506
+ * earlier releases of init wrote is replaced.
507
+ */
508
+ function mergeIntoPackageJson(pkgPath, opts, deps) {
509
+ try {
510
+ const existing = parseJsonObject(readFileSync(pkgPath, "utf8"));
511
+ if (!existing.ok)
512
+ throw new Error("package.json is not a JSON object");
513
+ const merged = mergeSupatypePackageJson(existing.value, opts, deps);
514
+ writeFileSync(pkgPath, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
515
+ file("updated", "package.json (added Supatype dependencies)");
516
+ const before = scriptOf(existing.value, "prepare");
517
+ const after = merged.scripts?.["prepare"];
518
+ if (before !== undefined && after !== undefined && before !== after) {
519
+ info(`package.json's prepare script was "${before}" and is now "${after}", so a fresh clone generates the seed builder.`);
536
520
  }
537
521
  }
538
- else {
522
+ catch {
523
+ warn("Could not merge into package.json. Add @supatype/client to dependencies, @supatype/cli and " +
524
+ `@supatype/types to devDependencies, and a "prepare" script of "${PREPARE_COMMAND}".`);
525
+ file("skipped", "package.json (invalid JSON)");
526
+ }
527
+ }
528
+ /** The package.json script `name`, when it is a string. */
529
+ function scriptOf(pkg, name) {
530
+ const scripts = pkg["scripts"];
531
+ const script = isJsonObject(scripts) ? scripts[name] : undefined;
532
+ return typeof script === "string" ? script : undefined;
533
+ }
534
+ /**
535
+ * The front end's local API address, in `.env.development.local` (frontend-env.ts) for a docker
536
+ * project, whose gateway port is known now. In `.env`, a production build read it and shipped it.
537
+ */
538
+ function scaffoldDevFrontendEnv(dir, opts) {
539
+ if (opts.provider !== "docker" || opts.kongPort === undefined)
540
+ return;
541
+ const existed = existsSync(join(dir, DEV_FRONTEND_ENV_FILE));
542
+ writeFrontendEnv(dir, { apiUrl: initLocalApiUrl(opts) });
543
+ file(existed ? "updated" : "created", DEV_FRONTEND_ENV_FILE);
544
+ }
545
+ function scaffoldGitignore(dir, write) {
546
+ const gitignorePath = join(dir, ".gitignore");
547
+ if (!existsSync(gitignorePath)) {
539
548
  write(".gitignore", gitignoreTemplate());
549
+ return;
540
550
  }
551
+ const existing = readFileSync(gitignorePath, "utf8");
552
+ const merged = mergeGitignoreTemplate(existing);
553
+ if (merged === existing) {
554
+ file("skipped", ".gitignore (already exists)");
555
+ return;
556
+ }
557
+ writeFileSync(gitignorePath, merged, "utf8");
558
+ file("updated", ".gitignore (added Supatype's local files)");
559
+ }
560
+ /**
561
+ * The directory a static app is served from: the one typed at init, else the stack's own default
562
+ * (defaultAppStaticDir). The config, the holding page and Vite's build all read it here, so none
563
+ * of them can name a different one.
564
+ */
565
+ function staticDirOf(app) {
566
+ return app.staticDir ?? defaultAppStaticDir(Boolean(app.viteDevUrl));
541
567
  }
542
568
  function staticDirRelative(staticDir) {
543
- const raw = (staticDir ?? "./public").trim();
544
- return raw.replace(/^\.\//, "").replace(/\/+$/, "") || "public";
569
+ return staticDir.trim().replace(/^\.\//, "").replace(/\/+$/, "") || "public";
545
570
  }
546
571
  function scaffoldAppAssets(dir, opts, write) {
547
572
  const writeUnlessExists = (rel, content) => {
@@ -555,14 +580,8 @@ function scaffoldAppAssets(dir, opts, write) {
555
580
  const holding = holdingPageTemplate(opts.projectName, initLocalApiUrl(opts));
556
581
  const hasVite = Boolean(opts.app.viteDevUrl);
557
582
  if (opts.app.mode === "static") {
558
- const staticRel = staticDirRelative(opts.app.staticDir);
559
- if (opts.app.viteDevUrl && opts.productionTarget !== "later") {
560
- writeUnlessExists("dist/index.html", holding);
561
- scaffoldVite(dir, opts, writeUnlessExists, holding);
562
- return;
563
- }
564
- writeUnlessExists(`${staticRel}/index.html`, holding);
565
- if (opts.app.viteDevUrl)
583
+ writeUnlessExists(`${staticDirRelative(staticDirOf(opts.app))}/index.html`, holding);
584
+ if (hasVite)
566
585
  scaffoldVite(dir, opts, writeUnlessExists, holding);
567
586
  return;
568
587
  }
@@ -587,7 +606,18 @@ function scaffoldVite(dir, opts, write, holding) {
587
606
  file("skipped", `${viteConfigRel} (already exists)`);
588
607
  return;
589
608
  }
590
- write("vite.config.ts", viteConfigTemplate(opts.app.viteDevUrl));
609
+ write("vite.config.ts", viteConfigTemplate(opts.app.viteDevUrl, viteBuildOutDir(opts)));
610
+ }
611
+ /**
612
+ * Where `vite build` writes, when it is not Vite's own `dist`: the static directory a static app is
613
+ * served from, so its build lands there. Undefined otherwise.
614
+ */
615
+ function viteBuildOutDir(opts) {
616
+ if (opts.app.mode !== "static")
617
+ return undefined;
618
+ const outDir = staticDirRelative(staticDirOf(opts.app));
619
+ // Not into "./public" either: that is Vite's own assets folder, served as it is (promptStaticDir).
620
+ return outDir === "dist" || outDir === "public" ? undefined : outDir;
591
621
  }
592
622
  function scaffoldHelloFunction(dir, write) {
593
623
  write("functions/hello/index.ts", functionTemplateSource("hello"));
@@ -612,72 +642,32 @@ async function resolveDependencyVersions() {
612
642
  const deps = await resolveInitDependencyVersions();
613
643
  const runningCli = cliPackageVersion();
614
644
  if (deps.cli !== runningCli || deps.types !== runningCli || deps.client !== runningCli) {
615
- info(`Using published npm versions: @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}, ` +
645
+ info(`Pinning @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}, ` +
616
646
  `@supatype/client ^${deps.client}`);
617
647
  }
618
648
  return deps;
619
649
  }
620
- function packageJsonTemplate(opts, deps) {
621
- const scripts = [
622
- ` "dev": "supatype dev"`,
623
- ` "push": "supatype push"`,
624
- ` "seed": "supatype seed"`,
625
- // The generated seed builder is gitignored, so a fresh clone has to produce it before
626
- // anything can import it. `generate` is fully offline, which is the condition that makes
627
- // gitignoring generated code reasonable rather than a trap; without this hook it would be
628
- // one, and the failure would be a missing module rather than anything naming the remedy.
629
- ` "prepare": "supatype generate"`,
630
- ];
631
- if (opts.app.viteDevUrl) {
632
- scripts.push(` "vite": "vite"`);
633
- }
634
- if (opts.helloFunction) {
635
- scripts.push(` "functions": "supatype functions serve"`);
636
- }
637
- // Both are development-time only, so they belong in devDependencies. Validated end to end
638
- // against a real database: schema/index.ts imports @supatype/types with `import type`, which is
639
- // erased at build; supatype.config.ts imports defineConfig, which only the CLI evaluates; and
640
- // seed.ts is run by `tsx seed.ts`. Nothing `supatype push` or `supatype generate` writes refers
641
- // to either package: the generated types import nothing. The generated client
642
- // (supatype/generated/client.ts) imports @supatype/client at runtime, so that one is a real
643
- // dependency.
644
- //
645
- // In dependencies they were installed by `npm install --omit=dev`, so every production install
646
- // of a Supatype app pulled the whole CLI toolchain (ink, react, typescript, ts-morph, pg, tsx)
647
- // to support three files that never run in production.
648
- const devDeps = [
649
- ` "@supatype/cli": "^${deps.cli}"`,
650
- ` "@supatype/types": "^${deps.types}"`,
651
- ` "tsx": "^4.19.2"`,
652
- ` "typescript": "^5"`,
653
- ];
654
- if (opts.app.viteDevUrl) {
655
- devDeps.push(` "vite": "^6"`);
656
- }
657
- return `{
658
- "name": "${opts.projectName}",
659
- "private": true,
660
- "type": "module",
661
- "scripts": {
662
- ${scripts.join(",\n")}
663
- },
664
- "dependencies": {
665
- "@supatype/client": "^${deps.client}"
666
- },
667
- "devDependencies": {
668
- ${devDeps.join(",\n")}
669
- }
650
+ /**
651
+ * Whether init writes a supatype.local.config.ts: for a production target, whose committed config
652
+ * is production's, and for a static app developed with Vite, whose dev server `supatype dev` starts
653
+ * only in proxy mode. A "Decide later" project with Vite used to get neither, and nothing started
654
+ * Vite.
655
+ */
656
+ function writesLocalOverride(opts) {
657
+ return opts.productionTarget !== "later" || viteDevelopsStaticApp(opts.app);
670
658
  }
671
- `;
659
+ /** A static app with a Vite dev server: served from its build, developed through Vite. */
660
+ function viteDevelopsStaticApp(app) {
661
+ return app.mode === "static" && Boolean(app.viteDevUrl);
672
662
  }
673
663
  function tsConfigTemplate(opts) {
674
664
  const serverMode = serverModeForTarget(opts.productionTarget);
675
- const hasLocalOverride = opts.productionTarget !== "later";
676
665
  const lines = [];
677
666
  lines.push(`import { defineConfig } from "@supatype/cli"`);
678
667
  lines.push("");
679
- if (hasLocalOverride) {
668
+ if (opts.productionTarget !== "later")
680
669
  lines.push(`// Committed config = ${opts.productionTarget} production target.`);
670
+ if (writesLocalOverride(opts)) {
681
671
  lines.push(`// Local development overrides live in supatype.local.config.ts (gitignored).`);
682
672
  }
683
673
  lines.push(`export default defineConfig({`);
@@ -762,23 +752,9 @@ function localDevAppConfigLines(app) {
762
752
  }
763
753
  function appConfigLines(app, productionTarget) {
764
754
  if (app.mode === "static") {
765
- if (productionTarget !== "later" && app.viteDevUrl) {
766
- return [
767
- ` app: {`,
768
- ` mode: "static",`,
769
- ` static_dir: "./dist", // production build output`,
770
- ` },`,
771
- ];
772
- }
773
- const out = [
774
- ` app: {`,
775
- ` mode: "static",`,
776
- ` static_dir: "${app.staticDir ?? "./public"}",`,
777
- ];
778
- if (app.viteDevUrl)
779
- out.push(` vite_dev_url: "${app.viteDevUrl}",`);
780
- out.push(` },`);
781
- return out;
755
+ // Vite's dev server is the local override's (writesLocalOverride); this is the built site.
756
+ const built = viteDevelopsStaticApp(app) ? " // production build output" : "";
757
+ return [` app: {`, ` mode: "static",`, ` static_dir: "${staticDirOf(app)}",${built}`, ` },`];
782
758
  }
783
759
  if (app.mode === "proxy") {
784
760
  if (productionTarget !== "later") {
@@ -830,6 +806,14 @@ function initLocalApiUrl(opts) {
830
806
  ? `http://localhost:${opts.kongPort ?? COMPOSE_DEV_KONG_PORT}`
831
807
  : `http://localhost:${NATIVE_SERVER_PORT}`;
832
808
  }
809
+ /**
810
+ * Where auth emails send people back to. A static or proxied app is served on the same address as
811
+ * the API, so that is the app's address too; it was `http://localhost:3000` for every project,
812
+ * where nothing listened. With no app, the address is the developer's own, and 3000 is a guess.
813
+ */
814
+ function initSiteUrl(opts) {
815
+ return opts.app.mode === "none" ? "http://localhost:3000" : initLocalApiUrl(opts);
816
+ }
833
817
  function holdingPageTemplate(projectName, apiUrl) {
834
818
  const name = escapeHtml(projectName);
835
819
  return `<!doctype html>
@@ -964,12 +948,13 @@ function vitePortFromDevUrl(viteDevUrl) {
964
948
  return 5173;
965
949
  }
966
950
  }
967
- function viteConfigTemplate(viteDevUrl) {
951
+ function viteConfigTemplate(viteDevUrl, outDir) {
968
952
  const port = vitePortFromDevUrl(viteDevUrl);
953
+ const build = outDir === undefined ? "" : ` // Built into the directory supatype.config.ts serves.\n build: { outDir: "${outDir}" },\n`;
969
954
  return `import { defineConfig } from "vite"
970
955
 
971
956
  export default defineConfig({
972
- server: {
957
+ ${build} server: {
973
958
  host: "127.0.0.1",
974
959
  port: ${port},
975
960
  strictPort: true,
@@ -1063,15 +1048,13 @@ SERVICE_ROLE_KEY=`);
1063
1048
  # request without it, so code running in the functions worker cannot call it directly.
1064
1049
  ${CONTROL_PLANE_SECRET_ENV}=${generateControlPlaneSecret()}`);
1065
1050
  sections.push(`# Site URL (used for email redirects)
1066
- SITE_URL=http://localhost:3000`);
1051
+ SITE_URL=${initSiteUrl(opts)}`);
1067
1052
  if (opts.provider === "docker" && opts.kongPort !== undefined) {
1068
- const apiUrl = `http://localhost:${opts.kongPort}`;
1053
+ // The front end's copies of this address and the anon key are in .env.development.local
1054
+ // (scaffoldDevFrontendEnv, and the keys step), where a production build does not read them.
1069
1055
  sections.push(`# Local API gateway (Kong), unique per project so multiple stacks can run concurrently
1070
1056
  SUPATYPE_KONG_PORT=${opts.kongPort}
1071
- PUBLIC_SUPATYPE_URL=${apiUrl}
1072
- API_EXTERNAL_URL=${apiUrl}
1073
- VITE_SUPATYPE_URL=${apiUrl}
1074
- VITE_SUPATYPE_ANON_KEY=`);
1057
+ API_EXTERNAL_URL=${initLocalApiUrl(opts)}`);
1075
1058
  }
1076
1059
  sections.push(emailEnvSection(opts.email, opts.projectName));
1077
1060
  sections.push(storageEnvSections(opts.storageLocal, opts.storageProduction));
@@ -1090,7 +1073,7 @@ SUPATYPE_ADMIN_PASSWORD=${opts.adminPassword}`);
1090
1073
  const SELF_HOST_PORTS_ENV_SECTION = `# Self-host stack ports (supatype self-host compose). Kong, at SUPATYPE_KONG_PORT, is the way in.
1091
1074
  # Postgres, the API server and SeaweedFS bind 127.0.0.1 only. To reach them from other machines,
1092
1075
  # set SUPATYPE_PUBLISH_ADDRESS=0.0.0.0 (put a firewall in front of the server first).
1093
- # A self-host push points DATABASE_URL at SUPATYPE_DB_PORT.
1076
+ # Self-host commands reach Postgres at SUPATYPE_DB_PORT for their own run; DATABASE_URL above stays dev's.
1094
1077
  # SUPATYPE_PUBLISH_ADDRESS=127.0.0.1
1095
1078
  # SUPATYPE_DB_PORT=5432
1096
1079
  # SUPATYPE_SERVER_PORT=9999
@@ -1229,14 +1212,20 @@ src/types/supatype.d.ts
1229
1212
  src/lib/supatype.ts
1230
1213
  `;
1231
1214
  }
1215
+ /**
1216
+ * An existing `.gitignore` with what init adds to a project: `.supatype/` (link.json holds secrets)
1217
+ * and `.env.*.local`, where init writes the front end's development-only API address. Each is added
1218
+ * only when the file does not already cover it.
1219
+ */
1232
1220
  export function mergeGitignoreTemplate(existingContent) {
1233
- if (existingContent.includes(".supatype/") || existingContent.includes(".supatype\n")) {
1221
+ const lines = existingContent.split(/\r?\n/).map((line) => line.trim());
1222
+ const missing = [
1223
+ ...(existingContent.includes(".supatype/") || lines.includes(".supatype") ? [] : [".supatype/"]),
1224
+ ...(lines.includes(".env.*.local") || lines.includes("*.local") ? [] : [".env.*.local"]),
1225
+ ];
1226
+ if (missing.length === 0)
1234
1227
  return existingContent;
1235
- }
1236
- const block = `
1237
- # Supatype: local runtime (contains secrets in link.json)
1238
- .supatype/
1239
- `;
1228
+ const block = `\n# Supatype: local runtime (secrets in .supatype/link.json) and development-only env files\n${missing.join("\n")}\n`;
1240
1229
  return existingContent.endsWith("\n") ? `${existingContent}${block}` : `${existingContent}\n${block}`;
1241
1230
  }
1242
1231
  // ─── Next steps ────────────────────────────────────────────────────────────--
@@ -1262,27 +1251,50 @@ function startInitQuestions(provider) {
1262
1251
  const kongPort = import("../dev-ports.js").then(({ chooseInitKongPort }) => chooseInitKongPort());
1263
1252
  return { kongPort, daemon: probeDockerDaemonAsync(), deps };
1264
1253
  }
1254
+ /** The script in `dir`'s package.json that runs `supatype dev`, or `dev` when it cannot be read. */
1255
+ function projectDevScript(dir) {
1256
+ try {
1257
+ const pkg = parseJsonObject(readFileSync(join(dir, "package.json"), "utf8"));
1258
+ return pkg.ok ? supatypeDevScript(pkg.value["scripts"]) : "dev";
1259
+ }
1260
+ catch {
1261
+ return "dev";
1262
+ }
1263
+ }
1265
1264
  /** True when nothing is left to set up, only to run. */
1266
1265
  function initSetupComplete(args) {
1267
1266
  return args.installed && args.keysGenerated && args.binariesReady;
1268
1267
  }
1269
1268
  function printNextSteps(args) {
1270
- const { name, result } = args;
1269
+ const { name } = args;
1271
1270
  info(`Supatype project ready${name ? ` in ${name}/` : ""}.`);
1272
- nextSteps(initSetupComplete(args) ? "Next steps:" : "Finish setup:", initFirstSteps(args));
1273
- printProductionSteps(result);
1274
- if (result.productionTarget === "self-host")
1275
- nextSteps("Develop locally:", initDevSteps(result));
1271
+ for (const block of initStepBlocks(args)) {
1272
+ nextSteps(block.title, block.steps);
1273
+ if (block.after !== undefined)
1274
+ plain(` ${block.after}`);
1275
+ }
1276
+ const target = args.result.productionTarget;
1277
+ if (target === "cloud" || target === "self-host") {
1278
+ info(`supatype.local.config.ts keeps \`supatype dev\` local while the committed config targets ${target}.`);
1279
+ }
1280
+ plain();
1276
1281
  }
1277
1282
  /**
1278
- * The commands to run next, in order, after `init`: setting up, then what the project is for. A
1279
- * self-host project leads with taking it to its server, and its local development is printed after
1280
- * ({@link printNextSteps}); every other project leads with `supatype dev`.
1283
+ * Everything init prints when it is done, in order: running the project locally, then its secrets,
1284
+ * then taking it to production. Production comes last whatever the target: it is the step for
1285
+ * later, and a self-host project used to lead with a domain the person had just said they lacked.
1281
1286
  */
1287
+ export function initStepBlocks(args) {
1288
+ const blocks = [
1289
+ { title: initSetupComplete(args) ? "Next steps:" : "Finish setup:", steps: initFirstSteps(args) },
1290
+ { title: "Secrets: generated for this project, kept in .env:", steps: initSecretLines(), after: SECRETS_CLOSING },
1291
+ ];
1292
+ const deploy = deployBlock(args.result);
1293
+ return deploy === undefined ? blocks : [...blocks, deploy];
1294
+ }
1295
+ /** Setting up, then running the project locally, for every production target. */
1282
1296
  export function initFirstSteps(args) {
1283
- const { result } = args;
1284
- const next = result.productionTarget === "self-host" ? selfHostProductionSteps(result) : initDevSteps(result);
1285
- return [...initSetupSteps(args), ...next];
1297
+ return [...initSetupSteps(args), ...initDevSteps(args)];
1286
1298
  }
1287
1299
  function initSetupSteps(args) {
1288
1300
  const { name, result, installed, keysGenerated, binariesReady } = args;
@@ -1293,76 +1305,93 @@ function initSetupSteps(args) {
1293
1305
  if (!installed)
1294
1306
  steps.push(`${result.packageManager} install`);
1295
1307
  if (!binariesReady)
1296
- steps.push("supatype update # download component binaries");
1308
+ steps.push("supatype update # download component binaries");
1297
1309
  if (!keysGenerated)
1298
1310
  steps.push("supatype keys");
1299
1311
  }
1300
1312
  return steps;
1301
1313
  }
1314
+ /** `script` run the way `pm` runs a package.json script. */
1315
+ function runScriptCommand(pm, script) {
1316
+ return pm === "npm" || pm === "bun" ? `${pm} run ${script}` : `${pm} ${script}`;
1317
+ }
1318
+ /** `command` with `comments` after it, each comment after the first on its own line in the same column. */
1319
+ function commented(command, comments) {
1320
+ const column = command.length + 3;
1321
+ return comments.map((comment, index) => `${(index === 0 ? command : "").padEnd(column)}# ${comment}`);
1322
+ }
1302
1323
  /**
1303
- * `supatype dev`, which applies the schema and generates the types, then watches both. `push` is for
1304
- * another database (`push --env <name>`), and listing it here sent people to it anyway.
1324
+ * The dev script, which applies the schema and generates the types, then watches both; then where
1325
+ * to open the project. `push` is for another database (`push --env <name>`), and listing it here
1326
+ * sent people to it anyway.
1305
1327
  */
1306
- function initDevSteps(result) {
1307
- const steps = [];
1308
- const stack = `${result.provider === "docker" ? "Docker Compose stack" : "native binaries"}, API on ${initLocalApiUrl(result)}`;
1309
- steps.push("supatype dev # applies the schema, generates types, and watches both");
1310
- steps.push(` # ${stack}`);
1311
- if (result.adminEmail) {
1312
- steps.push(" # first admin user is created on dev");
1313
- }
1328
+ function initDevSteps(args) {
1329
+ const { result } = args;
1330
+ const comments = [
1331
+ "applies the schema, generates types, and watches both",
1332
+ result.provider === "docker" ? "runs the Docker Compose stack" : "runs the native binaries",
1333
+ ];
1334
+ if (result.adminEmail)
1335
+ comments.push("first admin user is created on dev");
1336
+ const steps = commented(runScriptCommand(result.packageManager, args.devScript ?? "dev"), comments);
1337
+ steps.push(`Open ${initLocalApiUrl(result)}`);
1314
1338
  if (result.helloFunction) {
1315
- steps.push("supatype functions serve # run edge functions locally");
1339
+ steps.push(...commented(runScriptCommand(result.packageManager, "functions"), ["run edge functions locally"]));
1316
1340
  }
1317
1341
  return steps;
1318
1342
  }
1319
- /** The secrets, frontend and production blocks printed after the first steps. */
1320
- export function printProductionSteps(result) {
1321
- // Shown once, at creation. These are generated per project rather than shipped as
1322
- // constants, so this is the moment to say they exist and where they live, nothing prints
1323
- // them again, and the JWT secret is only echoed as a fingerprint from here on.
1324
- nextSteps("Secrets: generated for this project, kept in .env:", [
1325
- "POSTGRES_PASSWORD direct SQL access as the superuser",
1326
- "AUTHENTICATOR_PASSWORD PostgREST's own login; rotating the one above does not affect it",
1327
- "SUPATYPE_SQL_EDITOR_PASSWORD Studio's SQL editor login, a role that is not a superuser",
1328
- "JWT_SECRET signs ANON_KEY and SERVICE_ROLE_KEY; changing it invalidates every token",
1329
- "Keep .env out of version control, and use different values in production.",
1330
- ]);
1331
- // No frontend block: someone who chose "No app" was told how to serve a static one. `supatype app
1332
- // add` is there when they want one.
1343
+ /**
1344
+ * The secrets init generated, shown once, at creation. They are generated per project rather than
1345
+ * shipped as constants, so this is the moment to say they exist and where they live: nothing prints
1346
+ * them again, and the JWT secret is only echoed as a fingerprint from here on.
1347
+ */
1348
+ const INIT_SECRETS = [
1349
+ ["POSTGRES_PASSWORD", "direct SQL access as the superuser"],
1350
+ ["AUTHENTICATOR_PASSWORD", "PostgREST's own login; rotating the one above does not affect it"],
1351
+ ["SUPATYPE_SQL_EDITOR_PASSWORD", "Studio's SQL editor login, a role that is not a superuser"],
1352
+ ["JWT_SECRET", "signs ANON_KEY and SERVICE_ROLE_KEY; changing it invalidates every token"],
1353
+ ];
1354
+ const SECRETS_CLOSING = "Keep .env out of version control, and use different values in production.";
1355
+ /** One line per secret, each description two spaces past the longest name. */
1356
+ export function initSecretLines() {
1357
+ const width = Math.max(...INIT_SECRETS.map(([name]) => name.length)) + 2;
1358
+ return INIT_SECRETS.map(([name, description]) => `${name.padEnd(width)}${description}`);
1359
+ }
1360
+ /** Taking the project to production, for a target that has one. No frontend block: `supatype app add` covers that. */
1361
+ function deployBlock(result) {
1333
1362
  if (result.productionTarget === "cloud") {
1334
- nextSteps("Deploy to Supatype Cloud:", [
1335
- "supatype login",
1336
- "supatype link --env production --project <ref>",
1337
- "supatype push --env production",
1338
- ]);
1339
- info("supatype.local.config.ts keeps `supatype dev` local while the committed config targets cloud.");
1363
+ return {
1364
+ title: "When you're ready to deploy (Supatype Cloud):",
1365
+ steps: ["supatype login", "supatype link --env production --project <ref>", "supatype push --env production"],
1366
+ };
1340
1367
  }
1341
- else if (result.productionTarget === "self-host") {
1342
- // The self-host steps lead the first block (initFirstSteps); local development follows this.
1343
- info("supatype.local.config.ts keeps `supatype dev` local while the committed config targets self-host.");
1368
+ if (result.productionTarget === "self-host") {
1369
+ return { title: "When you're ready to deploy (self-host):", steps: selfHostDeploySteps(result) };
1344
1370
  }
1345
- plain();
1371
+ return undefined;
1346
1372
  }
1347
- /** Taking a self-host project to its own server, with or without a domain for HTTPS. */
1348
- function selfHostProductionSteps(result) {
1349
- const steps = [];
1373
+ /**
1374
+ * Taking a self-host project to its own server. With a domain, DNS and the firewall come first;
1375
+ * without one, HTTPS is the last step and an optional one, since the person just said they had none.
1376
+ */
1377
+ export function selfHostDeploySteps(result) {
1350
1378
  const domain = result.domain?.trim();
1351
- if (domain) {
1352
- steps.push(`1. Point DNS: an A record for ${domain} -> your server's public IP`);
1353
- steps.push("2. Open ports 80 and 443 on the server firewall");
1354
- if (!result.tlsEmail) {
1355
- steps.push("3. Set server.tls.email in supatype.config.ts (required for HTTPS)");
1356
- }
1357
- steps.push("supatype self-host compose up -d # Kong provisions HTTPS automatically");
1358
- steps.push(`Your Supatype platform goes live at https://${domain}`);
1359
- steps.push("Your app, REST, Auth, Storage, Realtime, Functions, and Studio, all behind one HTTPS domain (certificates outlive restarts)");
1360
- }
1361
- else {
1362
- steps.push("Set server.domain + server.tls.email in supatype.config.ts to enable automatic HTTPS");
1363
- steps.push("supatype self-host compose up -d # Docker stack");
1379
+ const link = "supatype link --env production ... # then: supatype push --env production";
1380
+ if (!domain) {
1381
+ return [
1382
+ "supatype self-host compose up -d # on your server: the Docker stack",
1383
+ link,
1384
+ "Later, optionally: set server.domain and server.tls.email in supatype.config.ts for automatic HTTPS",
1385
+ ];
1364
1386
  }
1365
- steps.push("supatype link --env production ... # then: supatype push --env production");
1366
- return steps;
1387
+ return [
1388
+ `1. Point DNS: an A record for ${domain} -> your server's public IP`,
1389
+ "2. Open ports 80 and 443 on the server firewall",
1390
+ ...(result.tlsEmail ? [] : ["3. Set server.tls.email in supatype.config.ts (required for HTTPS)"]),
1391
+ "supatype self-host compose up -d # Kong provisions HTTPS automatically",
1392
+ link,
1393
+ `Your Supatype platform goes live at https://${domain}`,
1394
+ "Your app, REST, Auth, Storage, Realtime, Functions, and Studio, all behind one HTTPS domain (certificates outlive restarts)",
1395
+ ];
1367
1396
  }
1368
1397
  //# sourceMappingURL=init.js.map