import { buildDeployDurable } from "./code-gen/esbuild"; import { getResocketConfig } from "./config"; import { getWorkerFilePath } from "./utils"; import { requireAuth } from "./auth/auth"; import type { OutputFile } from "esbuild"; import { getUser } from "./auth/user"; import { apiFetch } from "./utils/apiFetch"; import type { ResocketConfig } from "./types"; import { FRAMEWORK_VERSION } from "./constants"; import chalk from "chalk"; import ora from "ora"; export interface DeployCliOverrides { config?: string; } export const resocketDeploy = async (overrides: DeployCliOverrides) => { const config = getResocketConfig(overrides); const workerFilePath = getWorkerFilePath(overrides.config, config); // const bundle = await buildDeploy(workerFilePath, config); const bundle = await buildDeployDurable(workerFilePath); await deployToServer(bundle, config); }; const deployToServer = async (bundle: OutputFile, config: ResocketConfig) => { const spinner = ora(`${chalk.bold("deploying...")} `).start(); try { const { accountId, token } = requireAuth(); const clerkUser = await getUser(); const res = (await apiFetch("/projects/deploy", { user: clerkUser, options: { method: "POST", body: JSON.stringify({ cfAuth: { accountId, token }, bundle: bundle.text, framework: { name: "cloudflare", version: FRAMEWORK_VERSION, }, config, }), }, })) as any; spinner.stop(); console.log(`${chalk.green(res.message)}`); if ( res.deployedUrls && Array.isArray(res.deployedUrls) && res.deployedUrls.length > 0 ) { const msg = `\nPublished ${config.name}`; console.log(msg); for (const url of res.deployedUrls) { // Append protocol only on workers.dev domains console.log( " ", chalk.green((url.endsWith("workers.dev") ? "https://" : "") + url) ); } } else { console.log("No server deploy targets for", config.name); } } catch (error) { spinner.stop(); throw error; } };