@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.
- package/CHANGELOG.md +314 -0
- package/bin/supatype.js +40 -4
- package/deno.d.ts +1 -1
- package/dist/admin-prompt-state.d.ts +13 -0
- package/dist/admin-prompt-state.d.ts.map +1 -0
- package/dist/admin-prompt-state.js +30 -0
- package/dist/admin-prompt-state.js.map +1 -0
- package/dist/adopt-columns.d.ts.map +1 -1
- package/dist/adopt-columns.js +13 -17
- package/dist/adopt-columns.js.map +1 -1
- package/dist/after-hooks-health.d.ts +19 -0
- package/dist/after-hooks-health.d.ts.map +1 -0
- package/dist/after-hooks-health.js +69 -0
- package/dist/after-hooks-health.js.map +1 -0
- package/dist/app-config.d.ts +1 -1
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +103 -144
- package/dist/app-config.js.map +1 -1
- package/dist/app-vite-env.d.ts +5 -1
- package/dist/app-vite-env.d.ts.map +1 -1
- package/dist/app-vite-env.js +9 -15
- package/dist/app-vite-env.js.map +1 -1
- package/dist/applied-ast-artifacts.d.ts +16 -0
- package/dist/applied-ast-artifacts.d.ts.map +1 -0
- package/dist/applied-ast-artifacts.js +37 -0
- package/dist/applied-ast-artifacts.js.map +1 -0
- package/dist/archive-extract.d.ts +3 -0
- package/dist/archive-extract.d.ts.map +1 -0
- package/dist/archive-extract.js +19 -0
- package/dist/archive-extract.js.map +1 -0
- package/dist/augmentation-generator.d.ts +5 -0
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +13 -4
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/binary-cache.d.ts +27 -3
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +117 -85
- package/dist/binary-cache.js.map +1 -1
- package/dist/binary-download-lock.d.ts.map +1 -1
- package/dist/binary-download-lock.js +1 -3
- package/dist/binary-download-lock.js.map +1 -1
- package/dist/byo-preflight.d.ts.map +1 -1
- package/dist/byo-preflight.js +2 -10
- package/dist/byo-preflight.js.map +1 -1
- package/dist/byte-size.d.ts +9 -0
- package/dist/byte-size.d.ts.map +1 -0
- package/dist/byte-size.js +36 -0
- package/dist/byte-size.js.map +1 -0
- package/dist/cache-clean.d.ts +0 -2
- package/dist/cache-clean.d.ts.map +1 -1
- package/dist/cache-clean.js +1 -27
- package/dist/cache-clean.js.map +1 -1
- package/dist/cache-pins.d.ts.map +1 -1
- package/dist/cache-pins.js +3 -20
- package/dist/cache-pins.js.map +1 -1
- package/dist/cache-root.d.ts +7 -0
- package/dist/cache-root.d.ts.map +1 -0
- package/dist/cache-root.js +11 -0
- package/dist/cache-root.js.map +1 -0
- package/dist/cli-artifacts.d.ts.map +1 -1
- package/dist/cli-artifacts.js +2 -1
- package/dist/cli-artifacts.js.map +1 -1
- package/dist/cli-install-method.d.ts.map +1 -1
- package/dist/cli-install-method.js +7 -1
- package/dist/cli-install-method.js.map +1 -1
- package/dist/cli-launcher.d.ts +21 -0
- package/dist/cli-launcher.d.ts.map +1 -0
- package/dist/cli-launcher.js +112 -0
- package/dist/cli-launcher.js.map +1 -0
- package/dist/cli-old-versions.d.ts +44 -0
- package/dist/cli-old-versions.d.ts.map +1 -0
- package/dist/cli-old-versions.js +83 -0
- package/dist/cli-old-versions.js.map +1 -0
- package/dist/cli-program-path.d.ts +20 -0
- package/dist/cli-program-path.d.ts.map +1 -0
- package/dist/cli-program-path.js +41 -0
- package/dist/cli-program-path.js.map +1 -0
- package/dist/cli-standalone.d.ts +2 -3
- package/dist/cli-standalone.d.ts.map +1 -1
- package/dist/cli-standalone.js +51 -24
- package/dist/cli-standalone.js.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/cloud-credentials.d.ts +6 -0
- package/dist/cloud-credentials.d.ts.map +1 -1
- package/dist/cloud-credentials.js +13 -0
- package/dist/cloud-credentials.js.map +1 -1
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +18 -18
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +27 -8
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +37 -11
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.js +2 -4
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +116 -106
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +3 -3
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts +50 -4
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +276 -267
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +32 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +66 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/functions.d.ts +30 -0
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +503 -507
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +11 -8
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/hooks.d.ts.map +1 -1
- package/dist/commands/hooks.js +46 -23
- package/dist/commands/hooks.js.map +1 -1
- package/dist/commands/init.d.ts +37 -4
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +509 -386
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/internal.d.ts.map +1 -1
- package/dist/commands/internal.js +2 -1
- package/dist/commands/internal.js.map +1 -1
- package/dist/commands/keys.d.ts +46 -20
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +196 -156
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/link-helpers.d.ts.map +1 -1
- package/dist/commands/link-helpers.js +30 -11
- package/dist/commands/link-helpers.js.map +1 -1
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +5 -4
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/migrate.js +1 -1
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/pg.js +2 -0
- package/dist/commands/pg.js.map +1 -1
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +17 -7
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/push.d.ts +39 -0
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +221 -77
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/seed.d.ts +35 -0
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +72 -38
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +71 -42
- package/dist/commands/self-host.js.map +1 -1
- package/dist/commands/self-update.d.ts.map +1 -1
- package/dist/commands/self-update.js +9 -3
- package/dist/commands/self-update.js.map +1 -1
- package/dist/commands/status.js +5 -5
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.js +2 -5
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +212 -101
- package/dist/commands/update.js.map +1 -1
- package/dist/component-launch.d.ts +11 -0
- package/dist/component-launch.d.ts.map +1 -0
- package/dist/component-launch.js +35 -0
- package/dist/component-launch.js.map +1 -0
- package/dist/components.d.ts +7 -2
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +7 -2
- package/dist/components.js.map +1 -1
- package/dist/compose-db-roles.d.ts.map +1 -1
- package/dist/compose-db-roles.js +5 -14
- package/dist/compose-db-roles.js.map +1 -1
- package/dist/compose-engine-run.d.ts +6 -5
- package/dist/compose-engine-run.d.ts.map +1 -1
- package/dist/compose-engine-run.js +44 -37
- package/dist/compose-engine-run.js.map +1 -1
- package/dist/compose-engine-service.d.ts +10 -0
- package/dist/compose-engine-service.d.ts.map +1 -0
- package/dist/compose-engine-service.js +16 -0
- package/dist/compose-engine-service.js.map +1 -0
- package/dist/compose-host-path.d.ts +14 -0
- package/dist/compose-host-path.d.ts.map +1 -0
- package/dist/compose-host-path.js +18 -0
- package/dist/compose-host-path.js.map +1 -0
- package/dist/compose-image-pull.d.ts +43 -0
- package/dist/compose-image-pull.d.ts.map +1 -0
- package/dist/compose-image-pull.js +27 -0
- package/dist/compose-image-pull.js.map +1 -0
- package/dist/compose-kong.d.ts +4 -0
- package/dist/compose-kong.d.ts.map +1 -1
- package/dist/compose-kong.js +23 -9
- package/dist/compose-kong.js.map +1 -1
- package/dist/compose-local-server-image.d.ts.map +1 -1
- package/dist/compose-local-server-image.js +7 -3
- package/dist/compose-local-server-image.js.map +1 -1
- package/dist/compose-render-mode.d.ts.map +1 -1
- package/dist/compose-render-mode.js +7 -4
- package/dist/compose-render-mode.js.map +1 -1
- package/dist/compose-services.d.ts +12 -2
- package/dist/compose-services.d.ts.map +1 -1
- package/dist/compose-services.js +27 -12
- package/dist/compose-services.js.map +1 -1
- package/dist/config-snapshot.d.ts +6 -0
- package/dist/config-snapshot.d.ts.map +1 -0
- package/dist/config-snapshot.js +23 -0
- package/dist/config-snapshot.js.map +1 -0
- package/dist/config.d.ts +11 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -3
- package/dist/config.js.map +1 -1
- package/dist/database-url-owner.d.ts +59 -0
- package/dist/database-url-owner.d.ts.map +1 -0
- package/dist/database-url-owner.js +133 -0
- package/dist/database-url-owner.js.map +1 -0
- package/dist/db-port-offer.d.ts +18 -0
- package/dist/db-port-offer.d.ts.map +1 -0
- package/dist/db-port-offer.js +68 -0
- package/dist/db-port-offer.js.map +1 -0
- package/dist/db-port.d.ts +42 -18
- package/dist/db-port.d.ts.map +1 -1
- package/dist/db-port.js +34 -32
- package/dist/db-port.js.map +1 -1
- package/dist/db-preflight.d.ts +37 -0
- package/dist/db-preflight.d.ts.map +1 -1
- package/dist/db-preflight.js +219 -77
- package/dist/db-preflight.js.map +1 -1
- package/dist/db-rows.d.ts +11 -0
- package/dist/db-rows.d.ts.map +1 -1
- package/dist/db-rows.js +27 -0
- package/dist/db-rows.js.map +1 -1
- package/dist/debounce.d.ts +11 -0
- package/dist/debounce.d.ts.map +1 -0
- package/dist/debounce.js +23 -0
- package/dist/debounce.js.map +1 -0
- package/dist/dev-api-keys.d.ts +12 -2
- package/dist/dev-api-keys.d.ts.map +1 -1
- package/dist/dev-api-keys.js +33 -17
- package/dist/dev-api-keys.js.map +1 -1
- package/dist/dev-compose.d.ts +10 -12
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +252 -288
- package/dist/dev-compose.js.map +1 -1
- package/dist/dev-db-ready.d.ts.map +1 -1
- package/dist/dev-db-ready.js +2 -1
- package/dist/dev-db-ready.js.map +1 -1
- package/dist/dev-db-reset.d.ts.map +1 -1
- package/dist/dev-db-reset.js +5 -4
- package/dist/dev-db-reset.js.map +1 -1
- package/dist/dev-functions-watch.d.ts.map +1 -1
- package/dist/dev-functions-watch.js +5 -16
- package/dist/dev-functions-watch.js.map +1 -1
- package/dist/dev-log-bus.d.ts +8 -0
- package/dist/dev-log-bus.d.ts.map +1 -1
- package/dist/dev-log-bus.js +13 -0
- package/dist/dev-log-bus.js.map +1 -1
- package/dist/dev-ports.d.ts +27 -7
- package/dist/dev-ports.d.ts.map +1 -1
- package/dist/dev-ports.js +68 -41
- package/dist/dev-ports.js.map +1 -1
- package/dist/dev-schema-watch.d.ts.map +1 -1
- package/dist/dev-schema-watch.js +7 -12
- package/dist/dev-schema-watch.js.map +1 -1
- package/dist/dev-session-lock.js +4 -3
- package/dist/dev-session-lock.js.map +1 -1
- package/dist/dev-session.d.ts +15 -0
- package/dist/dev-session.d.ts.map +1 -1
- package/dist/dev-session.js +27 -1
- package/dist/dev-session.js.map +1 -1
- package/dist/dev-shutdown.d.ts +45 -0
- package/dist/dev-shutdown.d.ts.map +1 -1
- package/dist/dev-shutdown.js +221 -33
- package/dist/dev-shutdown.js.map +1 -1
- package/dist/diff-output.d.ts +7 -1
- package/dist/diff-output.d.ts.map +1 -1
- package/dist/diff-output.js +91 -2
- package/dist/diff-output.js.map +1 -1
- package/dist/docker-address-pool.d.ts +23 -0
- package/dist/docker-address-pool.d.ts.map +1 -0
- package/dist/docker-address-pool.js +56 -0
- package/dist/docker-address-pool.js.map +1 -0
- package/dist/docker-exec.d.ts +92 -0
- package/dist/docker-exec.d.ts.map +1 -0
- package/dist/docker-exec.js +139 -0
- package/dist/docker-exec.js.map +1 -0
- package/dist/docker-postgres.d.ts +1 -6
- package/dist/docker-postgres.d.ts.map +1 -1
- package/dist/docker-postgres.js +67 -85
- package/dist/docker-postgres.js.map +1 -1
- package/dist/docker-runtime.d.ts +14 -1
- package/dist/docker-runtime.d.ts.map +1 -1
- package/dist/docker-runtime.js +55 -24
- package/dist/docker-runtime.js.map +1 -1
- package/dist/dotenv-parse.d.ts +22 -0
- package/dist/dotenv-parse.d.ts.map +1 -0
- package/dist/dotenv-parse.js +63 -0
- package/dist/dotenv-parse.js.map +1 -0
- package/dist/engine-answers.d.ts +0 -2
- package/dist/engine-answers.d.ts.map +1 -1
- package/dist/engine-answers.js +4 -3
- package/dist/engine-answers.js.map +1 -1
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +13 -12
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-floor.d.ts +29 -0
- package/dist/engine-floor.d.ts.map +1 -1
- package/dist/engine-floor.js +56 -0
- package/dist/engine-floor.js.map +1 -1
- package/dist/engine-ownership-gate.d.ts +13 -1
- package/dist/engine-ownership-gate.d.ts.map +1 -1
- package/dist/engine-ownership-gate.js +36 -6
- package/dist/engine-ownership-gate.js.map +1 -1
- package/dist/ensure-binary.d.ts +9 -0
- package/dist/ensure-binary.d.ts.map +1 -1
- package/dist/ensure-binary.js +38 -5
- package/dist/ensure-binary.js.map +1 -1
- package/dist/ensure-component-binaries.d.ts.map +1 -1
- package/dist/ensure-component-binaries.js +2 -1
- package/dist/ensure-component-binaries.js.map +1 -1
- package/dist/env-file.d.ts +30 -8
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +84 -57
- package/dist/env-file.js.map +1 -1
- package/dist/env-lines.d.ts +11 -0
- package/dist/env-lines.d.ts.map +1 -0
- package/dist/env-lines.js +36 -0
- package/dist/env-lines.js.map +1 -0
- package/dist/error-message.d.ts +34 -1
- package/dist/error-message.d.ts.map +1 -1
- package/dist/error-message.js +102 -2
- package/dist/error-message.js.map +1 -1
- package/dist/fetch-within.d.ts +10 -0
- package/dist/fetch-within.d.ts.map +1 -0
- package/dist/fetch-within.js +12 -0
- package/dist/fetch-within.js.map +1 -0
- package/dist/field-masking-tier.d.ts.map +1 -1
- package/dist/field-masking-tier.js +7 -5
- package/dist/field-masking-tier.js.map +1 -1
- package/dist/frontend-env.d.ts +43 -0
- package/dist/frontend-env.d.ts.map +1 -0
- package/dist/frontend-env.js +81 -0
- package/dist/frontend-env.js.map +1 -0
- package/dist/functions-context-refresh.d.ts +6 -2
- package/dist/functions-context-refresh.d.ts.map +1 -1
- package/dist/functions-context-refresh.js +11 -3
- package/dist/functions-context-refresh.js.map +1 -1
- package/dist/functions-deno-types.d.ts.map +1 -1
- package/dist/functions-deno-types.js +9 -2
- package/dist/functions-deno-types.js.map +1 -1
- package/dist/{functions-router-gen.d.ts → functions-discovery.d.ts} +8 -10
- package/dist/functions-discovery.d.ts.map +1 -0
- package/dist/functions-discovery.js +87 -0
- package/dist/functions-discovery.js.map +1 -0
- package/dist/functions-template.d.ts.map +1 -1
- package/dist/functions-template.js +20 -12
- package/dist/functions-template.js.map +1 -1
- package/dist/functions-worker-files.d.ts +55 -0
- package/dist/functions-worker-files.d.ts.map +1 -0
- package/dist/functions-worker-files.js +149 -0
- package/dist/functions-worker-files.js.map +1 -0
- package/dist/generated/functions-worker-source.d.ts +2 -0
- package/dist/generated/functions-worker-source.d.ts.map +1 -0
- package/dist/generated/functions-worker-source.js +12 -0
- package/dist/generated/functions-worker-source.js.map +1 -0
- package/dist/generated/release-images.d.ts +18 -0
- package/dist/generated/release-images.d.ts.map +1 -0
- package/dist/generated/release-images.js +8 -0
- package/dist/generated/release-images.js.map +1 -0
- package/dist/generated-files-engine.d.ts +33 -0
- package/dist/generated-files-engine.d.ts.map +1 -0
- package/dist/generated-files-engine.js +45 -0
- package/dist/generated-files-engine.js.map +1 -0
- package/dist/hook-actor.d.ts +17 -0
- package/dist/hook-actor.d.ts.map +1 -0
- package/dist/hook-actor.js +37 -0
- package/dist/hook-actor.js.map +1 -0
- package/dist/hook-columns.d.ts +30 -0
- package/dist/hook-columns.d.ts.map +1 -0
- package/dist/hook-columns.js +77 -0
- package/dist/hook-columns.js.map +1 -0
- package/dist/hook-events.d.ts +11 -0
- package/dist/hook-events.d.ts.map +1 -0
- package/dist/hook-events.js +11 -0
- package/dist/hook-events.js.map +1 -0
- package/dist/hook-upload.d.ts +29 -15
- package/dist/hook-upload.d.ts.map +1 -1
- package/dist/hook-upload.js +88 -59
- package/dist/hook-upload.js.map +1 -1
- package/dist/hooks-generator.d.ts +5 -0
- package/dist/hooks-generator.d.ts.map +1 -1
- package/dist/hooks-generator.js +92 -21
- package/dist/hooks-generator.js.map +1 -1
- package/dist/host-database.d.ts.map +1 -1
- package/dist/host-database.js +31 -4
- package/dist/host-database.js.map +1 -1
- package/dist/init-dependency-versions.d.ts +3 -1
- package/dist/init-dependency-versions.d.ts.map +1 -1
- package/dist/init-dependency-versions.js +32 -6
- package/dist/init-dependency-versions.js.map +1 -1
- package/dist/init-example.d.ts +48 -0
- package/dist/init-example.d.ts.map +1 -0
- package/dist/init-example.js +110 -0
- package/dist/init-example.js.map +1 -0
- package/dist/init-package-json.d.ts +38 -1
- package/dist/init-package-json.d.ts.map +1 -1
- package/dist/init-package-json.js +150 -37
- package/dist/init-package-json.js.map +1 -1
- package/dist/init-setup-steps.d.ts +37 -0
- package/dist/init-setup-steps.d.ts.map +1 -0
- package/dist/init-setup-steps.js +118 -0
- package/dist/init-setup-steps.js.map +1 -0
- package/dist/jwt-secret-length.d.ts +5 -13
- package/dist/jwt-secret-length.d.ts.map +1 -1
- package/dist/jwt-secret-length.js +7 -22
- package/dist/jwt-secret-length.js.map +1 -1
- package/dist/jwt-secret-rules.d.ts +24 -0
- package/dist/jwt-secret-rules.d.ts.map +1 -0
- package/dist/jwt-secret-rules.js +46 -0
- package/dist/jwt-secret-rules.js.map +1 -0
- package/dist/local-gateway.d.ts +3 -6
- package/dist/local-gateway.d.ts.map +1 -1
- package/dist/local-gateway.js +7 -9
- package/dist/local-gateway.js.map +1 -1
- package/dist/local-secrets.d.ts +95 -11
- package/dist/local-secrets.d.ts.map +1 -1
- package/dist/local-secrets.js +153 -18
- package/dist/local-secrets.js.map +1 -1
- package/dist/local-stack.d.ts.map +1 -1
- package/dist/local-stack.js +2 -7
- package/dist/local-stack.js.map +1 -1
- package/dist/local-storage.d.ts +7 -2
- package/dist/local-storage.d.ts.map +1 -1
- package/dist/local-storage.js +11 -3
- package/dist/local-storage.js.map +1 -1
- package/dist/mailer-env.d.ts +37 -0
- package/dist/mailer-env.d.ts.map +1 -0
- package/dist/mailer-env.js +98 -0
- package/dist/mailer-env.js.map +1 -0
- package/dist/model-cache.d.ts +4 -8
- package/dist/model-cache.d.ts.map +1 -1
- package/dist/model-cache.js.map +1 -1
- package/dist/model-hooks.d.ts +21 -7
- package/dist/model-hooks.d.ts.map +1 -1
- package/dist/model-hooks.js +62 -39
- package/dist/model-hooks.js.map +1 -1
- package/dist/native-dev-env.d.ts +37 -1
- package/dist/native-dev-env.d.ts.map +1 -1
- package/dist/native-dev-env.js +64 -2
- package/dist/native-dev-env.js.map +1 -1
- package/dist/native-functions-watch.d.ts +56 -5
- package/dist/native-functions-watch.d.ts.map +1 -1
- package/dist/native-functions-watch.js +119 -38
- package/dist/native-functions-watch.js.map +1 -1
- package/dist/native-keyspace.d.ts.map +1 -1
- package/dist/native-keyspace.js +2 -2
- package/dist/native-keyspace.js.map +1 -1
- package/dist/native-realtime.d.ts +11 -3
- package/dist/native-realtime.d.ts.map +1 -1
- package/dist/native-realtime.js +162 -10
- package/dist/native-realtime.js.map +1 -1
- package/dist/native-roles-sql.d.ts +14 -0
- package/dist/native-roles-sql.d.ts.map +1 -1
- package/dist/native-roles-sql.js +82 -1
- package/dist/native-roles-sql.js.map +1 -1
- package/dist/native-storage-import.d.ts +19 -0
- package/dist/native-storage-import.d.ts.map +1 -0
- package/dist/native-storage-import.js +327 -0
- package/dist/native-storage-import.js.map +1 -0
- package/dist/native-storage.d.ts +45 -0
- package/dist/native-storage.d.ts.map +1 -0
- package/dist/native-storage.js +140 -0
- package/dist/native-storage.js.map +1 -0
- package/dist/native-worker.d.ts +26 -0
- package/dist/native-worker.d.ts.map +1 -0
- package/dist/native-worker.js +63 -0
- package/dist/native-worker.js.map +1 -0
- package/dist/owner-default.d.ts +9 -1
- package/dist/owner-default.d.ts.map +1 -1
- package/dist/owner-default.js +17 -4
- package/dist/owner-default.js.map +1 -1
- package/dist/post-apply.d.ts +3 -0
- package/dist/post-apply.d.ts.map +1 -0
- package/dist/post-apply.js +17 -0
- package/dist/post-apply.js.map +1 -0
- package/dist/postgres-ctl.d.ts +98 -7
- package/dist/postgres-ctl.d.ts.map +1 -1
- package/dist/postgres-ctl.js +273 -40
- package/dist/postgres-ctl.js.map +1 -1
- package/dist/postgres-image.d.ts +15 -3
- package/dist/postgres-image.d.ts.map +1 -1
- package/dist/postgres-image.js +18 -15
- package/dist/postgres-image.js.map +1 -1
- package/dist/postgrest-release.d.ts +9 -0
- package/dist/postgrest-release.d.ts.map +1 -1
- package/dist/postgrest-release.js +23 -0
- package/dist/postgrest-release.js.map +1 -1
- package/dist/process-manager.d.ts.map +1 -1
- package/dist/process-manager.js +3 -1
- package/dist/process-manager.js.map +1 -1
- package/dist/project-config.d.ts +44 -7
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +48 -4
- package/dist/project-config.js.map +1 -1
- package/dist/pull-utils.d.ts +15 -0
- package/dist/pull-utils.d.ts.map +1 -1
- package/dist/pull-utils.js +149 -23
- package/dist/pull-utils.js.map +1 -1
- package/dist/push-refusal.d.ts.map +1 -1
- package/dist/push-refusal.js +3 -2
- package/dist/push-refusal.js.map +1 -1
- package/dist/realtime-launch.d.ts +2 -5
- package/dist/realtime-launch.d.ts.map +1 -1
- package/dist/realtime-launch.js +6 -23
- package/dist/realtime-launch.js.map +1 -1
- package/dist/recorded-field-masking-tier.d.ts.map +1 -1
- package/dist/recorded-field-masking-tier.js +4 -3
- package/dist/recorded-field-masking-tier.js.map +1 -1
- package/dist/release-images.d.ts +31 -0
- package/dist/release-images.d.ts.map +1 -0
- package/dist/release-images.js +90 -0
- package/dist/release-images.js.map +1 -0
- package/dist/required-host-components.d.ts.map +1 -1
- package/dist/required-host-components.js +4 -0
- package/dist/required-host-components.js.map +1 -1
- package/dist/resolve-api-url.d.ts +17 -3
- package/dist/resolve-api-url.d.ts.map +1 -1
- package/dist/resolve-api-url.js +71 -30
- package/dist/resolve-api-url.js.map +1 -1
- package/dist/resolve-target.d.ts +64 -0
- package/dist/resolve-target.d.ts.map +1 -1
- package/dist/resolve-target.js +75 -27
- package/dist/resolve-target.js.map +1 -1
- package/dist/rest-ready.d.ts.map +1 -1
- package/dist/rest-ready.js +2 -1
- package/dist/rest-ready.js.map +1 -1
- package/dist/route-manifest.d.ts +25 -2
- package/dist/route-manifest.d.ts.map +1 -1
- package/dist/route-manifest.js +48 -4
- package/dist/route-manifest.js.map +1 -1
- package/dist/run-until-stopped.d.ts +12 -0
- package/dist/run-until-stopped.d.ts.map +1 -0
- package/dist/run-until-stopped.js +42 -0
- package/dist/run-until-stopped.js.map +1 -0
- package/dist/schema-ast-v2.d.ts +2 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/schema-push-lock.d.ts.map +1 -1
- package/dist/schema-push-lock.js +59 -46
- package/dist/schema-push-lock.js.map +1 -1
- package/dist/schema-sources.d.ts +19 -4
- package/dist/schema-sources.d.ts.map +1 -1
- package/dist/schema-sources.js +56 -35
- package/dist/schema-sources.js.map +1 -1
- package/dist/seed-auth-connect.d.ts +14 -0
- package/dist/seed-auth-connect.d.ts.map +1 -0
- package/dist/seed-auth-connect.js +97 -0
- package/dist/seed-auth-connect.js.map +1 -0
- package/dist/seed-runner.d.ts.map +1 -1
- package/dist/seed-runner.js +22 -1
- package/dist/seed-runner.js.map +1 -1
- package/dist/seed.d.ts +6 -3
- package/dist/seed.d.ts.map +1 -1
- package/dist/self-host-compose.d.ts +44 -29
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +311 -159
- package/dist/self-host-compose.js.map +1 -1
- package/dist/service-role-key-file.d.ts +32 -0
- package/dist/service-role-key-file.d.ts.map +1 -0
- package/dist/service-role-key-file.js +90 -0
- package/dist/service-role-key-file.js.map +1 -0
- package/dist/shell-ports.d.ts +13 -2
- package/dist/shell-ports.d.ts.map +1 -1
- package/dist/shell-ports.js +20 -15
- package/dist/shell-ports.js.map +1 -1
- package/dist/stop-signals.d.ts +7 -0
- package/dist/stop-signals.d.ts.map +1 -0
- package/dist/stop-signals.js +12 -0
- package/dist/stop-signals.js.map +1 -0
- package/dist/storage-launch.d.ts +11 -0
- package/dist/storage-launch.d.ts.map +1 -0
- package/dist/storage-launch.js +41 -0
- package/dist/storage-launch.js.map +1 -0
- package/dist/storage-provision.d.ts +50 -5
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +101 -33
- package/dist/storage-provision.js.map +1 -1
- package/dist/systemd.d.ts +1 -1
- package/dist/systemd.d.ts.map +1 -1
- package/dist/systemd.js +26 -11
- package/dist/systemd.js.map +1 -1
- package/dist/tar-reader.d.ts +29 -0
- package/dist/tar-reader.d.ts.map +1 -0
- package/dist/tar-reader.js +99 -0
- package/dist/tar-reader.js.map +1 -0
- package/dist/target-client.d.ts +14 -1
- package/dist/target-client.d.ts.map +1 -1
- package/dist/target-client.js +134 -23
- package/dist/target-client.js.map +1 -1
- package/dist/target-request.d.ts +25 -0
- package/dist/target-request.d.ts.map +1 -0
- package/dist/target-request.js +33 -0
- package/dist/target-request.js.map +1 -0
- package/dist/target-warning.d.ts +7 -0
- package/dist/target-warning.d.ts.map +1 -0
- package/dist/target-warning.js +12 -0
- package/dist/target-warning.js.map +1 -0
- package/dist/tsx-runner.d.ts.map +1 -1
- package/dist/tsx-runner.js +2 -1
- package/dist/tsx-runner.js.map +1 -1
- package/dist/type-extractor.d.ts +6 -0
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +138 -70
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/clack.d.ts.map +1 -1
- package/dist/ui/clack.js +11 -1
- package/dist/ui/clack.js.map +1 -1
- package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
- package/dist/ui/dev/DevDashboard.js +13 -5
- package/dist/ui/dev/DevDashboard.js.map +1 -1
- package/dist/ui/fatal.d.ts.map +1 -1
- package/dist/ui/fatal.js +6 -7
- package/dist/ui/fatal.js.map +1 -1
- package/dist/ui/flows/FlowApp.d.ts.map +1 -1
- package/dist/ui/flows/FlowApp.js +16 -1
- package/dist/ui/flows/FlowApp.js.map +1 -1
- package/dist/ui/flows/prompt-fields.d.ts +16 -6
- package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
- package/dist/ui/flows/prompt-fields.js +19 -9
- package/dist/ui/flows/prompt-fields.js.map +1 -1
- package/dist/ui/messages.d.ts +6 -0
- package/dist/ui/messages.d.ts.map +1 -1
- package/dist/ui/messages.js +17 -0
- package/dist/ui/messages.js.map +1 -1
- package/dist/ui/progress.d.ts +7 -0
- package/dist/ui/progress.d.ts.map +1 -1
- package/dist/ui/progress.js +22 -8
- package/dist/ui/progress.js.map +1 -1
- package/dist/ui/runtime/command-chrome.d.ts.map +1 -1
- package/dist/ui/runtime/command-chrome.js +2 -0
- package/dist/ui/runtime/command-chrome.js.map +1 -1
- package/dist/ui/runtime/prompt-interrupt.d.ts +10 -0
- package/dist/ui/runtime/prompt-interrupt.d.ts.map +1 -0
- package/dist/ui/runtime/prompt-interrupt.js +24 -0
- package/dist/ui/runtime/prompt-interrupt.js.map +1 -0
- package/dist/ui/runtime/run-clack-flow.d.ts.map +1 -1
- package/dist/ui/runtime/run-clack-flow.js +5 -2
- package/dist/ui/runtime/run-clack-flow.js.map +1 -1
- package/dist/ui/runtime/stdin-after-ink.d.ts +14 -1
- package/dist/ui/runtime/stdin-after-ink.d.ts.map +1 -1
- package/dist/ui/runtime/stdin-after-ink.js +44 -3
- package/dist/ui/runtime/stdin-after-ink.js.map +1 -1
- package/dist/url-safe-passwords.d.ts +25 -0
- package/dist/url-safe-passwords.d.ts.map +1 -0
- package/dist/url-safe-passwords.js +70 -0
- package/dist/url-safe-passwords.js.map +1 -0
- package/dist/valkey-sidecar.d.ts +33 -6
- package/dist/valkey-sidecar.d.ts.map +1 -1
- package/dist/valkey-sidecar.js +90 -61
- package/dist/valkey-sidecar.js.map +1 -1
- package/dist/worker-module-files.d.ts +3 -0
- package/dist/worker-module-files.d.ts.map +1 -0
- package/dist/worker-module-files.js +18 -0
- package/dist/worker-module-files.js.map +1 -0
- package/package.json +22 -16
- package/dist/functions-router-gen.d.ts.map +0 -1
- package/dist/functions-router-gen.js +0 -302
- package/dist/functions-router-gen.js.map +0 -1
package/dist/commands/init.js
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
const projectName =
|
|
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
|
|
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
|
-
|
|
301
|
-
|
|
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
|
-
|
|
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
|
-
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
|
|
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 =
|
|
376
|
-
|
|
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
|
-
|
|
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
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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 =
|
|
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(
|
|
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",
|
|
484
|
+
write("package.json", scaffoldPackageJson(opts, deps));
|
|
471
485
|
}
|
|
472
486
|
else {
|
|
473
|
-
|
|
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
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
529
|
-
if (
|
|
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
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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 (
|
|
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
|
|
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:
|
|
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
|
-
|
|
722
|
-
|
|
723
|
-
|
|
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, ">")
|
|
777
797
|
.replace(/"/g, """);
|
|
778
798
|
}
|
|
779
|
-
|
|
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
|
|
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
|
-
|
|
981
|
-
|
|
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=${
|
|
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
|
|
1051
|
+
SITE_URL=${initSiteUrl(opts)}`);
|
|
1006
1052
|
if (opts.provider === "docker" && opts.kongPort !== undefined) {
|
|
1007
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
-
|
|
1042
|
-
|
|
1090
|
+
SUPATYPE_RESEND_API_KEY=
|
|
1091
|
+
SUPATYPE_RESEND_FROM=onboarding@resend.dev`;
|
|
1043
1092
|
case "ses":
|
|
1044
1093
|
return `# Email (Amazon SES)
|
|
1045
|
-
|
|
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
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
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
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
1269
|
+
const { name } = args;
|
|
1192
1270
|
info(`Supatype project ready${name ? ` in ${name}/` : ""}.`);
|
|
1193
|
-
|
|
1194
|
-
|
|
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
|
-
/**
|
|
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
|
|
1308
|
+
steps.push("supatype update # download component binaries");
|
|
1207
1309
|
if (!keysGenerated)
|
|
1208
1310
|
steps.push("supatype keys");
|
|
1209
1311
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
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("
|
|
1339
|
+
steps.push(...commented(runScriptCommand(result.packageManager, "functions"), ["run edge functions locally"]));
|
|
1222
1340
|
}
|
|
1223
1341
|
return steps;
|
|
1224
1342
|
}
|
|
1225
|
-
/**
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
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
|
-
|
|
1241
|
-
"
|
|
1242
|
-
"supatype link --env production --project <ref>",
|
|
1243
|
-
|
|
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
|
-
|
|
1248
|
-
|
|
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
|
-
|
|
1371
|
+
return undefined;
|
|
1252
1372
|
}
|
|
1253
|
-
/**
|
|
1254
|
-
|
|
1255
|
-
|
|
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
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
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
|
-
|
|
1272
|
-
|
|
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
|