forked from iNavFlight/blackbox-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
405 lines (353 loc) · 11.9 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
'use strict';
var pkg = require('./package.json');
var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var archiver = require('archiver');
var del = require('del');
var NwBuilder = require('nw-builder');
var gulp = require('gulp');
var concat = require('gulp-concat');
var install = require("gulp-install");
var runSequence = require('run-sequence');
var os = require('os');
var distDir = './dist/';
var appsDir = './apps/';
var debugDir = './debug/';
var releaseDir = './release/';
var destDir;
var platforms = [];
// -----------------
// Helper functions
// -----------------
// Get platform from commandline args
// #
// # gulp <task> [<platform>]+ Run only for platform(s) (with <platform> one of --linux64, --osx64, or --win32 --chromeos)
// #
function getPlatforms(includeChromeOs) {
var supportedPlatforms = ['linux64', 'osx64', 'win32'];
var result = [];
var regEx = /--(\w+)/;
for (var i = 3; i < process.argv.length; i++) {
var arg = process.argv[i].match(regEx)[1];
if (supportedPlatforms.indexOf(arg) > -1) {
result.push(arg);
} else if (arg === 'chromeos') {
if (includeChromeOs) {
result.push(arg);
}
} else {
console.log('Unknown platform: ' + arg);
process.exit();
}
}
if (result.length === 0) {
switch (os.platform()) {
case 'darwin':
result.push('osx64');
break;
case 'linux':
result.push('linux64');
break;
case 'win32':
result.push('win32');
break;
default:
break;
}
}
console.log('Building for platform(s): ' + result + '.');
return result;
}
function getRunDebugAppCommand() {
switch (os.platform()) {
case 'darwin':
return 'open ' + path.join(debugDir, pkg.name, 'osx64', pkg.name + '.app');
break;
case 'linux':
return path.join(debugDir, pkg.name, 'linux64', pkg.name);
break;
case 'win32':
return path.join(debugDir, pkg.name, 'win32', pkg.name + '.exe');
break;
default:
return '';
break;
}
}
function get_release_filename(platform, ext) {
return 'INAV-BlackboxExplorer_' + platform + '_' + pkg.version + '.' + ext;
}
// -----------------
// Tasks
// -----------------
gulp.task('clean', function () {
return runSequence('clean-dist', 'clean-apps', 'clean-debug', 'clean-release');
});
gulp.task('clean-dist', function () {
return del([distDir + '**'], { force: true });
});
gulp.task('clean-apps', function () {
return del([appsDir + '**'], { force: true });
});
gulp.task('clean-debug', function () {
return del([debugDir + '**'], { force: true });
});
gulp.task('clean-release', function () {
return del([releaseDir + '**'], { force: true });
});
gulp.task('clean-cache', function () {
return del(['./cache/**'], { force: true });
});
// Real work for dist task. Done in another task to call it via
// run-sequence.
gulp.task('dist', ['clean-dist'], function () {
var distSources = [
// CSS files
'./css/bootstrap-theme.css',
'./css/bootstrap-theme.css.map',
'./css/bootstrap-theme.min.css',
'./css/bootstrap.css',
'./css/bootstrap.css.map',
'./css/bootstrap.min.css',
'./css/header_dialog.css',
'./css/jquery.nouislider.min.css',
'./css/keys_dialog.css',
'./css/main.css',
'./css/user_settings_dialog.css',
// JavaScript
'./js/cache.js',
'./js/complex.js',
'./js/configuration.js',
'./js/craft_2d.js',
'./js/craft_3d.js',
'./js/datastream.js',
'./js/decoders.js',
'./js/expo.js',
'./js/flightlog.js',
'./js/flightlog_fielddefs.js',
'./js/flightlog_fields_presenter.js',
'./js/flightlog_index.js',
'./js/flightlog_parser.js',
'./js/flightlog_video_renderer.js',
'./js/graph_config.js',
'./js/graph_config_dialog.js',
'./js/graph_legend.js',
'./js/graph_spectrum.js',
'./js/grapher.js',
'./js/header_dialog.js',
'./js/imu.js',
'./js/keys_dialog.js',
'./js/laptimer.js',
'./js/main.js',
'./js/pref_storage.js',
'./js/real.js',
'./js/seekbar.js',
'./js/tools.js',
'./js/user_settings_dialog.js',
'./js/video_export_dialog.js',
'./js/vendor/FileSaver.js',
'./js/vendor/bootstrap.js',
'./js/vendor/bootstrap.min.js',
'./js/vendor/jquery-1.11.3.min.js',
'./js/vendor/jquery-ui-1.11.4.min.js',
'./js/vendor/jquery.ba-throttle-debounce.js',
'./js/vendor/jquery.nouislider.all.min.js',
'./js/vendor/modernizr-2.6.2-respond-1.1.0.min.js',
'./js/vendor/npm.js',
'./js/vendor/semver.js',
'./js/vendor/three.js',
'./js/vendor/three.min.js',
'./js/vendor/webm-writer-0.1.1.js',
// everything else
'./package.json', // For NW.js
'./manifest.json', // For Chrome app
'./background.js',
'./*.html',
'./images/**/*',
'./_locales/**/*',
'./fonts/*',
];
return gulp.src(distSources, { base: '.' })
.pipe(gulp.dest(distDir))
.pipe(install({
npm: '--production --ignore-scripts'
}));;
});
// Create runable app directories in ./apps
gulp.task('apps', ['dist', 'clean-apps'], function (done) {
platforms = getPlatforms();
console.log('Release build.');
destDir = appsDir;
var builder = new NwBuilder({
files: './dist/**/*',
buildDir: appsDir,
platforms: platforms,
flavor: 'normal',
zip: false,
macIcns: './images/bf_icon.icns',
macPlist: { 'CFBundleDisplayName': 'INAV Blackbox Explorer'},
winIco: './images/bf_icon.ico'
});
builder.on('log', console.log);
builder.build(function (err) {
if (err) {
console.log('Error building NW apps: ' + err);
runSequence('clean-apps', function() {
process.exit(1);
});
}
// Execute post build task
runSequence('post-build', function() {
done();
});
});
});
// Create debug app directories in ./debug
gulp.task('debug', ['dist', 'clean-debug'], function (done) {
platforms = getPlatforms();
console.log('Debug build.');
destDir = debugDir;
var builder = new NwBuilder({
files: './dist/**/*',
buildDir: debugDir,
platforms: platforms,
flavor: 'sdk',
macIcns: './images/bf_icon.icns',
macPlist: { 'CFBundleDisplayName': 'INAV Blackbox Explorer'},
winIco: './images/bf_icon.ico'
});
builder.on('log', console.log);
builder.build(function (err) {
if (err) {
console.log('Error building NW apps: ' + err);
runSequence('clean-debug', function() {
process.exit(1);
});
}
// Execute post build task
runSequence('post-build', function() {
// Start debug app
var exec = require('child_process').exec;
var run = getRunDebugAppCommand();
console.log('Starting debug app (' + run + ')...');
exec(run);
done();
});
});
});
gulp.task('post-build', function(done) {
if (platforms.indexOf('osx64') != -1) {
// Determine the WebKit version distributed in nw.js
var pathToVersions = path.join(destDir, pkg.name, 'osx64', pkg.name + '.app', 'Contents', 'Versions');
var files = fs.readdirSync(pathToVersions);
if (files.length >= 1) {
var webKitVersion = files[0];
console.log('Found Webkit version: ' + webKitVersion)
// Copy ffmpeg codec library into macOS app
var libSrc = './library/osx64/libffmpeg.dylib'
var libDest = path.join(pathToVersions, webKitVersion) + '/';
console.log('Copy ffmpeg library to macOS app (' + libSrc + ' to ' + libDest + ')');
gulp.src(libSrc)
.pipe(gulp.dest(libDest));
} else {
console.log('Error: could not find the Version folder.');
}
}
if (platforms.indexOf('linux64') != -1) {
// Copy ffmpeg codec library into Linux app
var libSrc = './library/linux64/libffmpeg.so'
var libDest = path.join(destDir, pkg.name, 'linux64', 'lib') + '/';
console.log('Copy ffmpeg library to Linux app (' + libSrc + ' to ' + libDest + ')');
gulp.src(libSrc)
.pipe(gulp.dest(libDest));
}
if (platforms.indexOf('win32') != -1) {
// Copy ffmpeg codec library into Windows app
var libSrc = './library/win32/ffmpeg.dll'
var libDest = path.join(destDir, pkg.name, 'win32') + '/';
console.log('Copy ffmpeg library to Windows app (' + libSrc + ' to ' + libDest + ')');
gulp.src(libSrc)
.pipe(gulp.dest(libDest));
}
done();
});
// Create distribution package for windows platform
function release_win32() {
var src = path.join(appsDir, pkg.name, 'win32');
var output = fs.createWriteStream(path.join(releaseDir, get_release_filename('win32', 'zip')));
var archive = archiver('zip', {
zlib: { level: 9 }
});
archive.on('warning', function (err) { throw err; });
archive.on('error', function (err) { throw err; });
archive.pipe(output);
archive.directory(src, 'INAV Blackbox Explorer');
return archive.finalize();
}
// Create distribution package for linux platform
function release_linux64() {
var src = path.join(appsDir, pkg.name, 'linux64');
var output = fs.createWriteStream(path.join(releaseDir, get_release_filename('linux64', 'zip')));
var archive = archiver('zip', {
zlib: { level: 9 }
});
archive.on('warning', function (err) { throw err; });
archive.on('error', function (err) { throw err; });
archive.pipe(output);
archive.directory(src, 'INAV Blackbox Explorer');
return archive.finalize();
}
// Create distribution package for chromeos platform
function release_chromeos() {
var src = distDir;
var output = fs.createWriteStream(path.join(releaseDir, get_release_filename('chromeos', 'zip')));
var archive = archiver('zip', {
zlib: { level: 9 }
});
archive.on('warning', function (err) { throw err; });
archive.on('error', function (err) { throw err; });
archive.pipe(output);
archive.directory(src, false);
return archive.finalize();
}
// Create distribution package for macOS platform
function release_osx64() {
var pkg = require('./package.json');
var src = path.join(appsDir, pkg.name, 'osx64', pkg.name + '.app');
// Check if we want to sign the .app bundle
var output = fs.createWriteStream(path.join(releaseDir, get_release_filename('macOS', 'zip')));
var archive = archiver('zip', {
zlib: { level: 9 }
});
archive.on('warning', function(err) { throw err; });
archive.on('error', function(err) { throw err; });
archive.pipe(output);
archive.directory(src, 'INAV Blackbox Explorer.app');
return archive.finalize();
}
// Create distributable .zip files in ./release
gulp.task('release', ['apps', 'clean-release'], function () {
fs.mkdir(releaseDir, '0775', function(err) {
if (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
});
platforms = getPlatforms(true);
console.log('Packing release.');
if (platforms.indexOf('chromeos') !== -1) {
release_chromeos();
}
if (platforms.indexOf('linux64') !== -1) {
release_linux64();
}
if (platforms.indexOf('osx64') !== -1) {
release_osx64();
}
if (platforms.indexOf('win32') !== -1) {
release_win32();
}
});
gulp.task('default', ['debug']);