-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild-stylus.js
64 lines (37 loc) · 1.05 KB
/
build-stylus.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
63
64
// Hack: npm run has poor cross-platform env var support.
if (process.env.DEBUG === undefined) process.env.DEBUG = 'build:*';
const fs = require('fs');
const debug = require('debug')('build:stylus');
const stylus = require('stylus');
const { watch, args } = require('./build-util');
let building = false;
function build() {
if (building) return; // block builds until they finish
debug('bundling');
building = true;
fs.readFile('src/index.styl', 'utf8', renderBundle);
}
function renderBundle(err, data) {
if (err) return error(err);
stylus.render(data, {
paths: [ 'src' ],
compress: (args.prod === true),
}, writeBundle)
}
function writeBundle(err, data) {
if (err) return error(err);
fs.writeFile(__dirname + '/out/index.css', data, done);
}
function done(err) {
if (err) return error(err);
debug(`bundled`);
building = false;
}
function error(err) {
debug('error while bundling:\n' + (err.stack || err.message));
building = false;
}
if (args.watch) {
watch('src', { include: /styl$/gi }, build);
}
build();