Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
137 lines (112 loc) · 3.13 KB
/
Copy pathgulpfile.js
File metadata and controls
137 lines (112 loc) · 3.13 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var gulp = require('gulp');
var gutil = require('gutil');
var webpack = require('webpack');
var eslint = require('gulp-eslint');
var runSequence = require('run-sequence');
var clean = require('gulp-clean');
var replace = require('gulp-replace');
var exec = require('child_process').exec;
var mkdirp = require('mkdirp');
var bump = require('gulp-bump');
var getManifest = function () {
var fs = require('fs');
return JSON.parse(fs.readFileSync('./build/manifest.json', 'utf8'));
};
/**
* Clean
* Cleans the build directory before a build.
* Used for the build task.
*/
gulp.task('clean', function() {
return gulp.src(['./build', './dist']).pipe(clean());
});
/**
* ESLint
* Checks the sourcecode for errors with ESLint. Used for the build and dev tasks.
*/
gulp.task('lint', function () {
return gulp.src(['app/js/*.js'])
.pipe(eslint({ useEslintrc: true }))
.pipe(eslint.format());
});
gulp.task('pre-build', function (callback) {
runSequence(
'clean',
'bump',
'lint',
'static',
callback
);
});
gulp.task('bump', function (){
return gulp.src(['./manifest.json', './package.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
gulp.task('build', ['pre-build'], function (callback) {
var config = require('./config/webpack.config.js');
var compiler = webpack(config);
compiler.run(function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack-build', err);
}
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
var manifest = getManifest();
var name = manifest.name + '.' + manifest.version;
mkdirp('./dist', function(err) {
if (err) {
throw new gutil.PluginError('build', err);
}
var command = './node_modules/.bin/crx pack ./build -p ./config/extension.pem -o ./dist/';
command += name + '.crx';
exec(command, function (err, stdout, stderr) {
callback();
});
});
});
});
gulp.task('static', function () {
gulp.src(['manifest.json', 'src/**/*.css', 'src/**/*.png'])
.pipe(gulp.dest('./build'));
});
gulp.task('build-dev', [], function (callback) {
var config = require('./config/webpack.config.js');
var compiler = webpack(config);
compiler.run(function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack-build', err);
}
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task('reload', function () {
gulp.src('src/assets/reload.html')
.pipe(replace('__TIMESTAMP__', new Date().getTime().toString()))
.pipe(gulp.dest('./build'));
});
gulp.task('watch-static', [], function (callback) {
runSequence(
'static',
'reload',
callback
);
});
gulp.task('watch-webpack', [], function (callback) {
runSequence(
'build-dev',
'reload',
callback
);
});
gulp.task('dev', ['static', 'build-dev', 'reload'], function () {
gulp.watch(['src/*.json'], ['watch-static']);
gulp.watch(['src/css/*.css'], ['watch-static']);
gulp.watch(['src/assets/*.png'], ['watch-static']);
gulp.watch(['src/js/*.js', 'src/views/*.html'], ['watch-webpack']);
});
gulp.task('default', ['dev'])