-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
45 lines (38 loc) · 1.31 KB
/
build.mjs
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
import { createHash } from 'crypto';
import { readdir, readFile, writeFile, rm } from 'fs/promises';
import { existsSync } from 'fs';
import { build } from 'esbuild';
const MD5 = (data) => createHash('md5').update(data).digest('hex').toString();
if (existsSync('dist')) await rm('dist', { recursive: true });
for (const plug of await readdir('plugins')) {
const outfile = `dist/${plug}/plugin.js`;
const entryPoint = `plugins/${plug}/index.js`;
await build({
entryPoints: [entryPoint],
bundle: true,
outfile: outfile,
minify: true,
plugins: [
{
name: 'solid-shelter-resolver',
setup(build) {
build.onResolve({ filter: /solid-js\/web/ }, ({ path }) => ({
path,
namespace: 'shltr-res-ns',
}));
build.onLoad({ filter: /.*/, namespace: 'shltr-res-ns' }, () => ({
contents: 'module.exports = shelter.solidWeb',
loader: 'js',
}));
},
},
],
globalName: 'e',
});
await writeFile(outfile, (await readFile(outfile)).toString().replace(/var e\s*=/, ''));
const manifest = (await readFile(`plugins/${plug}/plugin.json`)).toString();
await writeFile(
`dist/${plug}/plugin.json`,
manifest.replace('<HASH_PLACEHOLDER>', MD5((await readFile(outfile)).toString())),
);
}