@supatype/cli 0.7.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 (671) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/bin/supatype.js +40 -4
  3. package/deno.d.ts +1 -1
  4. package/dist/admin-prompt-state.d.ts +13 -0
  5. package/dist/admin-prompt-state.d.ts.map +1 -0
  6. package/dist/admin-prompt-state.js +30 -0
  7. package/dist/admin-prompt-state.js.map +1 -0
  8. package/dist/adopt-columns.d.ts.map +1 -1
  9. package/dist/adopt-columns.js +13 -17
  10. package/dist/adopt-columns.js.map +1 -1
  11. package/dist/after-hooks-health.d.ts +19 -0
  12. package/dist/after-hooks-health.d.ts.map +1 -0
  13. package/dist/after-hooks-health.js +69 -0
  14. package/dist/after-hooks-health.js.map +1 -0
  15. package/dist/app-config.d.ts +1 -1
  16. package/dist/app-config.d.ts.map +1 -1
  17. package/dist/app-config.js +103 -144
  18. package/dist/app-config.js.map +1 -1
  19. package/dist/app-vite-env.d.ts +5 -1
  20. package/dist/app-vite-env.d.ts.map +1 -1
  21. package/dist/app-vite-env.js +9 -15
  22. package/dist/app-vite-env.js.map +1 -1
  23. package/dist/applied-ast-artifacts.d.ts +16 -0
  24. package/dist/applied-ast-artifacts.d.ts.map +1 -0
  25. package/dist/applied-ast-artifacts.js +37 -0
  26. package/dist/applied-ast-artifacts.js.map +1 -0
  27. package/dist/archive-extract.d.ts +3 -0
  28. package/dist/archive-extract.d.ts.map +1 -0
  29. package/dist/archive-extract.js +19 -0
  30. package/dist/archive-extract.js.map +1 -0
  31. package/dist/augmentation-generator.d.ts +5 -0
  32. package/dist/augmentation-generator.d.ts.map +1 -1
  33. package/dist/augmentation-generator.js +13 -4
  34. package/dist/augmentation-generator.js.map +1 -1
  35. package/dist/binary-cache.d.ts +27 -3
  36. package/dist/binary-cache.d.ts.map +1 -1
  37. package/dist/binary-cache.js +117 -85
  38. package/dist/binary-cache.js.map +1 -1
  39. package/dist/binary-download-lock.d.ts.map +1 -1
  40. package/dist/binary-download-lock.js +1 -3
  41. package/dist/binary-download-lock.js.map +1 -1
  42. package/dist/byo-preflight.d.ts.map +1 -1
  43. package/dist/byo-preflight.js +2 -10
  44. package/dist/byo-preflight.js.map +1 -1
  45. package/dist/byte-size.d.ts +9 -0
  46. package/dist/byte-size.d.ts.map +1 -0
  47. package/dist/byte-size.js +36 -0
  48. package/dist/byte-size.js.map +1 -0
  49. package/dist/cache-clean.d.ts +0 -2
  50. package/dist/cache-clean.d.ts.map +1 -1
  51. package/dist/cache-clean.js +1 -27
  52. package/dist/cache-clean.js.map +1 -1
  53. package/dist/cache-pins.d.ts.map +1 -1
  54. package/dist/cache-pins.js +3 -20
  55. package/dist/cache-pins.js.map +1 -1
  56. package/dist/cache-root.d.ts +7 -0
  57. package/dist/cache-root.d.ts.map +1 -0
  58. package/dist/cache-root.js +11 -0
  59. package/dist/cache-root.js.map +1 -0
  60. package/dist/cli-artifacts.d.ts.map +1 -1
  61. package/dist/cli-artifacts.js +2 -1
  62. package/dist/cli-artifacts.js.map +1 -1
  63. package/dist/cli-install-method.d.ts.map +1 -1
  64. package/dist/cli-install-method.js +7 -1
  65. package/dist/cli-install-method.js.map +1 -1
  66. package/dist/cli-launcher.d.ts +21 -0
  67. package/dist/cli-launcher.d.ts.map +1 -0
  68. package/dist/cli-launcher.js +112 -0
  69. package/dist/cli-launcher.js.map +1 -0
  70. package/dist/cli-old-versions.d.ts +44 -0
  71. package/dist/cli-old-versions.d.ts.map +1 -0
  72. package/dist/cli-old-versions.js +83 -0
  73. package/dist/cli-old-versions.js.map +1 -0
  74. package/dist/cli-program-path.d.ts +20 -0
  75. package/dist/cli-program-path.d.ts.map +1 -0
  76. package/dist/cli-program-path.js +41 -0
  77. package/dist/cli-program-path.js.map +1 -0
  78. package/dist/cli-standalone.d.ts +2 -3
  79. package/dist/cli-standalone.d.ts.map +1 -1
  80. package/dist/cli-standalone.js +51 -24
  81. package/dist/cli-standalone.js.map +1 -1
  82. package/dist/cli-version-embedded.js +1 -1
  83. package/dist/cloud-credentials.d.ts +6 -0
  84. package/dist/cloud-credentials.d.ts.map +1 -1
  85. package/dist/cloud-credentials.js +13 -0
  86. package/dist/cloud-credentials.js.map +1 -1
  87. package/dist/commands/admin.d.ts.map +1 -1
  88. package/dist/commands/admin.js +18 -18
  89. package/dist/commands/admin.js.map +1 -1
  90. package/dist/commands/app.d.ts.map +1 -1
  91. package/dist/commands/app.js +27 -8
  92. package/dist/commands/app.js.map +1 -1
  93. package/dist/commands/cache.d.ts.map +1 -1
  94. package/dist/commands/cache.js +37 -11
  95. package/dist/commands/cache.js.map +1 -1
  96. package/dist/commands/cloud.js +2 -4
  97. package/dist/commands/cloud.js.map +1 -1
  98. package/dist/commands/db.d.ts.map +1 -1
  99. package/dist/commands/db.js +116 -106
  100. package/dist/commands/db.js.map +1 -1
  101. package/dist/commands/deploy.d.ts.map +1 -1
  102. package/dist/commands/deploy.js +3 -3
  103. package/dist/commands/deploy.js.map +1 -1
  104. package/dist/commands/dev.d.ts +50 -4
  105. package/dist/commands/dev.d.ts.map +1 -1
  106. package/dist/commands/dev.js +276 -267
  107. package/dist/commands/dev.js.map +1 -1
  108. package/dist/commands/doctor.d.ts +32 -0
  109. package/dist/commands/doctor.d.ts.map +1 -1
  110. package/dist/commands/doctor.js +66 -1
  111. package/dist/commands/doctor.js.map +1 -1
  112. package/dist/commands/functions.d.ts +30 -0
  113. package/dist/commands/functions.d.ts.map +1 -1
  114. package/dist/commands/functions.js +503 -507
  115. package/dist/commands/functions.js.map +1 -1
  116. package/dist/commands/generate.d.ts.map +1 -1
  117. package/dist/commands/generate.js +11 -8
  118. package/dist/commands/generate.js.map +1 -1
  119. package/dist/commands/hooks.d.ts.map +1 -1
  120. package/dist/commands/hooks.js +46 -23
  121. package/dist/commands/hooks.js.map +1 -1
  122. package/dist/commands/init.d.ts +37 -4
  123. package/dist/commands/init.d.ts.map +1 -1
  124. package/dist/commands/init.js +509 -386
  125. package/dist/commands/init.js.map +1 -1
  126. package/dist/commands/internal.d.ts.map +1 -1
  127. package/dist/commands/internal.js +2 -1
  128. package/dist/commands/internal.js.map +1 -1
  129. package/dist/commands/keys.d.ts +46 -20
  130. package/dist/commands/keys.d.ts.map +1 -1
  131. package/dist/commands/keys.js +196 -156
  132. package/dist/commands/keys.js.map +1 -1
  133. package/dist/commands/link-helpers.d.ts.map +1 -1
  134. package/dist/commands/link-helpers.js +30 -11
  135. package/dist/commands/link-helpers.js.map +1 -1
  136. package/dist/commands/logs.d.ts.map +1 -1
  137. package/dist/commands/logs.js +5 -4
  138. package/dist/commands/logs.js.map +1 -1
  139. package/dist/commands/migrate.js +1 -1
  140. package/dist/commands/migrate.js.map +1 -1
  141. package/dist/commands/pg.js +2 -0
  142. package/dist/commands/pg.js.map +1 -1
  143. package/dist/commands/plugins.d.ts.map +1 -1
  144. package/dist/commands/plugins.js +17 -7
  145. package/dist/commands/plugins.js.map +1 -1
  146. package/dist/commands/push.d.ts +39 -0
  147. package/dist/commands/push.d.ts.map +1 -1
  148. package/dist/commands/push.js +221 -77
  149. package/dist/commands/push.js.map +1 -1
  150. package/dist/commands/seed.d.ts +35 -0
  151. package/dist/commands/seed.d.ts.map +1 -1
  152. package/dist/commands/seed.js +72 -38
  153. package/dist/commands/seed.js.map +1 -1
  154. package/dist/commands/self-host.d.ts.map +1 -1
  155. package/dist/commands/self-host.js +71 -42
  156. package/dist/commands/self-host.js.map +1 -1
  157. package/dist/commands/self-update.d.ts.map +1 -1
  158. package/dist/commands/self-update.js +9 -3
  159. package/dist/commands/self-update.js.map +1 -1
  160. package/dist/commands/status.js +5 -5
  161. package/dist/commands/status.js.map +1 -1
  162. package/dist/commands/types.js +2 -5
  163. package/dist/commands/types.js.map +1 -1
  164. package/dist/commands/update.d.ts.map +1 -1
  165. package/dist/commands/update.js +212 -101
  166. package/dist/commands/update.js.map +1 -1
  167. package/dist/component-launch.d.ts +11 -0
  168. package/dist/component-launch.d.ts.map +1 -0
  169. package/dist/component-launch.js +35 -0
  170. package/dist/component-launch.js.map +1 -0
  171. package/dist/components.d.ts +7 -2
  172. package/dist/components.d.ts.map +1 -1
  173. package/dist/components.js +7 -2
  174. package/dist/components.js.map +1 -1
  175. package/dist/compose-db-roles.d.ts.map +1 -1
  176. package/dist/compose-db-roles.js +5 -14
  177. package/dist/compose-db-roles.js.map +1 -1
  178. package/dist/compose-engine-run.d.ts +6 -5
  179. package/dist/compose-engine-run.d.ts.map +1 -1
  180. package/dist/compose-engine-run.js +44 -37
  181. package/dist/compose-engine-run.js.map +1 -1
  182. package/dist/compose-engine-service.d.ts +10 -0
  183. package/dist/compose-engine-service.d.ts.map +1 -0
  184. package/dist/compose-engine-service.js +16 -0
  185. package/dist/compose-engine-service.js.map +1 -0
  186. package/dist/compose-host-path.d.ts +14 -0
  187. package/dist/compose-host-path.d.ts.map +1 -0
  188. package/dist/compose-host-path.js +18 -0
  189. package/dist/compose-host-path.js.map +1 -0
  190. package/dist/compose-image-pull.d.ts +43 -0
  191. package/dist/compose-image-pull.d.ts.map +1 -0
  192. package/dist/compose-image-pull.js +27 -0
  193. package/dist/compose-image-pull.js.map +1 -0
  194. package/dist/compose-kong.d.ts +4 -0
  195. package/dist/compose-kong.d.ts.map +1 -1
  196. package/dist/compose-kong.js +23 -9
  197. package/dist/compose-kong.js.map +1 -1
  198. package/dist/compose-local-server-image.d.ts.map +1 -1
  199. package/dist/compose-local-server-image.js +7 -3
  200. package/dist/compose-local-server-image.js.map +1 -1
  201. package/dist/compose-render-mode.d.ts.map +1 -1
  202. package/dist/compose-render-mode.js +7 -4
  203. package/dist/compose-render-mode.js.map +1 -1
  204. package/dist/compose-services.d.ts +12 -2
  205. package/dist/compose-services.d.ts.map +1 -1
  206. package/dist/compose-services.js +27 -12
  207. package/dist/compose-services.js.map +1 -1
  208. package/dist/config-snapshot.d.ts +6 -0
  209. package/dist/config-snapshot.d.ts.map +1 -0
  210. package/dist/config-snapshot.js +23 -0
  211. package/dist/config-snapshot.js.map +1 -0
  212. package/dist/config.d.ts +11 -1
  213. package/dist/config.d.ts.map +1 -1
  214. package/dist/config.js +20 -3
  215. package/dist/config.js.map +1 -1
  216. package/dist/database-url-owner.d.ts +59 -0
  217. package/dist/database-url-owner.d.ts.map +1 -0
  218. package/dist/database-url-owner.js +133 -0
  219. package/dist/database-url-owner.js.map +1 -0
  220. package/dist/db-port-offer.d.ts +18 -0
  221. package/dist/db-port-offer.d.ts.map +1 -0
  222. package/dist/db-port-offer.js +68 -0
  223. package/dist/db-port-offer.js.map +1 -0
  224. package/dist/db-port.d.ts +42 -18
  225. package/dist/db-port.d.ts.map +1 -1
  226. package/dist/db-port.js +34 -32
  227. package/dist/db-port.js.map +1 -1
  228. package/dist/db-preflight.d.ts +37 -0
  229. package/dist/db-preflight.d.ts.map +1 -1
  230. package/dist/db-preflight.js +219 -77
  231. package/dist/db-preflight.js.map +1 -1
  232. package/dist/db-rows.d.ts +11 -0
  233. package/dist/db-rows.d.ts.map +1 -1
  234. package/dist/db-rows.js +27 -0
  235. package/dist/db-rows.js.map +1 -1
  236. package/dist/debounce.d.ts +11 -0
  237. package/dist/debounce.d.ts.map +1 -0
  238. package/dist/debounce.js +23 -0
  239. package/dist/debounce.js.map +1 -0
  240. package/dist/dev-api-keys.d.ts +12 -2
  241. package/dist/dev-api-keys.d.ts.map +1 -1
  242. package/dist/dev-api-keys.js +33 -17
  243. package/dist/dev-api-keys.js.map +1 -1
  244. package/dist/dev-compose.d.ts +10 -12
  245. package/dist/dev-compose.d.ts.map +1 -1
  246. package/dist/dev-compose.js +252 -288
  247. package/dist/dev-compose.js.map +1 -1
  248. package/dist/dev-db-ready.d.ts.map +1 -1
  249. package/dist/dev-db-ready.js +2 -1
  250. package/dist/dev-db-ready.js.map +1 -1
  251. package/dist/dev-db-reset.d.ts.map +1 -1
  252. package/dist/dev-db-reset.js +5 -4
  253. package/dist/dev-db-reset.js.map +1 -1
  254. package/dist/dev-functions-watch.d.ts.map +1 -1
  255. package/dist/dev-functions-watch.js +5 -16
  256. package/dist/dev-functions-watch.js.map +1 -1
  257. package/dist/dev-log-bus.d.ts +8 -0
  258. package/dist/dev-log-bus.d.ts.map +1 -1
  259. package/dist/dev-log-bus.js +13 -0
  260. package/dist/dev-log-bus.js.map +1 -1
  261. package/dist/dev-ports.d.ts +27 -7
  262. package/dist/dev-ports.d.ts.map +1 -1
  263. package/dist/dev-ports.js +68 -41
  264. package/dist/dev-ports.js.map +1 -1
  265. package/dist/dev-schema-watch.d.ts.map +1 -1
  266. package/dist/dev-schema-watch.js +7 -12
  267. package/dist/dev-schema-watch.js.map +1 -1
  268. package/dist/dev-session-lock.js +4 -3
  269. package/dist/dev-session-lock.js.map +1 -1
  270. package/dist/dev-session.d.ts +15 -0
  271. package/dist/dev-session.d.ts.map +1 -1
  272. package/dist/dev-session.js +27 -1
  273. package/dist/dev-session.js.map +1 -1
  274. package/dist/dev-shutdown.d.ts +45 -0
  275. package/dist/dev-shutdown.d.ts.map +1 -1
  276. package/dist/dev-shutdown.js +221 -33
  277. package/dist/dev-shutdown.js.map +1 -1
  278. package/dist/diff-output.d.ts +7 -1
  279. package/dist/diff-output.d.ts.map +1 -1
  280. package/dist/diff-output.js +91 -2
  281. package/dist/diff-output.js.map +1 -1
  282. package/dist/docker-address-pool.d.ts +23 -0
  283. package/dist/docker-address-pool.d.ts.map +1 -0
  284. package/dist/docker-address-pool.js +56 -0
  285. package/dist/docker-address-pool.js.map +1 -0
  286. package/dist/docker-exec.d.ts +92 -0
  287. package/dist/docker-exec.d.ts.map +1 -0
  288. package/dist/docker-exec.js +139 -0
  289. package/dist/docker-exec.js.map +1 -0
  290. package/dist/docker-postgres.d.ts +1 -6
  291. package/dist/docker-postgres.d.ts.map +1 -1
  292. package/dist/docker-postgres.js +67 -85
  293. package/dist/docker-postgres.js.map +1 -1
  294. package/dist/docker-runtime.d.ts +14 -1
  295. package/dist/docker-runtime.d.ts.map +1 -1
  296. package/dist/docker-runtime.js +55 -24
  297. package/dist/docker-runtime.js.map +1 -1
  298. package/dist/dotenv-parse.d.ts +22 -0
  299. package/dist/dotenv-parse.d.ts.map +1 -0
  300. package/dist/dotenv-parse.js +63 -0
  301. package/dist/dotenv-parse.js.map +1 -0
  302. package/dist/engine-answers.d.ts +0 -2
  303. package/dist/engine-answers.d.ts.map +1 -1
  304. package/dist/engine-answers.js +4 -3
  305. package/dist/engine-answers.js.map +1 -1
  306. package/dist/engine-client.d.ts.map +1 -1
  307. package/dist/engine-client.js +13 -12
  308. package/dist/engine-client.js.map +1 -1
  309. package/dist/engine-floor.d.ts +29 -0
  310. package/dist/engine-floor.d.ts.map +1 -1
  311. package/dist/engine-floor.js +56 -0
  312. package/dist/engine-floor.js.map +1 -1
  313. package/dist/engine-ownership-gate.d.ts +13 -1
  314. package/dist/engine-ownership-gate.d.ts.map +1 -1
  315. package/dist/engine-ownership-gate.js +36 -6
  316. package/dist/engine-ownership-gate.js.map +1 -1
  317. package/dist/ensure-binary.d.ts +9 -0
  318. package/dist/ensure-binary.d.ts.map +1 -1
  319. package/dist/ensure-binary.js +38 -5
  320. package/dist/ensure-binary.js.map +1 -1
  321. package/dist/ensure-component-binaries.d.ts.map +1 -1
  322. package/dist/ensure-component-binaries.js +2 -1
  323. package/dist/ensure-component-binaries.js.map +1 -1
  324. package/dist/env-file.d.ts +30 -8
  325. package/dist/env-file.d.ts.map +1 -1
  326. package/dist/env-file.js +84 -57
  327. package/dist/env-file.js.map +1 -1
  328. package/dist/env-lines.d.ts +11 -0
  329. package/dist/env-lines.d.ts.map +1 -0
  330. package/dist/env-lines.js +36 -0
  331. package/dist/env-lines.js.map +1 -0
  332. package/dist/error-message.d.ts +34 -1
  333. package/dist/error-message.d.ts.map +1 -1
  334. package/dist/error-message.js +102 -2
  335. package/dist/error-message.js.map +1 -1
  336. package/dist/fetch-within.d.ts +10 -0
  337. package/dist/fetch-within.d.ts.map +1 -0
  338. package/dist/fetch-within.js +12 -0
  339. package/dist/fetch-within.js.map +1 -0
  340. package/dist/field-masking-tier.d.ts.map +1 -1
  341. package/dist/field-masking-tier.js +7 -5
  342. package/dist/field-masking-tier.js.map +1 -1
  343. package/dist/frontend-env.d.ts +43 -0
  344. package/dist/frontend-env.d.ts.map +1 -0
  345. package/dist/frontend-env.js +81 -0
  346. package/dist/frontend-env.js.map +1 -0
  347. package/dist/functions-context-refresh.d.ts +6 -2
  348. package/dist/functions-context-refresh.d.ts.map +1 -1
  349. package/dist/functions-context-refresh.js +11 -3
  350. package/dist/functions-context-refresh.js.map +1 -1
  351. package/dist/functions-deno-types.d.ts.map +1 -1
  352. package/dist/functions-deno-types.js +9 -2
  353. package/dist/functions-deno-types.js.map +1 -1
  354. package/dist/{functions-router-gen.d.ts → functions-discovery.d.ts} +8 -10
  355. package/dist/functions-discovery.d.ts.map +1 -0
  356. package/dist/functions-discovery.js +87 -0
  357. package/dist/functions-discovery.js.map +1 -0
  358. package/dist/functions-template.d.ts.map +1 -1
  359. package/dist/functions-template.js +20 -12
  360. package/dist/functions-template.js.map +1 -1
  361. package/dist/functions-worker-files.d.ts +55 -0
  362. package/dist/functions-worker-files.d.ts.map +1 -0
  363. package/dist/functions-worker-files.js +149 -0
  364. package/dist/functions-worker-files.js.map +1 -0
  365. package/dist/generated/functions-worker-source.d.ts +2 -0
  366. package/dist/generated/functions-worker-source.d.ts.map +1 -0
  367. package/dist/generated/functions-worker-source.js +12 -0
  368. package/dist/generated/functions-worker-source.js.map +1 -0
  369. package/dist/generated/release-images.d.ts +18 -0
  370. package/dist/generated/release-images.d.ts.map +1 -0
  371. package/dist/generated/release-images.js +8 -0
  372. package/dist/generated/release-images.js.map +1 -0
  373. package/dist/generated-files-engine.d.ts +33 -0
  374. package/dist/generated-files-engine.d.ts.map +1 -0
  375. package/dist/generated-files-engine.js +45 -0
  376. package/dist/generated-files-engine.js.map +1 -0
  377. package/dist/hook-actor.d.ts +17 -0
  378. package/dist/hook-actor.d.ts.map +1 -0
  379. package/dist/hook-actor.js +37 -0
  380. package/dist/hook-actor.js.map +1 -0
  381. package/dist/hook-columns.d.ts +30 -0
  382. package/dist/hook-columns.d.ts.map +1 -0
  383. package/dist/hook-columns.js +77 -0
  384. package/dist/hook-columns.js.map +1 -0
  385. package/dist/hook-events.d.ts +11 -0
  386. package/dist/hook-events.d.ts.map +1 -0
  387. package/dist/hook-events.js +11 -0
  388. package/dist/hook-events.js.map +1 -0
  389. package/dist/hook-upload.d.ts +29 -15
  390. package/dist/hook-upload.d.ts.map +1 -1
  391. package/dist/hook-upload.js +88 -59
  392. package/dist/hook-upload.js.map +1 -1
  393. package/dist/hooks-generator.d.ts +5 -0
  394. package/dist/hooks-generator.d.ts.map +1 -1
  395. package/dist/hooks-generator.js +92 -21
  396. package/dist/hooks-generator.js.map +1 -1
  397. package/dist/host-database.d.ts.map +1 -1
  398. package/dist/host-database.js +31 -4
  399. package/dist/host-database.js.map +1 -1
  400. package/dist/init-dependency-versions.d.ts +3 -1
  401. package/dist/init-dependency-versions.d.ts.map +1 -1
  402. package/dist/init-dependency-versions.js +32 -6
  403. package/dist/init-dependency-versions.js.map +1 -1
  404. package/dist/init-example.d.ts +48 -0
  405. package/dist/init-example.d.ts.map +1 -0
  406. package/dist/init-example.js +110 -0
  407. package/dist/init-example.js.map +1 -0
  408. package/dist/init-package-json.d.ts +38 -1
  409. package/dist/init-package-json.d.ts.map +1 -1
  410. package/dist/init-package-json.js +150 -37
  411. package/dist/init-package-json.js.map +1 -1
  412. package/dist/init-setup-steps.d.ts +37 -0
  413. package/dist/init-setup-steps.d.ts.map +1 -0
  414. package/dist/init-setup-steps.js +118 -0
  415. package/dist/init-setup-steps.js.map +1 -0
  416. package/dist/jwt-secret-length.d.ts +5 -13
  417. package/dist/jwt-secret-length.d.ts.map +1 -1
  418. package/dist/jwt-secret-length.js +7 -22
  419. package/dist/jwt-secret-length.js.map +1 -1
  420. package/dist/jwt-secret-rules.d.ts +24 -0
  421. package/dist/jwt-secret-rules.d.ts.map +1 -0
  422. package/dist/jwt-secret-rules.js +46 -0
  423. package/dist/jwt-secret-rules.js.map +1 -0
  424. package/dist/local-gateway.d.ts +3 -6
  425. package/dist/local-gateway.d.ts.map +1 -1
  426. package/dist/local-gateway.js +7 -9
  427. package/dist/local-gateway.js.map +1 -1
  428. package/dist/local-secrets.d.ts +95 -11
  429. package/dist/local-secrets.d.ts.map +1 -1
  430. package/dist/local-secrets.js +153 -18
  431. package/dist/local-secrets.js.map +1 -1
  432. package/dist/local-stack.d.ts.map +1 -1
  433. package/dist/local-stack.js +2 -7
  434. package/dist/local-stack.js.map +1 -1
  435. package/dist/local-storage.d.ts +7 -2
  436. package/dist/local-storage.d.ts.map +1 -1
  437. package/dist/local-storage.js +11 -3
  438. package/dist/local-storage.js.map +1 -1
  439. package/dist/mailer-env.d.ts +37 -0
  440. package/dist/mailer-env.d.ts.map +1 -0
  441. package/dist/mailer-env.js +98 -0
  442. package/dist/mailer-env.js.map +1 -0
  443. package/dist/model-cache.d.ts +4 -8
  444. package/dist/model-cache.d.ts.map +1 -1
  445. package/dist/model-cache.js.map +1 -1
  446. package/dist/model-hooks.d.ts +21 -7
  447. package/dist/model-hooks.d.ts.map +1 -1
  448. package/dist/model-hooks.js +62 -39
  449. package/dist/model-hooks.js.map +1 -1
  450. package/dist/native-dev-env.d.ts +37 -1
  451. package/dist/native-dev-env.d.ts.map +1 -1
  452. package/dist/native-dev-env.js +64 -2
  453. package/dist/native-dev-env.js.map +1 -1
  454. package/dist/native-functions-watch.d.ts +56 -5
  455. package/dist/native-functions-watch.d.ts.map +1 -1
  456. package/dist/native-functions-watch.js +119 -38
  457. package/dist/native-functions-watch.js.map +1 -1
  458. package/dist/native-keyspace.d.ts.map +1 -1
  459. package/dist/native-keyspace.js +2 -2
  460. package/dist/native-keyspace.js.map +1 -1
  461. package/dist/native-realtime.d.ts +11 -3
  462. package/dist/native-realtime.d.ts.map +1 -1
  463. package/dist/native-realtime.js +162 -10
  464. package/dist/native-realtime.js.map +1 -1
  465. package/dist/native-roles-sql.d.ts +14 -0
  466. package/dist/native-roles-sql.d.ts.map +1 -1
  467. package/dist/native-roles-sql.js +82 -1
  468. package/dist/native-roles-sql.js.map +1 -1
  469. package/dist/native-storage-import.d.ts +19 -0
  470. package/dist/native-storage-import.d.ts.map +1 -0
  471. package/dist/native-storage-import.js +327 -0
  472. package/dist/native-storage-import.js.map +1 -0
  473. package/dist/native-storage.d.ts +45 -0
  474. package/dist/native-storage.d.ts.map +1 -0
  475. package/dist/native-storage.js +140 -0
  476. package/dist/native-storage.js.map +1 -0
  477. package/dist/native-worker.d.ts +26 -0
  478. package/dist/native-worker.d.ts.map +1 -0
  479. package/dist/native-worker.js +63 -0
  480. package/dist/native-worker.js.map +1 -0
  481. package/dist/owner-default.d.ts +9 -1
  482. package/dist/owner-default.d.ts.map +1 -1
  483. package/dist/owner-default.js +17 -4
  484. package/dist/owner-default.js.map +1 -1
  485. package/dist/post-apply.d.ts +3 -0
  486. package/dist/post-apply.d.ts.map +1 -0
  487. package/dist/post-apply.js +17 -0
  488. package/dist/post-apply.js.map +1 -0
  489. package/dist/postgres-ctl.d.ts +98 -7
  490. package/dist/postgres-ctl.d.ts.map +1 -1
  491. package/dist/postgres-ctl.js +273 -40
  492. package/dist/postgres-ctl.js.map +1 -1
  493. package/dist/postgres-image.d.ts +15 -3
  494. package/dist/postgres-image.d.ts.map +1 -1
  495. package/dist/postgres-image.js +18 -15
  496. package/dist/postgres-image.js.map +1 -1
  497. package/dist/postgrest-release.d.ts +9 -0
  498. package/dist/postgrest-release.d.ts.map +1 -1
  499. package/dist/postgrest-release.js +23 -0
  500. package/dist/postgrest-release.js.map +1 -1
  501. package/dist/process-manager.d.ts.map +1 -1
  502. package/dist/process-manager.js +3 -1
  503. package/dist/process-manager.js.map +1 -1
  504. package/dist/project-config.d.ts +44 -7
  505. package/dist/project-config.d.ts.map +1 -1
  506. package/dist/project-config.js +48 -4
  507. package/dist/project-config.js.map +1 -1
  508. package/dist/pull-utils.d.ts +15 -0
  509. package/dist/pull-utils.d.ts.map +1 -1
  510. package/dist/pull-utils.js +149 -23
  511. package/dist/pull-utils.js.map +1 -1
  512. package/dist/push-refusal.d.ts.map +1 -1
  513. package/dist/push-refusal.js +3 -2
  514. package/dist/push-refusal.js.map +1 -1
  515. package/dist/realtime-launch.d.ts +2 -5
  516. package/dist/realtime-launch.d.ts.map +1 -1
  517. package/dist/realtime-launch.js +6 -23
  518. package/dist/realtime-launch.js.map +1 -1
  519. package/dist/recorded-field-masking-tier.d.ts.map +1 -1
  520. package/dist/recorded-field-masking-tier.js +4 -3
  521. package/dist/recorded-field-masking-tier.js.map +1 -1
  522. package/dist/release-images.d.ts +31 -0
  523. package/dist/release-images.d.ts.map +1 -0
  524. package/dist/release-images.js +90 -0
  525. package/dist/release-images.js.map +1 -0
  526. package/dist/required-host-components.d.ts.map +1 -1
  527. package/dist/required-host-components.js +4 -0
  528. package/dist/required-host-components.js.map +1 -1
  529. package/dist/resolve-api-url.d.ts +17 -3
  530. package/dist/resolve-api-url.d.ts.map +1 -1
  531. package/dist/resolve-api-url.js +71 -30
  532. package/dist/resolve-api-url.js.map +1 -1
  533. package/dist/resolve-target.d.ts +64 -0
  534. package/dist/resolve-target.d.ts.map +1 -1
  535. package/dist/resolve-target.js +75 -27
  536. package/dist/resolve-target.js.map +1 -1
  537. package/dist/rest-ready.d.ts.map +1 -1
  538. package/dist/rest-ready.js +2 -1
  539. package/dist/rest-ready.js.map +1 -1
  540. package/dist/route-manifest.d.ts +25 -2
  541. package/dist/route-manifest.d.ts.map +1 -1
  542. package/dist/route-manifest.js +48 -4
  543. package/dist/route-manifest.js.map +1 -1
  544. package/dist/run-until-stopped.d.ts +12 -0
  545. package/dist/run-until-stopped.d.ts.map +1 -0
  546. package/dist/run-until-stopped.js +42 -0
  547. package/dist/run-until-stopped.js.map +1 -0
  548. package/dist/schema-ast-v2.d.ts +2 -1
  549. package/dist/schema-ast-v2.d.ts.map +1 -1
  550. package/dist/schema-ast-v2.js.map +1 -1
  551. package/dist/schema-push-lock.d.ts.map +1 -1
  552. package/dist/schema-push-lock.js +59 -46
  553. package/dist/schema-push-lock.js.map +1 -1
  554. package/dist/schema-sources.d.ts +19 -4
  555. package/dist/schema-sources.d.ts.map +1 -1
  556. package/dist/schema-sources.js +56 -35
  557. package/dist/schema-sources.js.map +1 -1
  558. package/dist/seed-auth-connect.d.ts +14 -0
  559. package/dist/seed-auth-connect.d.ts.map +1 -0
  560. package/dist/seed-auth-connect.js +97 -0
  561. package/dist/seed-auth-connect.js.map +1 -0
  562. package/dist/seed-runner.d.ts.map +1 -1
  563. package/dist/seed-runner.js +22 -1
  564. package/dist/seed-runner.js.map +1 -1
  565. package/dist/seed.d.ts +6 -3
  566. package/dist/seed.d.ts.map +1 -1
  567. package/dist/self-host-compose.d.ts +44 -29
  568. package/dist/self-host-compose.d.ts.map +1 -1
  569. package/dist/self-host-compose.js +311 -159
  570. package/dist/self-host-compose.js.map +1 -1
  571. package/dist/service-role-key-file.d.ts +32 -0
  572. package/dist/service-role-key-file.d.ts.map +1 -0
  573. package/dist/service-role-key-file.js +90 -0
  574. package/dist/service-role-key-file.js.map +1 -0
  575. package/dist/shell-ports.d.ts +13 -2
  576. package/dist/shell-ports.d.ts.map +1 -1
  577. package/dist/shell-ports.js +20 -15
  578. package/dist/shell-ports.js.map +1 -1
  579. package/dist/stop-signals.d.ts +7 -0
  580. package/dist/stop-signals.d.ts.map +1 -0
  581. package/dist/stop-signals.js +12 -0
  582. package/dist/stop-signals.js.map +1 -0
  583. package/dist/storage-launch.d.ts +11 -0
  584. package/dist/storage-launch.d.ts.map +1 -0
  585. package/dist/storage-launch.js +41 -0
  586. package/dist/storage-launch.js.map +1 -0
  587. package/dist/storage-provision.d.ts +50 -5
  588. package/dist/storage-provision.d.ts.map +1 -1
  589. package/dist/storage-provision.js +101 -33
  590. package/dist/storage-provision.js.map +1 -1
  591. package/dist/systemd.d.ts +1 -1
  592. package/dist/systemd.d.ts.map +1 -1
  593. package/dist/systemd.js +26 -11
  594. package/dist/systemd.js.map +1 -1
  595. package/dist/tar-reader.d.ts +29 -0
  596. package/dist/tar-reader.d.ts.map +1 -0
  597. package/dist/tar-reader.js +99 -0
  598. package/dist/tar-reader.js.map +1 -0
  599. package/dist/target-client.d.ts +14 -1
  600. package/dist/target-client.d.ts.map +1 -1
  601. package/dist/target-client.js +134 -23
  602. package/dist/target-client.js.map +1 -1
  603. package/dist/target-request.d.ts +25 -0
  604. package/dist/target-request.d.ts.map +1 -0
  605. package/dist/target-request.js +33 -0
  606. package/dist/target-request.js.map +1 -0
  607. package/dist/target-warning.d.ts +7 -0
  608. package/dist/target-warning.d.ts.map +1 -0
  609. package/dist/target-warning.js +12 -0
  610. package/dist/target-warning.js.map +1 -0
  611. package/dist/tsx-runner.d.ts.map +1 -1
  612. package/dist/tsx-runner.js +2 -1
  613. package/dist/tsx-runner.js.map +1 -1
  614. package/dist/type-extractor.d.ts +6 -0
  615. package/dist/type-extractor.d.ts.map +1 -1
  616. package/dist/type-extractor.js +138 -70
  617. package/dist/type-extractor.js.map +1 -1
  618. package/dist/ui/clack.d.ts.map +1 -1
  619. package/dist/ui/clack.js +11 -1
  620. package/dist/ui/clack.js.map +1 -1
  621. package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
  622. package/dist/ui/dev/DevDashboard.js +13 -5
  623. package/dist/ui/dev/DevDashboard.js.map +1 -1
  624. package/dist/ui/fatal.d.ts.map +1 -1
  625. package/dist/ui/fatal.js +6 -7
  626. package/dist/ui/fatal.js.map +1 -1
  627. package/dist/ui/flows/FlowApp.d.ts.map +1 -1
  628. package/dist/ui/flows/FlowApp.js +16 -1
  629. package/dist/ui/flows/FlowApp.js.map +1 -1
  630. package/dist/ui/flows/prompt-fields.d.ts +16 -6
  631. package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
  632. package/dist/ui/flows/prompt-fields.js +19 -9
  633. package/dist/ui/flows/prompt-fields.js.map +1 -1
  634. package/dist/ui/messages.d.ts +6 -0
  635. package/dist/ui/messages.d.ts.map +1 -1
  636. package/dist/ui/messages.js +17 -0
  637. package/dist/ui/messages.js.map +1 -1
  638. package/dist/ui/progress.d.ts +7 -0
  639. package/dist/ui/progress.d.ts.map +1 -1
  640. package/dist/ui/progress.js +22 -8
  641. package/dist/ui/progress.js.map +1 -1
  642. package/dist/ui/runtime/command-chrome.d.ts.map +1 -1
  643. package/dist/ui/runtime/command-chrome.js +2 -0
  644. package/dist/ui/runtime/command-chrome.js.map +1 -1
  645. package/dist/ui/runtime/prompt-interrupt.d.ts +10 -0
  646. package/dist/ui/runtime/prompt-interrupt.d.ts.map +1 -0
  647. package/dist/ui/runtime/prompt-interrupt.js +24 -0
  648. package/dist/ui/runtime/prompt-interrupt.js.map +1 -0
  649. package/dist/ui/runtime/run-clack-flow.d.ts.map +1 -1
  650. package/dist/ui/runtime/run-clack-flow.js +5 -2
  651. package/dist/ui/runtime/run-clack-flow.js.map +1 -1
  652. package/dist/ui/runtime/stdin-after-ink.d.ts +14 -1
  653. package/dist/ui/runtime/stdin-after-ink.d.ts.map +1 -1
  654. package/dist/ui/runtime/stdin-after-ink.js +44 -3
  655. package/dist/ui/runtime/stdin-after-ink.js.map +1 -1
  656. package/dist/url-safe-passwords.d.ts +25 -0
  657. package/dist/url-safe-passwords.d.ts.map +1 -0
  658. package/dist/url-safe-passwords.js +70 -0
  659. package/dist/url-safe-passwords.js.map +1 -0
  660. package/dist/valkey-sidecar.d.ts +33 -6
  661. package/dist/valkey-sidecar.d.ts.map +1 -1
  662. package/dist/valkey-sidecar.js +90 -61
  663. package/dist/valkey-sidecar.js.map +1 -1
  664. package/dist/worker-module-files.d.ts +3 -0
  665. package/dist/worker-module-files.d.ts.map +1 -0
  666. package/dist/worker-module-files.js +18 -0
  667. package/dist/worker-module-files.js.map +1 -0
  668. package/package.json +22 -16
  669. package/dist/functions-router-gen.d.ts.map +0 -1
  670. package/dist/functions-router-gen.js +0 -302
  671. package/dist/functions-router-gen.js.map +0 -1
