-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
99 lines (77 loc) · 1.9 KB
/
gulpfile.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
var gulp = require('gulp');
var SRC = 'src';
var OUT = 'out';
var BROWSERIFY_ENTRY_POINT = 'src';
function pack(options) {
var webpack = require('webpack');
return new Promise(function (resolve, reject) {
webpack({
entry: './lib/index.js',
output: {
path: OUT,
filename: 'contexta.js',
library: 'Contexta',
libraryTarget: 'umd',
},
devtool: '#source-map'
}, function (err, stats) {
if (err) {
return reject(err);
}
var errors = stats.compilation.errors;
if (errors.length > 0) {
return reject(errors[0]);
}
return resolve();
});
});
}
gulp.task('default', ['build']);
gulp.task('build', function () {
return pack({
debug: false
});
});
gulp.task('pack', ['build'], function (cb) {
var exec = require('child_process').exec;
var path = require('path');
var gutil = require('gulp-util');
var compilerDir = path.dirname(require.resolve('google-closure-compiler'));
var compilerJar = path.join(compilerDir, 'compiler.jar');
var options = (function (options) {
var keys = Object.keys(options);
return keys.reduce(function (s, key) {
var value = options[key];
if (value === true) {
return s + ' --' + key;
} else if (value) {
if (Array.isArray(value)) {
return s + value.reduce(function (s, x) {
return s + ' --' + key + ' ' + x;
}, '');
} else {
return s + ' --' + key + ' ' + value;
}
} else {
return s;
}
}, '');
}(function () {
var options = require('./gcc-options');
options.js = OUT + '/contexta.js';
options.js_output_file = OUT + '/contexta.min.js';
return options;
}()));
var cmd = 'java -server -XX:+TieredCompilation -jar ' + compilerJar + options;
gutil.log(cmd);
exec(cmd, function (err, stdout, stderr) {
if (stdout) {
gutil.log(stdout);
}
if (stderr) {
return cb(new gutil.PluginError('google-closure-compiler', stderr));
}
cb();
});
});