completionId: cgen-501e89513d5342e4a2c04a825bae5594

cgen-501e89513d5342e4a2c04a825bae5594
This commit is contained in:
Builder.io 2025-11-16 01:49:28 +00:00
parent 98478f3129
commit 0b14637233

View file

@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function processDir(src, dest, processFile) {
function copyDir(src, dest) {
if (!fs.existsSync(src)) {
console.warn(`Source directory not found: ${src}`);
return;
@ -24,49 +24,13 @@ function processDir(src, dest, processFile) {
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
processDir(srcPath, destPath, processFile);
copyDir(srcPath, destPath);
} else {
processFile(srcPath, destPath);
fs.copyFileSync(srcPath, destPath);
}
}
}
function copyFile(src, dest) {
fs.copyFileSync(src, dest);
}
function processAndCopyFile(src, dest) {
let content = fs.readFileSync(src, "utf-8");
// Fix relative imports to include .ts extension for Vercel
// This helps Node.js module resolution work correctly at runtime
if (src.endsWith(".ts")) {
// Add .ts extension to relative imports if not already present
content = content.replace(
/from\s+['"](\.[^'"]*?)(?<!\.ts)(['"])/g,
'from "$1.ts"$2'
);
// Also handle import statements
content = content.replace(
/import\s+([^'"]*?)\s+from\s+['"](\.[^'"]*?)(?<!\.ts)(['"])/g,
'import $1 from "$2.ts"$3'
);
}
// Copy the original TypeScript file
fs.copyFileSync(src, dest);
// Also create a .js version by replacing imports
if (src.endsWith(".ts") && !src.endsWith(".d.ts")) {
const jsPath = dest.replace(/\.ts$/, ".js");
// For .js files, remove .ts extensions from imports
const jsContent = content.replace(
/from\s+['"](\.[^'"]*?)\.ts(['"])/g,
'from "$1.js"$2'
);
fs.writeFileSync(jsPath, jsContent);
}
console.log(`✓ Copied ${src} to ${dest}`);
}
// When this file is at code/copy-api.js:
@ -76,6 +40,4 @@ function processAndCopyFile(src, dest) {
const srcApi = path.resolve(__dirname, "api");
const destApi = path.resolve(__dirname, "..", "api");
console.log(`Processing API files from ${srcApi} to ${destApi}...`);
processDir(srcApi, destApi, processAndCopyFile);
console.log(`✓ API files processed and copied to ${destApi}`);
copyDir(srcApi, destApi);