completionId: cgen-501e89513d5342e4a2c04a825bae5594
cgen-501e89513d5342e4a2c04a825bae5594
This commit is contained in:
parent
98478f3129
commit
0b14637233
1 changed files with 5 additions and 43 deletions
48
copy-api.js
48
copy-api.js
|
|
@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function processDir(src, dest, processFile) {
|
function copyDir(src, dest) {
|
||||||
if (!fs.existsSync(src)) {
|
if (!fs.existsSync(src)) {
|
||||||
console.warn(`Source directory not found: ${src}`);
|
console.warn(`Source directory not found: ${src}`);
|
||||||
return;
|
return;
|
||||||
|
|
@ -24,49 +24,13 @@ function processDir(src, dest, processFile) {
|
||||||
const destPath = path.join(dest, entry.name);
|
const destPath = path.join(dest, entry.name);
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
processDir(srcPath, destPath, processFile);
|
copyDir(srcPath, destPath);
|
||||||
} else {
|
} else {
|
||||||
processFile(srcPath, destPath);
|
fs.copyFileSync(srcPath, destPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function copyFile(src, dest) {
|
console.log(`✓ Copied ${src} to ${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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When this file is at code/copy-api.js:
|
// When this file is at code/copy-api.js:
|
||||||
|
|
@ -76,6 +40,4 @@ function processAndCopyFile(src, dest) {
|
||||||
const srcApi = path.resolve(__dirname, "api");
|
const srcApi = path.resolve(__dirname, "api");
|
||||||
const destApi = path.resolve(__dirname, "..", "api");
|
const destApi = path.resolve(__dirname, "..", "api");
|
||||||
|
|
||||||
console.log(`Processing API files from ${srcApi} to ${destApi}...`);
|
copyDir(srcApi, destApi);
|
||||||
processDir(srcApi, destApi, processAndCopyFile);
|
|
||||||
console.log(`✓ API files processed and copied to ${destApi}`);
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue