/** * Cloud Function Builder * Copies pre-inlined cloud function files from cloud-functions/ to cloud-functions/.build/ * The vXxx.js files already have all shared code inlined - they are ready to deploy. */ import { readFile, writeFile, mkdir } from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; const __dirname = dirname(fileURLToPath(import.meta.url)); const cloudFunctionsDir = resolve(__dirname, '..', 'cloud-functions'); const outputDir = resolve(cloudFunctionsDir, '.build'); const CLOUD_FUNCTIONS = [ 'vContext.js', 'vDomesticVoc.js', 'vSync.js', 'vCompetitor.js', 'vListing.js', 'vListingJob.js', 'vAnalysis.js', 'vActions.js', 'vKnowledge.js', 'vAI.js', 'vUpstream.js', ]; async function main() { console.log('Building self-contained cloud functions...\n'); await mkdir(outputDir, { recursive: true }); for (const filename of CLOUD_FUNCTIONS) { const sourcePath = resolve(cloudFunctionsDir, filename); const outPath = resolve(outputDir, filename); const code = await readFile(sourcePath, 'utf8'); await writeFile(outPath, code, 'utf8'); console.log(` ✓ ${filename} (${(code.length / 1024).toFixed(0)}KB)`); } console.log(`\nOutput: ${outputDir}`); } main().catch((error) => { console.error('Build failed:', error); process.exitCode = 1; });