Simplify build-api.js to just validate API setup
cgen-179894c1c0814fe18f4d289dcf3dfaac
This commit is contained in:
parent
b981999dcc
commit
23f07b98e6
1 changed files with 8 additions and 37 deletions
45
build-api.js
45
build-api.js
|
|
@ -5,44 +5,15 @@ import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
console.log("Preparing API files for Vercel...");
|
console.log("Validating API setup for Vercel...");
|
||||||
|
|
||||||
const srcApi = path.resolve(__dirname, "api");
|
const apiDir = path.resolve(__dirname, "api");
|
||||||
const destApi = path.resolve(__dirname, "api");
|
|
||||||
|
|
||||||
const UTILITY_PATTERNS = [
|
if (!fs.existsSync(apiDir)) {
|
||||||
/^_/,
|
console.error("❌ API directory not found at", apiDir);
|
||||||
/^opportunities\.ts$/,
|
process.exit(1);
|
||||||
/^opportunities\.js$/,
|
|
||||||
];
|
|
||||||
|
|
||||||
function isUtilityFile(filename) {
|
|
||||||
return UTILITY_PATTERNS.some((pattern) => pattern.test(filename));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyDir(src, dest) {
|
const files = fs.readdirSync(apiDir);
|
||||||
if (fs.existsSync(dest)) {
|
console.log(`✓ Found API directory with ${files.length} entries`);
|
||||||
fs.rmSync(dest, { recursive: true, force: true });
|
console.log("✓ Vercel will compile TypeScript files automatically");
|
||||||
}
|
|
||||||
fs.mkdirSync(dest, { recursive: true });
|
|
||||||
|
|
||||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
||||||
for (const entry of entries) {
|
|
||||||
const srcPath = path.join(src, entry.name);
|
|
||||||
const destPath = path.join(dest, entry.name);
|
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
copyDir(srcPath, destPath);
|
|
||||||
} else if (!entry.name.startsWith(".")) {
|
|
||||||
// Skip utility files at the root api level
|
|
||||||
if (!isUtilityFile(entry.name) || src !== srcApi) {
|
|
||||||
fs.copyFileSync(srcPath, destPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Copying API files from ${srcApi}...`);
|
|
||||||
copyDir(srcApi, destApi);
|
|
||||||
console.log(`✓ Copied to ${destApi}`);
|
|
||||||
console.log("Vercel will compile and serve TypeScript files.");
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue