Files

36 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

#!/usr/bin/env bun
/**
* Build and deploy storefronts to their Cloudflare Workers.
*
* bun run deploy # every storefront in config/stores.mjs
* bun run deploy kase # a single storefront (by code or worker name)
*
* Each storefront is built as its own static export and deployed to its own
* Worker, one after another the Cloudflare equivalent of the original
* "build each store, deploy to its own app" pipeline.
*/
import { execSync } from 'node:child_process';
import { copyFileSync } from 'node:fs';
import { stores } from '../config/stores.ts';
const only = process.argv[2];
const targets = only
? stores.filter((store) => store.code === only || store.worker === only)
: stores;
if (!targets.length) {
console.error(`No storefront matches "${only}". Known: ${stores.map((s) => s.code).join(', ')}`);
process.exit(1);
}
for (const { code, worker } of targets) {
const env = { ...process.env, NEXT_PUBLIC_STORE_CODE: code };
console.log(`\n${code} → worker "${worker}"`);
copyFileSync(`config/store_${code}.ts`, 'config/store.ts');
execSync('bun run build', { stdio: 'inherit', env });
execSync(`bunx wrangler deploy --name ${worker}`, { stdio: 'inherit', env });
}
console.log(`\n✓ Deployed ${targets.length} storefront(s).`);