From 65c110e03be4fe47397d054cc5b54ea4d4fd3890 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 16 Nov 2025 01:48:52 +0000 Subject: [PATCH] completionId: cgen-8293208186f24554bc636affd053c746 cgen-8293208186f24554bc636affd053c746 --- copy-api.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/copy-api.js b/copy-api.js index fe5862fd..e015022a 100644 --- a/copy-api.js +++ b/copy-api.js @@ -2,6 +2,7 @@ import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; +import { execSync } from "child_process"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -41,3 +42,46 @@ const srcApi = path.resolve(__dirname, "api"); const destApi = path.resolve(__dirname, "..", "api"); 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 +}