| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- * INTERNAL: Cloud Function Builder Script
- * Generates self-contained cloud function files for Fmode Parse platform
- * (which runs in isolated VM without require/import support)
- */
- import { readFile, writeFile } 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');
- // Extract shared helpers from vContext.js (everything after the Constants block)
- async function getSharedHelpers() {
- const vContext = await readFile(resolve(cloudFunctionsDir, 'vContext.js'), 'utf8');
- const helpersStart = vContext.indexOf('// ============= Utilities =============');
- const handlerStart = vContext.indexOf('// ============= Handler =============');
- return vContext.substring(helpersStart, handlerStart);
- }
- // Function definitions: file, actions, needs repository functions
- const FUNCTIONS = [
- { file: 'vContext.js', actions: ['context.get', 'workspace.list', 'workspace.member.update'] },
- { file: 'vDomesticVoc.js', actions: ['domestic.snapshot', 'domestic.products.list', 'domestic.product.get', 'domestic.reviews.list', 'domestic.relations.list', 'data-source.list', 'import.list', 'audit.list'] },
- { file: 'vSync.js', actions: ['sync.enqueue', 'sync.jobs.list', 'sync.job.get', 'sync.job.events', 'sync.job.retry', 'sync.job.cancel'] },
- { file: 'vCompetitor.js', actions: ['competitor.overview', 'competitor.refresh', 'competitor.history', 'competitor.alerts', 'competitor.impacts', 'competitor.tasks.list', 'competitor.tasks.create', 'competitor.tasks.update', 'competitor.run.get'] },
- { file: 'vListing.js', actions: ['listing.overview', 'listing.products.list', 'listing.product.get', 'listing.product.score', 'listing.jd-voc-score.get', 'listing.jd-voc-image-review.run'] },
- { file: 'vListingJob.js', actions: ['listing.score-job.create', 'listing.score-job.list', 'listing.score-job.get', 'listing.score-job.items', 'listing.score-job.retry', 'listing.score-job.cancel', 'listing.versions.list', 'listing.version.create', 'listing.version.adopt'] },
- { file: 'vAnalysis.js', actions: ['analysis.list', 'analysis.create', 'analysis.update', 'insight-decision.list', 'insight-decision.get', 'insight-decision.create'] },
- { file: 'vActions.js', actions: ['action.list', 'action.create', 'action.update', 'alert.list', 'alert.create', 'alert.update'] },
- { file: 'vKnowledge.js', actions: ['knowledge.products.list', 'knowledge.product.upsert', 'knowledge.product.delete'] },
- { file: 'vAI.js', actions: ['ai.status', 'ai.test', 'ai.prompts.list', 'ai.prompt.update', 'ai.chat'] },
- { file: 'vUpstream.js', actions: ['upstream.amazon', 'upstream.sorftime', 'upstream.tikhub', 'upstream.domestic'] },
- ];
- async function main() {
- const shared = await getSharedHelpers();
- console.log(`Extracted ${shared.split('\n').length} lines of shared code from vContext.js`);
- // Currently all files already exist, just verify they have no require statements
- for (const func of FUNCTIONS) {
- const filePath = resolve(cloudFunctionsDir, func.file);
- const content = await readFile(filePath, 'utf8');
- const hasRequire = /require\s*\(/.test(content);
- const hasImport = /^import\s/m.test(content);
- const status = (!hasRequire && !hasImport) ? 'OK' : 'NEEDS FIX';
- console.log(` ${status} ${func.file} (${content.length} bytes, ${func.actions.length} actions)`);
- }
- }
- main().catch((error) => {
- console.error('Build failed:', error);
- process.exitCode = 1;
- });
|