diff options
author | Alberto García Hierro <alberto@garciahierro.com> | 2018-07-10 00:26:58 +0300 |
---|---|---|
committer | Alberto García Hierro <alberto@garciahierro.com> | 2018-07-10 00:29:47 +0300 |
commit | 321d7046759f2692e1fda75c026ed49e6ebf0927 (patch) | |
tree | 864169949d957ac4a93b4a9ecaf832618d98312c /gulpfile.js | |
parent | b8fd9578c321afbbf094705f8856cd8f43ef5d29 (diff) |
Complete migration to Gulp 4, add linux32 support
- Remove usages of runSequence(), which doesn't work with Gulp 4,
using gulp.series() instead.
- Add support for linux32 builds
- Add new --platform argument for building only for a single platform
(e.g. --platform=osx64).
Fixes build problems introduced in #527
Fixes #531
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 92 |
1 files changed, 40 insertions, 52 deletions
diff --git a/gulpfile.js b/gulpfile.js index 210ae75b..15bb0f8b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,6 +3,7 @@ var child_process = require('child_process'); var fs = require('fs'); var path = require('path'); +var minimist = require('minimist'); var archiver = require('archiver'); var del = require('del'); @@ -10,8 +11,6 @@ var NwBuilder = require('nw-builder'); var gulp = require('gulp'); var concat = require('gulp-concat'); -var runSequence = require('run-sequence'); - // Each key in the *sources* variable must be an array of // the source files that will be combined into a single @@ -159,6 +158,18 @@ function get_task_name(key) { return 'build-' + key.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();}); } +function getPlatforms() { + var defaultPlatforms = ['win32', 'osx64', 'linux32', 'linux64']; + var argv = minimist(process.argv.slice(2)); + if (argv.platform) { + if (defaultPlatforms.indexOf(argv.platform) < 0) { + throw "Invalid platform '" + argv.platform + "'. Available ones are: " + defaultPlatforms; + } + return [argv.platform]; + } + return defaultPlatforms; +} + // Define build tasks dynamically based on the sources // and output variables. var buildCssTasks = []; @@ -192,7 +203,7 @@ gulp.task('clean', function() { return del(['./build/**', './dist/**'], {force: // Real work for dist task. Done in another task to call it via // run-sequence. -gulp.task('dist-build', gulp.series('build'), function() { +gulp.task('dist-build', gulp.series('build', function() { var distSources = [ './package.json', // For NW.js './manifest.json', // For Chrome app @@ -211,18 +222,16 @@ gulp.task('dist-build', gulp.series('build'), function() { ]; return gulp.src(distSources, { base: '.' }) .pipe(gulp.dest(distDir)); -}); +})); -gulp.task('dist', function(done) { - return runSequence('clean', 'dist-build', done); -}); +gulp.task('dist', gulp.series('clean', 'dist-build')); // Create app directories in ./apps -gulp.task('apps', gulp.series('dist'), function(done) { +gulp.task('apps', gulp.series('dist', function(done) { var builder = new NwBuilder({ files: './dist/**/*', buildDir: appsDir, - platforms: ['win32', 'osx64', 'linux64'], + platforms: getPlatforms(), flavor: 'normal', macIcns: './images/inav.icns', winIco: './images/inav.ico', @@ -237,14 +246,14 @@ gulp.task('apps', gulp.series('dist'), function(done) { // Package apps as .zip files done(); }); -}); +})); function get_release_filename(platform, ext) { var pkg = require('./package.json'); return 'INAV-Configurator_' + platform + '_' + pkg.version + '.' + ext; } -gulp.task('release-windows', function() { +gulp.task('release-win32', function() { var pkg = require('./package.json'); var src = path.join(appsDir, pkg.name, 'win32'); var output = fs.createWriteStream(path.join(appsDir, get_release_filename('win32', 'zip'))); @@ -258,7 +267,7 @@ gulp.task('release-windows', function() { return archive.finalize(); }); -gulp.task('release-macos', function() { +gulp.task('release-osx64', function() { 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 @@ -277,49 +286,28 @@ gulp.task('release-macos', function() { return archive.finalize(); }); -gulp.task('release-linux64', function() { - var pkg = require('./package.json'); - var src = path.join(appsDir, pkg.name, 'linux64'); - var output = fs.createWriteStream(path.join(appsDir, 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 Configurator'); - return archive.finalize(); -}); +function releaseLinux(bits) { + return function() { + var dirname = 'linux' + bits; + var pkg = require('./package.json'); + var src = path.join(appsDir, pkg.name, dirname); + var output = fs.createWriteStream(path.join(appsDir, get_release_filename(dirname, '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 Configurator'); + return archive.finalize(); + } +} -//For build only linux, without install Wine -//run task `apps` get error -//Error building NW apps:Error while updating the Windows icon. Wine (winehq.org) must be installed to add custom icons from Mac and Linux. -gulp.task('release-only-linux', gulp.series('dist'), function (done) { - var builder = new NwBuilder({ - files: './dist/**/*', - buildDir: appsDir, - platforms: ['linux64'], - flavor: 'normal', - }); - builder.on('log', console.log); - builder.build().then(function(){ - //Start zip app after complete - runSequence('release-linux64'); - }).catch(function(err){ - if (err) { - console.log("Error building NW apps:" + err); - done(); - return; - } - // Package apps as .zip files - done(); - }); -}); +gulp.task('release-linux32', releaseLinux(32)); +gulp.task('release-linux64', releaseLinux(64)); // Create distributable .zip files in ./apps -gulp.task('release', function() { - return runSequence('apps', 'release-macos', 'release-windows', 'release-linux64'); -}); +gulp.task('release', gulp.series('apps', getPlatforms().map(function(v) { return 'release-' + v; }))); gulp.task('watch', function () { for(var k in output) { |