completionId: cgen-8293208186f24554bc636affd053c746
cgen-8293208186f24554bc636affd053c746
This commit is contained in:
parent
08a4994f4d
commit
65c110e03b
1 changed files with 44 additions and 0 deletions
44
copy-api.js
44
copy-api.js
|
|
@ -2,6 +2,7 @@
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
import { execSync } from "child_process";
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
|
@ -41,3 +42,46 @@ const srcApi = path.resolve(__dirname, "api");
|
||||||
const destApi = path.resolve(__dirname, "..", "api");
|
const destApi = path.resolve(__dirname, "..", "api");
|
||||||
|
|
||||||
copyDir(srcApi, destApi);
|
copyDir(srcApi, destApi);
|
||||||
|
|
||||||
|
// Compile TypeScript files to JavaScript for Vercel
|
||||||
|
try {
|
||||||
|
console.log("Transpiling TypeScript API files...");
|
||||||
|
const tscPath = path.resolve(__dirname, "node_modules/.bin/tsc");
|
||||||
|
|
||||||
|
// Use tsx to transpile the API directory
|
||||||
|
execSync(`npx tsx --eval "
|
||||||
|
const ts = require('typescript');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
function transpileDir(dir) {
|
||||||
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
const fullPath = path.join(dir, entry.name);
|
||||||
|
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
transpileDir(fullPath);
|
||||||
|
} else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
|
||||||
|
const source = fs.readFileSync(fullPath, 'utf-8');
|
||||||
|
const result = ts.transpileModule(source, {
|
||||||
|
compilerOptions: {
|
||||||
|
module: ts.ModuleKind.ES2020,
|
||||||
|
target: ts.ScriptTarget.ES2020
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const jsPath = fullPath.replace(/\.ts$/, '.js');
|
||||||
|
fs.writeFileSync(jsPath, result.outputText);
|
||||||
|
console.log('✓ Transpiled', fullPath, 'to', jsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transpileDir('${destApi}');
|
||||||
|
"`, { stdio: 'inherit' });
|
||||||
|
|
||||||
|
console.log("✓ TypeScript transpilation complete");
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Note: TypeScript transpilation may not be necessary if using proper runtime");
|
||||||
|
// Don't fail the build if transpilation fails
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue