@supatype/cli 0.1.0-alpha.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (407) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/.turbo/turbo-test.log +285 -69
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/assets/supatype-logo-wordmark.ascii.txt +6 -0
  5. package/bin/dev-entry.ts +2 -1
  6. package/dist/app/framework.js +1 -3
  7. package/dist/app/framework.js.map +1 -1
  8. package/dist/app/proxy-dev-app.d.ts +14 -0
  9. package/dist/app/proxy-dev-app.d.ts.map +1 -1
  10. package/dist/app/proxy-dev-app.js +110 -6
  11. package/dist/app/proxy-dev-app.js.map +1 -1
  12. package/dist/app-config.d.ts +10 -0
  13. package/dist/app-config.d.ts.map +1 -1
  14. package/dist/app-config.js +72 -0
  15. package/dist/app-config.js.map +1 -1
  16. package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
  17. package/dist/binary-cache.d.ts +19 -7
  18. package/dist/binary-cache.d.ts.map +1 -1
  19. package/dist/binary-cache.js +92 -46
  20. package/dist/binary-cache.js.map +1 -1
  21. package/dist/cli.d.ts +1 -1
  22. package/dist/cli.d.ts.map +1 -1
  23. package/dist/cli.js +17 -2
  24. package/dist/cli.js.map +1 -1
  25. package/dist/commands/add.d.ts +3 -0
  26. package/dist/commands/add.d.ts.map +1 -0
  27. package/dist/commands/add.js +86 -0
  28. package/dist/commands/add.js.map +1 -0
  29. package/dist/commands/admin.d.ts +28 -1
  30. package/dist/commands/admin.d.ts.map +1 -1
  31. package/dist/commands/admin.js +297 -149
  32. package/dist/commands/admin.js.map +1 -1
  33. package/dist/commands/adopt.d.ts +3 -0
  34. package/dist/commands/adopt.d.ts.map +1 -0
  35. package/dist/commands/adopt.js +55 -0
  36. package/dist/commands/adopt.js.map +1 -0
  37. package/dist/commands/app.d.ts.map +1 -1
  38. package/dist/commands/app.js +20 -17
  39. package/dist/commands/app.js.map +1 -1
  40. package/dist/commands/cache.d.ts.map +1 -1
  41. package/dist/commands/cache.js +11 -10
  42. package/dist/commands/cache.js.map +1 -1
  43. package/dist/commands/cloud.d.ts +4 -9
  44. package/dist/commands/cloud.d.ts.map +1 -1
  45. package/dist/commands/cloud.js +75 -125
  46. package/dist/commands/cloud.js.map +1 -1
  47. package/dist/commands/db.d.ts.map +1 -1
  48. package/dist/commands/db.js +37 -58
  49. package/dist/commands/db.js.map +1 -1
  50. package/dist/commands/deploy.d.ts.map +1 -1
  51. package/dist/commands/deploy.js +140 -96
  52. package/dist/commands/deploy.js.map +1 -1
  53. package/dist/commands/dev.d.ts.map +1 -1
  54. package/dist/commands/dev.js +74 -39
  55. package/dist/commands/dev.js.map +1 -1
  56. package/dist/commands/diff.d.ts.map +1 -1
  57. package/dist/commands/diff.js +39 -39
  58. package/dist/commands/diff.js.map +1 -1
  59. package/dist/commands/doctor.d.ts +3 -0
  60. package/dist/commands/doctor.d.ts.map +1 -0
  61. package/dist/commands/doctor.js +78 -0
  62. package/dist/commands/doctor.js.map +1 -0
  63. package/dist/commands/engine.d.ts.map +1 -1
  64. package/dist/commands/engine.js +5 -4
  65. package/dist/commands/engine.js.map +1 -1
  66. package/dist/commands/functions.d.ts.map +1 -1
  67. package/dist/commands/functions.js +172 -119
  68. package/dist/commands/functions.js.map +1 -1
  69. package/dist/commands/generate.d.ts.map +1 -1
  70. package/dist/commands/generate.js +5 -4
  71. package/dist/commands/generate.js.map +1 -1
  72. package/dist/commands/init.d.ts +35 -1
  73. package/dist/commands/init.d.ts.map +1 -1
  74. package/dist/commands/init.js +883 -107
  75. package/dist/commands/init.js.map +1 -1
  76. package/dist/commands/introspect.d.ts +3 -0
  77. package/dist/commands/introspect.d.ts.map +1 -0
  78. package/dist/commands/introspect.js +35 -0
  79. package/dist/commands/introspect.js.map +1 -0
  80. package/dist/commands/keys.d.ts +15 -1
  81. package/dist/commands/keys.d.ts.map +1 -1
  82. package/dist/commands/keys.js +46 -10
  83. package/dist/commands/keys.js.map +1 -1
  84. package/dist/commands/link-helpers.d.ts +15 -0
  85. package/dist/commands/link-helpers.d.ts.map +1 -0
  86. package/dist/commands/link-helpers.js +225 -0
  87. package/dist/commands/link-helpers.js.map +1 -0
  88. package/dist/commands/logs.d.ts.map +1 -1
  89. package/dist/commands/logs.js +5 -4
  90. package/dist/commands/logs.js.map +1 -1
  91. package/dist/commands/migrate-from-v1.d.ts.map +1 -1
  92. package/dist/commands/migrate-from-v1.js +3 -2
  93. package/dist/commands/migrate-from-v1.js.map +1 -1
  94. package/dist/commands/migrate.d.ts.map +1 -1
  95. package/dist/commands/migrate.js +119 -26
  96. package/dist/commands/migrate.js.map +1 -1
  97. package/dist/commands/pg.d.ts.map +1 -1
  98. package/dist/commands/pg.js +11 -12
  99. package/dist/commands/pg.js.map +1 -1
  100. package/dist/commands/plugins.d.ts.map +1 -1
  101. package/dist/commands/plugins.js +55 -46
  102. package/dist/commands/plugins.js.map +1 -1
  103. package/dist/commands/pull.d.ts.map +1 -1
  104. package/dist/commands/pull.js +33 -5
  105. package/dist/commands/pull.js.map +1 -1
  106. package/dist/commands/push.d.ts.map +1 -1
  107. package/dist/commands/push.js +111 -138
  108. package/dist/commands/push.js.map +1 -1
  109. package/dist/commands/seed.d.ts.map +1 -1
  110. package/dist/commands/seed.js +4 -3
  111. package/dist/commands/seed.js.map +1 -1
  112. package/dist/commands/self-host.d.ts +2 -2
  113. package/dist/commands/self-host.d.ts.map +1 -1
  114. package/dist/commands/self-host.js +65 -50
  115. package/dist/commands/self-host.js.map +1 -1
  116. package/dist/commands/self-update.d.ts.map +1 -1
  117. package/dist/commands/self-update.js +3 -2
  118. package/dist/commands/self-update.js.map +1 -1
  119. package/dist/commands/status.d.ts +1 -1
  120. package/dist/commands/status.d.ts.map +1 -1
  121. package/dist/commands/status.js +95 -29
  122. package/dist/commands/status.js.map +1 -1
  123. package/dist/commands/types.d.ts.map +1 -1
  124. package/dist/commands/types.js +3 -2
  125. package/dist/commands/types.js.map +1 -1
  126. package/dist/commands/update.d.ts.map +1 -1
  127. package/dist/commands/update.js +54 -21
  128. package/dist/commands/update.js.map +1 -1
  129. package/dist/compose-rename.d.ts +10 -0
  130. package/dist/compose-rename.d.ts.map +1 -0
  131. package/dist/compose-rename.js +67 -0
  132. package/dist/compose-rename.js.map +1 -0
  133. package/dist/config.d.ts +2 -1
  134. package/dist/config.d.ts.map +1 -1
  135. package/dist/config.js.map +1 -1
  136. package/dist/dev-compose.d.ts +26 -0
  137. package/dist/dev-compose.d.ts.map +1 -1
  138. package/dist/dev-compose.js +357 -79
  139. package/dist/dev-compose.js.map +1 -1
  140. package/dist/dev-log-bus.d.ts +30 -0
  141. package/dist/dev-log-bus.d.ts.map +1 -0
  142. package/dist/dev-log-bus.js +87 -0
  143. package/dist/dev-log-bus.js.map +1 -0
  144. package/dist/dev-log-filter.d.ts +10 -0
  145. package/dist/dev-log-filter.d.ts.map +1 -0
  146. package/dist/dev-log-filter.js +36 -0
  147. package/dist/dev-log-filter.js.map +1 -0
  148. package/dist/dev-logo.d.ts +12 -0
  149. package/dist/dev-logo.d.ts.map +1 -0
  150. package/dist/dev-logo.js +56 -0
  151. package/dist/dev-logo.js.map +1 -0
  152. package/dist/dev-ports.d.ts +27 -0
  153. package/dist/dev-ports.d.ts.map +1 -0
  154. package/dist/dev-ports.js +171 -0
  155. package/dist/dev-ports.js.map +1 -0
  156. package/dist/dev-session-lock.d.ts +25 -0
  157. package/dist/dev-session-lock.d.ts.map +1 -0
  158. package/dist/dev-session-lock.js +81 -0
  159. package/dist/dev-session-lock.js.map +1 -0
  160. package/dist/dev-session.d.ts +26 -0
  161. package/dist/dev-session.d.ts.map +1 -0
  162. package/dist/dev-session.js +106 -0
  163. package/dist/dev-session.js.map +1 -0
  164. package/dist/dev-shutdown.d.ts +25 -0
  165. package/dist/dev-shutdown.d.ts.map +1 -0
  166. package/dist/dev-shutdown.js +114 -0
  167. package/dist/dev-shutdown.js.map +1 -0
  168. package/dist/dev-task-colors.d.ts +13 -0
  169. package/dist/dev-task-colors.d.ts.map +1 -0
  170. package/dist/dev-task-colors.js +43 -0
  171. package/dist/dev-task-colors.js.map +1 -0
  172. package/dist/dev-tui.d.ts +24 -0
  173. package/dist/dev-tui.d.ts.map +1 -0
  174. package/dist/dev-tui.js +188 -0
  175. package/dist/dev-tui.js.map +1 -0
  176. package/dist/diff-output.d.ts +5 -1
  177. package/dist/diff-output.d.ts.map +1 -1
  178. package/dist/diff-output.js +69 -0
  179. package/dist/diff-output.js.map +1 -1
  180. package/dist/docker-runtime.d.ts +30 -0
  181. package/dist/docker-runtime.d.ts.map +1 -0
  182. package/dist/docker-runtime.js +118 -0
  183. package/dist/docker-runtime.js.map +1 -0
  184. package/dist/engine-client.d.ts +10 -1
  185. package/dist/engine-client.d.ts.map +1 -1
  186. package/dist/engine-client.js +76 -17
  187. package/dist/engine-client.js.map +1 -1
  188. package/dist/engine-push-output.d.ts +17 -0
  189. package/dist/engine-push-output.d.ts.map +1 -0
  190. package/dist/engine-push-output.js +64 -0
  191. package/dist/engine-push-output.js.map +1 -0
  192. package/dist/ensure-binary.js +2 -2
  193. package/dist/ensure-binary.js.map +1 -1
  194. package/dist/env-file.d.ts +5 -0
  195. package/dist/env-file.d.ts.map +1 -0
  196. package/dist/env-file.js +33 -0
  197. package/dist/env-file.js.map +1 -0
  198. package/dist/gitignore.d.ts +8 -0
  199. package/dist/gitignore.d.ts.map +1 -0
  200. package/dist/gitignore.js +41 -0
  201. package/dist/gitignore.js.map +1 -0
  202. package/dist/kong-config.d.ts +9 -0
  203. package/dist/kong-config.d.ts.map +1 -1
  204. package/dist/kong-config.js +18 -1
  205. package/dist/kong-config.js.map +1 -1
  206. package/dist/link.d.ts +66 -0
  207. package/dist/link.d.ts.map +1 -0
  208. package/dist/link.js +160 -0
  209. package/dist/link.js.map +1 -0
  210. package/dist/process-manager.d.ts +8 -0
  211. package/dist/process-manager.d.ts.map +1 -1
  212. package/dist/process-manager.js +53 -9
  213. package/dist/process-manager.js.map +1 -1
  214. package/dist/project-config.d.ts +30 -3
  215. package/dist/project-config.d.ts.map +1 -1
  216. package/dist/project-config.js +37 -4
  217. package/dist/project-config.js.map +1 -1
  218. package/dist/prompts.d.ts +3 -0
  219. package/dist/prompts.d.ts.map +1 -0
  220. package/dist/prompts.js +3 -0
  221. package/dist/prompts.js.map +1 -0
  222. package/dist/pull-utils.d.ts +50 -14
  223. package/dist/pull-utils.d.ts.map +1 -1
  224. package/dist/pull-utils.js +152 -12
  225. package/dist/pull-utils.js.map +1 -1
  226. package/dist/resolve-target.d.ts +86 -0
  227. package/dist/resolve-target.d.ts.map +1 -0
  228. package/dist/resolve-target.js +291 -0
  229. package/dist/resolve-target.js.map +1 -0
  230. package/dist/restore-system-relation-targets.d.ts +3 -0
  231. package/dist/restore-system-relation-targets.d.ts.map +1 -0
  232. package/dist/restore-system-relation-targets.js +45 -0
  233. package/dist/restore-system-relation-targets.js.map +1 -0
  234. package/dist/runtime-routes.d.ts.map +1 -1
  235. package/dist/runtime-routes.js +7 -0
  236. package/dist/runtime-routes.js.map +1 -1
  237. package/dist/schema-ast-v2.d.ts +1 -1
  238. package/dist/schema-ast-v2.d.ts.map +1 -1
  239. package/dist/schema-ast-v2.js +2 -2
  240. package/dist/schema-ast-v2.js.map +1 -1
  241. package/dist/schema-sources.d.ts +40 -0
  242. package/dist/schema-sources.d.ts.map +1 -0
  243. package/dist/schema-sources.js +183 -0
  244. package/dist/schema-sources.js.map +1 -0
  245. package/dist/scripts/postinstall.js +5 -1
  246. package/dist/scripts/postinstall.js.map +1 -1
  247. package/dist/self-host-compose.d.ts +37 -1
  248. package/dist/self-host-compose.d.ts.map +1 -1
  249. package/dist/self-host-compose.js +234 -43
  250. package/dist/self-host-compose.js.map +1 -1
  251. package/dist/storage-provision.d.ts +4 -0
  252. package/dist/storage-provision.d.ts.map +1 -1
  253. package/dist/storage-provision.js +24 -2
  254. package/dist/storage-provision.js.map +1 -1
  255. package/dist/supatype-eval-1781522769253.d.mts +2 -0
  256. package/dist/supatype-eval-1781522769253.d.mts.map +1 -0
  257. package/dist/supatype-eval-1781522769253.mjs +3 -0
  258. package/dist/supatype-eval-1781522769253.mjs.map +1 -0
  259. package/dist/systemd.js +2 -2
  260. package/dist/systemd.js.map +1 -1
  261. package/dist/target-client.d.ts +10 -0
  262. package/dist/target-client.d.ts.map +1 -0
  263. package/dist/target-client.js +22 -0
  264. package/dist/target-client.js.map +1 -0
  265. package/dist/type-extractor.d.ts +11 -0
  266. package/dist/type-extractor.d.ts.map +1 -1
  267. package/dist/type-extractor.js +95 -8
  268. package/dist/type-extractor.js.map +1 -1
  269. package/dist/ui/brand.d.ts +9 -0
  270. package/dist/ui/brand.d.ts.map +1 -0
  271. package/dist/ui/brand.js +11 -0
  272. package/dist/ui/brand.js.map +1 -0
  273. package/dist/ui/confirm.d.ts +12 -0
  274. package/dist/ui/confirm.d.ts.map +1 -0
  275. package/dist/ui/confirm.js +28 -0
  276. package/dist/ui/confirm.js.map +1 -0
  277. package/dist/ui/fatal.d.ts +10 -0
  278. package/dist/ui/fatal.d.ts.map +1 -0
  279. package/dist/ui/fatal.js +34 -0
  280. package/dist/ui/fatal.js.map +1 -0
  281. package/dist/ui/index.d.ts +9 -0
  282. package/dist/ui/index.d.ts.map +1 -0
  283. package/dist/ui/index.js +9 -0
  284. package/dist/ui/index.js.map +1 -0
  285. package/dist/ui/interactive.d.ts +3 -0
  286. package/dist/ui/interactive.d.ts.map +1 -0
  287. package/dist/ui/interactive.js +5 -0
  288. package/dist/ui/interactive.js.map +1 -0
  289. package/dist/ui/messages.d.ts +10 -0
  290. package/dist/ui/messages.d.ts.map +1 -0
  291. package/dist/ui/messages.js +35 -0
  292. package/dist/ui/messages.js.map +1 -0
  293. package/dist/ui/next-steps.d.ts +3 -0
  294. package/dist/ui/next-steps.d.ts.map +1 -0
  295. package/dist/ui/next-steps.js +10 -0
  296. package/dist/ui/next-steps.js.map +1 -0
  297. package/dist/ui/progress.d.ts +5 -0
  298. package/dist/ui/progress.d.ts.map +1 -0
  299. package/dist/ui/progress.js +24 -0
  300. package/dist/ui/progress.js.map +1 -0
  301. package/dist/ui/prompts.d.ts +14 -0
  302. package/dist/ui/prompts.d.ts.map +1 -0
  303. package/dist/ui/prompts.js +34 -0
  304. package/dist/ui/prompts.js.map +1 -0
  305. package/package.json +5 -2
  306. package/src/app/framework.ts +1 -3
  307. package/src/app/proxy-dev-app.ts +114 -6
  308. package/src/app-config.ts +80 -0
  309. package/src/binary-cache.ts +102 -52
  310. package/src/cli.ts +16 -2
  311. package/src/commands/add.ts +97 -0
  312. package/src/commands/admin.ts +381 -190
  313. package/src/commands/adopt.ts +82 -0
  314. package/src/commands/app.ts +20 -17
  315. package/src/commands/cache.ts +11 -10
  316. package/src/commands/cloud.ts +91 -142
  317. package/src/commands/db.ts +40 -63
  318. package/src/commands/deploy.ts +186 -126
  319. package/src/commands/dev.ts +98 -55
  320. package/src/commands/diff.ts +52 -43
  321. package/src/commands/doctor.ts +103 -0
  322. package/src/commands/engine.ts +5 -4
  323. package/src/commands/functions.ts +187 -123
  324. package/src/commands/generate.ts +5 -4
  325. package/src/commands/init.ts +1087 -104
  326. package/src/commands/introspect.ts +48 -0
  327. package/src/commands/keys.ts +56 -14
  328. package/src/commands/link-helpers.ts +273 -0
  329. package/src/commands/logs.ts +5 -4
  330. package/src/commands/migrate-from-v1.ts +3 -2
  331. package/src/commands/migrate.ts +167 -27
  332. package/src/commands/pg.ts +13 -18
  333. package/src/commands/plugins.ts +55 -46
  334. package/src/commands/pull.ts +38 -9
  335. package/src/commands/push.ts +148 -175
  336. package/src/commands/seed.ts +5 -4
  337. package/src/commands/self-host.ts +85 -54
  338. package/src/commands/self-update.ts +3 -2
  339. package/src/commands/status.ts +102 -33
  340. package/src/commands/types.ts +3 -2
  341. package/src/commands/update.ts +59 -23
  342. package/src/compose-rename.ts +76 -0
  343. package/src/config.ts +2 -1
  344. package/src/dev-compose.ts +462 -76
  345. package/src/dev-log-bus.ts +101 -0
  346. package/src/dev-log-filter.ts +32 -0
  347. package/src/dev-logo.ts +61 -0
  348. package/src/dev-ports.ts +212 -0
  349. package/src/dev-session-lock.ts +101 -0
  350. package/src/dev-session.ts +130 -0
  351. package/src/dev-shutdown.ts +147 -0
  352. package/src/dev-task-colors.ts +47 -0
  353. package/src/dev-tui.ts +232 -0
  354. package/src/diff-output.ts +79 -1
  355. package/src/docker-runtime.ts +151 -0
  356. package/src/engine-client.ts +81 -17
  357. package/src/engine-push-output.ts +75 -0
  358. package/src/ensure-binary.ts +2 -2
  359. package/src/env-file.ts +37 -0
  360. package/src/gitignore.ts +48 -0
  361. package/src/kong-config.ts +24 -1
  362. package/src/link.ts +243 -0
  363. package/src/process-manager.ts +66 -10
  364. package/src/project-config.ts +62 -7
  365. package/src/prompts.ts +2 -0
  366. package/src/pull-utils.ts +217 -23
  367. package/src/resolve-target.ts +419 -0
  368. package/src/restore-system-relation-targets.ts +45 -0
  369. package/src/runtime-routes.ts +7 -0
  370. package/src/schema-ast-v2.ts +2 -1
  371. package/src/schema-sources.ts +248 -0
  372. package/src/scripts/postinstall.ts +7 -1
  373. package/src/self-host-compose.ts +262 -46
  374. package/src/storage-provision.ts +33 -1
  375. package/src/supatype-eval-1781522769253.mts +1 -0
  376. package/src/systemd.ts +2 -2
  377. package/src/target-client.ts +40 -0
  378. package/src/type-extractor.ts +124 -11
  379. package/src/ui/README.md +17 -0
  380. package/src/ui/brand.ts +12 -0
  381. package/src/ui/confirm.ts +38 -0
  382. package/src/ui/fatal.ts +43 -0
  383. package/src/ui/index.ts +8 -0
  384. package/src/ui/interactive.ts +4 -0
  385. package/src/ui/messages.ts +43 -0
  386. package/src/ui/next-steps.ts +10 -0
  387. package/src/ui/progress.ts +28 -0
  388. package/src/ui/prompts.ts +40 -0
  389. package/tests/admin-ensure.test.ts +59 -0
  390. package/tests/cli-help.test.ts +27 -2
  391. package/tests/config.test.ts +29 -2
  392. package/tests/dev-ports.test.ts +41 -0
  393. package/tests/dev-session-lock.test.ts +54 -0
  394. package/tests/dev-ui.test.ts +162 -0
  395. package/tests/docker-runtime.test.ts +236 -0
  396. package/tests/engine-push-output.test.ts +67 -0
  397. package/tests/init.test.ts +197 -18
  398. package/tests/link.test.ts +148 -0
  399. package/tests/minisign.test.ts +102 -0
  400. package/tests/proxy-dev-app.test.ts +45 -1
  401. package/tests/pull-utils.test.ts +5 -4
  402. package/tests/runtime-contract.test.ts +186 -2
  403. package/tests/schema-sources.test.ts +119 -0
  404. package/tests/storage-provision.test.ts +100 -0
  405. package/tests/ui-confirm.test.ts +41 -0
  406. package/tests/ui-messages.test.ts +66 -0
  407. package/tsconfig.tsbuildinfo +1 -1