@@ -1,25 +1,31 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { resolve, join, basename } from "node:path";
3
- import { spawnSync } from "node:child_process";
4
3
  import { randomBytes } from "node:crypto";
5
4
  import { p, runClackFlow } from "../ui/clack.js";
5
+ import { withProgressView } from "../ui/progress.js";
6
+ import { installCommand, installDependencies, plainStepView, runTimedStep, spinnerStepView, } from "../init-setup-steps.js";
6
7
  import { ensureNotCancelled } from "../ui/prompts.js";
7
8
  import { generateAndWriteKeys } from "./keys.js";
8
- import { CONTROL_PLANE_SECRET_ENV, generateControlPlaneSecret } from "../local-secrets.js";
9
+ import { BUNDLED_DB_USER, CONTROL_PLANE_SECRET_ENV, generateControlPlaneSecret, givenJwtSecret, newJwtSecret, } from "../local-secrets.js";
9
10
  import { file, error, info, plain, warn } from "../ui/messages.js";
10
11
  import { nextSteps } from "../ui/next-steps.js";
11
- import { probeDockerDaemon, reportDockerUnavailable } from "../docker-runtime.js";
12
+ import { probeDockerDaemonAsync, reportDockerUnavailable } from "../docker-runtime.js";
12
13
  import { loadConfig } from "../config.js";
