-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.js
62 lines (52 loc) · 1.56 KB
/
tasks.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
const path = require('path');
const fs = require('fs');
const browserify = require('browserify');
const glob = require('glob');
const postcss = require('postcss');
const cssnext = require('postcss-cssnext');
const csso = require('csso');
const exorcist = require('exorcist');
const cmd = process.argv[2];
if (cmd === 'js') {
glob('./src/*.js', (err, files) => {
if (err) {
throw err;
}
files.map(entry => processFile(entry));
function processFile(entry) {
const filename = entry.split('/')[entry.split('/').length - 1];
return browserify({entries: [entry], debug: true})
.transform('babelify', {presets: ['es2015']})
.transform('uglifyify')
.bundle()
.pipe(exorcist(path.join(__dirname, 'public', filename + '.map')))
.pipe(fs.createWriteStream('public/' + filename));
}
});
} else if (cmd === 'css') {
glob('./src/*.css', (err, files) => {
if (err) {
throw err;
}
files.forEach(processFile);
function processFile(entry) {
const filename = entry.split('/')[entry.split('/').length - 1];
fs.readFile(entry, onFileRead);
function onFileRead(err, css) {
if (err) {
throw err;
}
postcss([cssnext])
.process(css, {from: entry, to: './public/' + filename})
.then(minify);
function minify(result) {
fs.writeFile('./public/' + filename, csso.minify(result.css).css);
}
}
}
});
} else {
console.error('usage: node tasks.js { js | css }');
process.exit(1);
}