@@ -12,15 +12,20 @@
12
12
  */
13
13
 
14
14
  import type { Command } from "commander"
15
- import { existsSync, readdirSync, statSync, createReadStream } from "node:fs"
16
- import { join } from "node:path"
15
+ import { existsSync, readdirSync, statSync, createReadStream, mkdirSync, cpSync } from "node:fs"
16
+ import { join, relative } from "node:path"
17
17
  import { loadConfig, loadSchemaAst } from "../config.js"
18
18
  import { connectionString, schemaPathFromProject } from "../project-config.js"
19
19
  import { deploySchemaToLinkedProject, loadCloudConfig, pushSchemaToLinkedProject } from "./cloud.js"
20
+ import { loadProjectLink } from "../link.js"
21
+ import { resolveTarget } from "../resolve-target.js"
22
+ import { targetFetch } from "../target-client.js"
20
23
  import { ensureEngine, engineRequest, type DiffResult } from "../engine-client.js"
21
24
  import { resolveAppConfig, validateStaticMode, validateBuildOutput, detectPackageManager } from "../app/framework.js"
22
25
  import { TIER_LIMITS, type Tier } from "./deploy-types.js"
23
26
  import { spawnSync } from "node:child_process"
27
+ import { error, info, plain, step, warn } from "../ui/messages.js"
28
+ import { withSpinner } from "../ui/progress.js"
24
29
 
