-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
80 lines (64 loc) · 1.71 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// settings
var FILE_ENCODING = 'utf-8',
EOL = '\n';
// Dependencies
var _cli = require('commander'),
_handlebars = require('hbs'),
_minify = require('clean-css'),
_fs = require('fs');
// Helper, will generate a CSV if package.json contains multiple licenses
_handlebars.registerHelper('license', function(items){
items = items.map(function(val){
return val.type;
});
return items.join(', ');
});
// Logic
// - concatinate all files
concat({
src : [
'css/_start.css',
'css/reset.css',
'css/normalize.css',
'css/tags.css',
'css/classes.css',
'css/attributes.css',
'css/touch.css'
],
dest : 'build/common.css'
});
// - Create / save minified file
minify('build/common.css', 'build/common-min.css');
//
// Methods
function concat(opts) {
var fileList = opts.src;
var distPath = opts.dest;
var lib = fileList.map(function(filePath){
return _fs.readFileSync(filePath, FILE_ENCODING);
});
var template = _handlebars.compile( lib.join(EOL) );
//reuse package.json data and add build date
var data = JSON.parse( _fs.readFileSync('package.json', FILE_ENCODING) );
data.build_date = (new Date()).toUTCString();
// Save uncompressed file
_fs.writeFileSync(distPath, template(data), FILE_ENCODING);
console.log(' '+ distPath +' built.');
}
function minify(srcPath, distPath) {
/*
var
jsp = uglyfyJS.parser,
pro = uglyfyJS.uglify,
ast = jsp.parse( _fs.readFileSync(srcPath, FILE_ENCODING) );
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
*/
var source = _fs.readFileSync(srcPath, FILE_ENCODING);
var result = _minify.process(source, {
keepSpecialComments: 1,
removeEmpty: true
});
_fs.writeFileSync(distPath, result, FILE_ENCODING);
console.log(' '+ distPath +' built.');
}