-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.js
More file actions
32 lines (27 loc) · 732 Bytes
/
build.js
File metadata and controls
32 lines (27 loc) · 732 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
const fs = require('fs');
const join = require('path').join;
const PassThrough = require('stream').PassThrough;
const DIST_DIR = join(__dirname, 'dist');
const DIST_LIB = join(DIST_DIR, 'index.js');
let lib = require(DIST_LIB);
function createEsmDist(cb) {
fs.createReadStream(DIST_LIB)
.pipe(
new PassThrough({
final: function(cb) {
this.push('\nexport {\n');
for (let key in lib) this.push(` ${key},\n`);
this.push('};\nexport default xbytes;\n');
cb();
},
})
)
.pipe(fs.createWriteStream(join(DIST_DIR, 'index.mjs')))
.on('close', cb);
}
function main() {
createEsmDist(function(err) {
if (err) console.error(err);
});
}
main();