-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
42 lines (37 loc) · 919 Bytes
/
Copy pathbuild.js
File metadata and controls
42 lines (37 loc) · 919 Bytes
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
//https://github.com/Pecacheu/Utils.js; GNU GPL v3
import fs from 'fs/promises';
import path from 'path';
import C from 'chalk';
import build from 'raiutils/build';
const log = console.log,
UTF = {encoding: 'utf8'},
LibDel = '(ext || (ext = {}))',
LibRep = '(U)';
build.setOpts({
esbuild: false,
stripDebug: false,
stripPriv: true,
jsMin: {...build.defaults.jsMin, ecma: 2020},
onPreMin: async () => {
log(C.bgYellow('Codegen'));
await build.recurse(libGen, build.opts.dist);
}
});
async function libGen(pin, _, fn) {
try {
const ext = path.extname(fn);
if(ext !== '.js') return;
const fin = pin + '/' + fn;
let f = await fs.readFile(fin, UTF);
const li = f.indexOf(LibDel);
if(li !== -1) {
f = f.slice(0, li) + LibRep + f.slice(li + LibDel.length);
await fs.writeFile(fin, f);
log(C.cyan(`- ${fn}`));
}
} catch(e) {
log(C.red(`- ${fn}`));
throw e;
}
}
await build.run();