@supatype/cli 0.8.0 → 0.9.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.
Files changed (501) hide show
  1. package/CHANGELOG.md +415 -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/proxy-dev-app.d.ts +13 -3
  8. package/dist/app/proxy-dev-app.d.ts.map +1 -1
  9. package/dist/app/proxy-dev-app.js +58 -62
  10. package/dist/app/proxy-dev-app.js.map +1 -1
  11. package/dist/app-vite-env.d.ts +5 -1
  12. package/dist/app-vite-env.d.ts.map +1 -1
  13. package/dist/app-vite-env.js +9 -15
  14. package/dist/app-vite-env.js.map +1 -1
  15. package/dist/augmentation-generator.d.ts +5 -0
  16. package/dist/augmentation-generator.d.ts.map +1 -1
  17. package/dist/augmentation-generator.js +13 -4
  18. package/dist/augmentation-generator.js.map +1 -1
  19. package/dist/auth-providers.d.ts +5 -4
  20. package/dist/auth-providers.d.ts.map +1 -1
  21. package/dist/auth-providers.js +3 -12
  22. package/dist/auth-providers.js.map +1 -1
  23. package/dist/binary-cache.d.ts +2 -1
  24. package/dist/binary-cache.d.ts.map +1 -1
  25. package/dist/binary-cache.js +2 -4
  26. package/dist/binary-cache.js.map +1 -1
  27. package/dist/build-spawn.d.ts +35 -0
  28. package/dist/build-spawn.d.ts.map +1 -0
  29. package/dist/build-spawn.js +75 -0
  30. package/dist/build-spawn.js.map +1 -0
  31. package/dist/byte-size.d.ts +9 -0
  32. package/dist/byte-size.d.ts.map +1 -0
  33. package/dist/byte-size.js +36 -0
  34. package/dist/byte-size.js.map +1 -0
  35. package/dist/cache-clean.d.ts +0 -2
  36. package/dist/cache-clean.d.ts.map +1 -1
  37. package/dist/cache-clean.js +1 -27
  38. package/dist/cache-clean.js.map +1 -1
  39. package/dist/cache-pins.d.ts.map +1 -1
  40. package/dist/cache-pins.js +1 -18
  41. package/dist/cache-pins.js.map +1 -1
  42. package/dist/cache-root.d.ts +7 -0
  43. package/dist/cache-root.d.ts.map +1 -0
  44. package/dist/cache-root.js +11 -0
  45. package/dist/cache-root.js.map +1 -0
  46. package/dist/cli-artifacts.d.ts.map +1 -1
  47. package/dist/cli-artifacts.js +2 -1
  48. package/dist/cli-artifacts.js.map +1 -1
  49. package/dist/cli-install-method.d.ts.map +1 -1
  50. package/dist/cli-install-method.js +7 -1
  51. package/dist/cli-install-method.js.map +1 -1
  52. package/dist/cli-launcher.d.ts +21 -0
  53. package/dist/cli-launcher.d.ts.map +1 -0
  54. package/dist/cli-launcher.js +112 -0
  55. package/dist/cli-launcher.js.map +1 -0
  56. package/dist/cli-old-versions.d.ts +44 -0
  57. package/dist/cli-old-versions.d.ts.map +1 -0
  58. package/dist/cli-old-versions.js +83 -0
  59. package/dist/cli-old-versions.js.map +1 -0
  60. package/dist/cli-program-path.d.ts +20 -0
  61. package/dist/cli-program-path.d.ts.map +1 -0
  62. package/dist/cli-program-path.js +41 -0
  63. package/dist/cli-program-path.js.map +1 -0
  64. package/dist/cli-standalone.d.ts +2 -3
  65. package/dist/cli-standalone.d.ts.map +1 -1
  66. package/dist/cli-standalone.js +51 -24
  67. package/dist/cli-standalone.js.map +1 -1
  68. package/dist/cli-version-embedded.js +1 -1
  69. package/dist/cli.d.ts.map +1 -1
  70. package/dist/cli.js +4 -0
  71. package/dist/cli.js.map +1 -1
  72. package/dist/cloud-credentials.d.ts.map +1 -1
  73. package/dist/cloud-credentials.js +3 -1
  74. package/dist/cloud-credentials.js.map +1 -1
  75. package/dist/commands/admin.d.ts.map +1 -1
  76. package/dist/commands/admin.js +6 -4
  77. package/dist/commands/admin.js.map +1 -1
  78. package/dist/commands/adopt.js +1 -1
  79. package/dist/commands/adopt.js.map +1 -1
  80. package/dist/commands/build.d.ts +29 -0
  81. package/dist/commands/build.d.ts.map +1 -0
  82. package/dist/commands/build.js +69 -0
  83. package/dist/commands/build.js.map +1 -0
  84. package/dist/commands/cache.d.ts.map +1 -1
  85. package/dist/commands/cache.js +37 -7
  86. package/dist/commands/cache.js.map +1 -1
  87. package/dist/commands/db.d.ts.map +1 -1
  88. package/dist/commands/db.js +46 -23
  89. package/dist/commands/db.js.map +1 -1
  90. package/dist/commands/deploy.d.ts +14 -0
  91. package/dist/commands/deploy.d.ts.map +1 -1
  92. package/dist/commands/deploy.js +68 -53
  93. package/dist/commands/deploy.js.map +1 -1
  94. package/dist/commands/dev.d.ts.map +1 -1
  95. package/dist/commands/dev.js +36 -19
  96. package/dist/commands/dev.js.map +1 -1
  97. package/dist/commands/diff.d.ts +3 -0
  98. package/dist/commands/diff.d.ts.map +1 -1
  99. package/dist/commands/diff.js +28 -34
  100. package/dist/commands/diff.js.map +1 -1
  101. package/dist/commands/doctor.d.ts +32 -0
  102. package/dist/commands/doctor.d.ts.map +1 -1
  103. package/dist/commands/doctor.js +67 -2
  104. package/dist/commands/doctor.js.map +1 -1
  105. package/dist/commands/functions.d.ts.map +1 -1
  106. package/dist/commands/functions.js +21 -16
  107. package/dist/commands/functions.js.map +1 -1
  108. package/dist/commands/hooks.d.ts.map +1 -1
  109. package/dist/commands/hooks.js +23 -15
  110. package/dist/commands/hooks.js.map +1 -1
  111. package/dist/commands/init.d.ts +33 -7
  112. package/dist/commands/init.d.ts.map +1 -1
  113. package/dist/commands/init.js +432 -333
  114. package/dist/commands/init.js.map +1 -1
  115. package/dist/commands/internal.d.ts.map +1 -1
  116. package/dist/commands/internal.js +27 -7
  117. package/dist/commands/internal.js.map +1 -1
  118. package/dist/commands/introspect.d.ts.map +1 -1
  119. package/dist/commands/introspect.js +3 -0
  120. package/dist/commands/introspect.js.map +1 -1
  121. package/dist/commands/keys-print.d.ts +20 -0
  122. package/dist/commands/keys-print.d.ts.map +1 -0
  123. package/dist/commands/keys-print.js +47 -0
  124. package/dist/commands/keys-print.js.map +1 -0
  125. package/dist/commands/keys.d.ts +10 -10
  126. package/dist/commands/keys.d.ts.map +1 -1
  127. package/dist/commands/keys.js +47 -43
  128. package/dist/commands/keys.js.map +1 -1
  129. package/dist/commands/link-helpers.d.ts.map +1 -1
  130. package/dist/commands/link-helpers.js +27 -7
  131. package/dist/commands/link-helpers.js.map +1 -1
  132. package/dist/commands/migrate.d.ts +5 -2
  133. package/dist/commands/migrate.d.ts.map +1 -1
  134. package/dist/commands/migrate.js +34 -36
  135. package/dist/commands/migrate.js.map +1 -1
  136. package/dist/commands/pull.d.ts.map +1 -1
  137. package/dist/commands/pull.js +6 -5
  138. package/dist/commands/pull.js.map +1 -1
  139. package/dist/commands/push.d.ts +2 -0
  140. package/dist/commands/push.d.ts.map +1 -1
  141. package/dist/commands/push.js +64 -26
  142. package/dist/commands/push.js.map +1 -1
  143. package/dist/commands/rename.js +1 -1
  144. package/dist/commands/rename.js.map +1 -1
  145. package/dist/commands/seed.d.ts +2 -11
  146. package/dist/commands/seed.d.ts.map +1 -1
  147. package/dist/commands/seed.js +11 -38
  148. package/dist/commands/seed.js.map +1 -1
  149. package/dist/commands/self-host.d.ts.map +1 -1
  150. package/dist/commands/self-host.js +88 -29
  151. package/dist/commands/self-host.js.map +1 -1
  152. package/dist/commands/self-update.d.ts.map +1 -1
  153. package/dist/commands/self-update.js +9 -3
  154. package/dist/commands/self-update.js.map +1 -1
  155. package/dist/commands/sso.d.ts +26 -0
  156. package/dist/commands/sso.d.ts.map +1 -0
  157. package/dist/commands/sso.js +362 -0
  158. package/dist/commands/sso.js.map +1 -0
  159. package/dist/commands/status.d.ts.map +1 -1
  160. package/dist/commands/status.js +25 -8
  161. package/dist/commands/status.js.map +1 -1
  162. package/dist/component-launch.d.ts.map +1 -1
  163. package/dist/component-launch.js +2 -1
  164. package/dist/component-launch.js.map +1 -1
  165. package/dist/compose-db-roles.d.ts +4 -4
  166. package/dist/compose-db-roles.d.ts.map +1 -1
  167. package/dist/compose-db-roles.js +11 -10
  168. package/dist/compose-db-roles.js.map +1 -1
  169. package/dist/compose-engine-run.d.ts +9 -2
  170. package/dist/compose-engine-run.d.ts.map +1 -1
  171. package/dist/compose-engine-run.js +30 -13
  172. package/dist/compose-engine-run.js.map +1 -1
  173. package/dist/compose-kong.d.ts +4 -0
  174. package/dist/compose-kong.d.ts.map +1 -1
  175. package/dist/compose-kong.js +13 -3
  176. package/dist/compose-kong.js.map +1 -1
  177. package/dist/compose-services.d.ts +18 -0
  178. package/dist/compose-services.d.ts.map +1 -1
  179. package/dist/compose-services.js +47 -22
  180. package/dist/compose-services.js.map +1 -1
  181. package/dist/config-mailer-env.d.ts +27 -0
  182. package/dist/config-mailer-env.d.ts.map +1 -0
  183. package/dist/config-mailer-env.js +47 -0
  184. package/dist/config-mailer-env.js.map +1 -0
  185. package/dist/config.d.ts +9 -1
  186. package/dist/config.d.ts.map +1 -1
  187. package/dist/config.js +18 -3
  188. package/dist/config.js.map +1 -1
  189. package/dist/database-url-owner.d.ts +5 -3
  190. package/dist/database-url-owner.d.ts.map +1 -1
  191. package/dist/database-url-owner.js +7 -4
  192. package/dist/database-url-owner.js.map +1 -1
  193. package/dist/db-port.d.ts +2 -0
  194. package/dist/db-port.d.ts.map +1 -1
  195. package/dist/db-port.js +1 -1
  196. package/dist/db-port.js.map +1 -1
  197. package/dist/db-preflight.d.ts +32 -3
  198. package/dist/db-preflight.d.ts.map +1 -1
  199. package/dist/db-preflight.js +211 -86
  200. package/dist/db-preflight.js.map +1 -1
  201. package/dist/db-rows.d.ts +3 -2
  202. package/dist/db-rows.d.ts.map +1 -1
  203. package/dist/db-rows.js +19 -4
  204. package/dist/db-rows.js.map +1 -1
  205. package/dist/dev-compose.d.ts +65 -5
  206. package/dist/dev-compose.d.ts.map +1 -1
  207. package/dist/dev-compose.js +262 -155
  208. package/dist/dev-compose.js.map +1 -1
  209. package/dist/dev-log-bus.d.ts +8 -0
  210. package/dist/dev-log-bus.d.ts.map +1 -1
  211. package/dist/dev-log-bus.js +13 -0
  212. package/dist/dev-log-bus.js.map +1 -1
  213. package/dist/dev-ports.d.ts +11 -4
  214. package/dist/dev-ports.d.ts.map +1 -1
  215. package/dist/dev-ports.js +87 -49
  216. package/dist/dev-ports.js.map +1 -1
  217. package/dist/dev-schema-watch.d.ts +8 -2
  218. package/dist/dev-schema-watch.d.ts.map +1 -1
  219. package/dist/dev-schema-watch.js +24 -13
  220. package/dist/dev-schema-watch.js.map +1 -1
  221. package/dist/dev-session.d.ts +27 -1
  222. package/dist/dev-session.d.ts.map +1 -1
  223. package/dist/dev-session.js +44 -4
  224. package/dist/dev-session.js.map +1 -1
  225. package/dist/dev-shutdown.d.ts.map +1 -1
  226. package/dist/dev-shutdown.js +19 -3
  227. package/dist/dev-shutdown.js.map +1 -1
  228. package/dist/diff-access.d.ts +10 -0
  229. package/dist/diff-access.d.ts.map +1 -0
  230. package/dist/diff-access.js +69 -0
  231. package/dist/diff-access.js.map +1 -0
  232. package/dist/diff-output.d.ts +7 -1
  233. package/dist/diff-output.d.ts.map +1 -1
  234. package/dist/diff-output.js +93 -3
  235. package/dist/diff-output.js.map +1 -1
  236. package/dist/docker-exec.d.ts.map +1 -1
  237. package/dist/docker-exec.js +4 -4
  238. package/dist/docker-exec.js.map +1 -1
  239. package/dist/docker-runtime.d.ts +10 -2
  240. package/dist/docker-runtime.d.ts.map +1 -1
  241. package/dist/docker-runtime.js +70 -23
  242. package/dist/docker-runtime.js.map +1 -1
  243. package/dist/engine-answers.d.ts +2 -1
  244. package/dist/engine-answers.d.ts.map +1 -1
  245. package/dist/engine-answers.js +11 -0
  246. package/dist/engine-answers.js.map +1 -1
  247. package/dist/engine-client.d.ts +20 -0
  248. package/dist/engine-client.d.ts.map +1 -1
  249. package/dist/engine-client.js +12 -8
  250. package/dist/engine-client.js.map +1 -1
  251. package/dist/engine-floor.d.ts +3 -2
  252. package/dist/engine-floor.d.ts.map +1 -1
  253. package/dist/engine-floor.js +2 -2
  254. package/dist/engine-floor.js.map +1 -1
  255. package/dist/engine-ownership-gate.d.ts +3 -1
  256. package/dist/engine-ownership-gate.d.ts.map +1 -1
  257. package/dist/engine-ownership-gate.js +5 -0
  258. package/dist/engine-ownership-gate.js.map +1 -1
  259. package/dist/engine-push-output.d.ts +8 -1
  260. package/dist/engine-push-output.d.ts.map +1 -1
  261. package/dist/engine-push-output.js +8 -1
  262. package/dist/engine-push-output.js.map +1 -1
  263. package/dist/env-file.d.ts +9 -2
  264. package/dist/env-file.d.ts.map +1 -1
  265. package/dist/env-file.js +56 -38
  266. package/dist/env-file.js.map +1 -1
  267. package/dist/env-lines.d.ts +3 -2
  268. package/dist/env-lines.d.ts.map +1 -1
  269. package/dist/env-lines.js +5 -2
  270. package/dist/env-lines.js.map +1 -1
  271. package/dist/env-value.d.ts +15 -0
  272. package/dist/env-value.d.ts.map +1 -0
  273. package/dist/env-value.js +34 -0
  274. package/dist/env-value.js.map +1 -0
  275. package/dist/error-message.d.ts +20 -0
  276. package/dist/error-message.d.ts.map +1 -1
  277. package/dist/error-message.js +42 -0
  278. package/dist/error-message.js.map +1 -1
  279. package/dist/frontend-env.d.ts +51 -0
  280. package/dist/frontend-env.d.ts.map +1 -0
  281. package/dist/frontend-env.js +101 -0
  282. package/dist/frontend-env.js.map +1 -0
  283. package/dist/frontend-values-linked.d.ts +22 -0
  284. package/dist/frontend-values-linked.d.ts.map +1 -0
  285. package/dist/frontend-values-linked.js +143 -0
  286. package/dist/frontend-values-linked.js.map +1 -0
  287. package/dist/frontend-values.d.ts +90 -0
  288. package/dist/frontend-values.d.ts.map +1 -0
  289. package/dist/frontend-values.js +208 -0
  290. package/dist/frontend-values.js.map +1 -0
  291. package/dist/functions-env-local.d.ts +13 -0
  292. package/dist/functions-env-local.d.ts.map +1 -0
  293. package/dist/functions-env-local.js +20 -0
  294. package/dist/functions-env-local.js.map +1 -0
  295. package/dist/generated/release-images.d.ts +4 -4
  296. package/dist/generated/release-images.js +2 -2
  297. package/dist/generated/release-images.js.map +1 -1
  298. package/dist/generated/typescript-libs.d.ts +4 -0
  299. package/dist/generated/typescript-libs.d.ts.map +1 -0
  300. package/dist/generated/typescript-libs.js +64 -0
  301. package/dist/generated/typescript-libs.js.map +1 -0
  302. package/dist/hook-actor.d.ts +17 -0
  303. package/dist/hook-actor.d.ts.map +1 -0
  304. package/dist/hook-actor.js +37 -0
  305. package/dist/hook-actor.js.map +1 -0
  306. package/dist/hook-columns.d.ts +30 -0
  307. package/dist/hook-columns.d.ts.map +1 -0
  308. package/dist/hook-columns.js +77 -0
  309. package/dist/hook-columns.js.map +1 -0
  310. package/dist/hook-events.d.ts +11 -0
  311. package/dist/hook-events.d.ts.map +1 -0
  312. package/dist/hook-events.js +11 -0
  313. package/dist/hook-events.js.map +1 -0
  314. package/dist/hooks-generator.d.ts.map +1 -1
  315. package/dist/hooks-generator.js +87 -21
  316. package/dist/hooks-generator.js.map +1 -1
  317. package/dist/host-database.d.ts +10 -10
  318. package/dist/host-database.d.ts.map +1 -1
  319. package/dist/host-database.js +18 -15
  320. package/dist/host-database.js.map +1 -1
  321. package/dist/init-answers.d.ts +18 -0
  322. package/dist/init-answers.d.ts.map +1 -0
  323. package/dist/init-answers.js +46 -0
  324. package/dist/init-answers.js.map +1 -0
  325. package/dist/init-dependency-versions.d.ts.map +1 -1
  326. package/dist/init-dependency-versions.js +11 -1
  327. package/dist/init-dependency-versions.js.map +1 -1
  328. package/dist/init-next-runtime-env.d.ts +30 -0
  329. package/dist/init-next-runtime-env.d.ts.map +1 -0
  330. package/dist/init-next-runtime-env.js +180 -0
  331. package/dist/init-next-runtime-env.js.map +1 -0
  332. package/dist/init-package-json.d.ts +38 -1
  333. package/dist/init-package-json.d.ts.map +1 -1
  334. package/dist/init-package-json.js +150 -39
  335. package/dist/init-package-json.js.map +1 -1
  336. package/dist/jwt.d.ts +5 -0
  337. package/dist/jwt.d.ts.map +1 -1
  338. package/dist/jwt.js +16 -0
  339. package/dist/jwt.js.map +1 -1
  340. package/dist/local-secrets.d.ts +22 -0
  341. package/dist/local-secrets.d.ts.map +1 -1
  342. package/dist/local-secrets.js +36 -0
  343. package/dist/local-secrets.js.map +1 -1
  344. package/dist/local-stack-guard.d.ts +37 -0
  345. package/dist/local-stack-guard.d.ts.map +1 -0
  346. package/dist/local-stack-guard.js +84 -0
  347. package/dist/local-stack-guard.js.map +1 -0
  348. package/dist/mailer-env.d.ts +4 -0
  349. package/dist/mailer-env.d.ts.map +1 -1
  350. package/dist/mailer-env.js +12 -1
  351. package/dist/mailer-env.js.map +1 -1
  352. package/dist/model-hooks.d.ts +5 -1
  353. package/dist/model-hooks.d.ts.map +1 -1
  354. package/dist/model-hooks.js +12 -2
  355. package/dist/model-hooks.js.map +1 -1
  356. package/dist/node-executable.d.ts +6 -0
  357. package/dist/node-executable.d.ts.map +1 -0
  358. package/dist/node-executable.js +43 -0
  359. package/dist/node-executable.js.map +1 -0
  360. package/dist/parent-watch.d.ts +8 -3
  361. package/dist/parent-watch.d.ts.map +1 -1
  362. package/dist/parent-watch.js +8 -3
  363. package/dist/parent-watch.js.map +1 -1
  364. package/dist/postgres-ctl.d.ts +2 -0
  365. package/dist/postgres-ctl.d.ts.map +1 -1
  366. package/dist/postgres-ctl.js +11 -5
  367. package/dist/postgres-ctl.js.map +1 -1
  368. package/dist/process-manager.d.ts +37 -5
  369. package/dist/process-manager.d.ts.map +1 -1
  370. package/dist/process-manager.js +127 -65
  371. package/dist/process-manager.js.map +1 -1
  372. package/dist/project-config.d.ts +31 -0
  373. package/dist/project-config.d.ts.map +1 -1
  374. package/dist/project-config.js +24 -0
  375. package/dist/project-config.js.map +1 -1
  376. package/dist/push-audit.d.ts +4 -1
  377. package/dist/push-audit.d.ts.map +1 -1
  378. package/dist/push-audit.js +33 -4
  379. package/dist/push-audit.js.map +1 -1
  380. package/dist/recorded-field-masking-tier.d.ts +2 -2
  381. package/dist/recorded-field-masking-tier.d.ts.map +1 -1
  382. package/dist/recorded-field-masking-tier.js +6 -6
  383. package/dist/recorded-field-masking-tier.js.map +1 -1
  384. package/dist/rename-journal.d.ts +1 -1
  385. package/dist/rename-journal.d.ts.map +1 -1
  386. package/dist/resolve-api-url.d.ts +2 -0
  387. package/dist/resolve-api-url.d.ts.map +1 -1
  388. package/dist/resolve-api-url.js +5 -1
  389. package/dist/resolve-api-url.js.map +1 -1
  390. package/dist/resolve-target.d.ts +18 -1
  391. package/dist/resolve-target.d.ts.map +1 -1
  392. package/dist/resolve-target.js +28 -16
  393. package/dist/resolve-target.js.map +1 -1
  394. package/dist/run-captured.d.ts +31 -0
  395. package/dist/run-captured.d.ts.map +1 -0
  396. package/dist/run-captured.js +36 -0
  397. package/dist/run-captured.js.map +1 -0
  398. package/dist/saml-config.d.ts +53 -0
  399. package/dist/saml-config.d.ts.map +1 -0
  400. package/dist/saml-config.js +177 -0
  401. package/dist/saml-config.js.map +1 -0
  402. package/dist/saml-key-rotation.d.ts +5 -0
  403. package/dist/saml-key-rotation.d.ts.map +1 -0
  404. package/dist/saml-key-rotation.js +26 -0
  405. package/dist/saml-key-rotation.js.map +1 -0
  406. package/dist/saml-sp-certificate.d.ts +15 -0
  407. package/dist/saml-sp-certificate.d.ts.map +1 -0
  408. package/dist/saml-sp-certificate.js +34 -0
  409. package/dist/saml-sp-certificate.js.map +1 -0
  410. package/dist/schema-reset.d.ts +41 -0
  411. package/dist/schema-reset.d.ts.map +1 -0
  412. package/dist/schema-reset.js +98 -0
  413. package/dist/schema-reset.js.map +1 -0
  414. package/dist/seed-child.d.ts +25 -0
  415. package/dist/seed-child.d.ts.map +1 -0
  416. package/dist/seed-child.js +61 -0
  417. package/dist/seed-child.js.map +1 -0
  418. package/dist/seed-runner.d.ts +3 -5
  419. package/dist/seed-runner.d.ts.map +1 -1
  420. package/dist/seed-runner.js +20 -42
  421. package/dist/seed-runner.js.map +1 -1
  422. package/dist/self-host-compose.d.ts +25 -4
  423. package/dist/self-host-compose.d.ts.map +1 -1
  424. package/dist/self-host-compose.js +108 -23
  425. package/dist/self-host-compose.js.map +1 -1
  426. package/dist/serial-runs.d.ts +7 -0
  427. package/dist/serial-runs.d.ts.map +1 -0
  428. package/dist/serial-runs.js +29 -0
  429. package/dist/serial-runs.js.map +1 -0
  430. package/dist/shell-ports.d.ts.map +1 -1
  431. package/dist/shell-ports.js +2 -8
  432. package/dist/shell-ports.js.map +1 -1
  433. package/dist/sso-admin.d.ts +114 -0
  434. package/dist/sso-admin.d.ts.map +1 -0
  435. package/dist/sso-admin.js +256 -0
  436. package/dist/sso-admin.js.map +1 -0
  437. package/dist/stack-engine.d.ts +28 -0
  438. package/dist/stack-engine.d.ts.map +1 -0
  439. package/dist/stack-engine.js +59 -0
  440. package/dist/stack-engine.js.map +1 -0
  441. package/dist/stack-exit-watch.d.ts +37 -0
  442. package/dist/stack-exit-watch.d.ts.map +1 -0
  443. package/dist/stack-exit-watch.js +70 -0
  444. package/dist/stack-exit-watch.js.map +1 -0
  445. package/dist/stack-setting-warnings.d.ts +8 -0
  446. package/dist/stack-setting-warnings.d.ts.map +1 -0
  447. package/dist/stack-setting-warnings.js +14 -0
  448. package/dist/stack-setting-warnings.js.map +1 -0
  449. package/dist/studio-dev-server.d.ts.map +1 -1
  450. package/dist/studio-dev-server.js +2 -1
  451. package/dist/studio-dev-server.js.map +1 -1
  452. package/dist/target-client.d.ts +12 -2
  453. package/dist/target-client.d.ts.map +1 -1
  454. package/dist/target-client.js +14 -1
  455. package/dist/target-client.js.map +1 -1
  456. package/dist/tsx-runner.d.ts +5 -0
  457. package/dist/tsx-runner.d.ts.map +1 -1
  458. package/dist/tsx-runner.js +18 -17
  459. package/dist/tsx-runner.js.map +1 -1
  460. package/dist/type-extractor.d.ts.map +1 -1
  461. package/dist/type-extractor.js +20 -11
  462. package/dist/type-extractor.js.map +1 -1
  463. package/dist/type-generation.d.ts +1 -1
  464. package/dist/type-generation.d.ts.map +1 -1
  465. package/dist/type-generation.js +2 -4
  466. package/dist/type-generation.js.map +1 -1
  467. package/dist/type-resolver.d.ts.map +1 -1
  468. package/dist/type-resolver.js +31 -12
  469. package/dist/type-resolver.js.map +1 -1
  470. package/dist/ui/clack-api.d.ts.map +1 -1
  471. package/dist/ui/clack-api.js +45 -23
  472. package/dist/ui/clack-api.js.map +1 -1
  473. package/dist/ui/components/LineInput.d.ts +26 -0
  474. package/dist/ui/components/LineInput.d.ts.map +1 -0
  475. package/dist/ui/components/LineInput.js +60 -0
  476. package/dist/ui/components/LineInput.js.map +1 -0
  477. package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
  478. package/dist/ui/dev/DevDashboard.js +9 -3
  479. package/dist/ui/dev/DevDashboard.js.map +1 -1
  480. package/dist/ui/flows/FlowApp.d.ts +3 -1
  481. package/dist/ui/flows/FlowApp.d.ts.map +1 -1
  482. package/dist/ui/flows/FlowApp.js +14 -5
  483. package/dist/ui/flows/FlowApp.js.map +1 -1
  484. package/dist/ui/flows/prompt-fields.d.ts +14 -7
  485. package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
  486. package/dist/ui/flows/prompt-fields.js +20 -12
  487. package/dist/ui/flows/prompt-fields.js.map +1 -1
  488. package/dist/ui/flows/types.d.ts +5 -1
  489. package/dist/ui/flows/types.d.ts.map +1 -1
  490. package/dist/ui/runtime/command-chrome.d.ts.map +1 -1
  491. package/dist/ui/runtime/command-chrome.js +2 -0
  492. package/dist/ui/runtime/command-chrome.js.map +1 -1
  493. package/dist/ui/runtime/flow-transcript.d.ts +17 -0
  494. package/dist/ui/runtime/flow-transcript.d.ts.map +1 -0
  495. package/dist/ui/runtime/flow-transcript.js +38 -0
  496. package/dist/ui/runtime/flow-transcript.js.map +1 -0
  497. package/dist/ui/runtime/run-clack-flow.d.ts +7 -0
  498. package/dist/ui/runtime/run-clack-flow.d.ts.map +1 -1
  499. package/dist/ui/runtime/run-clack-flow.js +131 -17
  500. package/dist/ui/runtime/run-clack-flow.js.map +1 -1
  501. package/package.json +16 -14
