-
Notifications
You must be signed in to change notification settings - Fork 1
/
compilePluginScripts.ts
56 lines (50 loc) · 1.44 KB
/
compilePluginScripts.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as esbuild from "https://deno.land/x/esbuild@v0.19.4/mod.js";
import * as path from "node:path";
import * as fs from "https://deno.land/std@0.207.0/fs/mod.ts";
import { compileTypeScript } from "./utilities/compileTypeScript.ts";
import editorScriptsToCompile from "./plugins/editor/scriptsToCompile.ts";
import webSocketScriptsToCompile from "./plugins/websocket/scriptsToCompile.ts";
async function compilePlugins() {
await compilePluginScripts(
"./plugins/editor",
editorScriptsToCompile,
);
await compilePluginScripts(
"./plugins/websocket",
webSocketScriptsToCompile,
);
// https://esbuild.github.io/getting-started/#deno
esbuild.stop();
}
async function compilePluginScripts(
pluginPath: string,
scriptsToCompile: {
name: string;
isExternal?: boolean;
externals?: string[];
}[],
) {
const outputPath = path.join(pluginPath, "compiled-scripts");
await fs.ensureDir(pluginPath);
await fs.ensureDir(outputPath);
try {
await Promise.all(
scriptsToCompile.map(async ({ name, externals }) =>
Deno.writeTextFile(
path.join(outputPath, `${name}.ts`),
await compileTypeScript(
path.join(Deno.cwd(), pluginPath, "scripts", `${name}.ts`),
"production",
externals,
),
)
),
);
} catch (error) {
console.error(error);
}
}
if (import.meta.main) {
await compilePlugins();
}
export { compilePlugins };