-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
158 lines (137 loc) · 4.1 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
/*jshint node: true*/
var gulp = require('gulp');
var runSequence = require('run-sequence');
var exec = require('child_process').exec;
var zip = require('gulp-zip');
var del = require('del');
var jshint = require('gulp-jshint');
var bump = require('gulp-bump');
var jeditor = require('gulp-json-editor');
var isChromeOnly = process.argv.indexOf('--chromeonly') !== -1;
var path = {
src: {
blocks: 'blocks/**',
javascriptSources: 'blocks/**/*.js',
cssSources: 'blocks/**/*.css',
manifest: 'manifest.json',
package: 'package.json',
node_modules: 'node_modules/js-md5/build/*'
},
not: {
tests: '!./**/*.test.js',
css: '!./**/*.css',
},
dist: {
all: 'dist/**',
blocks: 'dist/blocks',
manifest: 'dist',
node_modules: 'dist/components'
},
build: {
itself: 'build',
firefox: 'build/firefox',
chrome: 'build/chrome'
},
// environment file with API Credentials
// from addons.mozilla.org
// looks like:
// {
// "issuer": "************",
// "secret": "************************************************************"
// }
env: '.env.json'
};
// replace BUMP :C
// gulp.task('bump', function(){
// gulp.src([path.src.package, path.src.manifest])
// .pipe(bump({type:'prerelease'}))
// .pipe(gulp.dest('./'));
// });
gulp.task('clean', function() {
return del([path.build.itself, path.dist.all]);
});
gulp.task('styles', function() {
gulp.src(path.src.cssSources)
.pipe(gulp.dest(path.dist.blocks));
});
gulp.task('copy-blocks', function() {
return gulp.src([path.src.blocks, path.not.tests, path.not.css])
.pipe(gulp.dest(path.dist.blocks));
});
gulp.task('copy-manifest-and-adapt', function() {
return gulp.src(path.src.manifest)
.pipe(jeditor(function(manifest) {
if (isChromeOnly) {
delete manifest.applications;
}
return manifest; // must return JSON object.
}))
.pipe(gulp.dest(path.dist.manifest));
});
gulp.task('copy-node_modules', function() {
return gulp.src(path.src.node_modules)
.pipe(gulp.dest(path.dist.node_modules));
});
gulp.task('copy', function(finishCallback) {
runSequence('clean', ['copy-blocks', 'copy-manifest-and-adapt', 'copy-node_modules', 'styles'], finishCallback);
});
// Recopy all before watch
gulp.task('watch', ['copy'], function() {
gulp.watch(path.src.cssSources, ['styles']);
gulp.watch(path.src.blocks, ['copy-blocks']);
gulp.watch(path.src.manifest, ['copy-manifest-and-adapt']);
gulp.watch(path.src.node_modules, ['copy-node_modules']);
});
// Linter
gulp.task('lint', function() {
return gulp.src(path.src.javascriptSources)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
// Executing signing of Firefox WebExtension.
// It will send package to AMO and return
// signed extension to `build` folder
gulp.task('sign:firefox', function(cb) {
// getting issuer and secret from env file
var signParams = require('./' + path.env);
var execSign = 'web-ext sign' +
' -s dist' +
' -a ' + path.build.firefox +
' --api-secret ' + signParams.secret +
' --api-key ' + signParams.issuer;
exec(execSign, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('pack:firefox', function(cb) {
// -a build dir, -s source dir
var execPack = 'web-ext build' +
' -s dist' +
' -a ' + path.build.firefox;
exec(execPack, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// Packing for Chrome
gulp.task('pack:chrome', function() {
var manifest = require('./' + path.dist.manifest + '/manifest.json'),
distFileName = manifest.name + '-' + manifest.version + '.zip';
// Build distributable extension
return gulp.src(path.dist.all)
.pipe(zip(distFileName))
.pipe(gulp.dest(path.build.chrome));
});
gulp.task('build', function() {
runSequence('copy', 'pack:chrome', 'sign:firefox');
});
gulp.task('build:firefox', function() {
runSequence('bump', 'copy', 'sign:firefox', 'pack:firefox');
});
gulp.task('build:chrome', function() {
runSequence('copy', 'pack:chrome');
});