@samebase/convex-hosting 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -132
- package/README.md +188 -406
- package/dist/cli/convex.d.ts +63 -0
- package/dist/cli/convex.js +108 -0
- package/dist/cli/convex.js.map +1 -0
- package/dist/cli/files.d.ts +18 -0
- package/dist/cli/files.js +106 -0
- package/dist/cli/files.js.map +1 -0
- package/dist/cli/index.d.ts +1 -11
- package/dist/cli/index.js +3 -58
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +377 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/client/index.d.ts +8 -115
- package/dist/client/index.js +65 -242
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +5 -0
- package/dist/client/version-module.d.ts +6 -0
- package/dist/component/_generated/api.d.ts +0 -5
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +20 -18
- package/dist/component/_generated/dataModel.d.ts +0 -1
- package/dist/component/_generated/server.d.ts +12 -1
- package/dist/component/_generated/server.js +2 -0
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/convex.config.d.ts +0 -1
- package/dist/component/lib.d.ts +175 -156
- package/dist/component/lib.js +396 -710
- package/dist/component/lib.js.map +1 -1
- package/dist/component/schema.d.ts +76 -72
- package/dist/component/schema.js +35 -59
- package/dist/component/schema.js.map +1 -1
- package/dist/workers-shared/asset-worker/src/analytics.d.ts +39 -0
- package/dist/workers-shared/asset-worker/src/analytics.js +86 -0
- package/dist/workers-shared/asset-worker/src/analytics.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/compatibility-flags.d.ts +19 -0
- package/dist/workers-shared/asset-worker/src/compatibility-flags.js +29 -0
- package/dist/workers-shared/asset-worker/src/compatibility-flags.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/configuration.d.ts +3 -0
- package/dist/workers-shared/asset-worker/src/configuration.js +30 -0
- package/dist/workers-shared/asset-worker/src/configuration.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/constants.d.ts +1 -0
- package/dist/workers-shared/asset-worker/src/constants.js +3 -0
- package/dist/workers-shared/asset-worker/src/constants.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/handler.d.ts +28 -0
- package/dist/workers-shared/asset-worker/src/handler.js +717 -0
- package/dist/workers-shared/asset-worker/src/handler.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/types.d.ts +13 -0
- package/dist/workers-shared/asset-worker/src/types.js +2 -0
- package/dist/workers-shared/asset-worker/src/types.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/utils/base-path.d.ts +29 -0
- package/dist/workers-shared/asset-worker/src/utils/base-path.js +56 -0
- package/dist/workers-shared/asset-worker/src/utils/base-path.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/utils/headers.d.ts +11 -0
- package/dist/workers-shared/asset-worker/src/utils/headers.js +77 -0
- package/dist/workers-shared/asset-worker/src/utils/headers.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/utils/rules-engine.d.ts +23 -0
- package/dist/workers-shared/asset-worker/src/utils/rules-engine.js +133 -0
- package/dist/workers-shared/asset-worker/src/utils/rules-engine.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/worker.d.ts +14 -0
- package/dist/workers-shared/asset-worker/src/worker.js +12 -0
- package/dist/workers-shared/asset-worker/src/worker.js.map +1 -0
- package/dist/workers-shared/utils/base-path.d.ts +32 -0
- package/dist/workers-shared/utils/base-path.js +94 -0
- package/dist/workers-shared/utils/base-path.js.map +1 -0
- package/dist/workers-shared/utils/configuration/constants.d.ts +15 -0
- package/dist/workers-shared/utils/configuration/constants.js +16 -0
- package/dist/workers-shared/utils/configuration/constants.js.map +1 -0
- package/dist/workers-shared/utils/configuration/constructConfiguration.d.ts +12 -0
- package/dist/workers-shared/utils/configuration/constructConfiguration.js +103 -0
- package/dist/workers-shared/utils/configuration/constructConfiguration.js.map +1 -0
- package/dist/workers-shared/utils/configuration/parseHeaders.d.ts +5 -0
- package/dist/workers-shared/utils/configuration/parseHeaders.js +181 -0
- package/dist/workers-shared/utils/configuration/parseHeaders.js.map +1 -0
- package/dist/workers-shared/utils/configuration/parseRedirects.d.ts +8 -0
- package/dist/workers-shared/utils/configuration/parseRedirects.js +129 -0
- package/dist/workers-shared/utils/configuration/parseRedirects.js.map +1 -0
- package/dist/workers-shared/utils/configuration/parseStaticRouting.d.ts +2 -0
- package/dist/workers-shared/utils/configuration/parseStaticRouting.js +94 -0
- package/dist/workers-shared/utils/configuration/parseStaticRouting.js.map +1 -0
- package/dist/workers-shared/utils/configuration/types.d.ts +38 -0
- package/dist/workers-shared/utils/configuration/types.js +2 -0
- package/dist/workers-shared/utils/configuration/types.js.map +1 -0
- package/dist/workers-shared/utils/configuration/validateURL.d.ts +3 -0
- package/dist/workers-shared/utils/configuration/validateURL.js +56 -0
- package/dist/workers-shared/utils/configuration/validateURL.js.map +1 -0
- package/dist/workers-shared/utils/constants.d.ts +28 -0
- package/dist/workers-shared/utils/constants.js +34 -0
- package/dist/workers-shared/utils/constants.js.map +1 -0
- package/dist/workers-shared/utils/helpers.d.ts +22 -0
- package/dist/workers-shared/utils/helpers.js +73 -0
- package/dist/workers-shared/utils/helpers.js.map +1 -0
- package/dist/workers-shared/utils/responses.d.ts +43 -0
- package/dist/workers-shared/utils/responses.js +125 -0
- package/dist/workers-shared/utils/responses.js.map +1 -0
- package/dist/workers-shared/utils/tracing.d.ts +3 -0
- package/dist/workers-shared/utils/tracing.js +29 -0
- package/dist/workers-shared/utils/tracing.js.map +1 -0
- package/dist/workers-shared/utils/types.d.ts +131 -0
- package/dist/workers-shared/utils/types.js +72 -0
- package/dist/workers-shared/utils/types.js.map +1 -0
- package/package.json +21 -37
- package/INTEGRATION.md +0 -399
- package/dist/cli/args.d.ts +0 -28
- package/dist/cli/args.d.ts.map +0 -1
- package/dist/cli/args.js +0 -148
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/argumentChunks.d.ts +0 -3
- package/dist/cli/argumentChunks.d.ts.map +0 -1
- package/dist/cli/argumentChunks.js +0 -29
- package/dist/cli/argumentChunks.js.map +0 -1
- package/dist/cli/collectFiles.d.ts +0 -10
- package/dist/cli/collectFiles.d.ts.map +0 -1
- package/dist/cli/collectFiles.js +0 -53
- package/dist/cli/collectFiles.js.map +0 -1
- package/dist/cli/commands.d.ts +0 -8
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -56
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/componentName.d.ts +0 -32
- package/dist/cli/componentName.d.ts.map +0 -1
- package/dist/cli/componentName.js +0 -43
- package/dist/cli/componentName.js.map +0 -1
- package/dist/cli/deploy.d.ts +0 -16
- package/dist/cli/deploy.d.ts.map +0 -1
- package/dist/cli/deploy.js +0 -283
- package/dist/cli/deploy.js.map +0 -1
- package/dist/cli/deployEnvironment.d.ts +0 -10
- package/dist/cli/deployEnvironment.d.ts.map +0 -1
- package/dist/cli/deployEnvironment.js +0 -12
- package/dist/cli/deployEnvironment.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/upload.d.ts +0 -22
- package/dist/cli/upload.d.ts.map +0 -1
- package/dist/cli/upload.js +0 -630
- package/dist/cli/upload.js.map +0 -1
- package/dist/client/_generated/_ignore.d.ts +0 -1
- package/dist/client/_generated/_ignore.d.ts.map +0 -1
- package/dist/client/_generated/_ignore.js +0 -3
- package/dist/client/_generated/_ignore.js.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/component/_generated/api.d.ts.map +0 -1
- package/dist/component/_generated/component.d.ts.map +0 -1
- package/dist/component/_generated/dataModel.d.ts.map +0 -1
- package/dist/component/_generated/server.d.ts.map +0 -1
- package/dist/component/convex.config.d.ts.map +0 -1
- package/dist/component/http.d.ts +0 -4
- package/dist/component/http.d.ts.map +0 -1
- package/dist/component/http.js +0 -113
- package/dist/component/http.js.map +0 -1
- package/dist/component/lib.d.ts.map +0 -1
- package/dist/component/schema.d.ts.map +0 -1
- package/dist/component/serving.d.ts +0 -23
- package/dist/component/serving.d.ts.map +0 -1
- package/dist/component/serving.js +0 -161
- package/dist/component/serving.js.map +0 -1
- package/dist/react/index.d.ts +0 -59
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -137
- package/dist/react/index.js.map +0 -1
- package/src/cli/args.test.ts +0 -79
- package/src/cli/args.ts +0 -153
- package/src/cli/argumentChunks.test.ts +0 -27
- package/src/cli/argumentChunks.ts +0 -40
- package/src/cli/collectFiles.test.ts +0 -26
- package/src/cli/collectFiles.ts +0 -59
- package/src/cli/commands.ts +0 -68
- package/src/cli/componentName.test.ts +0 -41
- package/src/cli/componentName.ts +0 -46
- package/src/cli/deploy.ts +0 -336
- package/src/cli/deployEnvironment.test.ts +0 -27
- package/src/cli/deployEnvironment.ts +0 -17
- package/src/cli/index.ts +0 -65
- package/src/cli/upload.ts +0 -837
- package/src/client/_generated/_ignore.ts +0 -1
- package/src/client/index.test.ts +0 -549
- package/src/client/index.ts +0 -344
- package/src/client/setup.test.ts +0 -22
- package/src/component/_generated/api.ts +0 -54
- package/src/component/_generated/component.ts +0 -55
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/convex.config.ts +0 -3
- package/src/component/http.test.ts +0 -254
- package/src/component/http.ts +0 -133
- package/src/component/lib.test.ts +0 -1007
- package/src/component/lib.ts +0 -862
- package/src/component/schema.ts +0 -75
- package/src/component/serving.ts +0 -170
- package/src/component/setup.test.ts +0 -11
- package/src/react/index.tsx +0 -197
- package/src/test.ts +0 -23
package/src/cli/deploy.ts
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* One-shot deployment command that deploys both Convex backend and static files.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* npx @samebase/convex-hosting deploy [options]
|
|
7
|
-
*
|
|
8
|
-
* This command:
|
|
9
|
-
* 1. Builds the frontend with the correct VITE_CONVEX_URL
|
|
10
|
-
* 2. Deploys the Convex backend (npx convex deploy)
|
|
11
|
-
* 3. Deploys static files to Convex storage
|
|
12
|
-
*
|
|
13
|
-
* The goal is to minimize the inconsistency window between backend and frontend.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { existsSync } from "fs";
|
|
17
|
-
import { resolve } from "path";
|
|
18
|
-
import { runConvex, spawnConvex, spawnShell, spawnStaticHostingCli } from "./commands.js";
|
|
19
|
-
import { buildDeployUploadArgs, parseDeployArgs, type DeployArgs } from "./args.js";
|
|
20
|
-
import {
|
|
21
|
-
buildEnvironment,
|
|
22
|
-
buildEnvironmentChanged,
|
|
23
|
-
type DeploymentUrls,
|
|
24
|
-
} from "./deployEnvironment.js";
|
|
25
|
-
import {
|
|
26
|
-
componentNameCandidates,
|
|
27
|
-
isLegacyAutoDetected,
|
|
28
|
-
legacyComponentNameWarning,
|
|
29
|
-
} from "./componentName.js";
|
|
30
|
-
|
|
31
|
-
function showHelp(): void {
|
|
32
|
-
console.log(`
|
|
33
|
-
Usage: npx @samebase/convex-hosting deploy [options]
|
|
34
|
-
|
|
35
|
-
One-shot deployment: builds frontend, deploys Convex backend, then deploys static files.
|
|
36
|
-
Minimizes the inconsistency window between backend and frontend updates.
|
|
37
|
-
|
|
38
|
-
Options:
|
|
39
|
-
-d, --dist <path> Path to dist directory (default: ./dist)
|
|
40
|
-
-c, --component <name> Convex component name (default: hosting)
|
|
41
|
-
--skip-build Skip the build step (use existing dist)
|
|
42
|
-
--skip-convex Skip Convex backend deployment
|
|
43
|
-
--build-command <cmd> Build command to run (default: 'npm run build')
|
|
44
|
-
--no-spa Disable SPA fallback (404 instead of /index.html)
|
|
45
|
-
--spa Enable SPA fallback (default)
|
|
46
|
-
--cdn Use the legacy convex-fs integration
|
|
47
|
-
--cdn-delete-function <name> Legacy app function that deletes CDN blobs
|
|
48
|
-
-h, --help Show this help message
|
|
49
|
-
|
|
50
|
-
Deployment Flow:
|
|
51
|
-
1. Build frontend with production VITE_CONVEX_URL
|
|
52
|
-
2. Deploy Convex backend (npx convex deploy)
|
|
53
|
-
3. Rebuild if the backend changed the static mount path
|
|
54
|
-
4. Deploy static files to Convex storage
|
|
55
|
-
|
|
56
|
-
Examples:
|
|
57
|
-
# Full deployment
|
|
58
|
-
npx @samebase/convex-hosting deploy
|
|
59
|
-
|
|
60
|
-
# Skip build (if already built)
|
|
61
|
-
npx @samebase/convex-hosting deploy --skip-build
|
|
62
|
-
|
|
63
|
-
# Only deploy static files (skip Convex backend)
|
|
64
|
-
npx @samebase/convex-hosting deploy --skip-convex
|
|
65
|
-
`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Resolve the component's deployment URLs (siteUrl + cloudUrl). Returns null
|
|
70
|
-
* if the component isn't reachable yet; on first deploy the backend may not
|
|
71
|
-
* exist, in which case the caller should deploy it first and retry.
|
|
72
|
-
*/
|
|
73
|
-
function tryFetchUrls(componentName: string): DeploymentUrls | null {
|
|
74
|
-
try {
|
|
75
|
-
const out = runConvex([
|
|
76
|
-
"run",
|
|
77
|
-
"--component",
|
|
78
|
-
componentName,
|
|
79
|
-
"lib:getUrls",
|
|
80
|
-
"{}",
|
|
81
|
-
"--prod",
|
|
82
|
-
"--typecheck=disable",
|
|
83
|
-
"--codegen=disable",
|
|
84
|
-
]);
|
|
85
|
-
return JSON.parse(out);
|
|
86
|
-
} catch {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface ResolvedComponent {
|
|
92
|
-
urls: DeploymentUrls;
|
|
93
|
-
componentName: string;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// The legacy-name warning is printed at most once per invocation.
|
|
97
|
-
let warnedLegacyName = false;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Resolve the deployment URLs and the instance name that answered. When the
|
|
101
|
-
* caller relied on the default name we also probe the @convex-dev/static-hosting
|
|
102
|
-
* name, so an app that kept that instance works without `--component staticHosting`. Returns
|
|
103
|
-
* null if no candidate is deployed yet (the caller may deploy the backend and
|
|
104
|
-
* retry).
|
|
105
|
-
*/
|
|
106
|
-
function tryResolveComponent(requested: string): ResolvedComponent | null {
|
|
107
|
-
for (const componentName of componentNameCandidates(requested)) {
|
|
108
|
-
const urls = tryFetchUrls(componentName);
|
|
109
|
-
if (urls) {
|
|
110
|
-
if (isLegacyAutoDetected(requested, componentName) && !warnedLegacyName) {
|
|
111
|
-
console.warn(legacyComponentNameWarning(componentName));
|
|
112
|
-
warnedLegacyName = true;
|
|
113
|
-
}
|
|
114
|
-
return { urls, componentName };
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function resolveComponentOrExit(requested: string): ResolvedComponent {
|
|
121
|
-
const resolved = tryResolveComponent(requested);
|
|
122
|
-
if (!resolved) {
|
|
123
|
-
const names = componentNameCandidates(requested)
|
|
124
|
-
.map((name) => `"${name}"`)
|
|
125
|
-
.join(" or ");
|
|
126
|
-
console.error(
|
|
127
|
-
`Could not reach component ${names}. Deploy the Convex backend first (npx convex deploy) and ensure --component matches the name in convex.config.ts.`,
|
|
128
|
-
);
|
|
129
|
-
process.exit(1);
|
|
130
|
-
}
|
|
131
|
-
return resolved;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Run the Convex storage upload flow
|
|
136
|
-
*/
|
|
137
|
-
async function uploadToConvexStorage(args: DeployArgs): Promise<boolean> {
|
|
138
|
-
console.log("");
|
|
139
|
-
console.log(
|
|
140
|
-
args.cdn
|
|
141
|
-
? "📦 Uploading static files (HTML to Convex, assets to CDN)..."
|
|
142
|
-
: "📦 Uploading static files to Convex storage...",
|
|
143
|
-
);
|
|
144
|
-
console.log("");
|
|
145
|
-
|
|
146
|
-
const result = spawnStaticHostingCli(buildDeployUploadArgs(args));
|
|
147
|
-
|
|
148
|
-
return result === 0;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function runFrontendBuild(args: DeployArgs, urls: DeploymentUrls): void {
|
|
152
|
-
const environment = buildEnvironment(urls);
|
|
153
|
-
console.log(` Build command: ${args.buildCommand}`);
|
|
154
|
-
console.log(` VITE_CONVEX_URL=${environment.cloudUrl}`);
|
|
155
|
-
console.log(` CONVEX_HOSTING_BASE_PATH=${environment.basePath}`);
|
|
156
|
-
console.log("");
|
|
157
|
-
|
|
158
|
-
const buildResult = spawnShell(args.buildCommand, {
|
|
159
|
-
...process.env,
|
|
160
|
-
VITE_CONVEX_URL: environment.cloudUrl,
|
|
161
|
-
CONVEX_HOSTING_BASE_PATH: environment.basePath,
|
|
162
|
-
});
|
|
163
|
-
if (buildResult !== 0) {
|
|
164
|
-
throw new Error("Frontend build failed");
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async function main(): Promise<void> {
|
|
169
|
-
const args = parseDeployArgs(process.argv.slice(2));
|
|
170
|
-
|
|
171
|
-
if (args.help) {
|
|
172
|
-
showHelp();
|
|
173
|
-
process.exit(0);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
console.log("");
|
|
177
|
-
console.log("🚀 Convex + Static Files Deployment");
|
|
178
|
-
console.log("═══════════════════════════════════════════════════════════");
|
|
179
|
-
|
|
180
|
-
const startTime = Date.now();
|
|
181
|
-
|
|
182
|
-
// Step 1: Get deployment URLs (needed for build)
|
|
183
|
-
console.log("");
|
|
184
|
-
console.log("Step 1: Getting deployment URLs...");
|
|
185
|
-
|
|
186
|
-
let resolved = tryResolveComponent(args.component);
|
|
187
|
-
let urls = resolved?.urls ?? null;
|
|
188
|
-
// Falls back to the requested name until the backend is deployed and a real
|
|
189
|
-
// instance answers; re-resolved after each deploy below.
|
|
190
|
-
let componentName = resolved?.componentName ?? args.component;
|
|
191
|
-
const shouldDeployBackend = !args.skipConvex;
|
|
192
|
-
let backendAlreadyDeployed = false;
|
|
193
|
-
|
|
194
|
-
if (!urls && !args.skipConvex) {
|
|
195
|
-
console.log(" Component not yet deployed. Will fetch URLs after deploying backend.");
|
|
196
|
-
} else if (urls) {
|
|
197
|
-
console.log(` ✓ ${urls.siteUrl}`);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Step 2: Build frontend
|
|
201
|
-
if (!args.skipBuild) {
|
|
202
|
-
console.log("");
|
|
203
|
-
console.log("Step 2: Building frontend...");
|
|
204
|
-
|
|
205
|
-
// If the component isn't deployed yet, deploy the backend first so we
|
|
206
|
-
// can ask it for the URLs.
|
|
207
|
-
if (!urls && shouldDeployBackend) {
|
|
208
|
-
console.log(" Deploying Convex backend first to get URLs...");
|
|
209
|
-
console.log("");
|
|
210
|
-
|
|
211
|
-
const convexResult = spawnConvex(["deploy"]);
|
|
212
|
-
|
|
213
|
-
if (convexResult !== 0) {
|
|
214
|
-
console.error("");
|
|
215
|
-
console.error("❌ Convex deployment failed");
|
|
216
|
-
process.exit(1);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
resolved = resolveComponentOrExit(args.component);
|
|
220
|
-
urls = resolved.urls;
|
|
221
|
-
componentName = resolved.componentName;
|
|
222
|
-
console.log("");
|
|
223
|
-
console.log(` ✓ Site URL: ${urls.siteUrl}`);
|
|
224
|
-
backendAlreadyDeployed = true;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!urls) {
|
|
228
|
-
console.error("");
|
|
229
|
-
console.error("❌ Could not determine deployment URLs for build");
|
|
230
|
-
console.error(" Run 'npx convex deploy' first or remove --skip-convex");
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
runFrontendBuild(args, urls);
|
|
236
|
-
} catch {
|
|
237
|
-
console.error("");
|
|
238
|
-
console.error("❌ Build failed");
|
|
239
|
-
process.exit(1);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
console.log("");
|
|
243
|
-
console.log(" ✓ Build complete");
|
|
244
|
-
} else {
|
|
245
|
-
console.log("");
|
|
246
|
-
console.log("Step 2: Skipping build (--skip-build)");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Step 3: Deploy Convex backend
|
|
250
|
-
if (shouldDeployBackend && !backendAlreadyDeployed) {
|
|
251
|
-
console.log("");
|
|
252
|
-
console.log("Step 3: Deploying Convex backend...");
|
|
253
|
-
console.log("");
|
|
254
|
-
|
|
255
|
-
const convexResult = spawnConvex(["deploy"]);
|
|
256
|
-
|
|
257
|
-
if (convexResult !== 0) {
|
|
258
|
-
console.error("");
|
|
259
|
-
console.error("❌ Convex deployment failed");
|
|
260
|
-
process.exit(1);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
console.log("");
|
|
264
|
-
console.log(" ✓ Convex backend deployed");
|
|
265
|
-
|
|
266
|
-
const deployedComponent = resolveComponentOrExit(args.component);
|
|
267
|
-
const deployedUrls = deployedComponent.urls;
|
|
268
|
-
componentName = deployedComponent.componentName;
|
|
269
|
-
if (!args.skipBuild) {
|
|
270
|
-
if (!urls || buildEnvironmentChanged(urls, deployedUrls)) {
|
|
271
|
-
console.log("");
|
|
272
|
-
console.log(
|
|
273
|
-
" Site URL changed after backend deployment. Rebuilding with the new environment...",
|
|
274
|
-
);
|
|
275
|
-
try {
|
|
276
|
-
runFrontendBuild(args, deployedUrls);
|
|
277
|
-
} catch {
|
|
278
|
-
console.error("");
|
|
279
|
-
console.error("❌ Rebuild failed after backend URL change");
|
|
280
|
-
process.exit(1);
|
|
281
|
-
}
|
|
282
|
-
console.log("");
|
|
283
|
-
console.log(" ✓ Rebuild complete");
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
urls = deployedUrls;
|
|
287
|
-
} else {
|
|
288
|
-
console.log("");
|
|
289
|
-
console.log("Step 3: Skipping Convex deployment (--skip-convex or already deployed)");
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// Step 4: Deploy static files
|
|
293
|
-
console.log("");
|
|
294
|
-
console.log("Step 4: Deploying static files to Convex storage...");
|
|
295
|
-
|
|
296
|
-
const distDir = resolve(args.dist);
|
|
297
|
-
|
|
298
|
-
if (!existsSync(distDir)) {
|
|
299
|
-
console.error("");
|
|
300
|
-
console.error(`❌ Dist directory not found: ${distDir}`);
|
|
301
|
-
console.error(" Run build first or check --dist path");
|
|
302
|
-
process.exit(1);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Pass the resolved instance name to the upload subprocess so it targets the
|
|
306
|
-
// same component (and doesn't re-probe or re-warn).
|
|
307
|
-
const staticDeploySuccess = await uploadToConvexStorage({
|
|
308
|
-
...args,
|
|
309
|
-
dist: distDir,
|
|
310
|
-
component: componentName,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
if (!staticDeploySuccess) {
|
|
314
|
-
console.error("");
|
|
315
|
-
console.error("❌ Static file upload failed");
|
|
316
|
-
process.exit(1);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Done!
|
|
320
|
-
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
321
|
-
|
|
322
|
-
console.log("");
|
|
323
|
-
console.log("═══════════════════════════════════════════════════════════");
|
|
324
|
-
console.log(`✨ Deployment complete! (${duration}s)`);
|
|
325
|
-
console.log("");
|
|
326
|
-
|
|
327
|
-
const finalUrls = urls ?? resolveComponentOrExit(args.component).urls;
|
|
328
|
-
console.log(`Frontend: ${finalUrls.siteUrl}`);
|
|
329
|
-
|
|
330
|
-
console.log("");
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
main().catch((error) => {
|
|
334
|
-
console.error("Deployment failed:", error);
|
|
335
|
-
process.exit(1);
|
|
336
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vite-plus/test";
|
|
2
|
-
import { buildEnvironmentChanged } from "./deployEnvironment.js";
|
|
3
|
-
|
|
4
|
-
describe("deploy build environment", () => {
|
|
5
|
-
test("detects a mount-prefix change after backend deployment", () => {
|
|
6
|
-
expect(
|
|
7
|
-
buildEnvironmentChanged(
|
|
8
|
-
{
|
|
9
|
-
siteUrl: "https://example.convex.site/old/",
|
|
10
|
-
cloudUrl: "https://example.convex.cloud",
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
siteUrl: "https://example.convex.site/new/",
|
|
14
|
-
cloudUrl: "https://example.convex.cloud",
|
|
15
|
-
},
|
|
16
|
-
),
|
|
17
|
-
).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("does not rebuild when the build environment is unchanged", () => {
|
|
21
|
-
const urls = {
|
|
22
|
-
siteUrl: "https://example.convex.site/app/",
|
|
23
|
-
cloudUrl: "https://example.convex.cloud",
|
|
24
|
-
};
|
|
25
|
-
expect(buildEnvironmentChanged(urls, urls)).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface DeploymentUrls {
|
|
2
|
-
siteUrl: string;
|
|
3
|
-
cloudUrl: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function buildEnvironment(urls: DeploymentUrls) {
|
|
7
|
-
return {
|
|
8
|
-
cloudUrl: urls.cloudUrl,
|
|
9
|
-
basePath: new URL(urls.siteUrl).pathname || "/",
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function buildEnvironmentChanged(before: DeploymentUrls, after: DeploymentUrls): boolean {
|
|
14
|
-
const previous = buildEnvironment(before);
|
|
15
|
-
const next = buildEnvironment(after);
|
|
16
|
-
return previous.cloudUrl !== next.cloudUrl || previous.basePath !== next.basePath;
|
|
17
|
-
}
|
package/src/cli/index.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* CLI for Convex Hosting
|
|
4
|
-
*
|
|
5
|
-
* Commands:
|
|
6
|
-
* deploy One-shot deployment (Convex backend + static files)
|
|
7
|
-
* upload Upload static files to Convex storage
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const command = process.argv[2];
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
switch (command) {
|
|
14
|
-
case "deploy":
|
|
15
|
-
// Pass remaining args to deploy command
|
|
16
|
-
process.argv.splice(2, 1);
|
|
17
|
-
await import("./deploy.js");
|
|
18
|
-
break;
|
|
19
|
-
|
|
20
|
-
case "upload":
|
|
21
|
-
// Pass remaining args to upload command
|
|
22
|
-
process.argv.splice(2, 1);
|
|
23
|
-
await import("./upload.js");
|
|
24
|
-
break;
|
|
25
|
-
|
|
26
|
-
case "--help":
|
|
27
|
-
case "-h":
|
|
28
|
-
case undefined:
|
|
29
|
-
printHelp();
|
|
30
|
-
break;
|
|
31
|
-
|
|
32
|
-
default:
|
|
33
|
-
console.error(`Unknown command: ${command}`);
|
|
34
|
-
console.log("");
|
|
35
|
-
printHelp();
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function printHelp() {
|
|
41
|
-
console.log(`
|
|
42
|
-
Convex Hosting CLI
|
|
43
|
-
|
|
44
|
-
Usage:
|
|
45
|
-
npx @samebase/convex-hosting <command> [options]
|
|
46
|
-
|
|
47
|
-
Commands:
|
|
48
|
-
deploy One-shot deployment (Convex backend + static files)
|
|
49
|
-
upload Upload static files to Convex storage
|
|
50
|
-
|
|
51
|
-
Examples:
|
|
52
|
-
# One-shot deployment
|
|
53
|
-
npx @samebase/convex-hosting deploy
|
|
54
|
-
|
|
55
|
-
# Upload only (no Convex backend deploy)
|
|
56
|
-
npx @samebase/convex-hosting upload --build --prod
|
|
57
|
-
|
|
58
|
-
Run '<command> --help' for more information on a specific command.
|
|
59
|
-
`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
main().catch((err) => {
|
|
63
|
-
console.error("Error:", err);
|
|
64
|
-
process.exit(1);
|
|
65
|
-
});
|