build-cloud-functions.mjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Cloud Function Builder
  3. * Copies pre-inlined cloud function files from cloud-functions/ to cloud-functions/.build/
  4. * The vXxx.js files already have all shared code inlined - they are ready to deploy.
  5. */
  6. import { readFile, writeFile, mkdir } from 'node:fs/promises';
  7. import { fileURLToPath } from 'node:url';
  8. import { dirname, resolve } from 'node:path';
  9. const __dirname = dirname(fileURLToPath(import.meta.url));
  10. const cloudFunctionsDir = resolve(__dirname, '..', 'cloud-functions');
  11. const outputDir = resolve(cloudFunctionsDir, '.build');
  12. const CLOUD_FUNCTIONS = [
  13. 'vContext.js', 'vDomesticVoc.js', 'vSync.js', 'vCompetitor.js',
  14. 'vListing.js', 'vListingJob.js', 'vAnalysis.js', 'vActions.js',
  15. 'vKnowledge.js', 'vAI.js', 'vUpstream.js',
  16. ];
  17. async function main() {
  18. console.log('Building self-contained cloud functions...\n');
  19. await mkdir(outputDir, { recursive: true });
  20. for (const filename of CLOUD_FUNCTIONS) {
  21. const sourcePath = resolve(cloudFunctionsDir, filename);
  22. const outPath = resolve(outputDir, filename);
  23. const code = await readFile(sourcePath, 'utf8');
  24. await writeFile(outPath, code, 'utf8');
  25. console.log(` ✓ ${filename} (${(code.length / 1024).toFixed(0)}KB)`);
  26. }
  27. console.log(`\nOutput: ${outputDir}`);
  28. }
  29. main().catch((error) => {
  30. console.error('Build failed:', error);
  31. process.exitCode = 1;
  32. });