-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathgulpfile.js
389 lines (381 loc) · 13.6 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
'use strict';
var gulp = require('gulp');
var change = require('gulp-change');
var babel = require('gulp-babel');
var gulpif = require('gulp-if');
var gulpFilter = require('gulp-filter');
var shell = require('gulp-shell');
var wait = require('gulp-wait');
var clean = require('gulp-clean');
var zip = require('gulp-zip');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
/* clean */
gulp.task('clean', function () {
return gulp.src([
'builds/unpacked/chrome/*',
'builds/unpacked/opera/*',
'builds/unpacked/firefox/*',
'builds/unpacked/electron/*',
'builds/unpacked/android/*'
], {read: false})
.pipe(clean());
});
function json (clean) {
let config = require('./package.json');
let version = config.version;
if (clean) {
version = version.replace(/.beta*/, '');
}
function code (version) {
let [a, b, c] = version.split('.');
return (+b) * 1000 + (+c) * 10 + 1;
}
return gulpif(f => f.relative.endsWith('.json') || f.relative.endsWith('.xml'), change(content => content
.replace('%title;', config.title)
.replace('%name;', config.name)
.replace('%description;', config.description)
.replace('%license;', config.license)
.replace('%version;', version)
.replace('%version-code;', code(version))
.replace('%author;', config.author)
.replace('%email;', config.email)
.replace('%homepage;', config.homepage)
.replace('%repository.url;', config.repository.url)
.replace('%bugs.url;', config.bugs.url)
.replace('config.keywords', JSON.stringify(config.keywords))
));
}
function shadow (browser) {
let c1 = ` <script src="${browser}/${browser}.js"></script>\n <script src="index.js"></script>`;
let c2 = ` <script src="showdown.js"></script>\n <script src="${browser}/${browser}.js"></script>\n <script src="index.js"></script>`;
let c3 = ` <script src="videojs/video.js"></script>\n <script src="${browser}/${browser}.js"></script>\n <script src="index.js"></script>`;
return gulpif(f => f.relative.endsWith('info/index.html'),
change(content => content.replace(/.*shadow_index\.js.*/, c2)),
gulpif(f => f.relative.endsWith('preview/index.html'),
change(content => content.replace(/.*shadow_index\.js.*/, c3)),
gulpif(f => f.relative.endsWith('.html'), change(content => content.replace(/.*shadow_index\.js.*/, c1)))
)
)
}
/* electron build */
gulp.task('electron-build', function () {
return gulp.src([
'src/**/*'
])
.pipe(gulpFilter(function (f) {
if (f.relative.endsWith('.DS_Store') || f.relative.endsWith('Thumbs.db')) {
return false;
}
if (f.relative.indexOf('firefox') !== -1 || f.relative.indexOf('android') !== -1 || f.relative.indexOf('opera') !== -1) {
return false;
}
if (f.relative.indexOf('chrome') !== -1 && !f.relative.endsWith('electron/chrome-cm.js') && !f.relative.endsWith('electron/chrome-shim.js')) {
return false;
}
if (f.relative.split('/').length === 1) {
return f.relative === 'package-electron.json';
}
return true;
}))
.pipe(rename(function (path) {
if (path.basename === 'package-electron') {
path.basename = 'package';
}
return path;
}))
.pipe(json(true))
.pipe(gulpif(function (f) {
return f.path.indexOf('.js') !== -1 && f.path.indexOf('.json') === -1;
}, change(function (content) {
return content.replace('firefox/firefox', 'electron/starter');
})))
.pipe(shadow('electron'))
.pipe(gulp.dest('builds/unpacked/electron'))
});
gulp.task('electron-pack', function () {
return gulp.src([
'builds/unpacked/electron/**/*'
])
.pipe(zip('electron.zip'))
.pipe(gulp.dest('builds/packed'));
});
gulp.task('electron-install', function () {
let keys = Object.keys(gulp.env).filter(key => key !== '_');
let args = keys.map(key => `--${key}="${gulp.env[key]}"`).join(' ');
return gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'"/Applications/Electron.app/Contents/MacOS/Electron" `pwd` ' + args + ' &'
], {
cwd: './builds/unpacked/electron'
}));
});
gulp.task('electron-packager', function () {
let config = require('./package.json');
return gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'npm install',
`electron-packager . "Turbo Download Manager" --app-version=${config.version} --platform=darwin --arch=x64 --electron-version=1.4.15 --icon ../../packed/mac.icns`,
'mv "Turbo Download Manager-darwin-x64" tdm-darwin-x64',
'7z a -mx9 -r tdm-darwin-x64.7z tdm-darwin-x64/* > null',
'mv tdm-darwin-x64.7z ../..',
'rm -r tdm-darwin-x64/',
`electron-packager . "Turbo Download Manager" --app-version=${config.version} --platform=win32 --arch=x64 --electron-version=1.4.15 --icon ../../packed/windows.ico`,
'mv "Turbo Download Manager-win32-x64" tdm-win32-x64',
'7z a -mx9 -r tdm-win32-x64.7z tdm-win32-x64/* > null',
'mv tdm-win32-x64.7z ../..',
'rm -r tdm-win32-x64/',
`electron-packager . "Turbo Download Manager" --app-version=${config.version} --platform=win32 --arch=ia32 --electron-version=1.4.15 --icon ../../packed/windows.ico`,
'mv "Turbo Download Manager-win32-ia32" tdm-win32-ia32',
'7z a -mx9 -r tdm-win32-ia32.7z tdm-win32-ia32/* > null',
'mv tdm-win32-ia32.7z ../..',
'rm -r tdm-win32-ia32/',
`electron-packager . "Turbo Download Manager" --app-version=${config.version} --platform=linux --arch=x64 --electron-version=1.4.15`,
'mv "Turbo Download Manager-linux-x64" tdm-linux-x64',
'7z a -mx9 -r tdm-linux-x64.7z tdm-linux-x64/* > null',
'mv tdm-linux-x64.7z ../..',
'rm -r tdm-linux-x64/',
`electron-packager . "Turbo Download Manager" --app-version=${config.version} --platform=linux --arch=ia32 --electron-version=1.4.15`,
'mv "Turbo Download Manager-linux-ia32" tdm-linux-ia32',
'7z a -mx9 -r tdm-linux-ia32.7z tdm-linux-ia32/* > null',
'mv tdm-linux-ia32.7z ../..',
'rm -r tdm-linux-ia32/'
], {
cwd: './builds/unpacked/electron'
}));
});
/* chrome build */
gulp.task('chrome-build', function () {
return gulp.src([
'src/**/*'
])
.pipe(gulpFilter(function (f) {
if (f.relative.endsWith('.DS_Store') || f.relative.endsWith('Thumbs.db')) {
return false;
}
if (f.relative.indexOf('firefox') !== -1 || f.relative.indexOf('opera') !== -1 || f.relative.indexOf('android') !== -1 || f.relative.indexOf('electron') !== -1) {
return false;
}
if (f.relative.split('/').length === 1) {
return f.relative === 'manifest-app.json';
}
return true;
}))
.pipe(rename(function (path) {
if (path.basename === 'manifest-app') {
path.basename = 'manifest';
}
return path;
}))
.pipe(json(true))
.pipe(shadow('chrome'))
.pipe(gulp.dest('builds/unpacked/chrome'))
});
gulp.task('chrome-pack', function () {
return gulp.src([
'builds/unpacked/chrome/**/*'
])
.pipe(zip('chrome.zip'))
.pipe(gulp.dest('builds/packed'));
});
gulp.task('chrome-install', function () {
return gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --console --load-and-launch-app=`pwd` &'
], {
cwd: './builds/unpacked/chrome'
}));
});
/* opera build */
gulp.task('opera-build', function () {
return gulp.src([
'src/**/*'
])
.pipe(gulpFilter(function (f) {
if (f.relative.endsWith('.DS_Store') || f.relative.endsWith('Thumbs.db')) {
return false;
}
if (f.relative.indexOf('firefox') !== -1 || f.relative.indexOf('android') !== -1 || f.relative.indexOf('electron') !== -1) {
return false;
}
if (f.relative.indexOf('chrome') !== -1 && f.relative.indexOf('opera/chrome-cm.js') === -1 && f.relative.indexOf('opera/chrome-br.js') === -1) {
return false;
}
if (f.relative.split('/').length === 1) {
return f.relative === 'manifest-extension.json';
}
return true;
}))
.pipe(rename(function (path) {
if (path.basename === 'manifest-extension') {
path.basename = 'manifest';
}
return path;
}))
.pipe(json(true))
.pipe(shadow('opera'))
.pipe(gulp.dest('builds/unpacked/opera'))
});
gulp.task('opera-pack', function () {
return gulp.src([
'builds/unpacked/opera/**/*'
])
.pipe(zip('opera.zip'))
.pipe(gulp.dest('builds/packed'));
});
gulp.task('opera-install', function () {
gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --console --load-and-launch-app=`pwd` &'
], {
cwd: './builds/unpacked/opera'
}));
});
/* android build */
gulp.task('android-build', function () {
return gulp.src([
'src/**/*'
])
.pipe(gulpFilter(function (f) {
if (f.relative.endsWith('.DS_Store') || f.relative.endsWith('Thumbs.db')) {
return false;
}
if (f.relative.indexOf('firefox') !== -1 || f.relative.indexOf('opera') !== -1 || f.relative.indexOf('electron') !== -1) {
return false;
}
if (f.relative.indexOf('chrome') !== -1 && f.relative.indexOf('android/chrome-cm.js') === -1 && f.relative.indexOf('android/chrome-shim.js') === -1) {
return false;
}
if (f.relative.split('/').length === 1) {
return f.relative === 'config.xml';
}
return true;
}))
.pipe(json())
.pipe(shadow('android'))
.pipe(gulpif(function (f) {
return f.path.endsWith('.js') &&
!f.relative.endsWith('EventEmitter.js') &&
!f.relative.endsWith('video.js') &&
!f.relative.endsWith('showdown.js') &&
!f.relative.endsWith('dexie.js');
}, babel({
presets: ['es2015']
})))
.pipe(gulp.dest('builds/unpacked/android'))
});
gulp.task('android-pack', function () {
return gulp.src([
'builds/unpacked/android/**/*'
])
.pipe(zip('android.zip'))
.pipe(gulp.dest('builds/packed'));
});
gulp.task('android-apk', function () {
return gulp.src('')
.pipe(shell([
'cordova platform add android',
'cordova plugin add cordova-plugin-admobpro',
'cordova plugin add cordova-plugin-background-mode',
'cordova plugin add https://github.com/VersoSolutions/CordovaClipboard',
'cordova plugin add https://github.com/fastrde/phonegap-md5.git',
'cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.git',
'cordova plugin add ../../plugins/android/cordova-plugin-binaryfilewriter/',
'cordova plugin add ../../plugins/android/cordova-plugin-customconfig/',
'cordova plugin add ../../plugins/android/cordova-plugin-socksproxy/',
'cordova plugin add cordova-plugin-intent',
'cordova plugin add cordova-plugin-x-toast',
'cordova plugin add cordova-plugin-fileopener',
'openssl aes-256-cbc -k $ENCRYPTION_PASSWORD -in ../packed/keys.p12.enc -d -a -out platforms/android/keys.p12',
'printf "storeFile=keys.p12\\nkeyAlias=ReleaseKey\\nkeyPassword=$ENCRYPTION_PASSWORD\\nstorePassword=$ENCRYPTION_PASSWORD" > platforms/android/release-signing.properties',
'cordova build --release'
], {
cwd: 'builds/TDM'
}));
});
gulp.task('android-run', function () {
return gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'pwd & cordova run android'
], {
cwd: 'trash/android/TDM/'
}));
});
/* firefox build */
gulp.task('firefox-build', function () {
return gulp.src([
'src/**/*'
])
.pipe(gulpFilter(function (f) {
if (f.relative.endsWith('.DS_Store') || f.relative.endsWith('Thumbs.db')) {
return false;
}
if (f.relative.indexOf('chrome') !== -1 &&
f.relative !== 'chrome.manifest' &&
f.relative.indexOf('firefox/chrome') === -1
) {
return false;
}
if (f.relative.indexOf('opera') !== -1 || f.relative.indexOf('android') !== -1 || f.relative.indexOf('electron') !== -1) {
return false;
}
if (f.relative.split('/').length === 1) {
return ['package-firefox.json', 'chrome.manifest'].indexOf(f.relative) !== -1;
}
return true;
}))
.pipe(rename(function (path) {
if (path.basename === 'package-firefox') {
path.basename = 'package';
}
return path;
}))
.pipe(json())
.pipe(gulpif(function (f) {
return f.path.indexOf('.html') !== -1;
}, change(function (content) {
return content.replace(/\n.*shadow_index\.js.*/, '');
})))
.pipe(gulp.dest('builds/unpacked/firefox'));
});
/* firefox pack */
gulp.task('firefox-pack', function () {
return gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'jpm xpi',
'mv *.xpi ../../packed/firefox.xpi',
], {
cwd: './builds/unpacked/firefox'
}))
.pipe(shell([
'zip firefox.xpi icon.png icon64.png',
], {
cwd: './builds/packed'
}));
});
/* firefox install */
gulp.task('firefox-install', function () {
return gulp.src('')
.pipe(shell([
'jpm post --post-url http://localhost:8888/'
], {
cwd: './builds/unpacked/firefox'
}))
});
/* */
gulp.task('android', (callback) => runSequence('clean', 'android-build', 'android-pack', 'android-run', callback));
gulp.task('android-travis', (callback) => runSequence('clean', 'android-build', 'android-pack', callback));
gulp.task('chrome', (callback) => runSequence('clean', 'chrome-build', 'chrome-pack', 'chrome-install', callback));
gulp.task('chrome-travis', (callback) => runSequence('clean', 'chrome-build', 'chrome-pack', callback));
gulp.task('opera', (callback) => runSequence('clean', 'opera-build', 'opera-pack', callback));
gulp.task('opera-travis', (callback) => runSequence('clean', 'opera-build', 'opera-pack', callback));
gulp.task('firefox', (callback) => runSequence('clean', 'firefox-build', 'firefox-pack', 'firefox-install', callback));
gulp.task('firefox-travis', (callback) => runSequence('clean', 'firefox-build', 'firefox-pack', callback));
gulp.task('electron', (callback) => runSequence('clean', 'electron-build', 'electron-pack', 'electron-install', callback));
gulp.task('electron-travis', (callback) => runSequence('clean', 'electron-build', 'electron-pack', callback));