-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.js
59 lines (51 loc) · 1.75 KB
/
builder.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
var browserify = require('browserify');
var stringify = require('stringify');
var CombinedStream = require('combined-stream');
var ReadableStream = require('stream').Readable;
var fs = require('fs');
var version = require('./package.json').version;
var licenseComment = [
'/*!',
'* Koko JavaScript library v' + version,
'* (c) OneSpot, Inc. - http://onespot.com/',
'* License: MIT (http://www.opensource.org/licenses/mit-license.php)',
'*/'
].join('\n') + '\n';
function build(minify, addSourceMap) {
// Create bundler.
var bundler = browserify({
entries: './src/koko.js',
debug: addSourceMap,
standalone: 'koko'
});
// Import HTML files as strings using stringify.
bundler.transform({ global: true }, stringify(['.html']));
if (minify) {
bundler.transform({ global: true }, 'uglifyify');
}
// Bundle code.
var postfix = '';
if (minify) {
postfix = '.min';
} else if (addSourceMap) {
postfix = '.debug';
}
var path = './build/koko' + postfix + '.js';
var sourceStream = bundler.bundle();
// Create license stream.
var licenseStream = new ReadableStream();
licenseStream.push(licenseComment);
licenseStream.push(null); // End of file
// Prepend license stream.
var combinedStream = CombinedStream.create();
combinedStream.append(licenseStream);
combinedStream.append(sourceStream);
// Write to disk!
var outStream = fs.createWriteStream(path);
combinedStream.pipe(outStream);
}
if (require.main === module) {
build(false, false); // Default (non-minified w/out source maps)
build(false, true); // Debug (non-minified with source maps)
build(true, false); // Production (minified)
}