2024-02-22 12:14:58 +00:00
|
|
|
import { FileSchema } from "~/server/db/schema/file";
|
2024-02-24 03:55:50 +00:00
|
|
|
import { ProjectSettingsSchema } from "~/server/db/schema/project";
|
2024-02-22 12:14:58 +00:00
|
|
|
import { transformJs } from "~/server/lib/transform-js";
|
|
|
|
|
2024-02-24 03:55:50 +00:00
|
|
|
export const serveJs = async (
|
|
|
|
file: FileSchema,
|
|
|
|
cfg?: ProjectSettingsSchema["js"]
|
|
|
|
) => {
|
2024-02-22 12:14:58 +00:00
|
|
|
let content = file.content || "";
|
|
|
|
|
2024-02-24 03:55:50 +00:00
|
|
|
// transpile to es5
|
|
|
|
if (cfg?.transpiler === "swc") {
|
|
|
|
content = await transformJs(content);
|
|
|
|
}
|
2024-02-22 12:14:58 +00:00
|
|
|
|
|
|
|
return content;
|
|
|
|
};
|