25
30
  export function registerDeploy(program: Command): void {
26
31
  const deploy = program
@@ -29,7 +34,8 @@ export function registerDeploy(program: Command): void {
29
34
  "Deploy schema and app — Supatype Cloud by default when linked (`supatype link`); pass --local for engine + your database",
30
35
  )
31
36
  .option("--local", "Use local schema engine and database_url from config (skip cloud control plane)")
32
- .option("--environment <name>", "Cloud environment when using linked project", "production")
37
+ .option("--environment <name>", "Target environment when linked", "production")
38
+ .option("--env <name>", "Alias for --environment")
33
39
  .option("--app-only", "Skip schema push, only deploy the static site")
34
40
  .option("--schema-only", "Skip app build, only push schema changes")
35
41
  .option("--skip-build", "Deploy existing build output without building")
@@ -38,6 +44,7 @@ export function registerDeploy(program: Command): void {
38
44
  .action(async (opts: {
39
45
  local?: boolean
40
46
  environment?: string
47
+ env?: string
41
48
  appOnly?: boolean
42
49
  schemaOnly?: boolean
43
50
  skipBuild?: boolean
@@ -46,18 +53,19 @@ export function registerDeploy(program: Command): void {
46
53
  }) => {
47
54
  const cwd = process.cwd()
48
55
  const config = loadConfig(cwd)
56
+ const link = loadProjectLink(cwd)
49
57
  const cloudCfg = loadCloudConfig(cwd)
58
+ const envName = opts.env ?? opts.environment ?? "production"
50
59
 
51
60
  let schemaDone = false
52
61
 
53
- // Default: cloud — .supatype/cloud.json → control plane schema deploy
54
62
  if (
55
63
  !opts.local &&
56
- cloudCfg?.projectSlug &&
64
+ link &&
57
65
  !opts.appOnly &&
58
66
  !opts.skipBuild
59
67
  ) {
60
- await deploySchemaToLinkedProject(cwd, opts.environment ?? "production")
68
+ await deploySchemaToLinkedProject(cwd, envName)
61
69
  schemaDone = true
62
70
  if (opts.schemaOnly) {
63
71
  return
@@ -69,7 +77,7 @@ export function registerDeploy(program: Command): void {
69
77
  const ast = loadSchemaAst(schemaPathFromProject(config, cwd), cwd)
70
78
 
71
79
  if (opts.local) {
72
- console.log("=== Schema Push (local) ===")
80
+ step("Schema Push (local)")
73
81
  await ensureEngine()
74
82
 
75
83
  const diff = await engineRequest<DiffResult>("/diff", {
@@ -81,22 +89,22 @@ export function registerDeploy(program: Command): void {
81
89
  const ops = diff.operations ?? []
82
90
 
83
91
  if (ops.length > 0) {
84
- console.log(`${ops.length} schema change(s) to apply.`)
92
+ info(`${ops.length} schema change(s) to apply.`)
85
93
  await engineRequest("/push", {
86
94
  ast,
87
95
  database_url: connectionString(config),
88
96
  schema: "public",
89
97
  force: true,
90
98
  })
91
- console.log("Schema changes applied.")
99
+ info("Schema changes applied.")
92
100
  } else {
93
- console.log("Schema is up to date.")
101
+ info("Schema is up to date.")
94
102
  }
95
- } else if (cloudCfg?.projectSlug) {
96
- console.log("=== Schema Push (cloud) ===")
97
- await pushSchemaToLinkedProject(cwd, { force: opts.yes ?? true })
103
+ } else if (link) {
104
+ step("Schema Push (linked)")
105
+ await pushSchemaToLinkedProject(cwd, { force: opts.yes ?? true, env: envName })
98
106
  } else {
99
- console.error(
107
+ error(
100
108
  "Not linked to Supatype Cloud. Run: supatype link\n" +
101
109
  "Or deploy against your own database: supatype deploy --local",
102
110
  )
@@ -108,29 +116,29 @@ export function registerDeploy(program: Command): void {
108
116
  if (!opts.schemaOnly) {
109
117
  if (!config.build) {
110
118
  if (opts.appOnly) {
111
- console.error("No build section found in supatype.config.ts")
119
+ error("No build section found in supatype.config.ts")
112
120
  process.exit(1)
113
121
  }
114
122
  // No build config — skip app deployment silently
115
123
  return
116
124
  }
117
125
 
118
- console.log("\n=== App Build & Deploy ===")
126
+ step("App Build & Deploy")
119
127
  const appConfig = resolveAppConfig(config.build, cwd)
120
128
 
121
129
  // Validate static mode
122
130
  const staticError = validateStaticMode(appConfig.framework, appConfig.directory)
123
131
  if (staticError) {
124
- console.error(staticError)
132
+ error(staticError)
125
133
  process.exit(1)
126
134
  }
127
135
 
128
136
  // Build step
129
137
  if (!opts.skipBuild && appConfig.buildCommand) {
130
- console.log(`Framework: ${appConfig.framework}`)
131
- console.log(`Build command: ${appConfig.buildCommand}`)
132
- console.log(`Output directory: ${appConfig.outputDirectory}`)
133
- console.log()
138
+ info(`Framework: ${appConfig.framework}`)
139
+ info(`Build command: ${appConfig.buildCommand}`)
140
+ info(`Output directory: ${appConfig.outputDirectory}`)
141
+ plain()
134
142
 
135
143
  // Inject environment variables
136
144
  const buildEnv: Record<string, string> = {
@@ -148,7 +156,7 @@ export function registerDeploy(program: Command): void {
148
156
 
149
157
  // Install dependencies
150
158
  const pm = detectPackageManager(appConfig.directory)
151
- console.log(`Installing dependencies (${pm})...`)
159
+ info(`Installing dependencies (${pm})...`)
152
160
  const installResult = spawnSync(pm, ["install"], {
153
161
  cwd: appConfig.directory,
154
162
  stdio: "inherit",
@@ -156,12 +164,12 @@ export function registerDeploy(program: Command): void {
156
164
  timeout: 5 * 60 * 1000, // 5 minute timeout
157
165
  })
158
166
  if (installResult.status !== 0) {
159
- console.error("Dependency installation failed.")
167
+ error("Dependency installation failed.")
160
168
  process.exit(1)
161
169
  }
162
170
 
163
171
  // Run build
164
- console.log("\nBuilding...")
172
+ plain("\nBuilding...")
165
173
  const [buildCmd, ...buildArgs] = appConfig.buildCommand.split(" ")
166
174
  const buildResult = spawnSync(buildCmd!, buildArgs, {
167
175
  cwd: appConfig.directory,
@@ -170,7 +178,7 @@ export function registerDeploy(program: Command): void {
170
178
  timeout: 10 * 60 * 1000, // 10 minute timeout
171
179
  })
172
180
  if (buildResult.status !== 0) {
173
- console.error("Build failed.")
181
+ error("Build failed.")
174
182
  process.exit(1)
175
183
  }
176
184
  }
@@ -179,27 +187,27 @@ export function registerDeploy(program: Command): void {
179
187
  const maxSizeMb = 500 // Default, should be tier-aware in cloud
180
188
  const validationError = validateBuildOutput(appConfig.outputDirectory, maxSizeMb)
181
189
  if (validationError) {
182
- console.error(validationError)
190
+ error(validationError)
183
191
  process.exit(1)
184
192
  }
185
193
 
186
194
  // Deploy (--local never uploads to cloud, even if linked)
187
- if (cloudCfg?.projectSlug && !opts.local) {
188
- await deployToCloud(
189
- { projectRef: cloudCfg.projectSlug, apiUrl: cloudCfg.apiUrl, accessToken: cloudCfg.token },
190
- appConfig.outputDirectory,
191
- opts.preview ?? false,
192
- )
195
+ if (link && !opts.local) {
196
+ await deployStaticSite(cwd, appConfig.outputDirectory, {
197
+ preview: opts.preview ?? false,
198
+ env: envName,
199
+ })
193
200
  } else {
194
201
  deploySelfHost(appConfig.outputDirectory, cwd)
195
202
  }
196
203
 
197
- console.log("\nDeployment complete!")
198
- if (cloudCfg?.projectSlug && !opts.local) {
204
+ info("Deployment complete!")
205
+ if (link && !opts.local) {
206
+ const target = resolveTarget(cwd, { env: envName })
199
207
  const url = opts.preview
200
- ? `https://preview-${Date.now().toString(36)}.${cloudCfg.projectSlug}.supatype.dev`
201
- : `https://${cloudCfg.projectSlug}.supatype.dev`
202
- console.log(`URL: ${url}`)
208
+ ? `${target.apiBaseUrl}/preview`
209
+ : target.apiBaseUrl
210
+ info(`URL: ${url}`)
203
211
  }
204
212
  }
205
213
  })
@@ -208,123 +216,174 @@ export function registerDeploy(program: Command): void {
208
216
  deploy
209
217
  .command("rollback")
210
218
  .description("Roll back to the previous static site deployment")
211
- .action(async () => {
212
- const cloudCfg = loadCloudConfig(process.cwd())
213
- if (!cloudCfg?.projectSlug) {
214
- console.error("Not linked to a cloud project. Rollback is only available for cloud deployments.")
215
- process.exit(1)
216
- }
217
-
218
- const apiUrl = cloudCfg.apiUrl || "https://api.supatype.com"
219
- const token = cloudCfg.token || process.env["SUPATYPE_ACCESS_TOKEN"] || ""
220
-
221
- const res = await fetch(`${apiUrl}/platform/v1/projects/${cloudCfg.projectSlug}/deployments/rollback`, {
222
- method: "POST",
223
- headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
224
- })
225
-
226
- if (!res.ok) {
227
- const body = await res.text()
228
- console.error(`Rollback failed: ${res.status} ${body}`)
219
+ .option("--env <name>", "Target environment when linked")
220
+ .option("--to <id>", "Roll back to a specific deployment id or version")
221
+ .action(async (opts: { env?: string; to?: string }) => {
222
+ const cwd = process.cwd()
223
+ const link = loadProjectLink(cwd)
224
+ if (!link) {
225
+ error("Not linked to a project. Rollback requires a linked target.")
229
226
  process.exit(1)
230
227
  }
231
228
 
232
- const { data } = await res.json() as { data: { version: string; message: string } }
233
- console.log(`Rolled back to deployment ${data.version}.`)
229
+ const target = resolveTarget(cwd, { env: opts.env })
230
+ const body = opts.to ? { to: opts.to } : undefined
231
+ const data = await targetFetch<{ version: string; message: string }>(
232
+ target.apiBaseUrl,
233
+ target.apiPrefix,
234
+ {
235
+ method: "POST",
236
+ path: `/projects/${target.projectRef}/deployments/rollback`,
237
+ body,
238
+ token: target.token!,
239
+ orgId: target.orgId,
240
+ environment: target.mode === "cloud" ? target.environment : undefined,
241
+ },
242
+ )
243
+
244
+ info(`Rolled back to deployment ${data.version ?? "previous"}.`)
234
245
  })
235
246
 
236
247
  // supatype deploy status
237
248
  deploy
238
249
  .command("status")
239
250
  .description("Show current deployment status")
240
- .action(async () => {
241
- const cloudCfg = loadCloudConfig(process.cwd())
242
- if (!cloudCfg?.projectSlug) {
243
- console.error("Not linked to a cloud project.")
251
+ .option("--env <name>", "Target environment when linked")
252
+ .action(async (opts: { env?: string }) => {
253
+ const cwd = process.cwd()
254
+ const link = loadProjectLink(cwd)
255
+ if (!link) {
256
+ error("Not linked to a project.")
244
257
  process.exit(1)
245
258
  }
246
259
 
247
- const apiUrl = cloudCfg.apiUrl || "https://api.supatype.com"
248
- const token = cloudCfg.token || process.env["SUPATYPE_ACCESS_TOKEN"] || ""
249
-
250
- const res = await fetch(`${apiUrl}/platform/v1/projects/${cloudCfg.projectSlug}/deployments/current`, {
251
- headers: { Authorization: `Bearer ${token}` },
252
- })
253
-
254
- if (!res.ok) {
255
- console.error("No active deployment found.")
260
+ const target = resolveTarget(cwd, { env: opts.env })
261
+ const data = await targetFetch<{
262
+ version?: string
263
+ id?: string
264
+ timestamp?: string
265
+ createdAt?: string
266
+ size?: number
267
+ buildDuration?: number
268
+ url?: string
269
+ status?: string
270
+ } | null>(
271
+ target.apiBaseUrl,
272
+ target.apiPrefix,
273
+ {
274
+ method: "GET",
275
+ path: `/projects/${target.projectRef}/deployments/current`,
276
+ token: target.token!,
277
+ orgId: target.orgId,
278
+ environment: target.mode === "cloud" ? target.environment : undefined,
279
+ },
280
+ )
281
+
282
+ if (!data) {
283
+ info("No active deployment found.")
256
284
  return
257
285
  }
258
286
 
259
- const { data } = await res.json() as { data: {
260
- version: string
261
- timestamp: string
262
- size: number
263
- buildDuration: number
264
- url: string
265
- status: string
266
- }}
267
-
268
- console.log(`Deployment: ${data.version}`)
269
- console.log(`Status: ${data.status}`)
270
- console.log(`Deployed: ${data.timestamp}`)
271
- console.log(`Size: ${(data.size / (1024 * 1024)).toFixed(1)}MB`)
272
- console.log(`Build duration: ${data.buildDuration}s`)
273
- console.log(`URL: ${data.url}`)
287
+ info(`Deployment: ${data.version ?? data.id ?? "unknown"}`)
288
+ info(`Status: ${data.status ?? "live"}`)
289
+ if (data.timestamp ?? data.createdAt) {
290
+ info(`Deployed: ${data.timestamp ?? data.createdAt}`)
291
+ }
292
+ if (data.size) info(`Size: ${(data.size / (1024 * 1024)).toFixed(1)}MB`)
293
+ if (data.buildDuration) info(`Build duration: ${data.buildDuration}s`)
294
+ if (data.url) info(`URL: ${data.url}`)
274
295
  })
275
296
 
276
297
  // supatype deploy logs <version>
277
298
  deploy
278
299
  .command("logs [version]")
279
300
  .description("Show build logs for a deployment")
280
- .action(async (version?: string) => {
281
- const cloudCfg = loadCloudConfig(process.cwd())
282
- if (!cloudCfg?.projectSlug) {
283
- console.error("Not linked to a cloud project.")
301
+ .option("--env <name>", "Target environment when linked")
302
+ .action(async (version: string | undefined, opts: { env?: string }) => {
303
+ const cwd = process.cwd()
304
+ const link = loadProjectLink(cwd)
305
+ if (!link) {
306
+ error("Not linked to a project.")
284
307
  process.exit(1)
285
308
  }
286
309
 
287
- const apiUrl = cloudCfg.apiUrl || "https://api.supatype.com"
288
- const token = cloudCfg.token || process.env["SUPATYPE_ACCESS_TOKEN"] || ""
289
-
310
+ const target = resolveTarget(cwd, { env: opts.env })
290
311
  const versionPath = version ? `/${version}` : "/current"
291
- const res = await fetch(`${apiUrl}/platform/v1/projects/${cloudCfg.projectSlug}/deployments${versionPath}/logs`, {
292
- headers: { Authorization: `Bearer ${token}` },
293
- })
294
-
295
- if (!res.ok) {
296
- console.error("Logs not found.")
297
- process.exit(1)
298
- }
299
-
300
- const { data } = await res.json() as { data: { logs: string } }
301
- console.log(data.logs)
312
+ const data = await targetFetch<{ logs: string }>(
313
+ target.apiBaseUrl,
314
+ target.apiPrefix,
315
+ {
316
+ method: "GET",
317
+ path: `/projects/${target.projectRef}/deployments${versionPath}/logs`,
318
+ token: target.token!,
319
+ orgId: target.orgId,
320
+ environment: target.mode === "cloud" ? target.environment : undefined,
321
+ },
322
+ )
323
+
324
+ plain(data.logs ?? "(no logs)")
302
325
  })
303
326
  }
304
327
 
305
- async function deployToCloud(
306
- config: { projectRef?: string; apiUrl?: string; accessToken?: string },
328
+ async function deployStaticSite(
329
+ cwd: string,
307
330
  outputDir: string,
308
- isPreview: boolean,
331
+ opts: { preview?: boolean; env?: string },
309
332
  ): Promise<void> {
310
- const apiUrl = config.apiUrl || "https://api.supatype.com"
311
- const token = config.accessToken || process.env["SUPATYPE_ACCESS_TOKEN"] || ""
312
-
313
- console.log("Uploading build artifacts...")
333
+ const target = resolveTarget(cwd, { env: opts.env })
334
+ const token = target.token
335
+ if (!token) {
336
+ throw new Error("No token for linked target. Re-run supatype link --token ...")
337
+ }
314
338
 
315
- // Collect files from output directory
339
+ info("Uploading build artifacts...")
316
340
  const files = collectFiles(outputDir, outputDir)
317
- console.log(`${files.length} files to upload (${formatSize(files.reduce((s, f) => s + f.size, 0))})`)
341
+ info(`${files.length} files to upload (${formatSize(files.reduce((s, f) => s + f.size, 0))})`)
342
+
343
+ const { readFileSync } = await import("node:fs")
344
+
345
+ if (target.apiPrefix === "/platform/v1") {
346
+ const filePayload = files.map((f) => ({
347
+ path: f.relativePath,
348
+ content: readFileSync(f.absolutePath).toString("base64"),
349
+ encoding: "base64",
350
+ }))
351
+
352
+ const created = await targetFetch<{ id: string }>(
353
+ target.apiBaseUrl,
354
+ target.apiPrefix,
355
+ {
356
+ method: "POST",
357
+ path: `/projects/${target.projectRef}/deployments`,
358
+ body: { preview: opts.preview ?? false, files: filePayload },
359
+ token,
360
+ orgId: target.orgId,
361
+ },
362
+ )
363
+
364
+ await targetFetch(
365
+ target.apiBaseUrl,
366
+ target.apiPrefix,
367
+ {
368
+ method: "POST",
369
+ path: `/projects/${target.projectRef}/deployments/${created.id}/finalize`,
370
+ token,
371
+ orgId: target.orgId,
372
+ },
373
+ )
374
+ return
375
+ }
318
376
 
319
- // Create deployment
320
- const createRes = await fetch(`${apiUrl}/platform/v1/projects/${config.projectRef}/deployments`, {
377
+ const createRes = await fetch(`${target.apiBaseUrl}/api/v1/projects/${target.projectRef}/deployments`, {
321
378
  method: "POST",
322
379
  headers: {
323
380
  Authorization: `Bearer ${token}`,
324
381
  "Content-Type": "application/json",
382
+ ...(target.orgId ? { "X-Org-Id": target.orgId } : {}),
383
+ ...(target.environment ? { "X-Supatype-Environment": target.environment } : {}),
325
384
  },
326
385
  body: JSON.stringify({
327
- preview: isPreview,
386
+ preview: opts.preview ?? false,
328
387
  fileCount: files.length,
329
388
  totalSize: files.reduce((s, f) => s + f.size, 0),
330
389
  files: files.map((f) => ({ path: f.relativePath, size: f.size })),
@@ -338,9 +397,8 @@ async function deployToCloud(
338
397
 
339
398
  const { data } = await createRes.json() as { data: { deploymentId: string; uploadUrl: string } }
340
399
 
341
- // Upload files (simplified — in production, use multipart or presigned URLs)
342
400
  for (const file of files) {
343
- const content = require("node:fs").readFileSync(file.absolutePath)
401
+ const content = readFileSync(file.absolutePath)
344
402
  await fetch(`${data.uploadUrl}/${file.relativePath}`, {
345
403
  method: "PUT",
346
404
  headers: {
@@ -352,19 +410,23 @@ async function deployToCloud(
352
410
  })
353
411
  }
354
412
 
355
- // Finalize deployment
356
- await fetch(`${apiUrl}/platform/v1/projects/${config.projectRef}/deployments/${data.deploymentId}/finalize`, {
357
- method: "POST",
358
- headers: { Authorization: `Bearer ${token}` },
359
- })
413
+ await fetch(
414
+ `${target.apiBaseUrl}/api/v1/projects/${target.projectRef}/deployments/${data.deploymentId}/finalize`,
415
+ {
416
+ method: "POST",
417
+ headers: {
418
+ Authorization: `Bearer ${token}`,
419
+ ...(target.orgId ? { "X-Org-Id": target.orgId } : {}),
420
+ },
421
+ },
422
+ )
360
423
  }
361
424
 
362
425
  function deploySelfHost(outputDir: string, cwd: string): void {
363
426
  const servingDir = join(cwd, ".supatype", "static")
364
- const { mkdirSync, cpSync } = require("node:fs") as typeof import("node:fs")
365
427
  mkdirSync(servingDir, { recursive: true })
366
428
  cpSync(outputDir, servingDir, { recursive: true })
367
- console.log(`Static files deployed to ${servingDir}`)
429
+ info(`Static files deployed to ${servingDir}`)
368
430
  }
369
431
 
370
432
  interface FileEntry {
@@ -375,8 +437,6 @@ interface FileEntry {
375
437
 
376
438
  function collectFiles(dir: string, baseDir: string): FileEntry[] {
377
439
  const files: FileEntry[] = []
378
- const { readdirSync, statSync } = require("node:fs") as typeof import("node:fs")
379
- const { relative } = require("node:path") as typeof import("node:path")
380
440
 
381
441
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
382
442
  const fullPath = join(dir, entry.name)