mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-29 00:59:37 +07:00
21 lines
599 B
TypeScript
21 lines
599 B
TypeScript
import { getFileExt } from "~/lib/utils";
|
|
import { FileSchema } from "~/server/db/schema/file";
|
|
import { ProjectSettingsSchema } from "~/server/db/schema/project";
|
|
import { transformJs } from "~/server/lib/transform-js";
|
|
|
|
export const serveJs = async (
|
|
file: FileSchema,
|
|
cfg?: ProjectSettingsSchema["js"]
|
|
) => {
|
|
let content = file.content || "";
|
|
|
|
// transpile to es5
|
|
if (cfg?.transpiler === "swc") {
|
|
const ext = getFileExt(file.filename);
|
|
const typescript = ["ts", "tsx"].includes(ext);
|
|
content = await transformJs(content, typescript ? "ts" : "js");
|
|
}
|
|
|
|
return content;
|
|
};
|