@@ -5,8 +5,11 @@ import { p, runClackFlow } from "../ui/clack.js";
5
5
  import { withProgressView } from "../ui/progress.js";
6
6
  import { installCommand, installDependencies, plainStepView, runTimedStep, spinnerStepView, } from "../init-setup-steps.js";
7
7
  import { ensureNotCancelled } from "../ui/prompts.js";
8
+ import { adminEmailProblem, answerProblem, askText, smtpHostProblem, smtpPortProblem } from "../init-answers.js";
9
+ import { assertEnvValues } from "../env-value.js";
10
+ import { ensureFunctionsEnvLocal, FUNCTIONS_ENV_LOCAL } from "../functions-env-local.js";
8
11
  import { generateAndWriteKeys } from "./keys.js";
9
- import { BUNDLED_DB_USER, CONTROL_PLANE_SECRET_ENV, generateControlPlaneSecret, givenJwtSecret, newJwtSecret, } from "../local-secrets.js";
12
+ import { BUNDLED_DB_USER, CONTROL_PLANE_SECRET_ENV, generateControlPlaneSecret, generateObjectStoreCredentials, givenJwtSecret, newJwtSecret, OBJECT_STORE_ACCESS_KEY_ENV, OBJECT_STORE_SECRET_KEY_ENV, } from "../local-secrets.js";
10
13
  import { file, error, info, plain, warn } from "../ui/messages.js";
