forked from bitwarden/clients
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
238 lines (217 loc) · 7.44 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
const gulp = require('gulp'),
gulpif = require('gulp-if'),
filter = require('gulp-filter'),
replace = require('gulp-replace'),
googleWebFonts = require('gulp-google-webfonts'),
jeditor = require("gulp-json-editor"),
child = require('child_process'),
zip = require('gulp-zip'),
manifest = require('./src/manifest.json'),
del = require('del'),
fs = require('fs');
const paths = {
build: './build/',
dist: './dist/',
coverage: './coverage/',
node_modules: './node_modules/',
popupDir: './src/popup/',
cssDir: './src/popup/css/',
safari: './src/safari/'
};
const filters = {
fonts: [
'!build/popup/fonts/*',
'build/popup/fonts/Open_Sans*.woff',
'build/popup/fonts/fontawesome*.woff2',
'build/popup/fonts/fontawesome*.woff'
],
safari: [
'!build/safari/**/*'
],
webExt: [
'!build/manifest.json'
],
nonSafariApp: [
'!build/background.html',
'!build/popup/index.html'
],
};
function buildString() {
var build = '';
if (process.env.APPVEYOR_BUILD_NUMBER && process.env.APPVEYOR_BUILD_NUMBER !== '') {
build = `-${process.env.APPVEYOR_BUILD_NUMBER}`;
} else if (process.env.BUILD_NUMBER && process.env.BUILD_NUMBER !== '') {
build = `-${process.env.BUILD_NUMBER}`;
}
return build;
}
function distFileName(browserName, ext) {
return `dist-${browserName}${buildString()}.${ext}`;
}
function dist(browserName, manifest) {
return gulp.src(paths.build + '**/*')
.pipe(filter(['**'].concat(filters.fonts).concat(filters.safari)))
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'browser_' + browserName)))
.pipe(gulpif('manifest.json', jeditor(manifest)))
.pipe(zip(distFileName(browserName, 'zip')))
.pipe(gulp.dest(paths.dist));
}
function distFirefox() {
return dist('firefox', (manifest) => {
delete manifest.content_security_policy;
removeShortcuts(manifest);
return manifest;
});
}
function distOpera() {
return dist('opera', (manifest) => {
delete manifest.applications;
delete manifest.content_security_policy;
removeShortcuts(manifest);
return manifest;
});
}
function distChrome() {
return dist('chrome', (manifest) => {
delete manifest.applications;
delete manifest.content_security_policy;
delete manifest.sidebar_action;
delete manifest.commands._execute_sidebar_action;
return manifest;
});
}
function distEdge() {
return dist('edge', (manifest) => {
delete manifest.applications;
delete manifest.content_security_policy;
delete manifest.sidebar_action;
delete manifest.commands._execute_sidebar_action;
return manifest;
});
}
function removeShortcuts(manifest) {
if (manifest.content_scripts && manifest.content_scripts.length > 1) {
const shortcutsScript = manifest.content_scripts[1];
if (shortcutsScript.js.indexOf('content/shortcuts.js') > -1) {
manifest.content_scripts.splice(1, 1);
}
}
}
function distSafariMas(cb) {
return distSafariApp(cb, 'mas');
}
function distSafariMasDev(cb) {
return distSafariApp(cb, 'masdev');
}
function distSafariDmg(cb) {
return distSafariApp(cb, 'dmg');
}
function distSafariApp(cb, subBuildPath) {
const buildPath = paths.dist + 'Safari/' + subBuildPath + '/';
const builtAppexPath = buildPath + 'build/Release/safari.appex';
const builtAppexFrameworkPath = buildPath + 'build/Release/safari.appex/Contents/Frameworks/';
const entitlementsPath = paths.safari + 'safari/safari.entitlements';
var args = [
'--verbose',
'--force',
'-o',
'runtime',
'--sign',
'Developer ID Application: 8bit Solutions LLC',
'--entitlements',
entitlementsPath
];
if (subBuildPath !== 'dmg') {
args = [
'--verbose',
'--force',
'--sign',
subBuildPath === 'mas' ? '3rd Party Mac Developer Application: 8bit Solutions LLC' :
'6B287DD81FF922D86FD836128B0F62F358B38726',
'--entitlements',
entitlementsPath
];
}
return del([buildPath + '**/*'])
.then(() => safariCopyAssets(paths.safari + '**/*', buildPath))
.then(() => safariCopyBuild(paths.build + '**/*', buildPath + 'safari/app'))
.then(() => {
const proc = child.spawn('xcodebuild', [
'-project',
buildPath + 'desktop.xcodeproj',
'-alltargets',
'-configuration',
'Release']);
stdOutProc(proc);
return new Promise((resolve) => proc.on('close', resolve));
}).then(() => {
const libs = fs.readdirSync(builtAppexFrameworkPath).filter((p) => p.endsWith('.dylib'))
.map((p) => builtAppexFrameworkPath + p);
const libPromises = [];
libs.forEach((i) => {
const proc = child.spawn('codesign', args.concat([i]));
stdOutProc(proc);
libPromises.push(new Promise((resolve) => proc.on('close', resolve)));
});
return Promise.all(libPromises);
}).then(() => {
const proc = child.spawn('codesign', args.concat([builtAppexPath]));
stdOutProc(proc);
return new Promise((resolve) => proc.on('close', resolve));
}).then(() => {
return cb;
}, () => {
return cb;
});
}
function safariCopyAssets(source, dest) {
return new Promise((resolve, reject) => {
gulp.src(source)
.on('error', reject)
.pipe(gulpif('safari/Info.plist', replace('0.0.1', manifest.version)))
.pipe(gulpif('safari/Info.plist', replace('0.0.2', process.env.BUILD_NUMBER || manifest.version)))
.pipe(gulp.dest(dest))
.on('end', resolve);
});
}
function safariCopyBuild(source, dest) {
return new Promise((resolve, reject) => {
gulp.src(source)
.on('error', reject)
.pipe(filter(['**'].concat(filters.fonts)
.concat(filters.webExt).concat(filters.nonSafariApp)))
.pipe(gulp.dest(dest))
.on('end', resolve);
});
}
function stdOutProc(proc) {
proc.stdout.on('data', (data) => console.log(data.toString()));
proc.stderr.on('data', (data) => console.error(data.toString()));
}
function webfonts() {
return gulp.src('./webfonts.list')
.pipe(googleWebFonts({
fontsDir: 'webfonts',
cssFilename: 'webfonts.css'
}))
.pipe(gulp.dest(paths.cssDir));
}
function ciCoverage(cb) {
return gulp.src(paths.coverage + '**/*')
.pipe(filter(['**', '!coverage/coverage*.zip']))
.pipe(zip(`coverage${buildString()}.zip`))
.pipe(gulp.dest(paths.coverage));
}
exports['dist:firefox'] = distFirefox;
exports['dist:chrome'] = distChrome;
exports['dist:opera'] = distOpera;
exports['dist:edge'] = distEdge;
exports['dist:safari'] = gulp.parallel(distSafariMas, distSafariMasDev, distSafariDmg);
exports['dist:safari:mas'] = distSafariMas;
exports['dist:safari:masdev'] = distSafariMasDev;
exports['dist:safari:dmg'] = distSafariDmg;
exports.dist = gulp.parallel(distFirefox, distChrome, distOpera, distEdge);
exports['ci:coverage'] = ciCoverage;
exports.ci = ciCoverage;
exports.webfonts = webfonts;
exports.build = webfonts;