13
14
  import { ensureComponentBinaries, reportComponentBinaryFailures, } from "../ensure-component-binaries.js";
14
15
  import { ensureFunctionsDenoTypes, sharedFunctionsReadmeSource, } from "../functions-deno-types.js";
15
16
  import { functionTemplateSource } from "../functions-template.js";
16
- import { mergeSupatypePackageJson } from "../init-package-json.js";
17
- import { parseJsonObject } from "@supatype/shared";
17
+ import { mergeSupatypePackageJson, PREPARE_COMMAND, scaffoldPackageJson, supatypeDevScript, } from "../init-package-json.js";
18
+ import { downloadRelease, initFromExample } from "../init-example.js";
19
+ import { errorMessage } from "../error-message.js";
20
+ import { isJsonObject, parseJsonObject } from "@supatype/shared";
18
21
  import { cliPackageVersion } from "../cli-package-version.js";
19
22
  import { initDependencyVersionsFallback, resolveInitDependencyVersions, } from "../init-dependency-versions.js";
20
23
  import { detectProjectSetup } from "../init-project-detect.js";
21
24
  import { SUPATYPE_GITIGNORE_PATHS } from "../gitignore.js";
25
+ import { DEV_FRONTEND_ENV_FILE, writeFrontendEnv } from "../frontend-env.js";
22
26
  import { DEFAULT_CLIENT_PATH, DEFAULT_TYPES_PATH } from "../type-generation.js";
