-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.js
68 lines (58 loc) · 1.37 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
var pkg = require('./package.json');
var fs = require('fs');
var ugly = require('uglify-js');
var jshint = require('jshint').JSHINT;
var babel = require('babel');
var gaze = require('gaze');
function lint(full) {
jshint(full.toString(), {
browser: true,
undef: true,
unused: true,
immed: true,
eqeqeq: true,
eqnull: true,
noarg: true,
predef: ['define', 'module', 'exports']
});
if (jshint.errors.length) {
jshint.errors.forEach(function (err) {
console.log(err.line+':'+err.character+' '+err.reason);
});
} else {
console.log('linted')
}
return true;
}
function build(code) {
var minified = ugly.minify(code, {fromString: true}).code;
var header = [
'/*!',
' '+pkg.config.title+' '+pkg.version,
' license: MIT',
' '+pkg.homepage,
'*/',
''
].join('\n');
fs.writeFile('dist/'+pkg.config.filename+'.js', header+code);
fs.writeFile('dist/'+pkg.config.filename+'.min.js', header+minified);
console.log('dist built');
}
function transform(filepath) {
babel.transformFile(filepath, {modules: 'umd'}, function (err,res) {
if (err) {
return console.log(err);
} else {
lint(res.code);
build(res.code);
}
});
}
gaze('src/'+pkg.config.filename+'.js', function(err, watcher){
// On file changed
this.on('changed', function(filepath) {
transform(filepath);
});
console.log('watching');
});
transform('src/'+pkg.config.filename+'.js');