-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
84 lines (77 loc) · 2.21 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
require('babel-register')({presets: ['es2015']});
const {spawn} = require('child_process');
const fs = require('fs-extra');
const eslint = require('gulp-eslint');
const glob = require('glob');
const gulp = require('gulp');
const gutil = require('gulp-util');
const gzipSize = require('gzip-size');
const path = require('path');
const {rollup} = require('rollup');
const nodeResolve = require('rollup-plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const runSequence = require('run-sequence');
const webpack = require('webpack');
const build = require('./bin/build');
const logBuildErrors = require('./bin/errors');
const server = require('./bin/server');
/**
* @return {boolean} True if NODE_ENV is set to production or the build is
* running on CI.
*/
const isProd = () => {
return process.env.NODE_ENV == 'production' || process.env.CI;
};
gulp.task('js', () => {
if (isProd()) {
return build('ga-task-manager.js').then(({code, map}) => {
fs.outputFileSync('ga-task-manager.js', code, 'utf-8');
fs.outputFileSync('ga-task-manager.map', map, 'utf-8');
const size = (gzipSize.sync(code) / 1000).toFixed(1);
gutil.log(
`Built ga-task-manager.js ${gutil.colors.gray(`(${size} Kb gzipped)`)}`);
}).catch((err) => {
logBuildErrors(err);
throw new Error('failed to build ga-task-manager.js');
});
} else {
return rollup({
entry: './lib/index.js',
plugins: [
nodeResolve(),
babel({
babelrc: false,
plugins: ['external-helpers'],
presets: [['es2015', {modules: false}]],
}),
],
}).then((bundle) => {
return bundle.write({
dest: 'ga-task-manager.js',
format: 'iife',
sourceMap: true,
});
});
}
});
gulp.task('lint', () => {
return gulp.src([
'gulpfile.babel.js',
'bin/ga-task-manager',
'bin/*.js',
'lib/*.js',
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('serve', ['js'], (done) => {
server.start(done);
process.on('exit', server.stop.bind(server));
});
gulp.task('watch', ['serve'], () => {
gulp.watch('./lib/**/*.js', ['js']);
gulp.watch([
'./lib/**/*.js',
]);
});