@supatype/cli 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +221 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/bin/dev-entry.ts +2 -0
- package/bin/supatype.js +5 -0
- package/dist/app/framework.d.ts +44 -0
- package/dist/app/framework.d.ts.map +1 -0
- package/dist/app/framework.js +200 -0
- package/dist/app/framework.js.map +1 -0
- package/dist/app/proxy-dev-app.d.ts +13 -0
- package/dist/app/proxy-dev-app.d.ts.map +1 -0
- package/dist/app/proxy-dev-app.js +54 -0
- package/dist/app/proxy-dev-app.js.map +1 -0
- package/dist/app-config.d.ts +7 -0
- package/dist/app-config.d.ts.map +1 -0
- package/dist/app-config.js +113 -0
- package/dist/app-config.js.map +1 -0
- package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/dist/augmentation-generator.d.ts +2 -0
- package/dist/augmentation-generator.d.ts.map +1 -0
- package/dist/augmentation-generator.js +111 -0
- package/dist/augmentation-generator.js.map +1 -0
- package/dist/binary-cache.d.ts +98 -0
- package/dist/binary-cache.d.ts.map +1 -0
- package/dist/binary-cache.js +687 -0
- package/dist/binary-cache.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +61 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/admin.d.ts +4 -0
- package/dist/commands/admin.d.ts.map +1 -0
- package/dist/commands/admin.js +271 -0
- package/dist/commands/admin.js.map +1 -0
- package/dist/commands/app.d.ts +3 -0
- package/dist/commands/app.d.ts.map +1 -0
- package/dist/commands/app.js +82 -0
- package/dist/commands/app.js.map +1 -0
- package/dist/commands/cache.d.ts +6 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +105 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/cloud.d.ts +23 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +254 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/db.d.ts +8 -0
- package/dist/commands/db.d.ts.map +1 -0
- package/dist/commands/db.js +116 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/deploy-types.d.ts +14 -0
- package/dist/commands/deploy-types.d.ts.map +1 -0
- package/dist/commands/deploy-types.js +38 -0
- package/dist/commands/deploy-types.js.map +1 -0
- package/dist/commands/deploy.d.ts +15 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +322 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +14 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +806 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/diff.d.ts +3 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +54 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/engine.d.ts +7 -0
- package/dist/commands/engine.d.ts.map +1 -0
- package/dist/commands/engine.js +27 -0
- package/dist/commands/engine.js.map +1 -0
- package/dist/commands/functions.d.ts +3 -0
- package/dist/commands/functions.d.ts.map +1 -0
- package/dist/commands/functions.js +749 -0
- package/dist/commands/functions.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +38 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +228 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/keys.d.ts +4 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +57 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/logs.d.ts +6 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +52 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/migrate-from-v1.d.ts +5 -0
- package/dist/commands/migrate-from-v1.d.ts.map +1 -0
- package/dist/commands/migrate-from-v1.js +125 -0
- package/dist/commands/migrate-from-v1.js.map +1 -0
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +75 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/pg.d.ts +8 -0
- package/dist/commands/pg.d.ts.map +1 -0
- package/dist/commands/pg.js +102 -0
- package/dist/commands/pg.js.map +1 -0
- package/dist/commands/plugins.d.ts +3 -0
- package/dist/commands/plugins.d.ts.map +1 -0
- package/dist/commands/plugins.js +431 -0
- package/dist/commands/plugins.js.map +1 -0
- package/dist/commands/pull.d.ts +3 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +12 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +3 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +179 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/seed.d.ts +5 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +55 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/self-host.d.ts +9 -0
- package/dist/commands/self-host.d.ts.map +1 -0
- package/dist/commands/self-host.js +310 -0
- package/dist/commands/self-host.js.map +1 -0
- package/dist/commands/self-update.d.ts +9 -0
- package/dist/commands/self-update.d.ts.map +1 -0
- package/dist/commands/self-update.js +33 -0
- package/dist/commands/self-update.js.map +1 -0
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +70 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/types.d.ts +3 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +62 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +7 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +118 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/components.d.ts +5 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/config.d.ts +65 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +134 -0
- package/dist/config.js.map +1 -0
- package/dist/dev-compose.d.ts +19 -0
- package/dist/dev-compose.d.ts.map +1 -0
- package/dist/dev-compose.js +468 -0
- package/dist/dev-compose.js.map +1 -0
- package/dist/dev-log-bus.d.ts +30 -0
- package/dist/dev-log-bus.d.ts.map +1 -0
- package/dist/dev-log-bus.js +87 -0
- package/dist/dev-log-bus.js.map +1 -0
- package/dist/dev-log-filter.d.ts +10 -0
- package/dist/dev-log-filter.d.ts.map +1 -0
- package/dist/dev-log-filter.js +36 -0
- package/dist/dev-log-filter.js.map +1 -0
- package/dist/dev-logo.d.ts +12 -0
- package/dist/dev-logo.d.ts.map +1 -0
- package/dist/dev-logo.js +57 -0
- package/dist/dev-logo.js.map +1 -0
- package/dist/dev-session.d.ts +26 -0
- package/dist/dev-session.d.ts.map +1 -0
- package/dist/dev-session.js +106 -0
- package/dist/dev-session.js.map +1 -0
- package/dist/dev-shutdown.d.ts +9 -0
- package/dist/dev-shutdown.d.ts.map +1 -0
- package/dist/dev-shutdown.js +50 -0
- package/dist/dev-shutdown.js.map +1 -0
- package/dist/dev-task-colors.d.ts +14 -0
- package/dist/dev-task-colors.d.ts.map +1 -0
- package/dist/dev-task-colors.js +44 -0
- package/dist/dev-task-colors.js.map +1 -0
- package/dist/dev-tui.d.ts +24 -0
- package/dist/dev-tui.d.ts.map +1 -0
- package/dist/dev-tui.js +188 -0
- package/dist/dev-tui.js.map +1 -0
- package/dist/diff-output.d.ts +4 -0
- package/dist/diff-output.d.ts.map +1 -0
- package/dist/diff-output.js +12 -0
- package/dist/diff-output.js.map +1 -0
- package/dist/docker-postgres.d.ts +57 -0
- package/dist/docker-postgres.d.ts.map +1 -0
- package/dist/docker-postgres.js +208 -0
- package/dist/docker-postgres.js.map +1 -0
- package/dist/engine-client.d.ts +69 -0
- package/dist/engine-client.d.ts.map +1 -0
- package/dist/engine-client.js +157 -0
- package/dist/engine-client.js.map +1 -0
- package/dist/engine-push-output.d.ts +16 -0
- package/dist/engine-push-output.d.ts.map +1 -0
- package/dist/engine-push-output.js +61 -0
- package/dist/engine-push-output.js.map +1 -0
- package/dist/ensure-binary.d.ts +7 -0
- package/dist/ensure-binary.d.ts.map +1 -0
- package/dist/ensure-binary.js +17 -0
- package/dist/ensure-binary.js.map +1 -0
- package/dist/functions-router-gen.d.ts +14 -0
- package/dist/functions-router-gen.d.ts.map +1 -0
- package/dist/functions-router-gen.js +199 -0
- package/dist/functions-router-gen.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt.d.ts +3 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +13 -0
- package/dist/jwt.js.map +1 -0
- package/dist/kong-config.d.ts +25 -0
- package/dist/kong-config.d.ts.map +1 -0
- package/dist/kong-config.js +71 -0
- package/dist/kong-config.js.map +1 -0
- package/dist/local-gateway.d.ts +7 -0
- package/dist/local-gateway.d.ts.map +1 -0
- package/dist/local-gateway.js +9 -0
- package/dist/local-gateway.js.map +1 -0
- package/dist/local-storage.d.ts +8 -0
- package/dist/local-storage.d.ts.map +1 -0
- package/dist/local-storage.js +14 -0
- package/dist/local-storage.js.map +1 -0
- package/dist/pgbouncer-userlist.d.ts +5 -0
- package/dist/pgbouncer-userlist.d.ts.map +1 -0
- package/dist/pgbouncer-userlist.js +14 -0
- package/dist/pgbouncer-userlist.js.map +1 -0
- package/dist/postgres-ctl.d.ts +44 -0
- package/dist/postgres-ctl.d.ts.map +1 -0
- package/dist/postgres-ctl.js +137 -0
- package/dist/postgres-ctl.js.map +1 -0
- package/dist/process-manager.d.ts +49 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +177 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/project-config.d.ts +238 -0
- package/dist/project-config.d.ts.map +1 -0
- package/dist/project-config.js +159 -0
- package/dist/project-config.js.map +1 -0
- package/dist/pull-utils.d.ts +31 -0
- package/dist/pull-utils.d.ts.map +1 -0
- package/dist/pull-utils.js +77 -0
- package/dist/pull-utils.js.map +1 -0
- package/dist/release-pins.d.ts +7 -0
- package/dist/release-pins.d.ts.map +1 -0
- package/dist/release-pins.js +27 -0
- package/dist/release-pins.js.map +1 -0
- package/dist/release-public-key.d.ts +8 -0
- package/dist/release-public-key.d.ts.map +1 -0
- package/dist/release-public-key.js +13 -0
- package/dist/release-public-key.js.map +1 -0
- package/dist/restore-system-relation-targets.d.ts +3 -0
- package/dist/restore-system-relation-targets.d.ts.map +1 -0
- package/dist/restore-system-relation-targets.js +45 -0
- package/dist/restore-system-relation-targets.js.map +1 -0
- package/dist/runtime-routes.d.ts +34 -0
- package/dist/runtime-routes.d.ts.map +1 -0
- package/dist/runtime-routes.js +252 -0
- package/dist/runtime-routes.js.map +1 -0
- package/dist/schema-ast-v2.d.ts +127 -0
- package/dist/schema-ast-v2.d.ts.map +1 -0
- package/dist/schema-ast-v2.js +226 -0
- package/dist/schema-ast-v2.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +11 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +47 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/seed.d.ts +8 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +32 -0
- package/dist/seed.js.map +1 -0
- package/dist/self-host-compose.d.ts +43 -0
- package/dist/self-host-compose.d.ts.map +1 -0
- package/dist/self-host-compose.js +400 -0
- package/dist/self-host-compose.js.map +1 -0
- package/dist/storage-provision.d.ts +24 -0
- package/dist/storage-provision.d.ts.map +1 -0
- package/dist/storage-provision.js +44 -0
- package/dist/storage-provision.js.map +1 -0
- package/dist/studio-admin-roles.d.ts +7 -0
- package/dist/studio-admin-roles.d.ts.map +1 -0
- package/dist/studio-admin-roles.js +14 -0
- package/dist/studio-admin-roles.js.map +1 -0
- package/dist/studio-dev-server.d.ts +22 -0
- package/dist/studio-dev-server.d.ts.map +1 -0
- package/dist/studio-dev-server.js +28 -0
- package/dist/studio-dev-server.js.map +1 -0
- package/dist/supatype-eval-1781522769253.d.mts +2 -0
- package/dist/supatype-eval-1781522769253.d.mts.map +1 -0
- package/dist/supatype-eval-1781522769253.mjs +3 -0
- package/dist/supatype-eval-1781522769253.mjs.map +1 -0
- package/dist/systemd.d.ts +26 -0
- package/dist/systemd.d.ts.map +1 -0
- package/dist/systemd.js +102 -0
- package/dist/systemd.js.map +1 -0
- package/dist/tsx-runner.d.ts +18 -0
- package/dist/tsx-runner.d.ts.map +1 -0
- package/dist/tsx-runner.js +69 -0
- package/dist/tsx-runner.js.map +1 -0
- package/dist/type-extractor.d.ts +4 -0
- package/dist/type-extractor.d.ts.map +1 -0
- package/dist/type-extractor.js +1213 -0
- package/dist/type-extractor.js.map +1 -0
- package/dist/type-resolver.d.ts +33 -0
- package/dist/type-resolver.d.ts.map +1 -0
- package/dist/type-resolver.js +338 -0
- package/dist/type-resolver.js.map +1 -0
- package/package.json +41 -0
- package/releases/deno/VERSION +1 -0
- package/scripts/mirror-deno-release.sh +76 -0
- package/src/TYPE-RESOLUTION.md +294 -0
- package/src/app/framework.ts +249 -0
- package/src/app/proxy-dev-app.ts +68 -0
- package/src/app-config.ts +128 -0
- package/src/augmentation-generator.ts +126 -0
- package/src/binary-cache.ts +845 -0
- package/src/cli.ts +63 -0
- package/src/commands/admin.ts +372 -0
- package/src/commands/app.ts +97 -0
- package/src/commands/cache.ts +117 -0
- package/src/commands/cloud.ts +325 -0
- package/src/commands/db.ts +136 -0
- package/src/commands/deploy-types.ts +49 -0
- package/src/commands/deploy.ts +400 -0
- package/src/commands/dev.ts +1009 -0
- package/src/commands/diff.ts +63 -0
- package/src/commands/engine.ts +30 -0
- package/src/commands/functions.ts +901 -0
- package/src/commands/generate.ts +44 -0
- package/src/commands/init.ts +253 -0
- package/src/commands/keys.ts +66 -0
- package/src/commands/logs.ts +58 -0
- package/src/commands/migrate-from-v1.ts +131 -0
- package/src/commands/migrate.ts +87 -0
- package/src/commands/pg.ts +133 -0
- package/src/commands/plugins.ts +508 -0
- package/src/commands/pull.ts +17 -0
- package/src/commands/push.ts +226 -0
- package/src/commands/seed.ts +68 -0
- package/src/commands/self-host.ts +364 -0
- package/src/commands/self-update.ts +45 -0
- package/src/commands/status.ts +84 -0
- package/src/commands/types.ts +76 -0
- package/src/commands/update.ts +136 -0
- package/src/components.ts +6 -0
- package/src/config.ts +223 -0
- package/src/dev-compose.ts +583 -0
- package/src/dev-log-bus.ts +101 -0
- package/src/dev-log-filter.ts +32 -0
- package/src/dev-logo.ts +62 -0
- package/src/dev-session.ts +130 -0
- package/src/dev-shutdown.ts +54 -0
- package/src/dev-task-colors.ts +47 -0
- package/src/dev-tui.ts +232 -0
- package/src/diff-output.ts +12 -0
- package/src/docker-postgres.ts +295 -0
- package/src/engine-client.ts +236 -0
- package/src/engine-push-output.ts +71 -0
- package/src/ensure-binary.ts +28 -0
- package/src/functions-router-gen.ts +224 -0
- package/src/index.ts +11 -0
- package/src/jwt.ts +14 -0
- package/src/kong-config.ts +93 -0
- package/src/local-gateway.ts +9 -0
- package/src/local-storage.ts +14 -0
- package/src/pgbouncer-userlist.ts +15 -0
- package/src/postgres-ctl.ts +171 -0
- package/src/process-manager.ts +220 -0
- package/src/project-config.ts +388 -0
- package/src/pull-utils.ts +81 -0
- package/src/release-pins.ts +31 -0
- package/src/release-public-key.ts +12 -0
- package/src/restore-system-relation-targets.ts +45 -0
- package/src/runtime-routes.ts +291 -0
- package/src/schema-ast-v2.ts +324 -0
- package/src/scripts/postinstall.ts +51 -0
- package/src/seed.ts +43 -0
- package/src/self-host-compose.ts +452 -0
- package/src/storage-provision.ts +58 -0
- package/src/studio-admin-roles.ts +16 -0
- package/src/studio-dev-server.ts +53 -0
- package/src/supatype-eval-1781522769253.mts +1 -0
- package/src/systemd.ts +137 -0
- package/src/tsx-runner.ts +89 -0
- package/src/type-extractor.ts +1479 -0
- package/src/type-resolver.ts +457 -0
- package/tests/app-command.test.ts +54 -0
- package/tests/augmentation-generator.test.ts +59 -0
- package/tests/binary-cache-cloud-overrides.test.ts +123 -0
- package/tests/cached-artifact-format.test.ts +84 -0
- package/tests/cli-help.test.ts +133 -0
- package/tests/config.test.ts +252 -0
- package/tests/dev-ui.test.ts +139 -0
- package/tests/docker-postgres.test.ts +39 -0
- package/tests/engine-distribution.test.ts +418 -0
- package/tests/engine-push-output.test.ts +67 -0
- package/tests/ensure-binary.test.ts +59 -0
- package/tests/init.test.ts +127 -0
- package/tests/keys.test.ts +160 -0
- package/tests/migrate-from-v1.test.ts +29 -0
- package/tests/normalize-admin-config.test.ts +48 -0
- package/tests/pg-spawn-env.test.ts +18 -0
- package/tests/postgres-archive-tag.test.ts +9 -0
- package/tests/proxy-dev-app.test.ts +33 -0
- package/tests/pull-utils.test.ts +150 -0
- package/tests/release-pins.test.ts +28 -0
- package/tests/runtime-contract.test.ts +370 -0
- package/tests/seed-discover.test.ts +31 -0
- package/tests/studio-admin-roles.test.ts +27 -0
- package/tests/tsconfig.json +9 -0
- package/tests/tsx-runner.test.ts +66 -0
- package/tests/type-extractor.test.ts +985 -0
- package/tests/type-resolver.test.ts +59 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +12 -0
package/src/systemd.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* systemd.ts — generate systemd unit files for self-hosted deployments.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* generateUnits(config, outputDir)
|
|
6
|
+
* → writes supatype-postgres.service + supatype-server.service to outputDir
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { writeFileSync, mkdirSync } from "node:fs"
|
|
10
|
+
import { join, resolve } from "node:path"
|
|
11
|
+
import { homedir } from "node:os"
|
|
12
|
+
import type { SupatypeProjectConfig } from "./project-config.js"
|
|
13
|
+
|
|
14
|
+
export interface SystemdOptions {
|
|
15
|
+
/** Directory where unit files are written. Defaults to .supatype/systemd/. */
|
|
16
|
+
outputDir?: string
|
|
17
|
+
/** User to run services as. Defaults to current user. */
|
|
18
|
+
user?: string
|
|
19
|
+
/** EnvironmentFile path injected into the units. Defaults to project .env. */
|
|
20
|
+
envFile?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Public API
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generate supatype-postgres.service and supatype-server.service.
|
|
29
|
+
*
|
|
30
|
+
* Returns the paths of the written files.
|
|
31
|
+
*/
|
|
32
|
+
export function generateUnits(
|
|
33
|
+
config: SupatypeProjectConfig,
|
|
34
|
+
projectDir: string,
|
|
35
|
+
opts: SystemdOptions = {},
|
|
36
|
+
): { postgres: string; server: string } {
|
|
37
|
+
const outputDir = opts.outputDir ?? resolve(projectDir, ".supatype", "systemd")
|
|
38
|
+
mkdirSync(outputDir, { recursive: true })
|
|
39
|
+
|
|
40
|
+
const user = opts.user ?? process.env["USER"] ?? "supatype"
|
|
41
|
+
const envFile = opts.envFile ?? resolve(projectDir, ".env")
|
|
42
|
+
const stateDir = join(homedir(), ".supatype", "projects", config.project.name)
|
|
43
|
+
|
|
44
|
+
const postgresPath = join(outputDir, "supatype-postgres.service")
|
|
45
|
+
const serverPath = join(outputDir, "supatype-server.service")
|
|
46
|
+
|
|
47
|
+
writeFileSync(postgresPath, postgresUnit(config, stateDir, user, envFile), "utf8")
|
|
48
|
+
writeFileSync(serverPath, serverUnit(config, stateDir, user, envFile), "utf8")
|
|
49
|
+
|
|
50
|
+
return { postgres: postgresPath, server: serverPath }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Unit templates
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
function postgresUnit(
|
|
58
|
+
config: SupatypeProjectConfig,
|
|
59
|
+
stateDir: string,
|
|
60
|
+
user: string,
|
|
61
|
+
envFile: string,
|
|
62
|
+
): string {
|
|
63
|
+
const dataDir = config.database.data_dir ?? join(stateDir, "data")
|
|
64
|
+
const logDir = join(stateDir, "logs")
|
|
65
|
+
const pgBinDir = `%h/.supatype/cache/postgres/${config.versions?.postgres ?? "latest"}/bin`
|
|
66
|
+
|
|
67
|
+
return `[Unit]
|
|
68
|
+
Description=Supatype Postgres (${config.project.name})
|
|
69
|
+
After=network.target
|
|
70
|
+
StartLimitIntervalSec=60
|
|
71
|
+
StartLimitBurst=5
|
|
72
|
+
|
|
73
|
+
[Service]
|
|
74
|
+
Type=forking
|
|
75
|
+
User=${user}
|
|
76
|
+
EnvironmentFile=-${envFile}
|
|
77
|
+
ExecStartPre=/bin/mkdir -p ${logDir}
|
|
78
|
+
ExecStart=${pgBinDir}/pg_ctl start \\
|
|
79
|
+
-D ${dataDir} \\
|
|
80
|
+
-l ${logDir}/postgres.log \\
|
|
81
|
+
-w \\
|
|
82
|
+
-t 60
|
|
83
|
+
ExecStop=${pgBinDir}/pg_ctl stop -D ${dataDir} -m fast
|
|
84
|
+
ExecReload=${pgBinDir}/pg_ctl reload -D ${dataDir}
|
|
85
|
+
PIDFile=${stateDir}/pid/postgres.pid
|
|
86
|
+
Restart=on-failure
|
|
87
|
+
RestartSec=5s
|
|
88
|
+
TimeoutStartSec=90
|
|
89
|
+
TimeoutStopSec=30
|
|
90
|
+
|
|
91
|
+
[Install]
|
|
92
|
+
WantedBy=multi-user.target
|
|
93
|
+
`
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function serverUnit(
|
|
97
|
+
config: SupatypeProjectConfig,
|
|
98
|
+
stateDir: string,
|
|
99
|
+
user: string,
|
|
100
|
+
envFile: string,
|
|
101
|
+
): string {
|
|
102
|
+
const port = config.server.port ?? 54321
|
|
103
|
+
const serverBin = `%h/.supatype/cache/server/${config.versions?.server ?? "latest"}/supatype-server`
|
|
104
|
+
const logDir = join(stateDir, "logs")
|
|
105
|
+
|
|
106
|
+
const extraArgs: string[] = [`--mode ${config.server.mode}`]
|
|
107
|
+
if (config.server.domain) extraArgs.push(`--domain ${config.server.domain}`)
|
|
108
|
+
|
|
109
|
+
return `[Unit]
|
|
110
|
+
Description=Supatype Server (${config.project.name})
|
|
111
|
+
After=network.target supatype-postgres.service
|
|
112
|
+
Requires=supatype-postgres.service
|
|
113
|
+
StartLimitIntervalSec=60
|
|
114
|
+
StartLimitBurst=5
|
|
115
|
+
|
|
116
|
+
[Service]
|
|
117
|
+
Type=simple
|
|
118
|
+
User=${user}
|
|
119
|
+
EnvironmentFile=-${envFile}
|
|
120
|
+
ExecStartPre=/bin/mkdir -p ${logDir}
|
|
121
|
+
ExecStart=${serverBin} \\
|
|
122
|
+
--port ${port} \\
|
|
123
|
+
${extraArgs.join(" \\\n ")}
|
|
124
|
+
PIDFile=${stateDir}/pid/server.pid
|
|
125
|
+
StandardOutput=append:${logDir}/server.log
|
|
126
|
+
StandardError=append:${logDir}/server.log
|
|
127
|
+
Restart=on-failure
|
|
128
|
+
RestartSec=5s
|
|
129
|
+
TimeoutStartSec=30
|
|
130
|
+
TimeoutStopSec=15
|
|
131
|
+
KillMode=mixed
|
|
132
|
+
KillSignal=SIGTERM
|
|
133
|
+
|
|
134
|
+
[Install]
|
|
135
|
+
WantedBy=multi-user.target
|
|
136
|
+
`
|
|
137
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locates the tsx binary shipped with this package and provides a helper
|
|
3
|
+
* to run TypeScript files at runtime.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { spawnSync, type SpawnSyncOptions } from "node:child_process"
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
8
|
+
import { resolve, dirname } from "node:path"
|
|
9
|
+
import { createRequire } from "node:module"
|
|
10
|
+
import { fileURLToPath } from "node:url"
|
|
11
|
+
import { writeFileSync, unlinkSync } from "node:fs"
|
|
12
|
+
import { tmpdir } from "node:os"
|
|
13
|
+
|
|
14
|
+
const _require = createRequire(import.meta.url)
|
|
15
|
+
|
|
16
|
+
// The CLI's own source directory — workspace packages are
|
|
17
|
+
// resolvable from here. Eval snippets are written here so ESM resolution finds them.
|
|
18
|
+
const CLI_SRC_DIR = dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the absolute path to the tsx CLI entry point.
|
|
22
|
+
* tsx is a direct dependency so this will always succeed after `npm install`.
|
|
23
|
+
*/
|
|
24
|
+
function findTsxBin(): string {
|
|
25
|
+
try {
|
|
26
|
+
const pkgPath = _require.resolve("tsx/package.json")
|
|
27
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as {
|
|
28
|
+
bin?: string | Record<string, string>
|
|
29
|
+
}
|
|
30
|
+
const binRelative =
|
|
31
|
+
typeof pkg.bin === "string"
|
|
32
|
+
? pkg.bin
|
|
33
|
+
: (pkg.bin?.["tsx"] ?? "./dist/cli.mjs")
|
|
34
|
+
return resolve(dirname(pkgPath), binRelative)
|
|
35
|
+
} catch {
|
|
36
|
+
return "tsx" // last-resort: hope it's on PATH
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const TSX_BIN = findTsxBin()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export interface RunResult {
|
|
44
|
+
stdout: string
|
|
45
|
+
stderr: string
|
|
46
|
+
exitCode: number
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Run a TypeScript file with tsx and capture output. */
|
|
50
|
+
export function runTsFile(
|
|
51
|
+
filePath: string,
|
|
52
|
+
opts: SpawnSyncOptions = {},
|
|
53
|
+
): RunResult {
|
|
54
|
+
const result = spawnSync(process.execPath, [TSX_BIN, filePath], {
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
57
|
+
...opts,
|
|
58
|
+
})
|
|
59
|
+
return {
|
|
60
|
+
stdout: String(result.stdout ?? ""),
|
|
61
|
+
stderr: String(result.stderr ?? ""),
|
|
62
|
+
exitCode: result.status ?? 1,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Evaluate an ESM TypeScript snippet via tsx and return its stdout.
|
|
68
|
+
* The snippet should write JSON to process.stdout.
|
|
69
|
+
*/
|
|
70
|
+
export function evalTsSnippet(
|
|
71
|
+
snippet: string,
|
|
72
|
+
opts: SpawnSyncOptions = {},
|
|
73
|
+
): RunResult {
|
|
74
|
+
// Always write the temp file into the CLI's source directory so that ESM
|
|
75
|
+
// resolution can find workspace packages from there.
|
|
76
|
+
// The subprocess CWD is kept as opts.cwd (the user's project dir) so that
|
|
77
|
+
// any relative paths in the snippet resolve correctly.
|
|
78
|
+
const tmpFile = resolve(CLI_SRC_DIR, `supatype-eval-${Date.now()}.mts`)
|
|
79
|
+
writeFileSync(tmpFile, snippet, "utf8")
|
|
80
|
+
try {
|
|
81
|
+
return runTsFile(tmpFile, opts)
|
|
82
|
+
} finally {
|
|
83
|
+
try {
|
|
84
|
+
unlinkSync(tmpFile)
|
|
85
|
+
} catch {
|
|
86
|
+
// ignore cleanup errors
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|