-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gulpfile.js
162 lines (144 loc) · 4.75 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'use strict';
var path = require('path');
var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var bump = require('gulp-bump');
var zip = require('gulp-zip');
var git = require('gulp-git');
var ghRelease = require('gulp-github-release');
var crx = require('gulp-crx-pack');
var glob = require('glob');
var rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var es = require('event-stream');
var minimist = require('minimist');
var options = minimist(process.argv.slice(2));
var production = process.env.NODE_ENV === 'production';
var WATCH = false;
gulp.task('enable-watch', function() {
WATCH = true;
})
gulp.task('watch', ['enable-watch', 'build']);
gulp.task('build', function(done) {
glob('./src/pages/*/*.entry.js', function(err, files) {
if (err) {
done(err);
return;
}
var tasks = files.map(function(entry) {
var bundler = browserify({
entries: [entry],
debug: !production,
cache: {}, // required for watchify
packageCache: {}, // required for watchify
fullPaths: WATCH // required to be true only for watchify
});
if (WATCH) {
bundler.plugin(watchify, {
delay: 100,
ignoreWatch: ['**/node_modules/**'],
poll: true
});
}
bundler.transform('babelify', {presets: ['es2015', 'react']});
var rebundle = function() {
gutil.log('Start rebuild');
var stream = bundler
.bundle()
.on('error', function (err) {
gutil.log(err.name, err.loc);
console.log(err.codeFrame);
})
.pipe(source(entry))
.pipe(rename(function(path) {
path.basename = path.basename.replace(/entry$/, 'bundle')
}))
.pipe(gulp.dest('./'));
return stream;
};
bundler.on('log', gutil.log);
bundler.on('update', rebundle);
return rebundle();
});
es.merge(tasks).on('end', done);
});
});
gulp.task('bump', function() {
var types = {
p: 'patch',
m: 'minor'
}
var type = 'patch';
Object.keys(options).some(function(opt) {
if (types[opt]) {
type = types[opt];
return true;
}
});
gulp
.src(['./package.json', './src/manifest.json'], {
base: '.'
})
.pipe(bump({type: type}))
.pipe(gulp.dest('./'));
});
gulp.task('crx', function() {
var keyPath = path.join(process.env.HOME, '.keys', 'bem-chrome-devtools.pem');
var manifest = require('./src/manifest.json');
return gulp.src('./src')
.pipe(crx({
privateKey: fs.readFileSync(keyPath, 'utf8'),
filename: manifest.name + '-' + manifest.version + '.crx'
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('dist', function() {
var keyPath = path.join(process.env.HOME, '.keys', 'bem-chrome-devtools.pem');
var manifest = require('./src/manifest');
return es.merge([
gulp.src('src/**'),
gulp.src(keyPath).pipe(rename('key.pem'))
])
.pipe(zip(manifest.name + '-' + manifest.version + '.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('commit-release', function() {
return gulp
.src(['./package.json', './src/manifest.json'], {
base: '.'
})
.pipe(git.commit('release'));
});
gulp.task('tag-release', ['commit-release'], function() {
var manifest = require('./src/manifest');
return git.tag('v' + manifest.version, 'Release ' + manifest.version, function (err) {
if (err) {
throw err;
} else {
gutil.log('Create tag v' + manifest.version);
}
});
});
gulp.task('push-release', ['tag-release'], function() {
return git.push('origin', 'master', { args: ' --tags'}, function (err) {
if (err) {
throw err;
}
});
});
gulp.task('release', ['tag-release', 'crx'], function() {
var manifest = require('./src/manifest');
var packageJson = require('./package');
var version = manifest.version;
return gulp.src('./dist/' + manifest.name + '-' + manifest.version + '.crx')
.pipe(ghRelease({
token: require('./auth').ghToken,
name: 'Release ' + version,
notes: '',
draft: true,
manifest: packageJson
}));
});