Commit 321d7046 authored by Alberto García Hierro's avatar Alberto García Hierro
Browse files

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
parent b8fd9578
......@@ -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) {
......
......@@ -109,14 +109,6 @@
"ansi-wrap": "^0.1.0"
}
},
"ansi-cyan": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-cyan/-/ansi-cyan-0.1.1.tgz",
"integrity": "sha1-U4rlKK+JgvKK4w2G8vF0VtJgmHM=",
"requires": {
"ansi-wrap": "0.1.0"
}
},
"ansi-gray": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-gray/-/ansi-gray-0.1.1.tgz",
......@@ -125,14 +117,6 @@
"ansi-wrap": "0.1.0"
}
},
"ansi-red": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-red/-/ansi-red-0.1.1.tgz",
"integrity": "sha1-jGOPnRCAgAo1PJwoyKgcpHBdlGw=",
"requires": {
"ansi-wrap": "0.1.0"
}
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
......@@ -5415,52 +5399,6 @@
}
}
},
"plugin-error": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz",
"integrity": "sha1-O5uzM1zPAPQl4HQ34ZJ2ln2kes4=",
"requires": {
"ansi-cyan": "^0.1.1",
"ansi-red": "^0.1.1",
"arr-diff": "^1.0.1",
"arr-union": "^2.0.1",
"extend-shallow": "^1.1.2"
},
"dependencies": {
"arr-diff": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-1.1.0.tgz",
"integrity": "sha1-aHwydYFjWI/vfeezb6vklesaOZo=",
"requires": {
"arr-flatten": "^1.0.1",
"array-slice": "^0.2.3"
}
},
"arr-union": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz",
"integrity": "sha1-IPnqtexw9cfSFbEHexw5Fh0pLH0="
},
"array-slice": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz",
"integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU="
},
"extend-shallow": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz",
"integrity": "sha1-Gda/lN/AnXa6cR85uHLSH/TdkHE=",
"requires": {
"kind-of": "^1.1.0"
}
},
"kind-of": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz",
"integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ="
}
}
},
"posix-character-classes": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz",
......@@ -6026,16 +5964,6 @@
}
}
},
"run-sequence": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/run-sequence/-/run-sequence-2.2.1.tgz",
"integrity": "sha512-qkzZnQWMZjcKbh3CNly2srtrkaO/2H/SI5f2eliMCapdRD3UhMrwjfOAZJAnZ2H8Ju4aBzFZkBGXUqFs9V0yxw==",
"requires": {
"chalk": "^1.1.3",
"fancy-log": "^1.3.2",
"plugin-error": "^0.1.2"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment