-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
51 lines (39 loc) · 1.85 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
46
47
48
49
50
51
/*
gotoB - v2.3.1
Written by Federico Pereiro ([email protected]) and released into the public domain.
To build gotoB, run `node build`. If everything works well, a file named `gotoB.min.js` will be created. If you want to create a non-minified version, run `node build dev` instead.
*/
var fs = require ('fs');
var zlib = require ('zlib');
var dale = require ('dale');
var teishi = require ('teishi');
var UglifyJS = require ('uglify-js');
var clog = teishi.clog;
var build = function (files, dev) {
var code = '', t = teishi.time ();
dale.go (files, function (v) {
code += fs.readFileSync (v, 'utf8');
});
if (dev) {
return fs.writeFile ('gotoB.min.js', code, 'utf8', function (error) {
if (error) return clog ('Error', 'writeFile error.');
clog ('Success', 'gotoB.min.js built successfully!');
});
}
var lines = code.split ('\n').length - 1;
code = UglifyJS.minify (code, {ie8: true}).code;
if (! code) return clog ('Error', 'js build error.');
zlib.gzip (code, function (error, zipcode) {
zlib.gunzip (zipcode, function (error, check) {
if (error) return clog ('Error', 'Compression error.');
if (code !== check.toString ('utf8')) return clog ('Error', 'Compression mismatch error.');
fs.writeFile ('gotoB.min.js', code, 'utf8', function (error) {
if (error) return clog ('Error', 'writeFile error.');
clog ('Success', 'gotoB.min.js built successfully in ' + Math.round ((teishi.time () - t) / 10) / 100 + 's!', code.length + ' bytes total,', zipcode.length + ' bytes minified & gzipped,', lines, 'lines of source code.');
});
});
});
}
build (dale.go (['dale', 'teishi', 'lith', 'recalc', 'cocholate'], function (v) {
return 'node_modules/' + v + '/' + v + '.js';
}).concat ('./gotoB.js'), process.argv [2] === 'dev');