-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgulpfile.babel.js
113 lines (87 loc) · 2.75 KB
/
gulpfile.babel.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Native
import fs from 'fs';
import path from 'path';
import { exec } from 'child_process'
// npm
import rimraf from 'rimraf';
import clc from 'cli-color';
import yargs from 'yargs';
// gulp
import gulp from 'gulp';
import runSequence from 'run-sequence';
// package
import configGenerator from './dev-env/webpack.generator';
import webpackBuild from './dev-env/webpack.build';
import webpackDevServer from './dev-env/webpack.server';
import Manifest from './dev-env/manifest'
import overrideHotUpdater from './dev-env/lib/override_hot_updater'
import * as paths from './dev-env/paths'
// Program
const args = yargs
.alias('p', 'production')
.argv;
gulp.task('env', () => {
const env = args.production ? 'production' : 'development';
process.env.NODE_ENV = env; // eslint-disable-line no-undef
});
// gulp.task('test-manifest', () => {
// const watcher = new Manifest(paths.manifest)
// watcher.watch()
// })
let manifest
gulp.task('manifest', () => {
manifest = new Manifest(paths.manifest)
manifest.run()
});
gulp.task('override_webpack', () => {
overrideHotUpdater()
});
gulp.task('webpack-production', function(done) {
return webpackBuild(configGenerator(false, manifest))(done)
});
gulp.task('webpack-hot', function(done) {
return webpackDevServer(configGenerator(true, manifest))(done)
});
gulp.task('webpack-dev', function(done) {
return webpackBuild(configGenerator(true, manifest))(done)
});
gulp.task('webpack-local', (done) => {
runSequence('webpack-dev', 'webpack-hot', done);
});
gulp.task('development', (done) => {
runSequence('override_webpack', 'manifest', 'webpack-hot', done)
})
gulp.task('extension', (done) => {
// TODO detect system and Chrome path
const chromeBinaryPath = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
setTimeout(() => {
console.log(clc.yellow(`Building extension into '${paths.releaseBuild}'`))
exec(`\$('${chromeBinaryPath}' --pack-extension=${paths.releaseBuild})`, (error, stdout, stderr) => {
console.log(clc.green('Done'));
if(stdout)
console.log(clc.yellow('stdout: ' + stdout));
if(stderr)
console.log(clc.red('stderr: ' + stderr));
if(error !== null)
console.log(clc.red('exec error: ' + error));
done()
})
// Long enought to prevent some unexpected errors
}, 1000)
})
gulp.task('prepare-release-dir', (done) => {
rimraf(paths.release, () => {
fs.mkdir(paths.release, () => {
done()
})
})
})
gulp.task('production', (done) => {
runSequence('prepare-release-dir', 'manifest', 'webpack-production', 'extension', done)
})
gulp.task('run', (done) => {
runSequence('env', (args.production ? 'production' : 'development'), done)
});
gulp.task('default', (done) => {
runSequence('run', done);
});