forked from michelgrootjans/explaining-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
30 lines (26 loc) · 881 Bytes
/
Copy pathbundle.js
File metadata and controls
30 lines (26 loc) · 881 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
const fs = require('fs').promises;
const browserify = require('browserify');
const path = require('path');
const open = require('open');
const promisify = require('util').promisify;
async function bundle() {
await fs.rm('dist', { recursive: true, force:true });
await fs.mkdir('dist');
const sourceFiles = await getSourceFiles();
const bundle = await createBundle(sourceFiles);
await fs.writeFile(path.join('dist', 'index.js'), bundle, 'utf8');
// await open('index.html', { wait: true });
}
async function createBundle(files) {
const b = browserify();
files.forEach(f=> b.add(f));
var doBundle = promisify(b.bundle.bind(b));
var buf = await doBundle()
return buf;
}
async function getSourceFiles() {
const files = await fs.readdir('src');
const jsFiles = files.filter(f=> f.endsWith('.js'));
return jsFiles.map(f=> path.join('src', f));
}
bundle();