11
14
  import { nextSteps } from "../ui/next-steps.js";
12
15
  import { probeDockerDaemonAsync, reportDockerUnavailable } from "../docker-runtime.js";
@@ -14,17 +17,19 @@ import { loadConfig } from "../config.js";
14
17
  import { ensureComponentBinaries, reportComponentBinaryFailures, } from "../ensure-component-binaries.js";
15
18
  import { ensureFunctionsDenoTypes, sharedFunctionsReadmeSource, } from "../functions-deno-types.js";
16
19
  import { functionTemplateSource } from "../functions-template.js";
17
- import { mergeSupatypePackageJson } from "../init-package-json.js";
20
+ import { mergeSupatypePackageJson, PREPARE_COMMAND, scaffoldPackageJson, supatypeDevScript, } from "../init-package-json.js";
18
21
  import { downloadRelease, initFromExample } from "../init-example.js";
19
22
  import { errorMessage } from "../error-message.js";
20
- import { parseJsonObject } from "@supatype/shared";
23
+ import { isJsonObject, parseJsonObject } from "@supatype/shared";
21
24
  import { cliPackageVersion } from "../cli-package-version.js";
22
25
  import { initDependencyVersionsFallback, resolveInitDependencyVersions, } from "../init-dependency-versions.js";
23
26
  import { detectProjectSetup } from "../init-project-detect.js";
