-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
199 lines (170 loc) · 4.78 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"use strict";
const gulp = require('gulp');
const webpack = require('webpack-stream');
const clean = require('gulp-clean');
const bump = require('gulp-bump');
const fs = require('fs');
const semver = require('semver');
const path = require('path');
let tsProject;
let targetpaths = {};
// ts-script
function compileTS() {
const wpconfig = require('./webpack.config.js');
wpconfig.entry.index = './' + tsProject;
wpconfig.output.path = path.resolve(__dirname, targetpaths.target);
return gulp.src(tsProject)
.pipe(webpack(wpconfig))
.pipe(gulp.dest(targetpaths.target));
}
// firefox-setpaths
function prepareFirefox(cb) {
tsProject = 'scripts/firefox.ts';
targetpaths.target = 'release/firefox';
targetpaths.icons = targetpaths.target + '/icons';
targetpaths.html = targetpaths.target + '/html';
targetpaths.manifest = 'firefox/manifest.json';
cb();
}
// chrome-setpaths
function prepareChrome(cb) {
tsProject = 'scripts/chrome.ts';
targetpaths.target = 'release/chrome';
targetpaths.icons = targetpaths.target + '/icons';
targetpaths.html = targetpaths.target + '/html';
targetpaths.manifest = 'chrome/manifest.json';
cb();
}
// edge-setpaths
function prepareEdge(cb) {
tsProject = 'scripts/edge.ts';
targetpaths.target = 'release/edge';
targetpaths.icons = targetpaths.target + '/icons';
targetpaths.html = targetpaths.target + '/html';
targetpaths.manifest = 'edge/manifest.json';
cb();
}
// opera-setpaths
function prepareOpera(cb) {
tsProject = 'scripts/opera.ts';
targetpaths.target = 'release/opera';
targetpaths.icons = targetpaths.target + '/icons'
targetpaths.html = targetpaths.target + '/html'
targetpaths.manifest = 'opera/manifest.json';
cb();
}
// copy-icons
function copyIcons () {
return gulp.src(['icons/**/*']).pipe(gulp.dest(targetpaths.icons));
}
// copy-html
function copyHtml() {
return gulp
.src(['html/**/*'])
.pipe(gulp.dest(targetpaths.html))
}
function copyManifest() {
return gulp
.src([targetpaths.manifest])
.pipe(gulp.dest(targetpaths.target))
}
exports.firefox = gulp.series(
prepareFirefox,
gulp.parallel(copyIcons, copyHtml, compileTS, copyManifest)
);
exports.chrome = gulp.series(
prepareChrome,
gulp.parallel(copyIcons, copyHtml, compileTS, copyManifest)
);
exports.edge = gulp.series(
prepareChrome,
gulp.parallel(copyIcons, copyHtml, compileTS, copyManifest)
);
exports.opera = gulp.series(
prepareOpera,
gulp.parallel(copyIcons, copyHtml, compileTS, copyManifest)
)
function watchTS() {
gulp.watch('scripts/*.ts', compileTS)
gulp.watch('html/*', copyHtml)
}
// firefox-watch
exports.firefoxWatch = gulp.series(
prepareFirefox,
compileTS,
watchTS
);
// chrome-watch
exports.chromeWatch = gulp.series(
prepareChrome,
compileTS,
watchTS
);
// edge-watch
exports.edgeWatch = gulp.series(
prepareEdge,
compileTS,
watchTS
);
// opera-watch
exports.operaWatch = gulp.series(
prepareOpera,
compileTS,
watchTS
);
// bump versions on package/manifest
exports.bump = function () {
// read version from package.json
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));;
// increment version
var newVer = semver.inc(pkg.version, 'patch');
return gulp.src([
'./chrome/manifest.json',
'./firefox/manifest.json',
'./edge/manifest.json',
'./opera/manifest.json',
'./package.json'], { base: './' })
.pipe(bump({
version: newVer
}))
.pipe(gulp.dest('./'));
};
// bump versions on package/manifest
exports.bumpMinor = function () {
// read version from package.json
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));;
// increment version
var newVer = semver.inc(pkg.version, 'minor');
return gulp.src([
'./chrome/manifest.json',
'./firefox/manifest.json',
'./edge/manifest.json',
'./opera/manifest.json',
'./package.json'], { base: './' })
.pipe(bump({
version: newVer
}))
.pipe(gulp.dest('./'));
};
function cleanTarget() {
return gulp.src(targetpaths.target, { read: false, allowEmpty: true })
.pipe(clean());
}
// clean-firefox
const cleanFirefox = gulp.series(prepareFirefox, cleanTarget);
exports.cleanFirefox = cleanFirefox;
// clean-chrome
const cleanChrome = gulp.series(prepareChrome, cleanTarget);
exports.cleanChrome = cleanChrome;
// clean-edge
const cleanEdge = gulp.series(prepareEdge, cleanTarget);
exports.cleanEdge = cleanEdge;
// clean-opera
const cleanOpera = gulp.series(prepareOpera, cleanTarget);
exports.cleanOpera = cleanOpera;
exports.clean = gulp.parallel(
cleanFirefox,
cleanChrome,
cleanEdge,
cleanOpera
)