forked from aframevr/aframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
budo.js
62 lines (54 loc) · 1.59 KB
/
budo.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
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
var exec = require('child_process').exec;
var urlParse = require('url').parse;
var budo = require('budo');
function execCmd (cmd) {
var p = exec(cmd);
p.stderr.pipe(process.stderr);
p.stdout.pipe(process.stdout);
return p;
}
var consts = {
NAME: 'AFRAME',
ENTRY: './src/index.js',
DIST: 'dist/aframe-core.js',
BUILD: 'build/aframe-core.js',
WATCH: '{examples,lib,src,style}/**/*',
PORT: 9001
};
var opts = {
debug: process.env.NODE_ENVIRONMENT !== 'production',
verbose: true,
open: process.env.OPEN, // To enable: `OPEN=1 npm start`
live: process.env.LIVE, // To enable: `LIVE=1 npm start`
stream: process.stdout,
host: process.env.HOST,
port: process.env.PORT || consts.PORT,
browserifyArgs: ['-s', consts.NAME],
middleware: function (req, res, next) {
// Route `dist/aframe-core.js` to `build/aframe-core.js`
// so we can dev against the examples :)
var path = urlParse(req.url).pathname;
if (path.indexOf('/' + consts.DIST) !== -1) {
req.url = req.url.replace('/dist/', '/build/');
}
// TODO: Consider adding middleware that targets specific directories
// (such that editing `examples/a.html` doesn't reload `examples/b.html`).
next();
}
};
var app = budo(consts.ENTRY + ':' + consts.BUILD, opts);
app.watch(consts.WATCH)
.on('update', function () {
execCmd('semistandard -v');
});
if (opts.live) {
app.live()
.on('watch', function (eventType, fn) {
if (eventType !== 'change' && eventType !== 'add') { return; }
app.reload(fn);
})
.on('pending', function () {
app.reload(opts.output);
});
}