27
+ import { COMPOSE_DEV_KONG_PORT, defaultAppStaticDir, NATIVE_DB_PORT, NATIVE_SERVER_PORT, nativeDatabaseUrl, VITE_BUILD_DIR, } from "../project-config.js";
28
+ import { cliDatabaseUrlLines } from "../database-url-owner.js";
23
29
  const STORAGE_PROVIDER_OPTIONS = [
24
30
  { value: "local", label: "Local", hint: "storage you host yourself (SeaweedFS)" },
25
31
  { value: "s3", label: "S3", hint: "external bucket (AWS S3 or compatible)" },
@@ -53,6 +59,29 @@ export function defaultScaffoldOptions(projectName, productionTarget = "later")
53
59
  helloFunction: false,
54
60
  };
55
61
  }
62
+ /**
63
+ * `init <dir> --example <name>`: the example from this CLI's release, in place of the scaffold. Its
64
+ * README carries the rest of the setup, so the next steps end there.
65
+ */
66
+ async function runExampleInit(name, example) {
67
+ const target = name ?? example;
68
+ const dir = resolve(process.cwd(), target);
69
+ const version = cliPackageVersion();
70
+ try {
71
+ info(`Downloading the ${example} example from supatype v${version}...`);
72
+ const { files, hasReadme } = await initFromExample({ dir, example, version, download: downloadRelease });
73
+ info(`Wrote ${files} files to ${target}/, with @supatype dependencies pinned to ^${version}.`);
74
+ nextSteps("Next steps:", [
75
+ `cd ${target}`,
76
+ `${detectInvokingPackageManager()} install`,
77
+ hasReadme ? "Then follow README.md: it has the rest of this example's setup." : "supatype dev",
78
+ ]);
79
+ }
80
+ catch (err) {
81
+ error(errorMessage(err));
82
+ process.exit(1);
83
+ }
84
+ }
56
85
  export function registerInit(program) {
57
86
  program
58
87
  .command("init [name]")
@@ -64,7 +93,12 @@ export function registerInit(program) {
64
93
  .option("--admin-email <email>", "First admin panel user email (written to .env)")
65
94
  .option("--admin-password <password>", "First admin panel user password (written to .env)")
66
95
  .option("--no-admin", "Do not configure a first admin user")
96
+ .option("--example <name>", "Start from an example of this CLI's release (examples/<name> on GitHub)")
67
97
  .action(async (name, opts) => {
98
+ if (opts.example !== undefined) {
99
+ await runExampleInit(name, opts.example);
100
+ return;
101
+ }
68
102
  const dir = name ? resolve(process.cwd(), name) : process.cwd();
69
103
  if (name && existsSync(dir)) {
70
104
  error(`Directory already exists: ${dir}`);
@@ -73,77 +107,58 @@ export function registerInit(program) {
73
107
  const defaultName = name ?? basename(dir) ?? "my-project";
74
108
  const interactive = !opts.defaults && Boolean(process.stdin.isTTY);
75
109
  const modeTarget = productionTargetFromMode(opts.mode);
76
- let result;
77
110
  if (interactive) {
78
- await runInteractiveInit({
79
- name,
80
- dir,
81
- defaultName,
82
- modeTarget,
83
- opts,
84
- });
111
+ await runInteractiveInit({ name, dir, defaultName, modeTarget, opts });
85
112
  return;
86
113
  }
87
- else {
88
- result = {
89
- ...defaultScaffoldOptions(defaultName, modeTarget),
90
- packageManager: detectInvokingPackageManager(),
91
- install: true,
92
- generateKeys: true,
93
- };
94
- if (result.provider === "docker") {
95
- const { chooseInitKongPort } = await import("../dev-ports.js");
96
- result.kongPort = await chooseInitKongPort();
97
- }
98
- if (!opts.admin && opts.adminEmail && opts.adminPassword) {
99
- result.adminEmail = opts.adminEmail;
100
- result.adminPassword = opts.adminPassword;
101
- }
102
- }
103
- if (opts.admin === false) {
104
- delete result.adminEmail;
105
- delete result.adminPassword;
106
- }
107
- else if (opts.adminEmail && opts.adminPassword) {
108
- result.adminEmail = opts.adminEmail;
109
- result.adminPassword = opts.adminPassword;
110
- }
111
- // CLI flags override wizard / default action choices.
112
- const doInstall = opts.install !== false && result.install;
113
- const doKeys = opts.keys !== false && result.generateKeys;
114
- if (name)
115
- mkdirSync(dir, { recursive: true });
116
- const deps = await resolveInitDependencyVersions();
117
- const runningCli = cliPackageVersion();
118
- if (deps.cli !== runningCli || deps.types !== runningCli) {
119
- info(`Using published npm versions: @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}`);
120
- }
121
- scaffold(dir, result, deps);
122
- const installOk = doInstall ? runInstall(dir, result.packageManager) : false;
123
- const keysGenerated = doKeys ? writeKeys(dir) : false;
124
- const binariesReady = doInstall && installOk ? await ensureInitBinaries(dir) : false;
125
- if (doInstall && !installOk) {
126
- error(`Dependency install failed. Run "${result.packageManager} install" in the project directory, then "supatype update".`);
127
- process.exit(1);
128
- }
129
- if (doKeys && !keysGenerated) {
130
- error("Could not generate API keys. Check .env has JWT_SECRET, then run `supatype keys`.");
131
- process.exit(1);
132
- }
133
- if (doInstall && installOk && !binariesReady) {
134
- error("Component binaries could not be downloaded. Run `supatype update` in the project directory.");
135
- process.exit(1);
136
- }
137
- warnDockerUnavailableForProvider(result.provider);
138
- printNextSteps({
139
- name,
140
- result,
141
- installed: doInstall && installOk,
142
- keysGenerated,
143
- binariesReady,
144
- });
114
+ const result = {
115
+ ...defaultScaffoldOptions(defaultName, modeTarget),
116
+ packageManager: detectInvokingPackageManager(),
117
+ install: true,
118
+ generateKeys: true,
119
+ };
120
+ const asked = startInitQuestions(result.provider);
121
+ if (asked.kongPort)
122
+ result.kongPort = await asked.kongPort;
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),
145
149
  });
146
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
+ }
147
162
  /** Interactive init: one Ink session for wizard + scaffold + install + finish. */
148
163
  async function runInteractiveInit(args) {
149
164
  const { name, dir, defaultName, modeTarget, opts } = args;
@@ -153,76 +168,19 @@ async function runInteractiveInit(args) {
153
168
  if (detected.hasExistingFiles && detected.summaryLines.length > 0) {
154
169
  p.note(["Existing project detected:", ...detected.summaryLines.map((line) => ` • ${line}`)].join("\n"));
155
170
  }
156
- let result = await collectWizardAnswers(defaultName, modeTarget, dir, detected);
157
- if (opts.admin === false) {
158
- delete result.adminEmail;
159
- delete result.adminPassword;
160
- }
161
- else if (opts.adminEmail && opts.adminPassword) {
162
- result.adminEmail = opts.adminEmail;
163
- result.adminPassword = opts.adminPassword;
164
- }
165
- const doInstall = opts.install !== false && result.install;
166
- const doKeys = opts.keys !== false && result.generateKeys;
167
- if (name)
168
- mkdirSync(dir, { recursive: true });
169
- const deps = await resolveInitDependencyVersions();
170
- const runningCli = cliPackageVersion();
171
- if (deps.cli !== runningCli || deps.types !== runningCli) {
172
- info(`Using published npm versions: @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}`);
173
- }
174
- const setupSpinner = p.spinner();
175
- setupSpinner.start("Setting up your project...");
176
- scaffold(dir, result, deps);
177
- let installOk = !doInstall;
178
- if (doInstall) {
179
- setupSpinner.start(`Installing dependencies with ${result.packageManager}...`);
180
- installOk = runInstall(dir, result.packageManager);
181
- setupSpinner.stop(installOk ? "Dependencies installed." : "Dependency install failed.");
182
- }
183
- let keysGenerated = !doKeys;
184
- if (doKeys) {
185
- setupSpinner.start("Generating API keys...");
186
- keysGenerated = writeKeys(dir);
187
- setupSpinner.stop(keysGenerated ? "API keys generated." : "Could not generate API keys.");
188
- }
189
- let binariesReady = false;
190
- if (doInstall && installOk) {
191
- setupSpinner.start("Preparing component binaries...");
192
- binariesReady = await ensureInitBinaries(dir);
193
- setupSpinner.stop(binariesReady ? "Component binaries ready." : "Some binaries are missing.");
194
- }
195
- if (doInstall && !installOk) {
196
- error(`Dependency install failed. Run "${result.packageManager} install" in the project directory, then "supatype update".`);
197
- process.exit(1);
198
- }
199
- if (doKeys && !keysGenerated) {
200
- error("Could not generate API keys. Check .env has JWT_SECRET, then run `supatype keys`.");
201
- process.exit(1);
202
- }
203
- if (doInstall && installOk && !binariesReady) {
204
- error("Component binaries could not be downloaded. Run `supatype update` in the project directory.");
205
- process.exit(1);
206
- }
207
- warnDockerUnavailableForProvider(result.provider);
208
- p.outro(`Supatype project ready${name ? ` in ${name}/` : ""}.`);
209
- printNextSteps({
210
- name,
211
- result,
212
- installed: doInstall && installOk,
213
- keysGenerated,
214
- binariesReady,
171
+ const result = await collectWizardAnswers({
172
+ defaultName,
173
+ defaultTarget: modeTarget,
174
+ detected,
175
+ askName: name === undefined,
215
176
  });
177
+ await createProject({ name, dir, result, opts, deps: resolveDependencyVersions() });
216
178
  });
217
179
  process.exit(0);
218
180
  }
219
- // ─── Wizard ──────────────────────────────────────────────────────────────────
220
- async function collectWizardAnswers(defaultName, defaultTarget, dir, detected) {
221
- const projectName = ensureNotCancelled(await p.text({
222
- message: "Project name",
223
- defaultValue: defaultName,
224
- placeholder: defaultName,
225
- })).trim() || defaultName;
181
+ export async function collectWizardAnswers(context) {
182
+ const { defaultName, defaultTarget, detected } = context;
183
+ const projectName = context.askName ? await promptProjectName(defaultName) : defaultName;
226
184
  const admin = await promptAdminUser();
227
185
  const packageManager = ensureNotCancelled(await p.select({
228
186
  message: "Package manager",
@@ -273,14 +231,7 @@ async function collectWizardAnswers(defaultName, defaultTarget, dir, detected) {
273
231
  const { promptKongPortChoice } = await import("../dev-ports.js");
274
232
  kongPort = await promptKongPortChoice();
275
233
  }
276
- const defaultSchemaPath = existsSync(join(dir, "schema/index.ts"))
277
- ? "schema/index.ts"
278
- : "schema/index.ts";
279
- const schemaPath = ensureNotCancelled(await p.text({
280
- message: "Where should your schema live?",
281
- defaultValue: defaultSchemaPath,
282
- placeholder: "schema/index.ts",
283
- })).trim() || defaultSchemaPath;
234
+ const schemaPath = await askWithDefault("Where should your schema live?", "schema/index.ts");
284
235
  const app = await promptApp(detected, productionTarget);
285
236
  const email = ensureNotCancelled(await p.select({
286
237
  message: "Email provider",
@@ -297,11 +248,8 @@ async function collectWizardAnswers(defaultName, defaultTarget, dir, detected) {
297
248
  initialValue: "local",
298
249
  options: STORAGE_PROVIDER_OPTIONS,
299
250
  }));
300
- const storageProduction = ensureNotCancelled(await p.select({
301
- message: "Production storage?",
302
- initialValue: "local",
303
- options: STORAGE_PROVIDER_OPTIONS,
304
- }));
251
+ // No production to store for yet: production storage is chosen with the production target.
252
+ const storageProduction = productionTarget === "later" ? storageLocal : await promptProductionStorage();
305
253
  const helloFunction = ensureNotCancelled(await p.confirm({
306
254
  message: "Create a hello-world edge function?",
307
255
  initialValue: false,
@@ -325,6 +273,20 @@ async function collectWizardAnswers(defaultName, defaultTarget, dir, detected) {
325
273
  ...admin,
326
274
  };
327
275
  }
276
+ async function promptProjectName(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;
282
+ }
283
+ async function promptProductionStorage() {
284
+ return ensureNotCancelled(await p.select({
285
+ message: "Production storage?",
286
+ initialValue: "local",
287
+ options: STORAGE_PROVIDER_OPTIONS,
288
+ }));
289
+ }
328
290
  async function promptAdminUser() {
329
291
  const createAdmin = ensureNotCancelled(await p.confirm({
330
292
  message: "Create an admin user for Studio (/studio/)?",
@@ -338,14 +300,24 @@ async function promptAdminUser() {
338
300
  placeholder: "you@example.com",
339
301
  validate: (value) => (value.trim() ? undefined : "Email is required"),
340
302
  })).trim();
341
- 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() {
342
310
  while (true) {
343
- adminPassword = ensureNotCancelled(await p.password({ message: "Admin password (min 8 characters)" })).trim();
344
- if (adminPassword.length >= 8)
345
- break;
346
- 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.");
347
320
  }
348
- return { adminEmail, adminPassword };
349
321
  }
350
322
  async function promptApp(detected, productionTarget) {
351
323
  const initialMode = detected.hasVite && productionTarget !== "later"
@@ -363,30 +335,31 @@ async function promptApp(detected, productionTarget) {
363
335
  ],
364
336
  }));
365
337
  if (mode === "static") {
366
- const staticDir = ensureNotCancelled(await p.text({
367
- message: "Directory to serve",
368
- defaultValue: detected.staticDir,
369
- placeholder: detected.staticDir,
370
- })).trim() || detected.staticDir;
371
338
  const viteDevUrl = await promptViteDevUrl(detected, productionTarget);
372
- return { mode, staticDir, ...(viteDevUrl ? { viteDevUrl } : {}) };
339
+ return { mode, staticDir: await promptStaticDir(detected, viteDevUrl !== undefined), ...(viteDevUrl ? { viteDevUrl } : {}) };
373
340
  }
374
341
  if (mode === "proxy") {
375
- const upstream = ensureNotCancelled(await p.text({
376
- message: "URL of your running dev server",
377
- defaultValue: detected.hasVite ? detected.viteDevUrl : "http://localhost:3000",
378
- placeholder: detected.hasVite ? detected.viteDevUrl : "http://localhost:3000",
379
- })).trim() || (detected.hasVite ? detected.viteDevUrl : "http://localhost:3000");
380
- const start = ensureNotCancelled(await p.text({
381
- message: "package.json script that starts your dev server",
382
- defaultValue: detected.hasVite ? "vite" : "dev",
383
- placeholder: detected.hasVite ? "vite" : "dev",
384
- })).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");
385
344
  const viteDevUrl = await promptViteDevUrl(detected, productionTarget);
386
345
  return { mode, upstream, start, ...(viteDevUrl ? { viteDevUrl } : {}) };
387
346
  }
388
347
  return { mode: "none" };
389
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
+ }
390
363
  async function promptViteDevUrl(detected, productionTarget) {
391
364
  const defaultYes = detected.hasVite || productionTarget !== "later";
392
365
  const useVite = ensureNotCancelled(await p.confirm({
@@ -397,12 +370,7 @@ async function promptViteDevUrl(detected, productionTarget) {
397
370
  }));
398
371
  if (!useVite)
399
372
  return undefined;
400
- p.note(`Press Enter for ${detected.viteDevUrl}, or type a custom URL.`);
401
- return (ensureNotCancelled(await p.text({
402
- message: "Vite dev server URL",
403
- defaultValue: detected.viteDevUrl,
404
- placeholder: detected.viteDevUrl,
405
- })).trim() || detected.viteDevUrl);
373
+ return askWithDefault("Vite dev server URL", detected.viteDevUrl);
406
374
  }
407
375
  // ─── Package manager ───────────────────────────────────────────────────────--
408
376
  function detectInvokingPackageManager() {
@@ -415,16 +383,52 @@ function detectInvokingPackageManager() {
415
383
  return "bun";
416
384
  return "npm";
417
385
  }
418
- function runInstall(dir, pm) {
419
- const res = spawnSync(pm, ["install"], {
420
- cwd: dir,
421
- stdio: "inherit",
422
- shell: process.platform === "win32",
423
- });
424
- if (res.status !== 0 || res.error) {
425
- return false;
386
+ /**
387
+ * The view init's setup steps are shown on: a spinner in a terminal, the flow's or the command
388
+ * chrome's (ui/progress.ts decides, as for every spinner), and plain start and done lines otherwise.
389
+ */
390
+ async function withStepView(run) {
391
+ return withProgressView((spinner) => run(spinner === undefined ? plainStepView() : spinnerStepView(spinner)));
392
+ }
393
+ /** Install, then keys, then the component binaries an install makes possible, each timed on `view`. */
394
+ async function runSetupSteps(dir, pm, wants, view) {
395
+ const installOk = wants.install && (await runTimedStep(view, installStep(dir, pm, view.live)));
396
+ const keysGenerated = wants.keys &&
397
+ (await runTimedStep(view, {
398
+ label: "Generating API keys",
399
+ run: async () => writeKeys(dir),
400
+ done: (ok) => (ok ? "API keys generated" : "Could not generate API keys"),
401
+ }));
402
+ const binariesReady = installOk &&
403
+ (await runTimedStep(view, {
404
+ label: "Preparing component binaries",
405
+ run: () => ensureInitBinaries(dir),
406
+ done: (ok) => (ok ? "Component binaries ready" : "Some binaries are missing"),
407
+ }));
408
+ return { installOk, keysGenerated, binariesReady };
409
+ }
410
+ /** The install step: in a terminal its output is read for the spinner, otherwise it passes through. */
411
+ function installStep(dir, pm, live) {
412
+ return {
413
+ label: `Installing dependencies with ${pm}`,
414
+ run: (detail) => installDependencies(dir, installCommand(pm), live ? detail : undefined),
415
+ done: (ok) => (ok ? "Dependencies installed" : "Dependency install failed"),
416
+ };
417
+ }
418
+ /** Stop init, naming what to run, when a setup step it was asked for failed. */
419
+ function exitOnFailedSetup(outcome, wants, pm) {
420
+ if (wants.install && !outcome.installOk) {
421
+ error(`Dependency install failed. Run "${pm} install" in the project directory, then "supatype update".`);
422
+ process.exit(1);
423
+ }
424
+ if (wants.keys && !outcome.keysGenerated) {
425
+ error("Could not generate API keys. Check the project has a .env, then run `supatype keys`.");
426
+ process.exit(1);
427
+ }
428
+ if (wants.install && !outcome.binariesReady) {
429
+ error("Component binaries could not be downloaded. Run `supatype update` in the project directory.");
430
+ process.exit(1);
426
431
  }
427
- return true;
428
432
  }
429
433
  async function ensureInitBinaries(dir) {
430
434
  const previousCwd = process.cwd();
@@ -439,7 +443,7 @@ async function ensureInitBinaries(dir) {
439
443
  return true;
440
444
  }
441
445
  catch (err) {
442
- const message = err instanceof Error ? err.message : String(err);
446
+ const message = errorMessage(err);
443
447
  warn(`Could not verify component binaries: ${message}`);
444
448
  warn("Run manually from your project directory: supatype update");
445
449
  return false;
@@ -450,12 +454,22 @@ async function ensureInitBinaries(dir) {
450
454
  }
451
455
  function writeKeys(dir) {
452
456
  const keys = generateAndWriteKeys(dir);
453
- if (!keys) {
454
- warn("Could not generate keys (JWT_SECRET missing). Run `supatype keys` manually.");
457
+ if (!keys.ok) {
458
+ warn(`Could not write keys: ${keys.reason} Run \`supatype keys\` in the project once that is fixed.`);
455
459
  return false;
456
460
  }
457
461
  return true;
458
462
  }
463
+ /**
464
+ * The new .env's JWT_SECRET: the shell's when one is exported and usable, else a generated one.
465
+ * Warned about rather than refused when the shell's is unusable, since init is mid-wizard.
466
+ */
467
+ function initialJwtSecret() {
468
+ const { secret, problem } = newJwtSecret(givenJwtSecret());
469
+ if (problem !== undefined)
470
+ warn(`${problem} Generated a JWT_SECRET for .env instead.`);
471
+ return secret;
472
+ }
459
473
  // ─── Scaffold ──────────────────────────────────────────────────────────────--
460
474
  export function scaffold(dir, optsOrName, deps = initDependencyVersionsFallback()) {
461
475
  const opts = typeof optsOrName === "string" ? defaultScaffoldOptions(optsOrName) : optsOrName;
@@ -467,51 +481,92 @@ export function scaffold(dir, optsOrName, deps = initDependencyVersionsFallback(
467
481
  };
468
482
  const pkgPath = join(dir, "package.json");
469
483
  if (!existsSync(pkgPath)) {
470
- write("package.json", packageJsonTemplate(opts, deps));
484
+ write("package.json", scaffoldPackageJson(opts, deps));
471
485
  }
472
486
  else {
473
- try {
474
- const existing = parseJsonObject(readFileSync(pkgPath, "utf8"));
475
- if (!existing.ok)
476
- throw new Error("package.json is not a JSON object");
477
- const merged = mergeSupatypePackageJson(existing.value, opts, deps);
478
- writeFileSync(pkgPath, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
479
- file("updated", "package.json (added Supatype dependencies)");
480
- }
481
- catch {
482
- warn("Could not merge into package.json, add @supatype/cli and @supatype/types manually.");
483
- file("skipped", "package.json (invalid JSON)");
484
- }
487
+ mergeIntoPackageJson(pkgPath, opts, deps);
485
488
  }
486
489
  write("supatype.config.ts", tsConfigTemplate(opts));
487
- if (opts.productionTarget !== "later") {
490
+ if (writesLocalOverride(opts)) {
488
491
  write("supatype.local.config.ts", localConfigTemplate(opts.app));
489
492
  }
490
493
  write(opts.schemaPath, schemaTemplate());
491
494
  write(".env", envTemplate(opts));
495
+ scaffoldDevFrontendEnv(dir, opts);
492
496
  write("seed.ts", seedTemplate(opts.projectName));
493
497
  write("seeds/.gitkeep", "");
494
498
  scaffoldAppAssets(dir, opts, write);
495
499
  if (opts.helloFunction)
496
500
  scaffoldHelloFunction(dir, write);
497
- const gitignorePath = join(dir, ".gitignore");
498
- if (existsSync(gitignorePath)) {
499
- const merged = mergeGitignoreTemplate(readFileSync(gitignorePath, "utf8"));
500
- if (merged !== readFileSync(gitignorePath, "utf8")) {
501
- writeFileSync(gitignorePath, merged, "utf8");
502
- file("updated", ".gitignore (added .supatype/)");
503
- }
504
- else {
505
- 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.`);
506
520
  }
507
521
  }
508
- 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)) {
509
548
  write(".gitignore", gitignoreTemplate());
549
+ return;
550
+ }
551
+ const existing = readFileSync(gitignorePath, "utf8");
552
+ const merged = mergeGitignoreTemplate(existing);
553
+ if (merged === existing) {
554
+ file("skipped", ".gitignore (already exists)");
555
+ return;
510
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));
511
567
  }
512
568
  function staticDirRelative(staticDir) {
513
- const raw = (staticDir ?? "./public").trim();
514
- return raw.replace(/^\.\//, "").replace(/\/+$/, "") || "public";
569
+ return staticDir.trim().replace(/^\.\//, "").replace(/\/+$/, "") || "public";
515
570
  }
516
571
  function scaffoldAppAssets(dir, opts, write) {
517
572
  const writeUnlessExists = (rel, content) => {
@@ -522,17 +577,11 @@ function scaffoldAppAssets(dir, opts, write) {
522
577
  }
523
578
  write(rel, content);
524
579
  };
525
- const holding = holdingPageTemplate(opts.projectName);
580
+ const holding = holdingPageTemplate(opts.projectName, initLocalApiUrl(opts));
526
581
  const hasVite = Boolean(opts.app.viteDevUrl);
527
582
  if (opts.app.mode === "static") {
528
- const staticRel = staticDirRelative(opts.app.staticDir);
529
- if (opts.app.viteDevUrl && opts.productionTarget !== "later") {
530
- writeUnlessExists("dist/index.html", holding);
531
- scaffoldVite(dir, opts, writeUnlessExists, holding);
532
- return;
533
- }
534
- writeUnlessExists(`${staticRel}/index.html`, holding);
535
- if (opts.app.viteDevUrl)
583
+ writeUnlessExists(`${staticDirRelative(staticDirOf(opts.app))}/index.html`, holding);
584
+ if (hasVite)
536
585
  scaffoldVite(dir, opts, writeUnlessExists, holding);
537
586
  return;
538
587
  }
@@ -557,7 +606,18 @@ function scaffoldVite(dir, opts, write, holding) {
557
606
  file("skipped", `${viteConfigRel} (already exists)`);
558
607
  return;
559
608
  }
560
- 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;
561
621
  }
562
622
  function scaffoldHelloFunction(dir, write) {
563
623
  write("functions/hello/index.ts", functionTemplateSource("hello"));
@@ -577,63 +637,37 @@ function scaffoldHelloFunction(dir, write) {
577
637
  }
578
638
  }
579
639
  // ─── Templates ───────────────────────────────────────────────────────────────
580
- function packageJsonTemplate(opts, deps) {
581
- const scripts = [
582
- ` "dev": "supatype dev"`,
583
- ` "push": "supatype push"`,
584
- ` "seed": "supatype seed"`,
585
- // The generated seed builder is gitignored, so a fresh clone has to produce it before
586
- // anything can import it. `generate` is fully offline, which is the condition that makes
587
- // gitignoring generated code reasonable rather than a trap; without this hook it would be
588
- // one, and the failure would be a missing module rather than anything naming the remedy.
589
- ` "prepare": "supatype generate"`,
590
- ];
591
- if (opts.app.viteDevUrl) {
592
- scripts.push(` "vite": "vite"`);
593
- }
594
- if (opts.helloFunction) {
595
- scripts.push(` "functions": "supatype functions serve"`);
596
- }
597
- // Both are development-time only, so they belong in devDependencies. Validated end to end
598
- // against a real database: schema/index.ts imports @supatype/types with `import type`, which is
599
- // erased at build; supatype.config.ts imports defineConfig, which only the CLI evaluates; and
600
- // seed.ts is run by `tsx seed.ts`. Nothing `supatype push` or `supatype generate` writes refers
601
- // to either package: the generated types import nothing, and the client augmentation declares a
602
- // module for @supatype/client, which stays a real dependency.
603
- //
604
- // In dependencies they were installed by `npm install --omit=dev`, so every production install
605
- // of a Supatype app pulled the whole CLI toolchain (ink, react, typescript, ts-morph, pg, tsx)
606
- // to support three files that never run in production.
607
- const devDeps = [
608
- ` "@supatype/cli": "^${deps.cli}"`,
609
- ` "@supatype/types": "^${deps.types}"`,
610
- ` "tsx": "^4.19.2"`,
611
- ` "typescript": "^5"`,
612
- ];
613
- if (opts.app.viteDevUrl) {
614
- devDeps.push(` "vite": "^6"`);
640
+ /** The Supatype package versions to pin, saying so when the registry moved any off the running CLI's. */
641
+ async function resolveDependencyVersions() {
642
+ const deps = await resolveInitDependencyVersions();
643
+ const runningCli = cliPackageVersion();
644
+ if (deps.cli !== runningCli || deps.types !== runningCli || deps.client !== runningCli) {
645
+ info(`Pinning @supatype/cli ^${deps.cli}, @supatype/types ^${deps.types}, ` +
646
+ `@supatype/client ^${deps.client}`);
615
647
  }
616
- return `{
617
- "name": "${opts.projectName}",
618
- "private": true,
619
- "type": "module",
620
- "scripts": {
621
- ${scripts.join(",\n")}
622
- },
623
- "devDependencies": {
624
- ${devDeps.join(",\n")}
625
- }
648
+ return deps;
626
649
  }
627
- `;
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);
658
+ }
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);
628
662
  }
629
663
  function tsConfigTemplate(opts) {
630
664
  const serverMode = serverModeForTarget(opts.productionTarget);
631
- const hasLocalOverride = opts.productionTarget !== "later";
632
665
  const lines = [];
633
666
  lines.push(`import { defineConfig } from "@supatype/cli"`);
634
667
  lines.push("");
635
- if (hasLocalOverride) {
668
+ if (opts.productionTarget !== "later")
636
669
  lines.push(`// Committed config = ${opts.productionTarget} production target.`);
670
+ if (writesLocalOverride(opts)) {
637
671
  lines.push(`// Local development overrides live in supatype.local.config.ts (gitignored).`);
638
672
  }
639
673
  lines.push(`export default defineConfig({`);
@@ -648,9 +682,9 @@ function tsConfigTemplate(opts) {
648
682
  lines.push(` server: {`);
649
683
  lines.push(` mode: "${serverMode}",`);
650
684
  // The native server listens on server.port. A docker project's API is on the gateway port in
651
- // .env (SUPATYPE_KONG_PORT), so writing 54321 there only named a port nothing listened on.
685
+ // .env (SUPATYPE_KONG_PORT), so writing a server port there only named a port nothing listened on.
652
686
  if (opts.provider === "native")
653
- lines.push(` port: 54321,`);
687
+ lines.push(` port: ${NATIVE_SERVER_PORT},`);
654
688
  if (serverMode === "standalone") {
655
689
  lines.push(` domain: "${opts.domain ?? ""}", // e.g. "api.example.com" for ACME TLS`);
656
690
  if (opts.tlsEmail) {
@@ -718,23 +752,9 @@ function localDevAppConfigLines(app) {
718
752
  }
719
753
  function appConfigLines(app, productionTarget) {
720
754
  if (app.mode === "static") {
721
- if (productionTarget !== "later" && app.viteDevUrl) {
722
- return [
723
- ` app: {`,
724
- ` mode: "static",`,
725
- ` static_dir: "./dist", // production build output`,
726
- ` },`,
727
- ];
728
- }
729
- const out = [
730
- ` app: {`,
731
- ` mode: "static",`,
732
- ` static_dir: "${app.staticDir ?? "./public"}",`,
733
- ];
734
- if (app.viteDevUrl)
735
- out.push(` vite_dev_url: "${app.viteDevUrl}",`);
736
- out.push(` },`);
737
- 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}`, ` },`];
738
758
  }
739
759
  if (app.mode === "proxy") {
740
760
  if (productionTarget !== "later") {
@@ -776,7 +796,25 @@ function escapeHtml(text) {
776
796
  .replace(/>/g, "&gt;")
777
797
  .replace(/"/g, "&quot;");
778
798
  }
779
- function holdingPageTemplate(projectName) {
799
+ /**
800
+ * Where `supatype dev` answers for this project: the gateway's port for docker, the API server's
801
+ * for native. One answer for the page `init` writes and the steps it prints, which disagreed: the
802
+ * page named 18473 whatever port the project was given.
803
+ */
804
+ function initLocalApiUrl(opts) {
805
+ return opts.provider === "docker"
806
+ ? `http://localhost:${opts.kongPort ?? COMPOSE_DEV_KONG_PORT}`
807
+ : `http://localhost:${NATIVE_SERVER_PORT}`;
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
+ }
817
+ function holdingPageTemplate(projectName, apiUrl) {
780
818
  const name = escapeHtml(projectName);
781
819
  return `<!doctype html>
782
820
  <html lang="en">
@@ -893,7 +931,7 @@ function holdingPageTemplate(projectName) {
893
931
  <a href="${HOLDING_PAGE_GITHUB_URL}" target="_blank" rel="noopener noreferrer">GitHub</a>
894
932
  <a href="${HOLDING_PAGE_DISCORD_URL}" target="_blank" rel="noopener noreferrer">Discord</a>
895
933
  </nav>
896
- <p class="hint">Run <code>supatype dev</code> then open <code>http://localhost:18473/</code></p>
934
+ <p class="hint">Run <code>supatype dev</code> then open <code>${escapeHtml(apiUrl)}/</code></p>
897
935
  </main>
898
936
  </body>
899
937
  </html>
@@ -910,12 +948,13 @@ function vitePortFromDevUrl(viteDevUrl) {
910
948
  return 5173;
911
949
  }
912
950
  }
913
- function viteConfigTemplate(viteDevUrl) {
951
+ function viteConfigTemplate(viteDevUrl, outDir) {
914
952
  const port = vitePortFromDevUrl(viteDevUrl);
953
+ const build = outDir === undefined ? "" : ` // Built into the directory supatype.config.ts serves.\n build: { outDir: "${outDir}" },\n`;
915
954
  return `import { defineConfig } from "vite"
916
955
 
917
956
  export default defineConfig({
918
- server: {
957
+ ${build} server: {
919
958
  host: "127.0.0.1",
920
959
  port: ${port},
921
960
  strictPort: true,
@@ -977,8 +1016,13 @@ function envTemplate(opts) {
977
1016
  // and anyone holding that secret can mint a token naming any Postgres role. Safe to generate
978
1017
  // only because `supatype dev` no longer overwrites them on every run (see local-secrets.ts).
979
1018
  const postgresPassword = randomBytes(24).toString("base64url");
980
- sections.push(`DATABASE_URL=postgresql://supatype_admin:${postgresPassword}@localhost:5432/${opts.projectName}
981
- POSTGRES_USER=supatype_admin
1019
+ // Labelled as the CLI's, so it follows the provider the project runs (database-url-owner.ts). A
1020
+ // native project's is the one its dev uses, which used to rewrite a Docker URL on the first start.
1021
+ const databaseUrl = opts.provider === "native"
1022
+ ? nativeDatabaseUrl(opts.projectName, postgresPassword, NATIVE_DB_PORT)
1023
+ : `postgresql://${BUNDLED_DB_USER}:${encodeURIComponent(postgresPassword)}@localhost:5432/${opts.projectName}`;
1024
+ sections.push(`${cliDatabaseUrlLines(databaseUrl)}
1025
+ POSTGRES_USER=${BUNDLED_DB_USER}
982
1026
  POSTGRES_PASSWORD=${postgresPassword}
983
1027
  POSTGRES_DB=${opts.projectName}
984
1028
 
@@ -993,24 +1037,24 @@ AUTHENTICATOR_PASSWORD=${randomBytes(24).toString("base64url")}
993
1037
  # Studio's SQL editor connects as \`supatype_sql_editor\`, a role that is not a superuser, so a
994
1038
  # query typed there runs without superuser rights. Kept apart from both passwords above.
995
1039
  SUPATYPE_SQL_EDITOR_PASSWORD=${randomBytes(24).toString("base64url")}`);
1040
+ // A usable JWT_SECRET exported in the shell goes into the new .env, so tokens the developer
1041
+ // already signed with it keep working. From then on .env's wins over the shell's.
996
1042
  sections.push(`# JWT: ANON_KEY and SERVICE_ROLE_KEY are derived from this secret.
997
1043
  # Changing it invalidates every issued token; re-run \`supatype keys\` afterwards.
998
- JWT_SECRET=${randomBytes(48).toString("base64url")}
1044
+ JWT_SECRET=${initialJwtSecret()}
999
1045
  ANON_KEY=
1000
1046
  SERVICE_ROLE_KEY=`);
1001
1047
  sections.push(`# Shared by the API server and the control plane only. The control plane refuses any
1002
1048
  # request without it, so code running in the functions worker cannot call it directly.
1003
1049
  ${CONTROL_PLANE_SECRET_ENV}=${generateControlPlaneSecret()}`);
1004
1050
  sections.push(`# Site URL (used for email redirects)
1005
- SITE_URL=http://localhost:3000`);
1051
+ SITE_URL=${initSiteUrl(opts)}`);
1006
1052
  if (opts.provider === "docker" && opts.kongPort !== undefined) {
1007
- 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.
1008
1055
  sections.push(`# Local API gateway (Kong), unique per project so multiple stacks can run concurrently
1009
1056
  SUPATYPE_KONG_PORT=${opts.kongPort}
1010
- PUBLIC_SUPATYPE_URL=${apiUrl}
1011
- API_EXTERNAL_URL=${apiUrl}
1012
- VITE_SUPATYPE_URL=${apiUrl}
1013
- VITE_SUPATYPE_ANON_KEY=`);
1057
+ API_EXTERNAL_URL=${initLocalApiUrl(opts)}`);
1014
1058
  }
1015
1059
  sections.push(emailEnvSection(opts.email, opts.projectName));
1016
1060
  sections.push(storageEnvSections(opts.storageLocal, opts.storageProduction));
@@ -1029,39 +1073,44 @@ SUPATYPE_ADMIN_PASSWORD=${opts.adminPassword}`);
1029
1073
  const SELF_HOST_PORTS_ENV_SECTION = `# Self-host stack ports (supatype self-host compose). Kong, at SUPATYPE_KONG_PORT, is the way in.
1030
1074
  # Postgres, the API server and SeaweedFS bind 127.0.0.1 only. To reach them from other machines,
1031
1075
  # set SUPATYPE_PUBLISH_ADDRESS=0.0.0.0 (put a firewall in front of the server first).
1032
- # 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.
1033
1077
  # SUPATYPE_PUBLISH_ADDRESS=127.0.0.1
1034
1078
  # SUPATYPE_DB_PORT=5432
1035
1079
  # SUPATYPE_SERVER_PORT=9999
1036
1080
  # SUPATYPE_SEAWEEDFS_PORT=8333`;
1081
+ /**
1082
+ * The scaffolded `.env`'s email settings, under the names the auth server reads. They used to be
1083
+ * written unprefixed (RESEND_API_KEY, SES_FROM, SMTP_HOST), which nothing reads, so a developer who
1084
+ * filled them in still got no email.
1085
+ */
1037
1086
  function emailEnvSection(email, projectName) {
1038
1087
  switch (email) {
1039
1088
  case "resend":
1040
1089
  return `# Email (Resend)
1041
- RESEND_API_KEY=
1042
- RESEND_FROM=onboarding@resend.dev`;
1090
+ SUPATYPE_RESEND_API_KEY=
1091
+ SUPATYPE_RESEND_FROM=onboarding@resend.dev`;
1043
1092
  case "ses":
1044
1093
  return `# Email (Amazon SES)
1045
- SES_FROM=
1094
+ SUPATYPE_SES_FROM=
1046
1095
  AWS_REGION=us-east-1
1047
1096
  AWS_ACCESS_KEY_ID=
1048
1097
  AWS_SECRET_ACCESS_KEY=`;
1049
1098
  case "smtp":
1050
1099
  return `# Email (SMTP)
1051
- SMTP_HOST=
1052
- SMTP_PORT=587
1053
- SMTP_USER=
1054
- SMTP_PASS=
1055
- SMTP_SENDER_NAME=${projectName}`;
1100
+ SUPATYPE_SMTP_HOST=
1101
+ SUPATYPE_SMTP_PORT=587
1102
+ SUPATYPE_SMTP_USER=
1103
+ SUPATYPE_SMTP_PASS=
1104
+ SUPATYPE_SMTP_SENDER_NAME=${projectName}`;
1056
1105
  case "console":
1057
1106
  default:
1058
1107
  return `# SMTP: unused while email.provider is console, which logs each email instead of sending it.
1059
1108
  # Email confirmation is auth.email.enableConfirmations in supatype.config.ts.
1060
- SMTP_HOST=
1061
- SMTP_PORT=
1062
- SMTP_USER=
1063
- SMTP_PASS=
1064
- SMTP_SENDER_NAME=${projectName}`;
1109
+ # SUPATYPE_SMTP_HOST=
1110
+ # SUPATYPE_SMTP_PORT=587
1111
+ # SUPATYPE_SMTP_USER=
1112
+ # SUPATYPE_SMTP_PASS=
1113
+ # SUPATYPE_SMTP_SENDER_NAME=${projectName}`;
1065
1114
  }
1066
1115
  }
1067
1116
  function storageEnvSections(storageLocal, storageProduction) {
@@ -1163,38 +1212,91 @@ src/types/supatype.d.ts
1163
1212
  src/lib/supatype.ts
1164
1213
  `;
1165
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
+ */
1166
1220
  export function mergeGitignoreTemplate(existingContent) {
1167
- 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)
1168
1227
  return existingContent;
1169
- }
1170
- const block = `
1171
- # Supatype: local runtime (contains secrets in link.json)
1172
- .supatype/
1173
- `;
1228
+ const block = `\n# Supatype: local runtime (secrets in .supatype/link.json) and development-only env files\n${missing.join("\n")}\n`;
1174
1229
  return existingContent.endsWith("\n") ? `${existingContent}${block}` : `${existingContent}\n${block}`;
1175
1230
  }
1176
1231
  // ─── Next steps ────────────────────────────────────────────────────────────--
1177
- function warnDockerUnavailableForProvider(provider) {
1232
+ /** Say so when a Docker project's Docker is not running: from `started` when init already asked. */
1233
+ async function warnDockerUnavailableForProvider(provider, started) {
1178
1234
  if (provider !== "docker")
1179
1235
  return;
1180
- const probe = probeDockerDaemon();
1236
+ const probe = await (started ?? probeDockerDaemonAsync());
1181
1237
  if (probe.ok)
1182
1238
  return;
1183
1239
  reportDockerUnavailable(probe);
1184
1240
  plain();
1185
1241
  }
1242
+ /**
1243
+ * Start everything `init -y` asks of Docker and the npm registry, side by side and each with a short
1244
+ * limit (docker-exec.ts). They ran one after another with none: 16 to 27 seconds on a developer
1245
+ * machine, past 58 on a loaded one. A native project asks Docker nothing.
1246
+ */
1247
+ function startInitQuestions(provider) {
1248
+ const deps = resolveDependencyVersions();
1249
+ if (provider !== "docker")
1250
+ return { deps };
1251
+ const kongPort = import("../dev-ports.js").then(({ chooseInitKongPort }) => chooseInitKongPort());
1252
+ return { kongPort, daemon: probeDockerDaemonAsync(), deps };
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
+ }
1186
1264
  /** True when nothing is left to set up, only to run. */
1187
1265
  function initSetupComplete(args) {
1188
1266
  return args.installed && args.keysGenerated && args.binariesReady;
1189
1267
  }
1190
1268
  function printNextSteps(args) {
1191
- const { name, result } = args;
1269
+ const { name } = args;
1192
1270
  info(`Supatype project ready${name ? ` in ${name}/` : ""}.`);
1193
- nextSteps(initSetupComplete(args) ? "Next steps:" : "Finish setup:", initFirstSteps(args));
1194
- printProductionSteps(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();
1281
+ }
1282
+ /**
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.
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];
1195
1294
  }
1196
- /** The commands to run next, in order, after `init`. */
1295
+ /** Setting up, then running the project locally, for every production target. */
1197
1296
  export function initFirstSteps(args) {
1297
+ return [...initSetupSteps(args), ...initDevSteps(args)];
1298
+ }
1299
+ function initSetupSteps(args) {
1198
1300
  const { name, result, installed, keysGenerated, binariesReady } = args;
1199
1301
  const steps = [];
1200
1302
  if (name)
@@ -1203,72 +1305,93 @@ export function initFirstSteps(args) {
1203
1305
  if (!installed)
1204
1306
  steps.push(`${result.packageManager} install`);
1205
1307
  if (!binariesReady)
1206
- steps.push("supatype update # download component binaries");
1308
+ steps.push("supatype update # download component binaries");
1207
1309
  if (!keysGenerated)
1208
1310
  steps.push("supatype keys");
1209
1311
  }
1210
- // dev is the last step: it applies the schema and generates the types, then watches both. `push`
1211
- // is for another database (`push --env <name>`), and listing it here sent people to it anyway.
1212
- const stack = result.provider === "docker"
1213
- ? `Docker Compose stack, API on http://localhost:${result.kongPort ?? 18473}`
1214
- : "native binaries, API on http://localhost:54321";
1215
- steps.push("supatype dev # applies the schema, generates types, and watches both");
1216
- steps.push(` # ${stack}`);
1217
- if (result.adminEmail) {
1218
- steps.push(" # first admin user is created on dev");
1219
- }
1312
+ return steps;
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
+ }
1323
+ /**
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.
1327
+ */
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)}`);
1220
1338
  if (result.helloFunction) {
1221
- steps.push("supatype functions serve # run edge functions locally");
1339
+ steps.push(...commented(runScriptCommand(result.packageManager, "functions"), ["run edge functions locally"]));
1222
1340
  }
1223
1341
  return steps;
1224
1342
  }
1225
- /** The secrets, frontend and production blocks printed after the first steps. */
1226
- export function printProductionSteps(result) {
1227
- // Shown once, at creation. These are generated per project rather than shipped as
1228
- // constants, so this is the moment to say they exist and where they live, nothing prints
1229
- // them again, and the JWT secret is only echoed as a fingerprint from here on.
1230
- nextSteps("Secrets: generated for this project, kept in .env:", [
1231
- "POSTGRES_PASSWORD direct SQL access as the superuser",
1232
- "AUTHENTICATOR_PASSWORD PostgREST's own login; rotating the one above does not affect it",
1233
- "SUPATYPE_SQL_EDITOR_PASSWORD Studio's SQL editor login, a role that is not a superuser",
1234
- "JWT_SECRET signs ANON_KEY and SERVICE_ROLE_KEY; changing it invalidates every token",
1235
- "Keep .env out of version control, and use different values in production.",
1236
- ]);
1237
- // No frontend block: someone who chose "No app" was told how to serve a static one. `supatype app
1238
- // 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) {
1239
1362
  if (result.productionTarget === "cloud") {
1240
- nextSteps("Deploy to Supatype Cloud:", [
1241
- "supatype login",
1242
- "supatype link --env production --project <ref>",
1243
- "supatype push --env production",
1244
- ]);
1245
- 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
+ };
1246
1367
  }
1247
- else if (result.productionTarget === "self-host") {
1248
- nextSteps("Self-host production (your own server):", selfHostProductionSteps(result));
1249
- 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) };
1250
1370
  }
1251
- plain();
1371
+ return undefined;
1252
1372
  }
1253
- /** Taking a self-host project to its own server, with or without a domain for HTTPS. */
1254
- function selfHostProductionSteps(result) {
1255
- 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) {
1256
1378
  const domain = result.domain?.trim();
1257
- if (domain) {
1258
- steps.push(`1. Point DNS: an A record for ${domain} -> your server's public IP`);
1259
- steps.push("2. Open ports 80 and 443 on the server firewall");
1260
- if (!result.tlsEmail) {
1261
- steps.push("3. Set server.tls.email in supatype.config.ts (required for HTTPS)");
1262
- }
1263
- steps.push("supatype self-host compose up -d # Kong provisions HTTPS automatically");
1264
- steps.push(`Your Supatype platform goes live at https://${domain}`);
1265
- steps.push("Your app, REST, Auth, Storage, Realtime, Functions, and Studio, all behind one HTTPS domain (certificates outlive restarts)");
1266
- }
1267
- else {
1268
- steps.push("Set server.domain + server.tls.email in supatype.config.ts to enable automatic HTTPS");
1269
- 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
+ ];
1270
1386
  }
1271
- steps.push("supatype link --env production ... # then: supatype push --env production");
1272
- 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
+ ];
1273
1396
  }
1274
1397
  //# sourceMappingURL=init.js.map