-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.mjs
206 lines (181 loc) · 5.32 KB
/
gulpfile.mjs
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
200
201
202
203
204
205
206
import gulp from 'gulp';
import rename from 'gulp-rename';
import replace from 'gulp-replace';
import jsoneditor from 'gulp-json-editor';
import zip from 'gulp-zip';
import del from 'del';
import { readFileSync } from 'fs';
const manifest = JSON.parse(readFileSync('./src/manifest.json'));
const browserPlatforms = [
'firefox',
'chrome',
'edge',
'opera',
'safari'
];
// copy universal
const copyTaskNames = [];
createCopyTasks('pure_dist', {
source: './dist/',
destinations: browserPlatforms.map((platform) => `./builds/${platform}`),
});
function createCopyTasks (label, opts) {
const copyTaskName = `copy:${label}`;
copyTask(copyTaskName, opts);
copyTaskNames.push(copyTaskName);
}
function copyTask (taskName, opts) {
const source = opts.source;
const destination = opts.destination;
const destinations = opts.destinations || [destination];
const pattern = opts.pattern || '/**/*';
return gulp.task(taskName, function () {
return performCopy();
});
function performCopy () {
// stream from source
let stream = gulp.src(source + pattern, { base: source });
// copy to destinations
destinations.forEach(function (destination) {
stream = stream.pipe(gulp.dest(destination));
});
return stream;
}
}
// task generators
function zipTask (target) {
return () => {
return gulp.src(`./builds/${target}/**`)
.pipe(zip(`ext-${target}-${manifest.version}.zip`))
.pipe(gulp.dest('./builds'));
};
}
// clean dist
gulp.task('clean', function clean () {
return del(['./builds/*']);
});
// manifest tinkering
gulp.task('manifest:chrome', function () {
return gulp.src('./builds/chrome/manifest.json')
.pipe(jsoneditor(function (json) {
json.minimum_chrome_version = '88';
return json;
}))
.pipe(gulp.dest('./builds/chrome', { overwrite: true }));
});
gulp.task('manifest:firefox', function () {
return gulp.src('./builds/firefox/manifest.json')
.pipe(jsoneditor(function (json) {
json.browser_specific_settings = {
"gecko": {
"id": "[email protected]",
"strict_min_version": "107.0"
}
};
return json;
}))
.pipe(gulp.dest('./builds/firefox', { overwrite: true }));
});
gulp.task('manifest:opera', function () {
return gulp.src('./builds/opera/manifest.json')
.pipe(jsoneditor(function (json) {
delete json.short_name;
return json;
}))
.pipe(gulp.dest('./builds/opera', { overwrite: true }));
});
gulp.task('delete:development', function () {
return del(
browserPlatforms.map((platform) => `./builds/${platform}/livereload.js`)
.concat(browserPlatforms.map((platform) => `./builds/${platform}/chromereload.js`))
.concat(browserPlatforms.map((platform) => `./builds/${platform}/*.css.map`))
);
});
gulp.task('copy',
gulp.series(
gulp.parallel(...copyTaskNames),
'manifest:firefox',
'manifest:chrome',
'manifest:opera',
)
);
// zip tasks for distribution
gulp.task('zip:chrome', zipTask('chrome'));
gulp.task('zip:firefox', zipTask('firefox'));
gulp.task('zip:opera', zipTask('opera'));
gulp.task('zip:edge', zipTask('edge'));
gulp.task('zip:safari', zipTask('safari'));
gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:opera', 'zip:edge', 'zip:safari'));
// high level tasks
gulp.task('build',
gulp.series(
'clean',
'copy',
'delete:development',
'zip'
)
);
// clean mobile dist
gulp.task('clean:mobile', function clean_mobile () {
return del(['./builds/mobile*']);
});
// create mobile version
gulp.task('mobile:polyfill',
gulp.series(
function mobile_polyfill () {
return gulp.src('./tools/mobile-polyfill.js')
.pipe(rename('browser-polyfill.js'))
.pipe(gulp.dest('./builds/mobile/', { overwrite: true }));
},
function mobile_background () {
return gulp.src('./tools/background.html')
.pipe(gulp.dest('./builds/mobile/', { overwrite: true }));
}
)
);
// replace pathes for mobile version
gulp.task('mobile:assets',
gulp.series(
function replace_js() {
return gulp.src('./builds/mobile/*.js')
.pipe(replace('/assets/', '/assets/wallet-js/assets/'))
.pipe(gulp.dest('./builds/mobile/', { overwrite: true }));
},
function replace_css() {
return gulp.src('./builds/mobile/*.css')
.pipe(replace('./', '/assets/wallet-js/'))
.pipe(replace('(assets/', '(/assets/wallet-js/'))
.pipe(gulp.dest('./builds/mobile/', { overwrite: true }));
}
)
);
copyTask('copy:mobile', {
source: './dist/',
destination: './builds/mobile',
});
gulp.task('delete:development:mobile', function () {
return del(['./builds/mobile/livereload.js',
'./builds/mobile/chromereload.js',
'./builds/mobile/*.css.map'
]);
});
// high level tasks
gulp.task('mobile',
gulp.series(
'clean:mobile',
'copy:mobile',
'mobile:polyfill',
'mobile:assets',
'delete:development:mobile',
)
);
// patch version in manifest
gulp.task('patchVersion', function () {
return gulp.src('./src/manifest.json')
.pipe(jsoneditor(function (json) {
const lastIndex = json.version.lastIndexOf(".");
json.version = json.version.substr(0, lastIndex) + "." + (new Number(json.version.substr(lastIndex + 1)) + 1);
return json;
}))
.pipe(gulp.dest('./src/', { overwrite: true }));
});