-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
85 lines (78 loc) · 2.45 KB
/
build.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* eslint-disable new-cap */
import "colors";
import { build, formatMessages, serve } from "esbuild";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import del from "del";
import { promises as fs } from "fs";
import path from "path";
const projects = (await fs.readdir("./projects/"))
.filter(path => path !== "js" && path !== "css" && !path.match(/.\w+$/))
.map(project => path.resolve("./projects/", project));
console.log(projects.map(project => path.resolve(project, "js/dist/**")));
await del(projects.map(project => path.resolve(project, "js/dist/**")));
const watch = process.env.NODE_WATCH
? {
onRebuild(error, res) {
if (error) console.warn(`${ "[Watch]".bold.blue } ${ `${ error?.message }`.red }`);
else console.log(`${ "[Watch]".bold.blue } ${ "Rebuild successful!".white }`);
},
}
: undefined;
const workerEntryPoints = [
"vs/language/json/json.worker.js",
"vs/language/css/css.worker.js",
"vs/language/html/html.worker.js",
"vs/language/typescript/ts.worker.js",
"vs/editor/editor.worker.js",
];
const plugins = [
NodeModulesPolyfillPlugin(),
];
build({
entryPoints: workerEntryPoints.map(entry => `./node_modules/monaco-editor/esm/${ entry }`),
bundle: true,
format: "iife",
outbase: "./node_modules/monaco-editor/esm/",
outdir: "./js/dist",
allowOverwrite: true,
plugins,
target: ["esnext"],
sourcemap: true,
});
build({
entryPoints: ["./node_modules/eslint/lib/linter/linter.js"],
bundle: true,
format: "esm",
outdir: "./js/dist",
target: ["esnext"],
allowOverwrite: true,
plugins,
sourcemap: true,
});
const buildOptions = {
sourcemap: true,
entryPoints: ["./js/index.js"],
bundle: true,
format: "iife",
outdir: "./js/dist",
loader: {
".ttf": "file",
},
target: ["esnext"],
allowOverwrite: true,
plugins,
watch,
};
if (process.env.NODE_WATCH && process.env.PORT) {
const builder = await serve({
port: +process.env.PORT || 3000,
servedir: "../../",
onRequest({ method, path, status, timeInMS }) {
console.log(`${ "[Server]".bold.blue } ${ method.green } ${ status.toString().yellow } ${ `http://localhost:${ process.env.PORT }${ path }`.blue } in ${ `${ timeInMS }ms`.cyan.blue }`);
},
}, buildOptions).then(res => {
console.log(`${ "[Server]".blue.bold } ${ `Listening on ${ process.env.PORT.toString().magenta.bold }`.white }`);
});
} else await build(buildOptions).then(result => {
if (watch) console.log(`${ "[Watch]".bold.blue } ${ "Watching for changes...".white }`);
});