-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ts
39 lines (34 loc) · 860 Bytes
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fs from "fs";
import { transform } from "@swc/core";
(async () => {
const fileNames = fs.readdirSync("./src");
for (const fileName of fileNames) {
const source = fs.readFileSync(`./src/${fileName}`, "utf-8");
if (!fs.existsSync("./build")) fs.mkdirSync("./build");
let { code } = await transform(
`function createPolicy(cb) {
cb({
row: globalThis,
function: globalThis,
auth: globalThis.auth,
plv8: globalThis.plv8,
});
}
${source}`,
{
sourceMaps: false,
jsc: {
parser: {
syntax: "typescript",
tsx: false,
},
},
}
);
code = `-- ${fileName}.plv8.sql
boolean as $$
${code.trim()}
$$ language plv8;`.replace("export default", "return");
fs.writeFileSync(`./build/${fileName.split(".")[0]}.plv8.sql`, code);
}
})();