forked from twnlink/neptune-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
53 lines (48 loc) · 1.5 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
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const repl = require("repl");
const plugins = fs.readdirSync("./plugins");
for (const plugin of plugins) {
let pluginPath = path.join("./plugins/", plugin);
const pluginManifest = JSON.parse(
fs.readFileSync(path.join(pluginPath, "plugin.json"))
);
const outfile = path.join(pluginPath, "dist/index.js");
esbuild
.build({
entryPoints: [
"./" + path.join(pluginPath, pluginManifest.main ?? "index.js"),
],
bundle: true,
minify: true,
format: "esm",
// Make every node builtin external while still bundling for browsers.
external: [
...repl._builtinLibs,
...repl._builtinLibs.map((m) => "node:" + m),
"@neptune",
"@plugin",
],
platform: "browser",
outfile,
})
.then(() => {
fs.createReadStream(outfile)
// It being md5 does not matter, this is for caching and not security
.pipe(crypto.createHash("md5").setEncoding("hex"))
.on("finish", function () {
fs.writeFileSync(
path.join(pluginPath, "dist/manifest.json"),
JSON.stringify({
name: pluginManifest.name,
description: pluginManifest.description,
author: pluginManifest.author,
hash: this.read(),
})
);
console.log("Built " + pluginManifest.name + "!");
});
});
}