24
27
  import { SUPATYPE_GITIGNORE_PATHS } from "../gitignore.js";
28
+ import { DEV_FRONTEND_ENV_FILE, writeFrontendEnv } from "../frontend-env.js";
25
29
  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";
30
+ import { COMPOSE_DEV_KONG_PORT, defaultAppStaticDir, NATIVE_DB_PORT, NATIVE_SERVER_PORT, nativeDatabaseUrl, VITE_BUILD_DIR, } from "../project-config.js";
27
31
  import { cliDatabaseUrlLines } from "../database-url-owner.js";
32
+ import { scaffoldNextRuntimeEnv } from "../init-next-runtime-env.js";
28
33
  const STORAGE_PROVIDER_OPTIONS = [
29
34
  { value: "local", label: "Local", hint: "storage you host yourself (SeaweedFS)" },
30
35
  { value: "s3", label: "S3", hint: "external bucket (AWS S3 or compatible)" },
@@ -119,35 +124,57 @@ export function registerInit(program) {
119
124
  const asked = startInitQuestions(result.provider);
120
125
  if (asked.kongPort)
121
126
  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
- });
127
+ await createProject({ name, dir, result, opts, deps: asked.deps, ...(asked.daemon !== undefined && { daemon: asked.daemon }) });
128
+ });
129
+ }
130
+ /**
131
+ * Write the project, run its setup steps and print what is left, the same for the interactive init
132
+ * and `init -y`. They were two copies, and had come to disagree about whether keys nobody generated
133
+ * were a step left to do.
134
+ */
135
+ async function createProject(args) {
136
+ const { name, dir, result, opts } = args;
137
+ applyAdminFlags(result, opts);
138
+ // CLI flags override wizard / default action choices.
139
+ const wants = { install: opts.install !== false && result.install, keys: opts.keys !== false && result.generateKeys };
140
+ if (name)
141
+ mkdirSync(dir, { recursive: true });
142
+ scaffold(dir, result, await args.deps);
143
+ const outcome = await withStepView((view) => runSetupSteps(dir, result.packageManager, wants, view));
144
+ exitOnFailedSetup(outcome, wants, result.packageManager);
145
+ await warnDockerUnavailableForProvider(result.provider, args.daemon);
146
+ printNextSteps({
147
+ name,
148
+ result,
149
+ installed: wants.install && outcome.installOk,
150
+ keysGenerated: outcome.keysGenerated,
151
+ binariesReady: outcome.binariesReady,
152
+ devScript: projectDevScript(dir),
149
153
  });
150
154
  }
155
+ /** `--no-admin`, or `--admin-email` with `--admin-password`, over the answers. */
156
+ function applyAdminFlags(result, opts) {
157
+ if (opts.admin === false) {
158
+ delete result.adminEmail;
159
+ delete result.adminPassword;
160
+ }
161
+ else if (opts.adminEmail && opts.adminPassword) {
162
+ refuseAdminFlags(opts.adminEmail, opts.adminPassword);
163
+ result.adminEmail = opts.adminEmail.trim();
164
+ result.adminPassword = opts.adminPassword;
165
+ }
166
+ }
167
+ /** Exits before anything is written when the admin flags hold what the prompts would refuse. */
168
+ function refuseAdminFlags(email, password) {
169
+ const emailProblem = adminEmailProblem(email);
170
+ const passwordProblem = answerProblem(password);
171
+ if (emailProblem !== undefined)
172
+ error(`--admin-email: ${emailProblem}`);
173
+ if (passwordProblem !== undefined)
174
+ error(`--admin-password: ${passwordProblem}`);
175
+ if (emailProblem !== undefined || passwordProblem !== undefined)
176
+ process.exit(1);
177
+ }
151
178
  /** Interactive init: one Ink session for wizard + scaffold + install + finish. */
152
179
  async function runInteractiveInit(args) {
153
180
  const { name, dir, defaultName, modeTarget, opts } = args;
@@ -157,47 +184,18 @@ async function runInteractiveInit(args) {
157
184
  if (detected.hasExistingFiles && detected.summaryLines.length > 0) {
158
185
  p.note(["Existing project detected:", ...detected.summaryLines.map((line) => ` • ${line}`)].join("\n"));
159
186
  }
160
- let result = await collectWizardAnswers({
187
+ const result = await collectWizardAnswers({
161
188
  defaultName,
162
189
  defaultTarget: modeTarget,
163
- dir,
164
190
  detected,
165
191
  askName: name === undefined,
166
192
  });
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
- });
193
+ await createProject({ name, dir, result, opts, deps: resolveDependencyVersions() });
196
194
  });
197
195
  process.exit(0);
198
196
  }
