-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.js
45 lines (40 loc) · 1.12 KB
/
build.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
'use strict';
var fs = require('fs');
var path = require('path');
var map = require('map-stream');
var tmpl = require('lodash.template');
var browserify = require('browserify');
var mkdirp = require('mkdirp');
var output = process.cwd() + '/build';
var wrap = function(wrapperTemplate) {
return map(function(file, cb) {
var content = file.toString();
fs.readFile(path.resolve(wrapperTemplate), 'utf8', function(err, filedata) {
cb(null, tmpl(filedata, {yield:content}));
});
});
};
var bundleApp = function(callback) {
browserify(process.cwd() + '/script/app.js')
.bundle({
standalone: 'app'
})
.pipe(fs.createWriteStream(output + '/script/app.js'))
.on('close', function() {
if(callback) {
callback();
}
});
};
var templateApp = function(callback) {
fs.createReadStream(process.cwd() + '/template/app-main.us')
.pipe(wrap(process.cwd() + '/template/wrapper.us'))
.pipe(fs.createWriteStream(output + '/index.html'))
.on('close', function() {
if(callback) {
callback();
}
});
};
mkdirp.sync(output + '/script');
bundleApp(templateApp);