rwsdk 0.1.16 → 0.1.17
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/dist/lib/$.d.mts +8 -0
- package/dist/lib/$.mjs +5 -0
- package/dist/lib/compileTsModule.d.mts +1 -0
- package/dist/lib/compileTsModule.mjs +27 -0
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.mjs +6 -0
- package/dist/lib/findWranglerConfig.d.mts +1 -0
- package/dist/lib/findWranglerConfig.mjs +12 -0
- package/dist/lib/getShortName.d.mts +1 -0
- package/dist/lib/getShortName.mjs +2 -0
- package/dist/lib/getSrcPaths.d.ts +15 -0
- package/dist/lib/getSrcPaths.js +80 -0
- package/dist/lib/hasPkgScript.d.mts +1 -0
- package/dist/lib/hasPkgScript.mjs +9 -0
- package/dist/lib/jsonUtils.d.mts +28 -0
- package/dist/lib/jsonUtils.mjs +167 -0
- package/dist/lib/setupEnvFiles.d.mts +4 -0
- package/dist/lib/setupEnvFiles.mjs +31 -0
- package/dist/lib/smokeTests/artifacts.d.mts +10 -0
- package/dist/lib/smokeTests/artifacts.mjs +164 -0
- package/dist/lib/smokeTests/browser.d.mts +48 -0
- package/dist/lib/smokeTests/browser.mjs +1041 -0
- package/dist/lib/smokeTests/cleanup.d.mts +5 -0
- package/dist/lib/smokeTests/cleanup.mjs +214 -0
- package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
- package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
- package/dist/lib/smokeTests/constants.d.mts +5 -0
- package/dist/lib/smokeTests/constants.mjs +10 -0
- package/dist/lib/smokeTests/development.d.mts +11 -0
- package/dist/lib/smokeTests/development.mjs +209 -0
- package/dist/lib/smokeTests/environment.d.mts +14 -0
- package/dist/lib/smokeTests/environment.mjs +163 -0
- package/dist/lib/smokeTests/release.d.mts +61 -0
- package/dist/lib/smokeTests/release.mjs +526 -0
- package/dist/lib/smokeTests/reporting.d.mts +13 -0
- package/dist/lib/smokeTests/reporting.mjs +355 -0
- package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
- package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
- package/dist/lib/smokeTests/state.d.mts +48 -0
- package/dist/lib/smokeTests/state.mjs +57 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
- package/dist/lib/smokeTests/types.d.mts +75 -0
- package/dist/lib/smokeTests/types.mjs +1 -0
- package/dist/lib/smokeTests/utils.d.mts +15 -0
- package/dist/lib/smokeTests/utils.mjs +147 -0
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +35 -0
- package/dist/llms/rules/interruptors.d.ts +1 -0
- package/dist/llms/rules/interruptors.js +243 -0
- package/dist/llms/rules/middleware.d.ts +1 -0
- package/dist/llms/rules/middleware.js +71 -0
- package/dist/llms/rules/react.d.ts +1 -0
- package/dist/llms/rules/react.js +106 -0
- package/dist/llms/rules/request-response.d.ts +1 -0
- package/dist/llms/rules/request-response.js +209 -0
- package/dist/runtime/client.d.ts +17 -0
- package/dist/runtime/client.js +74 -0
- package/dist/runtime/clientNavigation.d.ts +4 -0
- package/dist/runtime/clientNavigation.js +53 -0
- package/dist/runtime/clientNavigation.test.d.ts +1 -0
- package/dist/runtime/clientNavigation.test.js +55 -0
- package/dist/runtime/constants.d.ts +1 -0
- package/dist/runtime/constants.js +1 -0
- package/dist/runtime/entries/auth.d.ts +1 -0
- package/dist/runtime/entries/auth.js +1 -0
- package/dist/runtime/entries/client.d.ts +4 -0
- package/dist/runtime/entries/client.js +4 -0
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +1 -0
- package/dist/runtime/entries/navigation.d.ts +1 -0
- package/dist/runtime/entries/navigation.js +1 -0
- package/dist/runtime/entries/no-react-server.d.ts +0 -0
- package/dist/runtime/entries/no-react-server.js +2 -0
- package/dist/runtime/entries/react-server-only.d.ts +0 -0
- package/dist/runtime/entries/react-server-only.js +2 -0
- package/dist/runtime/entries/router.d.ts +2 -0
- package/dist/runtime/entries/router.js +2 -0
- package/dist/runtime/entries/ssr.d.ts +1 -0
- package/dist/runtime/entries/ssr.js +1 -0
- package/dist/runtime/entries/worker.d.ts +9 -0
- package/dist/runtime/entries/worker.js +9 -0
- package/dist/runtime/error.d.ts +6 -0
- package/dist/runtime/error.js +8 -0
- package/dist/runtime/imports/ClientOnly.d.ts +3 -0
- package/dist/runtime/imports/ClientOnly.js +8 -0
- package/dist/runtime/imports/client.d.ts +4 -0
- package/dist/runtime/imports/client.js +33 -0
- package/dist/runtime/imports/ssr.d.ts +5 -0
- package/dist/runtime/imports/ssr.js +20 -0
- package/dist/runtime/imports/worker.d.ts +5 -0
- package/dist/runtime/imports/worker.js +22 -0
- package/dist/runtime/lib/auth/index.d.ts +1 -0
- package/dist/runtime/lib/auth/index.js +1 -0
- package/dist/runtime/lib/auth/session.d.ts +50 -0
- package/dist/runtime/lib/auth/session.js +148 -0
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
- package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
- package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
- package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
- package/dist/runtime/lib/db/createDb.d.ts +2 -0
- package/dist/runtime/lib/db/createDb.js +33 -0
- package/dist/runtime/lib/db/index.d.ts +4 -0
- package/dist/runtime/lib/db/index.js +3 -0
- package/dist/runtime/lib/db/migrations.d.ts +23 -0
- package/dist/runtime/lib/db/migrations.js +34 -0
- package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/assert.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
- package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/database.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
- package/dist/runtime/lib/db/typeInference/utils.js +2 -0
- package/dist/runtime/lib/debug.d.ts +2 -0
- package/dist/runtime/lib/debug.js +36 -0
- package/dist/runtime/lib/links.d.ts +14 -0
- package/dist/runtime/lib/links.js +38 -0
- package/dist/runtime/lib/realtime/client.d.ts +7 -0
- package/dist/runtime/lib/realtime/client.js +166 -0
- package/dist/runtime/lib/realtime/constants.d.ts +1 -0
- package/dist/runtime/lib/realtime/constants.js +1 -0
- package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
- package/dist/runtime/lib/realtime/durableObject.js +187 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
- package/dist/runtime/lib/realtime/shared.d.ts +10 -0
- package/dist/runtime/lib/realtime/shared.js +10 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
- package/dist/runtime/lib/realtime/worker.d.ts +3 -0
- package/dist/runtime/lib/realtime/worker.js +16 -0
- package/dist/runtime/lib/router.d.ts +56 -0
- package/dist/runtime/lib/router.js +210 -0
- package/dist/runtime/lib/router.test.d.ts +1 -0
- package/dist/runtime/lib/router.test.js +58 -0
- package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
- package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
- package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
- package/dist/runtime/lib/turnstile/turnstile.js +3 -0
- package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
- package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
- package/dist/runtime/lib/utils.d.ts +1 -0
- package/dist/runtime/lib/utils.js +1 -0
- package/dist/runtime/register/client.d.ts +1 -0
- package/dist/runtime/register/client.js +5 -0
- package/dist/runtime/register/ssr.d.ts +3 -0
- package/dist/runtime/register/ssr.js +26 -0
- package/dist/runtime/register/worker.d.ts +4 -0
- package/dist/runtime/register/worker.js +42 -0
- package/dist/runtime/render/createClientManifest.d.ts +1 -0
- package/dist/runtime/render/createClientManifest.js +7 -0
- package/dist/runtime/render/createModuleMap.d.ts +1 -0
- package/dist/runtime/render/createModuleMap.js +13 -0
- package/dist/runtime/render/injectRSCPayload.d.ts +3 -0
- package/dist/runtime/render/injectRSCPayload.js +79 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
- package/dist/runtime/render/renderToRscStream.d.ts +5 -0
- package/dist/runtime/render/renderToRscStream.js +46 -0
- package/dist/runtime/render/renderToStream.d.ts +9 -0
- package/dist/runtime/render/renderToStream.js +27 -0
- package/dist/runtime/render/renderToString.d.ts +7 -0
- package/dist/runtime/render/renderToString.js +26 -0
- package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
- package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
- package/dist/runtime/requestInfo/types.d.ts +11 -0
- package/dist/runtime/requestInfo/types.js +1 -0
- package/dist/runtime/requestInfo/worker.d.ts +5 -0
- package/dist/runtime/requestInfo/worker.js +33 -0
- package/dist/runtime/script.d.ts +5 -0
- package/dist/runtime/script.js +8 -0
- package/dist/runtime/ssrBridge.d.ts +2 -0
- package/dist/runtime/ssrBridge.js +11 -0
- package/dist/runtime/worker.d.ts +18 -0
- package/dist/runtime/worker.js +173 -0
- package/dist/scripts/__sdk.d.mts +1 -0
- package/dist/scripts/__sdk.mjs +14 -0
- package/dist/scripts/build-vendor-bundles.d.mts +1 -0
- package/dist/scripts/build-vendor-bundles.mjs +92 -0
- package/dist/scripts/debug-sync.d.mts +6 -0
- package/dist/scripts/debug-sync.mjs +224 -0
- package/dist/scripts/dev-init.d.mts +1 -0
- package/dist/scripts/dev-init.mjs +25 -0
- package/dist/scripts/ensure-deploy-env.d.mts +1 -0
- package/dist/scripts/ensure-deploy-env.mjs +271 -0
- package/dist/scripts/ensure-env.d.mts +1 -0
- package/dist/scripts/ensure-env.mjs +9 -0
- package/dist/scripts/migrate-new.d.mts +1 -0
- package/dist/scripts/migrate-new.mjs +51 -0
- package/dist/scripts/smoke-test.d.mts +1 -0
- package/dist/scripts/smoke-test.mjs +166 -0
- package/dist/scripts/worker-run.d.mts +1 -0
- package/dist/scripts/worker-run.mjs +82 -0
- package/dist/vite/aliasByEnvPlugin.d.mts +2 -0
- package/dist/vite/aliasByEnvPlugin.mjs +11 -0
- package/dist/vite/asyncSetupPlugin.d.mts +6 -0
- package/dist/vite/asyncSetupPlugin.mjs +23 -0
- package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
- package/dist/vite/checkIsUsingPrisma.mjs +18 -0
- package/dist/vite/configPlugin.d.mts +9 -0
- package/dist/vite/configPlugin.mjs +169 -0
- package/dist/vite/copyPrismaWasmPlugin.d.mts +4 -0
- package/dist/vite/copyPrismaWasmPlugin.mjs +32 -0
- package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
- package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
- package/dist/vite/customReactBuildPlugin.d.mts +4 -0
- package/dist/vite/customReactBuildPlugin.mjs +61 -0
- package/dist/vite/devServerTimingPlugin.d.mts +2 -0
- package/dist/vite/devServerTimingPlugin.mjs +24 -0
- package/dist/vite/directivesPlugin.d.mts +6 -0
- package/dist/vite/directivesPlugin.mjs +200 -0
- package/dist/vite/ensureAliasArray.d.mts +2 -0
- package/dist/vite/ensureAliasArray.mjs +17 -0
- package/dist/vite/findSpecifiers.d.mts +31 -0
- package/dist/vite/findSpecifiers.mjs +230 -0
- package/dist/vite/findSsrSpecifiers.d.mts +11 -0
- package/dist/vite/findSsrSpecifiers.mjs +67 -0
- package/dist/vite/hasDirective.d.mts +7 -0
- package/dist/vite/hasDirective.mjs +54 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
- package/dist/vite/index.d.mts +1 -0
- package/dist/vite/index.mjs +1 -0
- package/dist/vite/injectHmrPreambleJsxPlugin.d.mts +2 -0
- package/dist/vite/injectHmrPreambleJsxPlugin.mjs +22 -0
- package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
- package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
- package/dist/vite/invalidateModule.d.mts +6 -0
- package/dist/vite/invalidateModule.mjs +30 -0
- package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
- package/dist/vite/miniflareHMRPlugin.mjs +209 -0
- package/dist/vite/miniflarePlugin.d.mts +9 -0
- package/dist/vite/miniflarePlugin.mjs +135 -0
- package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
- package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
- package/dist/vite/normalizeModulePath.d.mts +1 -0
- package/dist/vite/normalizeModulePath.mjs +13 -0
- package/dist/vite/prismaPlugin.d.mts +4 -0
- package/dist/vite/prismaPlugin.mjs +43 -0
- package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
- package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
- package/dist/vite/redwoodPlugin.d.mts +12 -0
- package/dist/vite/redwoodPlugin.mjs +105 -0
- package/dist/vite/requestUtils.d.mts +6 -0
- package/dist/vite/requestUtils.mjs +35 -0
- package/dist/vite/setupEnvFiles.d.mts +4 -0
- package/dist/vite/setupEnvFiles.mjs +31 -0
- package/dist/vite/ssrBridgePlugin.d.mts +7 -0
- package/dist/vite/ssrBridgePlugin.mjs +137 -0
- package/dist/vite/transformClientComponents.d.mts +12 -0
- package/dist/vite/transformClientComponents.mjs +116 -0
- package/dist/vite/transformClientComponents.test.d.mts +1 -0
- package/dist/vite/transformClientComponents.test.mjs +264 -0
- package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
- package/dist/vite/transformServerFunctions.d.mts +16 -0
- package/dist/vite/transformServerFunctions.mjs +296 -0
- package/dist/vite/transformServerFunctions.test.d.mts +1 -0
- package/dist/vite/transformServerFunctions.test.mjs +124 -0
- package/dist/vite/useClientLookupPlugin.d.mts +5 -0
- package/dist/vite/useClientLookupPlugin.mjs +15 -0
- package/dist/vite/useClientPlugin.d.mts +8 -0
- package/dist/vite/useClientPlugin.mjs +295 -0
- package/dist/vite/useClientPlugin.test.d.mts +1 -0
- package/dist/vite/useClientPlugin.test.mjs +1204 -0
- package/dist/vite/useServerLookupPlugin.d.mts +5 -0
- package/dist/vite/useServerLookupPlugin.mjs +15 -0
- package/dist/vite/useServerPlugin.d.mts +1 -0
- package/dist/vite/useServerPlugin.mjs +1 -0
- package/dist/vite/virtualPlugin.d.mts +2 -0
- package/dist/vite/virtualPlugin.mjs +18 -0
- package/dist/vite/vitePreamblePlugin.d.mts +1 -0
- package/dist/vite/vitePreamblePlugin.mjs +11 -0
- package/dist/worker/__ssr_bridge.js +8947 -0
- package/dist/worker/__ssr_bridge.js.map +1 -0
- package/package.json +1 -1
- package/dist/vite/invalidateClientModule.d.mts +0 -2
- package/dist/vite/invalidateClientModule.mjs +0 -8
- package/dist/vite/invalidateModule copy.d.mts +0 -2
- package/dist/vite/invalidateModule copy.mjs +0 -14
- package/dist/vite/invalidateSSRModule.d.mts +0 -2
- package/dist/vite/invalidateSSRModule.mjs +0 -7
- package/dist/vite/mode.d.mts +0 -5
- package/dist/vite/mode.mjs +0 -25
- package/dist/vite/modePlugin.d.mts +0 -2
- package/dist/vite/modePlugin.mjs +0 -10
- /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
- /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { $ } from "execa";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import chokidar from "chokidar";
|
|
7
|
+
import { lock } from "proper-lockfile";
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const getPackageManagerInfo = (targetDir) => {
|
|
10
|
+
const pnpmResult = {
|
|
11
|
+
name: "pnpm",
|
|
12
|
+
lockFile: "pnpm-lock.yaml",
|
|
13
|
+
command: "add",
|
|
14
|
+
};
|
|
15
|
+
if (existsSync(path.join(targetDir, "yarn.lock"))) {
|
|
16
|
+
return { name: "yarn", lockFile: "yarn.lock", command: "add" };
|
|
17
|
+
}
|
|
18
|
+
if (existsSync(path.join(targetDir, "pnpm-lock.yaml"))) {
|
|
19
|
+
return pnpmResult;
|
|
20
|
+
}
|
|
21
|
+
if (existsSync(path.join(targetDir, "package-lock.json"))) {
|
|
22
|
+
return { name: "npm", lockFile: "package-lock.json", command: "install" };
|
|
23
|
+
}
|
|
24
|
+
return pnpmResult;
|
|
25
|
+
};
|
|
26
|
+
const performFullSync = async (sdkDir, targetDir) => {
|
|
27
|
+
console.log("📦 Packing SDK...");
|
|
28
|
+
const packResult = await $ `npm pack`;
|
|
29
|
+
const tarballName = packResult.stdout?.trim() ?? "";
|
|
30
|
+
if (!tarballName) {
|
|
31
|
+
console.error("❌ Failed to get tarball name from npm pack.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const tarballPath = path.resolve(sdkDir, tarballName);
|
|
35
|
+
console.log(`💿 Installing ${tarballName} in ${targetDir}...`);
|
|
36
|
+
const pm = getPackageManagerInfo(targetDir);
|
|
37
|
+
const packageJsonPath = path.join(targetDir, "package.json");
|
|
38
|
+
const lockfilePath = path.join(targetDir, pm.lockFile);
|
|
39
|
+
const originalPackageJson = await fs
|
|
40
|
+
.readFile(packageJsonPath, "utf-8")
|
|
41
|
+
.catch(() => null);
|
|
42
|
+
const originalLockfile = await fs
|
|
43
|
+
.readFile(lockfilePath, "utf-8")
|
|
44
|
+
.catch(() => null);
|
|
45
|
+
try {
|
|
46
|
+
const cmd = pm.name;
|
|
47
|
+
const args = [pm.command];
|
|
48
|
+
if (pm.name === "yarn") {
|
|
49
|
+
args.push(`file:${tarballPath}`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
args.push(tarballPath);
|
|
53
|
+
}
|
|
54
|
+
await $(cmd, args, {
|
|
55
|
+
cwd: targetDir,
|
|
56
|
+
stdio: "inherit",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
if (originalPackageJson) {
|
|
61
|
+
console.log("Restoring package.json...");
|
|
62
|
+
await fs.writeFile(packageJsonPath, originalPackageJson);
|
|
63
|
+
}
|
|
64
|
+
if (originalLockfile) {
|
|
65
|
+
console.log(`Restoring ${pm.lockFile}...`);
|
|
66
|
+
await fs.writeFile(lockfilePath, originalLockfile);
|
|
67
|
+
}
|
|
68
|
+
await fs.unlink(tarballPath).catch(() => {
|
|
69
|
+
// ignore if deletion fails
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const performFastSync = async (sdkDir, targetDir) => {
|
|
74
|
+
console.log("⚡️ No dependency changes, performing fast sync...");
|
|
75
|
+
const sdkPackageJson = JSON.parse(await fs.readFile(path.join(sdkDir, "package.json"), "utf-8"));
|
|
76
|
+
const filesToSync = sdkPackageJson.files || [];
|
|
77
|
+
for (const file of filesToSync) {
|
|
78
|
+
const source = path.join(sdkDir, file);
|
|
79
|
+
const destination = path.join(targetDir, "node_modules/rwsdk", file);
|
|
80
|
+
if (existsSync(source)) {
|
|
81
|
+
await fs.cp(source, destination, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Always copy package.json
|
|
85
|
+
await fs.copyFile(path.join(sdkDir, "package.json"), path.join(targetDir, "node_modules/rwsdk/package.json"));
|
|
86
|
+
};
|
|
87
|
+
const performSync = async (sdkDir, targetDir) => {
|
|
88
|
+
console.log("🏗️ Rebuilding SDK...");
|
|
89
|
+
await $ `pnpm build`;
|
|
90
|
+
const sdkPackageJsonPath = path.join(sdkDir, "package.json");
|
|
91
|
+
const installedSdkPackageJsonPath = path.join(targetDir, "node_modules/rwsdk/package.json");
|
|
92
|
+
let packageJsonChanged = true;
|
|
93
|
+
if (existsSync(installedSdkPackageJsonPath)) {
|
|
94
|
+
const sdkPackageJsonContent = await fs.readFile(sdkPackageJsonPath, "utf-8");
|
|
95
|
+
const installedSdkPackageJsonContent = await fs.readFile(installedSdkPackageJsonPath, "utf-8");
|
|
96
|
+
if (sdkPackageJsonContent === installedSdkPackageJsonContent) {
|
|
97
|
+
packageJsonChanged = false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (packageJsonChanged) {
|
|
101
|
+
console.log("📦 package.json changed, performing full sync...");
|
|
102
|
+
await performFullSync(sdkDir, targetDir);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await performFastSync(sdkDir, targetDir);
|
|
106
|
+
}
|
|
107
|
+
console.log("✅ Done syncing");
|
|
108
|
+
};
|
|
109
|
+
export const debugSync = async (opts) => {
|
|
110
|
+
const { targetDir, sdkDir = process.cwd(), watch } = opts;
|
|
111
|
+
if (!targetDir) {
|
|
112
|
+
console.error("❌ Please provide a target directory as an argument.");
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
// If not in watch mode, just do a one-time sync and exit.
|
|
116
|
+
if (!watch) {
|
|
117
|
+
await performSync(sdkDir, targetDir);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// --- Watch Mode Logic ---
|
|
121
|
+
const lockfilePath = path.join(targetDir, "node_modules", ".rwsync.lock");
|
|
122
|
+
let release;
|
|
123
|
+
// Ensure the directory for the lockfile exists
|
|
124
|
+
await fs.mkdir(path.dirname(lockfilePath), { recursive: true });
|
|
125
|
+
// "Touch" the file to ensure it exists before locking
|
|
126
|
+
await fs.appendFile(lockfilePath, "").catch(() => { });
|
|
127
|
+
try {
|
|
128
|
+
release = await lock(lockfilePath, { retries: 0 });
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
if (e.code === "ELOCKED") {
|
|
132
|
+
console.error(`❌ Another rwsync process is already watching ${targetDir}.`);
|
|
133
|
+
console.error(` If this is not correct, please remove the lockfile at ${lockfilePath}`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
// Initial sync for watch mode. We do it *after* acquiring the lock.
|
|
139
|
+
let initialSyncOk = false;
|
|
140
|
+
try {
|
|
141
|
+
await performSync(sdkDir, targetDir);
|
|
142
|
+
initialSyncOk = true;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error("❌ Initial sync failed:", error);
|
|
146
|
+
console.log(" Still watching for changes...");
|
|
147
|
+
}
|
|
148
|
+
const filesToWatch = [
|
|
149
|
+
path.join(sdkDir, "src"),
|
|
150
|
+
path.join(sdkDir, "types"),
|
|
151
|
+
path.join(sdkDir, "bin"),
|
|
152
|
+
path.join(sdkDir, "package.json"),
|
|
153
|
+
];
|
|
154
|
+
console.log("👀 Watching for changes...");
|
|
155
|
+
let childProc = null;
|
|
156
|
+
const runWatchedCommand = () => {
|
|
157
|
+
if (typeof watch === "string") {
|
|
158
|
+
console.log(`\n> ${watch}\n`);
|
|
159
|
+
childProc = $({
|
|
160
|
+
stdio: "inherit",
|
|
161
|
+
shell: true,
|
|
162
|
+
cwd: targetDir,
|
|
163
|
+
reject: false,
|
|
164
|
+
}) `${watch}`;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const watcher = chokidar.watch(filesToWatch, {
|
|
168
|
+
ignoreInitial: true,
|
|
169
|
+
cwd: sdkDir,
|
|
170
|
+
});
|
|
171
|
+
watcher.on("all", async () => {
|
|
172
|
+
console.log("\nDetected change, re-syncing...");
|
|
173
|
+
if (childProc && !childProc.killed) {
|
|
174
|
+
console.log("Stopping running process...");
|
|
175
|
+
childProc.kill();
|
|
176
|
+
await childProc.catch(() => {
|
|
177
|
+
/* ignore kill errors */
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
await performSync(sdkDir, targetDir);
|
|
182
|
+
runWatchedCommand();
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
console.error("❌ Sync failed:", error);
|
|
186
|
+
console.log(" Still watching for changes...");
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
const cleanup = async () => {
|
|
190
|
+
console.log("\nCleaning up...");
|
|
191
|
+
if (childProc && !childProc.killed) {
|
|
192
|
+
childProc.kill();
|
|
193
|
+
}
|
|
194
|
+
await release();
|
|
195
|
+
process.exit();
|
|
196
|
+
};
|
|
197
|
+
process.on("SIGINT", cleanup);
|
|
198
|
+
process.on("SIGTERM", cleanup);
|
|
199
|
+
if (initialSyncOk) {
|
|
200
|
+
runWatchedCommand();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
204
|
+
const args = process.argv.slice(2);
|
|
205
|
+
const watchFlagIndex = args.indexOf("--watch");
|
|
206
|
+
let watchCmd = watchFlagIndex !== -1;
|
|
207
|
+
let cmdArgs = args;
|
|
208
|
+
if (watchFlagIndex !== -1) {
|
|
209
|
+
if (watchFlagIndex + 1 < args.length &&
|
|
210
|
+
!args[watchFlagIndex + 1].startsWith("--")) {
|
|
211
|
+
watchCmd = args[watchFlagIndex + 1];
|
|
212
|
+
}
|
|
213
|
+
// remove --watch and its potential command from args
|
|
214
|
+
const watchArgCount = typeof watchCmd === "string" ? 2 : 1;
|
|
215
|
+
cmdArgs = args.filter((_, i) => i < watchFlagIndex || i >= watchFlagIndex + watchArgCount);
|
|
216
|
+
}
|
|
217
|
+
const targetDir = cmdArgs[0] ?? process.cwd();
|
|
218
|
+
const sdkDir = path.resolve(__dirname, "..", "..");
|
|
219
|
+
debugSync({
|
|
220
|
+
targetDir,
|
|
221
|
+
sdkDir,
|
|
222
|
+
watch: watchCmd,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initDev: () => Promise<never>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { $ } from "../lib/$.mjs";
|
|
2
|
+
import { hasPkgScript } from "../lib/hasPkgScript.mjs";
|
|
3
|
+
export const initDev = async () => {
|
|
4
|
+
console.log("Initializing development environment...");
|
|
5
|
+
const projectRootDir = process.cwd();
|
|
6
|
+
if (await hasPkgScript(projectRootDir, "generate")) {
|
|
7
|
+
console.log("Generating...");
|
|
8
|
+
await $ `npm run generate`;
|
|
9
|
+
}
|
|
10
|
+
if (await hasPkgScript(projectRootDir, "migrate:dev")) {
|
|
11
|
+
console.log("Running migrations...");
|
|
12
|
+
await $ `npm run migrate:dev`;
|
|
13
|
+
}
|
|
14
|
+
if (await hasPkgScript(projectRootDir, "seed")) {
|
|
15
|
+
console.log("Seeding database...");
|
|
16
|
+
await $ `npm run seed`;
|
|
17
|
+
}
|
|
18
|
+
console.log("Done!");
|
|
19
|
+
console.log();
|
|
20
|
+
// todo(justinvdm, 01 Apr 2025): Investigate what handles are remaining open
|
|
21
|
+
process.exit(0);
|
|
22
|
+
};
|
|
23
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
24
|
+
initDev();
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ensureDeployEnv: () => Promise<never>;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { $ } from "../lib/$.mjs";
|
|
2
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { resolve, basename, join } from "path";
|
|
4
|
+
import { randomBytes } from "crypto";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
|
+
import { uniqueNamesGenerator, adjectives, animals, } from "unique-names-generator";
|
|
8
|
+
import * as readline from "readline";
|
|
9
|
+
import { pathExists } from "fs-extra";
|
|
10
|
+
import { parseJson, extractAllJson } from "../lib/jsonUtils.mjs";
|
|
11
|
+
const promptForDeployment = async () => {
|
|
12
|
+
const rl = readline.createInterface({
|
|
13
|
+
input: process.stdin,
|
|
14
|
+
output: process.stdout,
|
|
15
|
+
});
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
// Handle Ctrl+C (SIGINT)
|
|
18
|
+
rl.on('SIGINT', () => {
|
|
19
|
+
rl.close();
|
|
20
|
+
console.log('\nDeployment cancelled.');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
});
|
|
23
|
+
rl.question("Do you want to proceed with deployment? (y/N): ", (answer) => {
|
|
24
|
+
rl.close();
|
|
25
|
+
resolve(answer.toLowerCase() === "y");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const generateSecretKey = () => {
|
|
30
|
+
return randomBytes(32).toString("base64");
|
|
31
|
+
};
|
|
32
|
+
const hasWebAuthn = async () => {
|
|
33
|
+
const files = await glob("src/**/*.{ts,tsx}", { ignore: "node_modules/**" });
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
const content = await readFile(file, "utf-8");
|
|
36
|
+
if (content.includes("WEBAUTHN")) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
const hasD1Database = async () => {
|
|
43
|
+
const files = await glob("src/**/*.{ts,tsx}", { ignore: "node_modules/**" });
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
const content = await readFile(file, "utf-8");
|
|
46
|
+
if (content.includes("env.DB")) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
const hasAuthUsage = async () => {
|
|
53
|
+
const files = await glob("src/**/*.{ts,tsx}", { ignore: "node_modules/**" });
|
|
54
|
+
for (const file of files) {
|
|
55
|
+
const content = await readFile(file, "utf-8");
|
|
56
|
+
if (content.includes("rwsdk/auth")) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
export const ensureDeployEnv = async () => {
|
|
63
|
+
const shouldDeploy = await promptForDeployment();
|
|
64
|
+
if (!shouldDeploy) {
|
|
65
|
+
console.log("Deployment cancelled.");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
console.log("Ensuring deployment environment is ready...");
|
|
69
|
+
const pkg = JSON.parse(await readFile(resolve(process.cwd(), "package.json"), "utf-8"));
|
|
70
|
+
// Read wrangler config
|
|
71
|
+
const wranglerPath = resolve(process.cwd(), "wrangler.jsonc");
|
|
72
|
+
const wranglerConfig = parseJsonc(await readFile(wranglerPath, "utf-8"));
|
|
73
|
+
// Update wrangler name if needed
|
|
74
|
+
if (wranglerConfig.name === "__change_me__" ||
|
|
75
|
+
process.env.RWSDK_RENAME_WORKER === "1") {
|
|
76
|
+
const dirName = basename(process.cwd());
|
|
77
|
+
wranglerConfig.name = dirName;
|
|
78
|
+
console.log(`Set wrangler name to ${dirName}`);
|
|
79
|
+
await writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
|
|
80
|
+
console.log("Updated wrangler.jsonc configuration");
|
|
81
|
+
}
|
|
82
|
+
if (process.env.CLOUDFLARE_ACCOUNT_ID == null ||
|
|
83
|
+
process.env.CLOUDFLARE_API_TOKEN == null) {
|
|
84
|
+
// Trigger account selection prompt if needed
|
|
85
|
+
console.log("Checking Cloudflare account setup...");
|
|
86
|
+
const accountCachePath = join(process.cwd(), "node_modules/.cache/wrangler/wrangler-account.json");
|
|
87
|
+
// todo(justinvdm): this is a hack to force the account selection prompt,
|
|
88
|
+
// we need to find a better way
|
|
89
|
+
if (!(await pathExists(accountCachePath))) {
|
|
90
|
+
await $({ stdio: "inherit" }) `npx wrangler d1 list --json`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Create a no-op secret to ensure worker exists
|
|
94
|
+
console.log(`Ensuring worker ${wranglerConfig.name} exists...`);
|
|
95
|
+
await $({ stdio: "pipe" }) `echo "true"`
|
|
96
|
+
.pipe `npx wrangler secret put TMP_WORKER_CREATED`;
|
|
97
|
+
// Check D1 database setup
|
|
98
|
+
const needsDatabase = await hasD1Database();
|
|
99
|
+
if (!needsDatabase) {
|
|
100
|
+
console.log("Skipping D1 setup - no env.DB usage detected in codebase");
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.log("Found env.DB usage, checking D1 database setup...");
|
|
104
|
+
try {
|
|
105
|
+
const existingDb = wranglerConfig.d1_databases?.find((db) => db.binding === "DB");
|
|
106
|
+
if (existingDb &&
|
|
107
|
+
existingDb.database_id !== "__change_me__" &&
|
|
108
|
+
process.env.RWSDK_RENAME_DB !== "1") {
|
|
109
|
+
console.log("D1 database already configured in wrangler.jsonc, skipping creation");
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const suffix = uniqueNamesGenerator({
|
|
113
|
+
dictionaries: [adjectives, animals],
|
|
114
|
+
separator: "-",
|
|
115
|
+
length: 2,
|
|
116
|
+
style: "lowerCase",
|
|
117
|
+
});
|
|
118
|
+
const dbName = `${wranglerConfig.name}-${suffix}`;
|
|
119
|
+
try {
|
|
120
|
+
// Create the database with real-time output so the user can see progress
|
|
121
|
+
console.log(`Creating D1 database: ${dbName}...`);
|
|
122
|
+
const createResult = await $({
|
|
123
|
+
stdio: "pipe",
|
|
124
|
+
}) `npx wrangler d1 create ${dbName}`;
|
|
125
|
+
// Log the result to the console
|
|
126
|
+
console.log(createResult.stdout);
|
|
127
|
+
// Parse all JSON objects from the output
|
|
128
|
+
const allJsonObjects = extractAllJson(createResult.stdout);
|
|
129
|
+
// First look for object with uuid directly
|
|
130
|
+
let dbInfo = { uuid: undefined, name: undefined };
|
|
131
|
+
for (const obj of allJsonObjects) {
|
|
132
|
+
if (obj && obj.uuid) {
|
|
133
|
+
dbInfo = obj;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// If not found, look for the d1_databases structure
|
|
138
|
+
if (!dbInfo.uuid) {
|
|
139
|
+
for (const obj of allJsonObjects) {
|
|
140
|
+
if (obj && obj.d1_databases && Array.isArray(obj.d1_databases)) {
|
|
141
|
+
const dbConfig = obj.d1_databases.find((db) => db.binding === "DB" || db.database_name === dbName);
|
|
142
|
+
if (dbConfig && dbConfig.database_id) {
|
|
143
|
+
dbInfo.uuid = dbConfig.database_id;
|
|
144
|
+
dbInfo.name = dbConfig.database_name || dbName;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!dbInfo.uuid) {
|
|
151
|
+
throw new Error("Failed to extract database ID from wrangler output");
|
|
152
|
+
}
|
|
153
|
+
// Update wrangler config with database info, preserving other databases
|
|
154
|
+
const existingDatabases = wranglerConfig.d1_databases || [];
|
|
155
|
+
wranglerConfig.d1_databases = [
|
|
156
|
+
...existingDatabases.filter((db) => db.binding !== "DB"),
|
|
157
|
+
{
|
|
158
|
+
binding: "DB",
|
|
159
|
+
database_name: dbName,
|
|
160
|
+
database_id: dbInfo.uuid,
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
await writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
|
|
164
|
+
console.log("Updated wrangler.jsonc configuration");
|
|
165
|
+
console.log(`D1 database configured: ${dbName} with ID: ${dbInfo.uuid}`);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error("Failed to create D1 database:", error instanceof Error ? error.message : String(error));
|
|
169
|
+
console.error("Please create it manually:");
|
|
170
|
+
console.error("1. Run: npx wrangler d1 create <your-db-name>");
|
|
171
|
+
console.error("2. Update wrangler.jsonc with the database details");
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error("Failed to create D1 database. Please create it manually:");
|
|
178
|
+
console.error("1. Run: npx wrangler d1 create <your-db-name>");
|
|
179
|
+
console.error("2. Update wrangler.jsonc with the database details");
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Check AUTH_SECRET_KEY setup
|
|
184
|
+
if (!(await hasAuthUsage())) {
|
|
185
|
+
console.log("Skipping AUTH_SECRET_KEY setup - no auth usage detected in codebase");
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
console.log("Found auth usage, checking secret setup...");
|
|
189
|
+
try {
|
|
190
|
+
// Get list of all secrets
|
|
191
|
+
const secretsResult = await $ `npx wrangler secret list --format=json`;
|
|
192
|
+
const existingSecrets = parseJson(secretsResult.stdout, []).map((secret) => secret.name);
|
|
193
|
+
// Check if AUTH_SECRET_KEY already exists
|
|
194
|
+
if (existingSecrets.includes("AUTH_SECRET_KEY")) {
|
|
195
|
+
console.log("AUTH_SECRET_KEY secret already exists in Cloudflare, skipping");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Secret doesn't exist, create it
|
|
199
|
+
const secretKey = generateSecretKey();
|
|
200
|
+
// Use the same pattern as TMP_WORKER_CREATED for consistency
|
|
201
|
+
await $({ stdio: "pipe" }) `echo "${secretKey}"`
|
|
202
|
+
.pipe `npx wrangler secret put AUTH_SECRET_KEY`;
|
|
203
|
+
console.log("Set AUTH_SECRET_KEY secret");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.error("Failed to set up AUTH_SECRET_KEY. Please configure it manually:");
|
|
208
|
+
console.error("1. Generate a secret key: node -e \"console.log(require('crypto').randomBytes(32).toString('base64'))\"");
|
|
209
|
+
console.error("2. Set the secret: npx wrangler secret put AUTH_SECRET_KEY");
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Check WebAuthn setup
|
|
214
|
+
const needsWebAuthn = await hasWebAuthn();
|
|
215
|
+
if (!needsWebAuthn) {
|
|
216
|
+
console.log("Skipping WebAuthn setup - no WEBAUTHN usage detected in codebase");
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
console.log("Found WEBAUTHN usage, checking WebAuthn setup...");
|
|
220
|
+
try {
|
|
221
|
+
wranglerConfig.vars = wranglerConfig.vars || {};
|
|
222
|
+
if (wranglerConfig.vars.WEBAUTHN_APP_NAME === wranglerConfig.name) {
|
|
223
|
+
console.log(`WEBAUTHN_APP_NAME already set to "${wranglerConfig.name}" in wrangler.jsonc`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
wranglerConfig.vars.WEBAUTHN_APP_NAME = wranglerConfig.name;
|
|
227
|
+
await writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
|
|
228
|
+
console.log("Updated wrangler.jsonc configuration");
|
|
229
|
+
console.log(`Set WEBAUTHN_APP_NAME to ${wranglerConfig.name}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
console.error("Failed to set up WebAuthn. Please configure it manually:");
|
|
234
|
+
console.error("Add to wrangler.jsonc vars:");
|
|
235
|
+
console.error(` "vars": { "WEBAUTHN_APP_NAME": "${wranglerConfig.name}" }`);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (pkg.scripts?.["migrate:prd"]) {
|
|
240
|
+
console.log("Checking migration status...");
|
|
241
|
+
try {
|
|
242
|
+
// Get the database name from wrangler config
|
|
243
|
+
const dbConfig = wranglerConfig.d1_databases?.find((db) => db.binding === "DB");
|
|
244
|
+
if (!dbConfig) {
|
|
245
|
+
throw new Error("No D1 database configuration found in wrangler.jsonc");
|
|
246
|
+
}
|
|
247
|
+
// Check remote migrations status
|
|
248
|
+
const migrationStatus = await $ `npx wrangler d1 migrations list ${dbConfig.database_name} --remote`;
|
|
249
|
+
// If stdout includes "No migrations found", this is a fresh database
|
|
250
|
+
if (migrationStatus.stdout?.includes("No migrations present")) {
|
|
251
|
+
console.log("No migrations found.");
|
|
252
|
+
}
|
|
253
|
+
else if (migrationStatus.stdout?.includes("Migrations to be applied")) {
|
|
254
|
+
await $({ stdio: "inherit" }) `npm run migrate:prd`;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
console.log("Migrations are up to date.");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.error("\n❌ Error checking migration status:");
|
|
262
|
+
console.error(error);
|
|
263
|
+
process.exit(1);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
console.log("\nDeployment initialization complete!");
|
|
267
|
+
process.exit(0);
|
|
268
|
+
};
|
|
269
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
270
|
+
ensureDeployEnv();
|
|
271
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ensureEnv: () => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const migrateNew: (name: string, skipApply?: boolean) => Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import snakeCase from "lodash/snakeCase.js";
|
|
2
|
+
import { $ } from "../lib/$.mjs";
|
|
3
|
+
import { readdir } from "fs/promises";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
import { mkdirp } from "fs-extra";
|
|
6
|
+
import { writeFile } from "fs/promises";
|
|
7
|
+
const getNextMigrationNumber = async () => {
|
|
8
|
+
await mkdirp(resolve(process.cwd(), "./migrations"));
|
|
9
|
+
const files = await readdir(resolve(process.cwd(), "./migrations"));
|
|
10
|
+
const numbers = files
|
|
11
|
+
.map((file) => parseInt(file.split("_")[0]))
|
|
12
|
+
.filter((num) => !isNaN(num));
|
|
13
|
+
const lastNumber = Math.max(0, ...numbers);
|
|
14
|
+
return String(lastNumber + 1).padStart(4, "0");
|
|
15
|
+
};
|
|
16
|
+
export const migrateNew = async (name, skipApply = false) => {
|
|
17
|
+
if (!name) {
|
|
18
|
+
console.log("Usage: npm run migrate:new <migration-name> [--no-apply]");
|
|
19
|
+
console.log("Example: npm run migrate:new add a user");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
const nextNum = await getNextMigrationNumber();
|
|
23
|
+
const filepath = `./migrations/${nextNum}_${snakeCase(name.toLowerCase())}.sql`;
|
|
24
|
+
const raw = await $ `npx prisma migrate diff --from-local-d1 --to-schema-datamodel ./prisma/schema.prisma --script`;
|
|
25
|
+
const cleaned = raw.stdout
|
|
26
|
+
?.split("\n")
|
|
27
|
+
.filter((line) => !line.includes("_cf_METADATA") && !line.includes("_cf_metadata"))
|
|
28
|
+
.join("\n");
|
|
29
|
+
if (!cleaned) {
|
|
30
|
+
console.error("No changes to apply");
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await writeFile(filepath, cleaned);
|
|
35
|
+
console.log("Generated migration:", filepath);
|
|
36
|
+
if (!skipApply) {
|
|
37
|
+
console.log("Applying migration in development...");
|
|
38
|
+
await $ `npm run migrate:dev`;
|
|
39
|
+
console.log("Generating Prisma Client");
|
|
40
|
+
await $ `npx prisma generate`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
44
|
+
const args = process.argv.slice(2);
|
|
45
|
+
// Separate flags from other arguments
|
|
46
|
+
const flags = new Set(args.filter((arg) => arg.startsWith("--")));
|
|
47
|
+
const nonFlags = args.filter((arg) => !arg.startsWith("--"));
|
|
48
|
+
const skipApply = flags.has("--no-apply");
|
|
49
|
+
const name = nonFlags.join("_").toLocaleLowerCase();
|
|
50
|
+
migrateNew(name, skipApply);
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|