199
197
  export async function collectWizardAnswers(context) {
200
- const { defaultName, defaultTarget, dir, detected } = context;
198
+ const { defaultName, defaultTarget, detected } = context;
201
199
  const projectName = context.askName ? await promptProjectName(defaultName) : defaultName;
202
200
  const admin = await promptAdminUser();
203
201
  const packageManager = ensureNotCancelled(await p.select({
@@ -219,23 +217,7 @@ export async function collectWizardAnswers(context) {
219
217
  { value: "later", label: "Decide later", hint: "local development only for now" },
220
218
  ],
221
219
  }));
222
- let domain;
223
- let tlsEmail;
224
- if (productionTarget === "self-host") {
225
- domain = ensureNotCancelled(await p.text({
226
- message: "Production domain for ACME TLS (optional, can set later)",
227
- placeholder: "api.example.com",
228
- defaultValue: "",
229
- })).trim();
230
- if (domain) {
231
- tlsEmail =
232
- ensureNotCancelled(await p.text({
233
- message: "Email for Let's Encrypt (HTTPS) certificates",
234
- placeholder: "you@example.com",
235
- defaultValue: "",
236
- })).trim() || undefined;
237
- }
238
- }
220
+ const tls = productionTarget === "self-host" ? await promptSelfHostTls() : {};
239
221
  const provider = ensureNotCancelled(await p.select({
240
222
  message: "How should Postgres and the server run for local development?",
241
223
  initialValue: "docker",
@@ -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",
@@ -268,6 +243,8 @@ export async function collectWizardAnswers(context) {
268
243
  { value: "ses", label: "Amazon SES" },
269
244
  ],
270
245
  }));
246
+ // Without a host the server uses its noop mailer and drops every email (issue 76).
247
+ const smtp = email === "smtp" ? await promptSmtpServer() : undefined;
271
248
  const storageLocal = ensureNotCancelled(await p.select({
272
249
  message: "Local storage (for development)?",
273
250
  initialValue: "local",
@@ -284,11 +261,11 @@ export async function collectWizardAnswers(context) {
284
261
  provider,
285
262
  ...(kongPort !== undefined ? { kongPort } : {}),
286
263
  productionTarget,
287
- ...(domain !== undefined ? { domain } : {}),
288
- ...(tlsEmail !== undefined ? { tlsEmail } : {}),
264
+ ...tls,
289
265
  schemaPath,
290
266
  app,
291
267
  email,
268
+ ...(smtp !== undefined && { smtp }),
292
269
  storageLocal,
293
270
  storageProduction,
294
271
  helloFunction,
@@ -298,9 +275,28 @@ export async function collectWizardAnswers(context) {
298
275
  ...admin,
299
276
  };
300
277
  }
278
+ /** The submission port most SMTP servers take, offered as the answer. */
279
+ const SMTP_PORT = "587";
280
+ /** The SMTP server's host and port, both required to send anything. */
281
+ async function promptSmtpServer() {
282
+ const host = (await askText({ message: "SMTP host", placeholder: "smtp.example.com", validate: smtpHostProblem })).trim();
283
+ const port = await askText({ message: "SMTP port", defaultValue: SMTP_PORT, placeholder: SMTP_PORT, validate: smtpPortProblem });
284
+ return { host, port: Number(port.trim() || SMTP_PORT) };
285
+ }
286
+ /** A self-hosted project's domain for ACME TLS, and the email for its certificates when it has one. */
287
+ async function promptSelfHostTls() {
288
+ const domain = (await askText({ message: "Production domain for ACME TLS (optional, can set later)", placeholder: "api.example.com", defaultValue: "" })).trim();
289
+ if (!domain)
290
+ return { domain };
291
+ const tlsEmail = (await askText({ message: "Email for Let's Encrypt (HTTPS) certificates", placeholder: "you@example.com", defaultValue: "" })).trim();
292
+ return { domain, ...(tlsEmail !== "" && { tlsEmail }) };
293
+ }
301
294
  async function promptProjectName(defaultName) {
302
- const answer = ensureNotCancelled(await p.text({ message: "Project name", defaultValue: defaultName, placeholder: defaultName }));
303
- return answer.trim() || defaultName;
295
+ return askWithDefault("Project name", defaultName);
296
+ }
297
+ /** A text answer, trimmed, or `defaultValue` when it was left empty. */
298
+ async function askWithDefault(message, defaultValue) {
299
+ return (await askText({ message, defaultValue })).trim() || defaultValue;
304
300
  }
305
301
  async function promptProductionStorage() {
306
302
  return ensureNotCancelled(await p.select({
@@ -317,19 +313,26 @@ async function promptAdminUser() {
317
313
  if (!createAdmin)
318
314
  return {};
319
315
  p.note("First sign-in to Studio at /studio/, created automatically on supatype dev or push.");
320
- const adminEmail = ensureNotCancelled(await p.text({
321
- message: "Admin email",
322
- placeholder: "you@example.com",
323
- validate: (value) => (value.trim() ? undefined : "Email is required"),
324
- })).trim();
325
- let adminPassword = "";
316
+ const adminEmail = (await askText({ message: "Admin email", placeholder: "you@example.com", validate: adminEmailProblem })).trim();
317
+ return { adminEmail, adminPassword: await promptAdminPassword() };
318
+ }
319
+ /**
320
+ * The admin password, typed twice: asked once, a typo became the Studio password with nothing to
321
+ * show it. Both are asked again when they differ.
322
+ */
323
+ async function promptAdminPassword() {
326
324
  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.");
325
+ const password = ensureNotCancelled(await p.password({ message: "Admin password (min 8 characters)" })).trim();
326
+ const problem = answerProblem(password) ?? (password.length < 8 ? "Password must be at least 8 characters." : undefined);
327
+ if (problem !== undefined) {
328
+ p.log.warn(problem);
329
+ continue;
330
+ }
331
+ const confirmed = ensureNotCancelled(await p.password({ message: "Confirm admin password" })).trim();
332
+ if (confirmed === password)
333
+ return password;
334
+ p.log.warn("Passwords do not match.");
331
335
  }
332
- return { adminEmail, adminPassword };
333
336
  }
334
337
  async function promptApp(detected, productionTarget) {
335
338
  const initialMode = detected.hasVite && productionTarget !== "later"
@@ -347,30 +350,31 @@ async function promptApp(detected, productionTarget) {
347
350
  ],
348
351
  }));
349
352
  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
353
  const viteDevUrl = await promptViteDevUrl(detected, productionTarget);
356
- return { mode, staticDir, ...(viteDevUrl ? { viteDevUrl } : {}) };
354
+ return { mode, staticDir: await promptStaticDir(detected, viteDevUrl !== undefined), ...(viteDevUrl ? { viteDevUrl } : {}) };
357
355
  }
358
356
  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");
357
+ const upstream = await askWithDefault("URL of your running dev server", detected.hasVite ? detected.viteDevUrl : "http://localhost:3000");
358
+ const start = await askWithDefault("package.json script that starts your dev server", detected.hasVite ? "vite" : "dev");
369
359
  const viteDevUrl = await promptViteDevUrl(detected, productionTarget);
370
360
  return { mode, upstream, start, ...(viteDevUrl ? { viteDevUrl } : {}) };
371
361
  }
372
362
  return { mode: "none" };
373
363
  }
364
+ /**
365
+ * The directory a static site is served from, asked after Vite: it was asked before, so a new Vite
366
+ * project was offered ./public. A Vite project is offered its build output, ./dist; a site with no
367
+ * build is offered what detection found, ./public when it found nothing. ./public for Vite is
368
+ * warned about and kept: it is Vite's folder of assets copied into the build, not the build.
369
+ */
370
+ async function promptStaticDir(detected, vite) {
371
+ const staticDir = await askWithDefault("Directory to serve", vite ? VITE_BUILD_DIR : detected.staticDir);
372
+ if (vite && staticDirRelative(staticDir) === "public") {
373
+ p.log.warn("./public is Vite's folder for static assets it copies into the build, so serving it skips the build. " +
374
+ "Vite builds into ./dist unless vite.config.ts says otherwise.");
375
+ }
376
+ return staticDir;
377
+ }
374
378
  async function promptViteDevUrl(detected, productionTarget) {
375
379
  const defaultYes = detected.hasVite || productionTarget !== "later";
376
380
  const useVite = ensureNotCancelled(await p.confirm({
@@ -381,12 +385,7 @@ async function promptViteDevUrl(detected, productionTarget) {
381
385
  }));
382
386
  if (!useVite)
383
387
  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);
388
+ return askWithDefault("Vite dev server URL", detected.viteDevUrl);
390
389
  }
391
390
  // ─── Package manager ───────────────────────────────────────────────────────--
392
391
  function detectInvokingPackageManager() {
@@ -495,53 +494,107 @@ export function scaffold(dir, optsOrName, deps = initDependencyVersionsFallback(
495
494
  writeFileSync(full, content, "utf8");
496
495
  file("created", rel);
497
496
  };
497
+ // First, so a value .env cannot hold is refused before any file is written.
498
+ const env = envTemplate(opts);
498
499
  const pkgPath = join(dir, "package.json");
499
500
  if (!existsSync(pkgPath)) {
500
- write("package.json", packageJsonTemplate(opts, deps));
501
+ write("package.json", scaffoldPackageJson(opts, deps));
501
502
  }
502
503
  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
- }
504
+ mergeIntoPackageJson(pkgPath, opts, deps);
515
505
  }
516
506
  write("supatype.config.ts", tsConfigTemplate(opts));
517
- if (opts.productionTarget !== "later") {
507
+ if (writesLocalOverride(opts)) {
518
508
  write("supatype.local.config.ts", localConfigTemplate(opts.app));
519
509
  }
520
510
  write(opts.schemaPath, schemaTemplate());
521
- write(".env", envTemplate(opts));
511
+ write(".env", env);
512
+ scaffoldDevFrontendEnv(dir, opts);
522
513
  write("seed.ts", seedTemplate(opts.projectName));
523
514
  write("seeds/.gitkeep", "");
524
515
  scaffoldAppAssets(dir, opts, write);
516
+ // The Next.js counterpart of the static page's script tag: the client and @supatype/ssr ship
517
+ // together, so the route's package is added at the client's range.
518
+ scaffoldNextRuntimeEnv(dir, write, `^${deps.client}`);
525
519
  if (opts.helloFunction)
526
520
  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)");
521
+ scaffoldGitignore(dir, write);
522
+ }
523
+ /**
524
+ * Supatype's scripts and packages merged into the project's own package.json, saying so when its
525
+ * `prepare` changed: a project's own (husky, say) gets `supatype-prepare` after it, and the one
526
+ * earlier releases of init wrote is replaced.
527
+ */
528
+ function mergeIntoPackageJson(pkgPath, opts, deps) {
529
+ try {
530
+ const existing = parseJsonObject(readFileSync(pkgPath, "utf8"));
531
+ if (!existing.ok)
532
+ throw new Error("package.json is not a JSON object");
533
+ const merged = mergeSupatypePackageJson(existing.value, opts, deps);
534
+ writeFileSync(pkgPath, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
535
+ file("updated", "package.json (added Supatype dependencies)");
536
+ const before = scriptOf(existing.value, "prepare");
537
+ const after = merged.scripts?.["prepare"];
538
+ if (before !== undefined && after !== undefined && before !== after) {
539
+ info(`package.json's prepare script was "${before}" and is now "${after}", so a fresh clone generates the seed builder.`);
536
540
  }
537
541
  }
538
- else {
542
+ catch {
543
+ warn("Could not merge into package.json. Add @supatype/client to dependencies, @supatype/cli and " +
544
+ `@supatype/types to devDependencies, and a "prepare" script of "${PREPARE_COMMAND}".`);
545
+ file("skipped", "package.json (invalid JSON)");
546
+ }
547
+ }
548
+ /** The package.json script `name`, when it is a string. */
549
+ function scriptOf(pkg, name) {
550
+ const scripts = pkg["scripts"];
551
+ const script = isJsonObject(scripts) ? scripts[name] : undefined;
552
+ return typeof script === "string" ? script : undefined;
553
+ }
554
+ /**
555
+ * The front end's local API address, in `.env.development.local` (frontend-env.ts) for a docker
556
+ * project, whose gateway port is known now. In `.env`, a production build read it and shipped it.
557
+ */
558
+ function scaffoldDevFrontendEnv(dir, opts) {
559
+ if (opts.provider !== "docker" || opts.kongPort === undefined)
560
+ return;
561
+ const existed = existsSync(join(dir, DEV_FRONTEND_ENV_FILE));
562
+ writeFrontendEnv(dir, { apiUrl: initLocalApiUrl(opts) });
563
+ file(existed ? "updated" : "created", DEV_FRONTEND_ENV_FILE);
564
+ }
565
+ function scaffoldGitignore(dir, write) {
566
+ const gitignorePath = join(dir, ".gitignore");
567
+ if (!existsSync(gitignorePath)) {
539
568
  write(".gitignore", gitignoreTemplate());
569
+ return;
540
570
  }
571
+ const existing = readFileSync(gitignorePath, "utf8");
572
+ const merged = mergeGitignoreTemplate(existing);
573
+ if (merged === existing) {
574
+ file("skipped", ".gitignore (already exists)");
575
+ return;
576
+ }
577
+ writeFileSync(gitignorePath, merged, "utf8");
578
+ file("updated", ".gitignore (added Supatype's local files)");
579
+ }
580
+ /**
581
+ * The directory a static app is served from: the one typed at init, else the stack's own default
582
+ * (defaultAppStaticDir). The config, the holding page and Vite's build all read it here, so none
583
+ * of them can name a different one.
584
+ */
585
+ function staticDirOf(app) {
586
+ return app.staticDir ?? defaultAppStaticDir(Boolean(app.viteDevUrl));
541
587
  }
542
588
  function staticDirRelative(staticDir) {
543
- const raw = (staticDir ?? "./public").trim();
544
- return raw.replace(/^\.\//, "").replace(/\/+$/, "") || "public";
589
+ return staticDir.trim().replace(/^\.\//, "").replace(/\/+$/, "") || "public";
590
+ }
591
+ /**
592
+ * Whether the committed config has Supatype serve the app's files: a static app, and a proxied one
593
+ * with a production target, whose committed config serves its build (appConfigLines). Only such a
594
+ * server answers `/supatype-env.js`; a proxied app is served by its own.
595
+ */
596
+ function servedStatically(opts) {
597
+ return opts.app.mode === "static" || (opts.app.mode === "proxy" && opts.productionTarget !== "later");
545
598
  }
546
599
  function scaffoldAppAssets(dir, opts, write) {
547
600
  const writeUnlessExists = (rel, content) => {
@@ -552,21 +605,15 @@ function scaffoldAppAssets(dir, opts, write) {
552
605
  }
553
606
  write(rel, content);
554
607
  };
555
- const holding = holdingPageTemplate(opts.projectName, initLocalApiUrl(opts));
608
+ const holding = holdingPageTemplate(opts.projectName, initLocalApiUrl(opts), servedStatically(opts));
556
609
  const hasVite = Boolean(opts.app.viteDevUrl);
557
610
  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)
611
+ writeUnlessExists(`${staticDirRelative(staticDirOf(opts.app))}/index.html`, holding);
612
+ if (hasVite)
566
613
  scaffoldVite(dir, opts, writeUnlessExists, holding);
567
614
  return;
568
615
  }
569
- if (opts.app.mode === "proxy" && opts.productionTarget !== "later") {
616
+ if (servedStatically(opts)) {
570
617
  writeUnlessExists("dist/index.html", holding);
571
618
  if (hasVite)
572
619
  scaffoldVite(dir, opts, writeUnlessExists, holding);
@@ -587,16 +634,26 @@ function scaffoldVite(dir, opts, write, holding) {
587
634
  file("skipped", `${viteConfigRel} (already exists)`);
588
635
  return;
589
636
  }
590
- write("vite.config.ts", viteConfigTemplate(opts.app.viteDevUrl));
637
+ write("vite.config.ts", viteConfigTemplate(opts.app.viteDevUrl, viteBuildOutDir(opts)));
638
+ }
639
+ /**
640
+ * Where `vite build` writes, when it is not Vite's own `dist`: the static directory a static app is
641
+ * served from, so its build lands there. Undefined otherwise.
642
+ */
643
+ function viteBuildOutDir(opts) {
644
+ if (opts.app.mode !== "static")
645
+ return undefined;
646
+ const outDir = staticDirRelative(staticDirOf(opts.app));
647
+ // Not into "./public" either: that is Vite's own assets folder, served as it is (promptStaticDir).
648
+ return outDir === "dist" || outDir === "public" ? undefined : outDir;
591
649
  }
592
650
  function scaffoldHelloFunction(dir, write) {
593
651
  write("functions/hello/index.ts", functionTemplateSource("hello"));
594
652
  if (!existsSync(join(dir, "functions/_shared/README.md"))) {
595
653
  write("functions/_shared/README.md", sharedFunctionsReadmeSource());
596
654
  }
597
- if (!existsSync(join(dir, "functions/.env.local"))) {
598
- write("functions/.env.local", functionsEnvLocalTemplate());
599
- }
655
+ if (ensureFunctionsEnvLocal(join(dir, "functions")).created)
656
+ file("created", `functions/${FUNCTIONS_ENV_LOCAL}`);
600
657
  const denoTypes = ensureFunctionsDenoTypes(dir, join(dir, "functions"));
601
658
  if (denoTypes.wroteDenoDts)
602
659
  file("created", "functions/deno.d.ts");
@@ -612,72 +669,32 @@ async function resolveDependencyVersions() {
612
669
  const deps = await resolveInitDependencyVersions();
613
670
  const runningCli = cliPackageVersion();
614
671
  if (deps.cli !== runningCli || deps.types !== runningCli || deps.client !== runningCli) {
615
- info(`Using published npm versions: @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}, ` +
672
+ info(`Pinning @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}, ` +
616
673
  `@supatype/client ^${deps.client}`);
617
674
  }
618
675
  return deps;
619
676
  }
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
- }
677
+ /**
678
+ * Whether init writes a supatype.local.config.ts: for a production target, whose committed config
679
+ * is production's, and for a static app developed with Vite, whose dev server `supatype dev` starts
680
+ * only in proxy mode. A "Decide later" project with Vite used to get neither, and nothing started
681
+ * Vite.
682
+ */
683
+ function writesLocalOverride(opts) {
684
+ return opts.productionTarget !== "later" || viteDevelopsStaticApp(opts.app);
670
685
  }
671
- `;
686
+ /** A static app with a Vite dev server: served from its build, developed through Vite. */
687
+ function viteDevelopsStaticApp(app) {
688
+ return app.mode === "static" && Boolean(app.viteDevUrl);
672
689
  }
673
690
  function tsConfigTemplate(opts) {
674
691
  const serverMode = serverModeForTarget(opts.productionTarget);
675
- const hasLocalOverride = opts.productionTarget !== "later";
676
692
  const lines = [];
677
693
  lines.push(`import { defineConfig } from "@supatype/cli"`);
678
694
  lines.push("");
679
- if (hasLocalOverride) {
695
+ if (opts.productionTarget !== "later")
680
696
  lines.push(`// Committed config = ${opts.productionTarget} production target.`);
697
+ if (writesLocalOverride(opts)) {
681
698
  lines.push(`// Local development overrides live in supatype.local.config.ts (gitignored).`);
682
699
  }
683
700
  lines.push(`export default defineConfig({`);
@@ -762,26 +779,12 @@ function localDevAppConfigLines(app) {
762
779
  }
763
780
  function appConfigLines(app, productionTarget) {
764
781
  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;
782
+ // Vite's dev server is the local override's (writesLocalOverride); this is the built site.
783
+ const built = viteDevelopsStaticApp(app) ? " // production build output" : "";
784
+ return [` app: {`, ` mode: "static",`, ` static_dir: "${staticDirOf(app)}",${built}`, ` },`];
782
785
  }
783
786
  if (app.mode === "proxy") {
784
- if (productionTarget !== "later") {
787
+ if (servedStatically({ app, productionTarget })) {
785
788
  return [
786
789
  ` app: {`,
787
790
  ` mode: "static",`,
@@ -830,7 +833,29 @@ function initLocalApiUrl(opts) {
830
833
  ? `http://localhost:${opts.kongPort ?? COMPOSE_DEV_KONG_PORT}`
831
834
  : `http://localhost:${NATIVE_SERVER_PORT}`;
832
835
  }
833
- function holdingPageTemplate(projectName, apiUrl) {
836
+ /**
837
+ * Where auth emails send people back to. A static or proxied app is served on the same address as
838
+ * the API, so that is the app's address too; it was `http://localhost:3000` for every project,
839
+ * where nothing listened. With no app, the address is the developer's own, and 3000 is a guess.
840
+ */
841
+ function initSiteUrl(opts) {
842
+ return opts.app.mode === "none" ? "http://localhost:3000" : initLocalApiUrl(opts);
843
+ }
844
+ /**
845
+ * The deployment's address and anon key, from the server that serves the page, for a build that
846
+ * carried none. A classic script in the head runs before any module script, wherever the app puts
847
+ * its own. Where no Supatype server answers it (Vite's dev server, opened directly, sends its
848
+ * index.html back) the script fails with one console error and the page runs on: only that script
849
+ * is lost, and the dev build has its values from `.env.development.local` anyway. `vite-ignore`
850
+ * tells Vite to leave the tag as it is: without it, every `vite build` warned that it could not
851
+ * bundle a script the project does not have. Vite drops the attribute from the page it builds, and
852
+ * a browser ignores it in a page nothing builds.
853
+ */
854
+ const RUNTIME_ENV_SCRIPT = `
855
+ <!-- The deployment's API address and anon key, from the server that serves this page.
856
+ vite-ignore tells Vite to leave it out of the bundle, so the build does not warn. -->
857
+ <script src="/supatype-env.js" vite-ignore></script>`;
858
+ function holdingPageTemplate(projectName, apiUrl, runtimeEnv) {
834
859
  const name = escapeHtml(projectName);
835
860
  return `<!doctype html>
836
861
  <html lang="en">
@@ -838,7 +863,7 @@ function holdingPageTemplate(projectName, apiUrl) {
838
863
  <meta charset="UTF-8" />
839
864
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
840
865
  <title>${name}: Supatype</title>
841
- <meta name="description" content="A Supatype project. Define your types, we generate your platform." />
866
+ <meta name="description" content="A Supatype project. Define your types, we generate your platform." />${runtimeEnv ? RUNTIME_ENV_SCRIPT : ""}
842
867
  <link rel="preconnect" href="https://fonts.googleapis.com" />
843
868
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
844
869
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
@@ -964,12 +989,13 @@ function vitePortFromDevUrl(viteDevUrl) {
964
989
  return 5173;
965
990
  }
966
991
  }
967
- function viteConfigTemplate(viteDevUrl) {
992
+ function viteConfigTemplate(viteDevUrl, outDir) {
968
993
  const port = vitePortFromDevUrl(viteDevUrl);
994
+ const build = outDir === undefined ? "" : ` // Built into the directory supatype.config.ts serves.\n build: { outDir: "${outDir}" },\n`;
969
995
  return `import { defineConfig } from "vite"
970
996
 
971
997
  export default defineConfig({
972
- server: {
998
+ ${build} server: {
973
999
  host: "127.0.0.1",
974
1000
  port: ${port},
975
1001
  strictPort: true,
@@ -1024,7 +1050,19 @@ export type SiteSettings = Model<{
1024
1050
  }>
1025
1051
  `;
1026
1052
  }
1053
+ /**
1054
+ * The values `.env` takes from what init was told, rather than generates, under the key each is
1055
+ * written as. The project name is the database's name and, for SMTP, the sender's.
1056
+ */
1057
+ function envAnswers(opts) {
1058
+ return {
1059
+ POSTGRES_DB: opts.projectName,
1060
+ ...(opts.adminEmail !== undefined && { SUPATYPE_ADMIN_EMAIL: opts.adminEmail }),
1061
+ ...(opts.adminPassword !== undefined && { SUPATYPE_ADMIN_PASSWORD: opts.adminPassword }),
1062
+ };
1063
+ }
1027
1064
  function envTemplate(opts) {
1065
+ assertEnvValues(envAnswers(opts), ".env");
1028
1066
  const sections = [];
1029
1067
  // Generated, not constant. These reach a server: the previous defaults meant a self-host
1030
1068
  // deployment ran with a password of `postgres` and a JWT secret published in this repo,
@@ -1063,17 +1101,15 @@ SERVICE_ROLE_KEY=`);
1063
1101
  # request without it, so code running in the functions worker cannot call it directly.
1064
1102
  ${CONTROL_PLANE_SECRET_ENV}=${generateControlPlaneSecret()}`);
1065
1103
  sections.push(`# Site URL (used for email redirects)
1066
- SITE_URL=http://localhost:3000`);
1104
+ SITE_URL=${initSiteUrl(opts)}`);
1067
1105
  if (opts.provider === "docker" && opts.kongPort !== undefined) {
1068
- const apiUrl = `http://localhost:${opts.kongPort}`;
1106
+ // The front end's copies of this address and the anon key are in .env.development.local
1107
+ // (scaffoldDevFrontendEnv, and the keys step), where a production build does not read them.
1069
1108
  sections.push(`# Local API gateway (Kong), unique per project so multiple stacks can run concurrently
1070
1109
  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=`);
1110
+ API_EXTERNAL_URL=${initLocalApiUrl(opts)}`);
1075
1111
  }
1076
- sections.push(emailEnvSection(opts.email, opts.projectName));
1112
+ sections.push(emailEnvSection(opts));
1077
1113
  sections.push(storageEnvSections(opts.storageLocal, opts.storageProduction));
1078
1114
  if (opts.adminEmail && opts.adminPassword) {
1079
1115
  sections.push(`# First Studio admin (/studio/), consumed on first supatype dev or push (password removed after use)
@@ -1090,7 +1126,7 @@ SUPATYPE_ADMIN_PASSWORD=${opts.adminPassword}`);
1090
1126
  const SELF_HOST_PORTS_ENV_SECTION = `# Self-host stack ports (supatype self-host compose). Kong, at SUPATYPE_KONG_PORT, is the way in.
1091
1127
  # Postgres, the API server and SeaweedFS bind 127.0.0.1 only. To reach them from other machines,
1092
1128
  # 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.
1129
+ # Self-host commands reach Postgres at SUPATYPE_DB_PORT for their own run; DATABASE_URL above stays dev's.
1094
1130
  # SUPATYPE_PUBLISH_ADDRESS=127.0.0.1
1095
1131
  # SUPATYPE_DB_PORT=5432
1096
1132
  # SUPATYPE_SERVER_PORT=9999
@@ -1100,7 +1136,7 @@ const SELF_HOST_PORTS_ENV_SECTION = `# Self-host stack ports (supatype self-host
1100
1136
  * written unprefixed (RESEND_API_KEY, SES_FROM, SMTP_HOST), which nothing reads, so a developer who
1101
1137
  * filled them in still got no email.
1102
1138
  */
1103
- function emailEnvSection(email, projectName) {
1139
+ function emailEnvSection({ email, projectName, smtp }) {
1104
1140
  switch (email) {
1105
1141
  case "resend":
1106
1142
  return `# Email (Resend)
@@ -1114,8 +1150,8 @@ AWS_ACCESS_KEY_ID=
1114
1150
  AWS_SECRET_ACCESS_KEY=`;
1115
1151
  case "smtp":
1116
1152
  return `# Email (SMTP)
1117
- SUPATYPE_SMTP_HOST=
1118
- SUPATYPE_SMTP_PORT=587
1153
+ SUPATYPE_SMTP_HOST=${smtp?.host ?? ""}
1154
+ SUPATYPE_SMTP_PORT=${smtp?.port ?? 587}
1119
1155
  SUPATYPE_SMTP_USER=
1120
1156
  SUPATYPE_SMTP_PASS=
1121
1157
  SUPATYPE_SMTP_SENDER_NAME=${projectName}`;
@@ -1148,8 +1184,12 @@ S3_SECRET_KEY=`;
1148
1184
  }
1149
1185
  return [localStorageEnvSection(storageLocal), productionStorageEnvSection(storageProduction)].join("\n\n");
1150
1186
  }
1187
+ /** Whether init generates the object store's login: for the local SeaweedFS, not a bucket of your own. */
1188
+ function generatesObjectStoreLogin(storage) {
1189
+ return storage !== "s3";
1190
+ }
1151
1191
  function localStorageEnvSection(storage) {
1152
- if (storage === "s3") {
1192
+ if (!generatesObjectStoreLogin(storage)) {
1153
1193
  return `# Storage (local development, external bucket)
1154
1194
  S3_ENDPOINT=
1155
1195
  S3_REGION=us-east-1
@@ -1157,10 +1197,13 @@ S3_BUCKET=
1157
1197
  S3_ACCESS_KEY=
1158
1198
  S3_SECRET_KEY=`;
1159
1199
  }
1200
+ const login = generateObjectStoreCredentials();
1160
1201
  return `# Storage (local development, SeaweedFS)
1202
+ # The object store's login, generated for this project. It opens every file in every bucket, so
1203
+ # keep it as private as the database password.
1161
1204
  S3_ENDPOINT=http://localhost:8333
1162
- S3_ACCESS_KEY=supatype
1163
- S3_SECRET_KEY=supatype-secret`;
1205
+ ${OBJECT_STORE_ACCESS_KEY_ENV}=${login.accessKey}
1206
+ ${OBJECT_STORE_SECRET_KEY_ENV}=${login.secretKey}`;
1164
1207
  }
1165
1208
  function productionStorageEnvSection(storage) {
1166
1209
  if (storage === "s3") {
@@ -1214,9 +1257,6 @@ export default async function seed(ctx: SeedContext) {
1214
1257
  }
1215
1258
  `;
1216
1259
  }
1217
- function functionsEnvLocalTemplate() {
1218
- return "# Local environment variables for edge functions\n# These are NOT committed to git\n# Set production env vars via: npx supatype functions env set KEY=value\n";
1219
- }
1220
1260
  function gitignoreTemplate() {
1221
1261
  // Supatype's own paths come from `SUPATYPE_GITIGNORE_PATHS` rather than being written out again
1222
1262
  // here. This template and that list were two copies of the same thing and had already diverged;
@@ -1224,19 +1264,22 @@ function gitignoreTemplate() {
1224
1264
  return `${SUPATYPE_GITIGNORE_PATHS.join("\n")}
1225
1265
  node_modules/
1226
1266
  dist/
1227
- # Generated by supatype push (legacy paths, prefer output.types in config)
1228
- src/types/supatype.d.ts
1229
- src/lib/supatype.ts
1230
1267
  `;
1231
1268
  }
1269
+ /**
1270
+ * An existing `.gitignore` with what init adds to a project: `.supatype/` (link.json holds secrets)
1271
+ * and `.env.*.local`, where init writes the front end's development-only API address. Each is added
1272
+ * only when the file does not already cover it.
1273
+ */
1232
1274
  export function mergeGitignoreTemplate(existingContent) {
1233
- if (existingContent.includes(".supatype/") || existingContent.includes(".supatype\n")) {
1275
+ const lines = existingContent.split(/\r?\n/).map((line) => line.trim());
1276
+ const missing = [
1277
+ ...(existingContent.includes(".supatype/") || lines.includes(".supatype") ? [] : [".supatype/"]),
1278
+ ...(lines.includes(".env.*.local") || lines.includes("*.local") ? [] : [".env.*.local"]),
1279
+ ];
1280
+ if (missing.length === 0)
1234
1281
  return existingContent;
1235
- }
1236
- const block = `
1237
- # Supatype: local runtime (contains secrets in link.json)
1238
- .supatype/
1239
- `;
1282
+ const block = `\n# Supatype: local runtime (secrets in .supatype/link.json) and development-only env files\n${missing.join("\n")}\n`;
1240
1283
  return existingContent.endsWith("\n") ? `${existingContent}${block}` : `${existingContent}\n${block}`;
1241
1284
  }
1242
1285
  // ─── Next steps ────────────────────────────────────────────────────────────--
@@ -1262,27 +1305,50 @@ function startInitQuestions(provider) {
1262
1305
  const kongPort = import("../dev-ports.js").then(({ chooseInitKongPort }) => chooseInitKongPort());
1263
1306
  return { kongPort, daemon: probeDockerDaemonAsync(), deps };
1264
1307
  }
1308
+ /** The script in `dir`'s package.json that runs `supatype dev`, or `dev` when it cannot be read. */
1309
+ function projectDevScript(dir) {
1310
+ try {
1311
+ const pkg = parseJsonObject(readFileSync(join(dir, "package.json"), "utf8"));
1312
+ return pkg.ok ? supatypeDevScript(pkg.value["scripts"]) : "dev";
1313
+ }
1314
+ catch {
1315
+ return "dev";
1316
+ }
1317
+ }
1265
1318
  /** True when nothing is left to set up, only to run. */
1266
1319
  function initSetupComplete(args) {
1267
1320
  return args.installed && args.keysGenerated && args.binariesReady;
1268
1321
  }
1269
1322
  function printNextSteps(args) {
1270
- const { name, result } = args;
1323
+ const { name } = args;
1271
1324
  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));
1325
+ for (const block of initStepBlocks(args)) {
1326
+ nextSteps(block.title, block.steps);
1327
+ if (block.after !== undefined)
1328
+ plain(` ${block.after}`);
1329
+ }
1330
+ const target = args.result.productionTarget;
1331
+ if (target === "cloud" || target === "self-host") {
1332
+ info(`supatype.local.config.ts keeps \`supatype dev\` local while the committed config targets ${target}.`);
1333
+ }
1334
+ plain();
1276
1335
  }
1277
1336
  /**
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`.
1337
+ * Everything init prints when it is done, in order: running the project locally, then its secrets,
1338
+ * then taking it to production. Production comes last whatever the target: it is the step for
1339
+ * later, and a self-host project used to lead with a domain the person had just said they lacked.
1281
1340
  */
1341
+ export function initStepBlocks(args) {
1342
+ const blocks = [
1343
+ { title: initSetupComplete(args) ? "Next steps:" : "Finish setup:", steps: initFirstSteps(args) },
1344
+ { title: "Secrets: generated for this project, kept in .env:", steps: initSecretLines(args.result.storageLocal), after: SECRETS_CLOSING },
1345
+ ];
1346
+ const deploy = deployBlock(args.result);
1347
+ return deploy === undefined ? blocks : [...blocks, deploy];
1348
+ }
1349
+ /** Setting up, then running the project locally, for every production target. */
1282
1350
  export function initFirstSteps(args) {
1283
- const { result } = args;
1284
- const next = result.productionTarget === "self-host" ? selfHostProductionSteps(result) : initDevSteps(result);
1285
- return [...initSetupSteps(args), ...next];
1351
+ return [...initSetupSteps(args), ...initDevSteps(args)];
1286
1352
  }
1287
1353
  function initSetupSteps(args) {
1288
1354
  const { name, result, installed, keysGenerated, binariesReady } = args;
@@ -1293,76 +1359,109 @@ function initSetupSteps(args) {
1293
1359
  if (!installed)
1294
1360
  steps.push(`${result.packageManager} install`);
1295
1361
  if (!binariesReady)
1296
- steps.push("supatype update # download component binaries");
1362
+ steps.push("supatype update # download component binaries");
1297
1363
  if (!keysGenerated)
1298
1364
  steps.push("supatype keys");
1299
1365
  }
1300
1366
  return steps;
1301
1367
  }
1368
+ /** `script` run the way `pm` runs a package.json script. */
1369
+ function runScriptCommand(pm, script) {
1370
+ return pm === "npm" || pm === "bun" ? `${pm} run ${script}` : `${pm} ${script}`;
1371
+ }
1372
+ /** `command` with `comments` after it, each comment after the first on its own line in the same column. */
1373
+ function commented(command, comments) {
1374
+ const column = command.length + 3;
1375
+ return comments.map((comment, index) => `${(index === 0 ? command : "").padEnd(column)}# ${comment}`);
1376
+ }
1302
1377
  /**
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.
1378
+ * The dev script, which applies the schema and generates the types, then watches both; then where
1379
+ * to open the project. `push` is for another database (`push --env <name>`), and listing it here
1380
+ * sent people to it anyway.
1305
1381
  */
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
- }
1382
+ function initDevSteps(args) {
1383
+ const { result } = args;
1384
+ const comments = [
1385
+ "applies the schema, generates types, and watches both",
1386
+ result.provider === "docker" ? "runs the Docker Compose stack" : "runs the native binaries",
1387
+ ];
1388
+ if (result.adminEmail)
1389
+ comments.push("first admin user is created on dev");
1390
+ const steps = commented(runScriptCommand(result.packageManager, args.devScript ?? "dev"), comments);
1391
+ steps.push(`Open ${initLocalApiUrl(result)}`);
1314
1392
  if (result.helloFunction) {
1315
- steps.push("supatype functions serve # run edge functions locally");
1393
+ steps.push(...commented(runScriptCommand(result.packageManager, "functions"), ["run edge functions locally"]));
1316
1394
  }
1317
1395
  return steps;
1318
1396
  }
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.
1397
+ /**
1398
+ * The secrets init generated, shown once, at creation. They are generated per project rather than
1399
+ * shipped as constants, so this is the moment to say they exist and where they live: nothing prints
1400
+ * them again, and the JWT secret is only echoed as a fingerprint from here on.
1401
+ */
1402
+ const INIT_SECRETS = [
1403
+ ["POSTGRES_PASSWORD", "direct SQL access as the superuser"],
1404
+ ["AUTHENTICATOR_PASSWORD", "PostgREST's own login; rotating the one above does not affect it"],
1405
+ ["SUPATYPE_SQL_EDITOR_PASSWORD", "Studio's SQL editor login, a role that is not a superuser"],
1406
+ ["JWT_SECRET", "signs ANON_KEY and SERVICE_ROLE_KEY; changing it invalidates every token"],
1407
+ ];
1408
+ /** The object store's login, when init generates one ({@link generatesObjectStoreLogin}). */
1409
+ const OBJECT_STORE_SECRETS = [
1410
+ [OBJECT_STORE_ACCESS_KEY_ENV, "the object store's login, which opens every file in every bucket"],
1411
+ [OBJECT_STORE_SECRET_KEY_ENV, "its password"],
1412
+ ];
1413
+ const SECRETS_CLOSING = "Keep .env out of version control, and use different values in production.";
1414
+ /**
1415
+ * One line per secret init wrote, each description two spaces past the longest name. With
1416
+ * development storage in an S3 bucket of your own, init generates no object-store login.
1417
+ */
1418
+ export function initSecretLines(storageLocal = "local") {
1419
+ const secrets = generatesObjectStoreLogin(storageLocal) ? [...INIT_SECRETS, ...OBJECT_STORE_SECRETS] : INIT_SECRETS;
1420
+ const width = Math.max(...secrets.map(([name]) => name.length)) + 2;
1421
+ return secrets.map(([name, description]) => `${name.padEnd(width)}${description}`);
1422
+ }
1423
+ /**
1424
+ * The app's production build, given the linked deployment's API URL and anon key. Without it a
1425
+ * production build read neither, and the deployed app rendered a blank page (issue 29).
1426
+ */
1427
+ const BUILD_STEP = "supatype build --env production # your app's production build, with the deployment's URL and anon key";
1428
+ /** Taking the project to production, for a target that has one. No frontend block: `supatype app add` covers that. */
1429
+ function deployBlock(result) {
1333
1430
  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.");
1431
+ return {
1432
+ title: "When you're ready to deploy (Supatype Cloud):",
1433
+ steps: ["supatype login", "supatype link --env production --project <ref>", "supatype push --env production", BUILD_STEP],
1434
+ };
1340
1435
  }
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.");
1436
+ if (result.productionTarget === "self-host") {
1437
+ return { title: "When you're ready to deploy (self-host):", steps: selfHostDeploySteps(result) };
1344
1438
  }
1345
- plain();
1439
+ return undefined;
1346
1440
  }
1347
- /** Taking a self-host project to its own server, with or without a domain for HTTPS. */
1348
- function selfHostProductionSteps(result) {
1349
- const steps = [];
1441
+ /**
1442
+ * Taking a self-host project to its own server. With a domain, DNS and the firewall come first;
1443
+ * without one, HTTPS is the last step and an optional one, since the person just said they had none.
1444
+ */
1445
+ export function selfHostDeploySteps(result) {
1350
1446
  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");
1447
+ const link = "supatype link --env production ... # then: supatype push --env production";
1448
+ if (!domain) {
1449
+ return [
1450
+ "supatype self-host compose up -d # on your server: the Docker stack",
1451
+ link,
1452
+ BUILD_STEP,
1453
+ "Later, optionally: set server.domain and server.tls.email in supatype.config.ts for automatic HTTPS",
1454
+ ];
1364
1455
  }
1365
- steps.push("supatype link --env production ... # then: supatype push --env production");
1366
- return steps;
1456
+ return [
1457
+ `1. Point DNS: an A record for ${domain} -> your server's public IP`,
1458
+ "2. Open ports 80 and 443 on the server firewall",
1459
+ ...(result.tlsEmail ? [] : ["3. Set server.tls.email in supatype.config.ts (required for HTTPS)"]),
1460
+ "supatype self-host compose up -d # Kong provisions HTTPS automatically",
1461
+ link,
1462
+ BUILD_STEP,
1463
+ `Your Supatype platform goes live at https://${domain}`,
1464
+ "Your app, REST, Auth, Storage, Realtime, Functions, and Studio, all behind one HTTPS domain (certificates outlive restarts)",
1465
+ ];
1367
1466
  }
1368
1467
  //# sourceMappingURL=init.js.map