2017-10-20 00:36:33 +00:00
'use strict' ;
2018-01-10 14:36:12 +00:00
const pkg = require ( './package.json' ) ;
const child _process = require ( 'child_process' ) ;
const fs = require ( 'fs' ) ;
2018-05-13 19:00:56 +00:00
const fse = require ( 'fs-extra' ) ;
const https = require ( 'follow-redirects' ) . https ;
2018-01-10 14:36:12 +00:00
const path = require ( 'path' ) ;
const zip = require ( 'gulp-zip' ) ;
const del = require ( 'del' ) ;
const NwBuilder = require ( 'nw-builder' ) ;
const makensis = require ( 'makensis' ) ;
const deb = require ( 'gulp-debian' ) ;
2018-01-29 15:14:24 +00:00
const buildRpm = require ( 'rpm-builder' ) ;
const commandExistsSync = require ( 'command-exists' ) . sync ;
2018-05-13 19:00:56 +00:00
const targz = require ( 'targz' ) ;
2018-01-10 14:36:12 +00:00
const gulp = require ( 'gulp' ) ;
const concat = require ( 'gulp-concat' ) ;
const install = require ( "gulp-install" ) ;
const rename = require ( 'gulp-rename' ) ;
const os = require ( 'os' ) ;
2018-08-12 08:19:02 +00:00
const git = require ( 'gulp-git' ) ;
2018-01-10 14:36:12 +00:00
const DIST _DIR = './dist/' ;
const APPS _DIR = './apps/' ;
const DEBUG _DIR = './debug/' ;
const RELEASE _DIR = './release/' ;
2017-10-20 00:36:33 +00:00
2018-01-09 00:44:13 +00:00
var nwBuilderOptions = {
2018-08-13 13:18:15 +00:00
version : '0.32.2' ,
2018-01-09 00:44:13 +00:00
files : './dist/**/*' ,
2018-01-21 16:09:36 +00:00
macIcns : './src/images/bf_icon.icns' ,
2018-01-09 00:44:13 +00:00
macPlist : { 'CFBundleDisplayName' : 'Betaflight Configurator' } ,
2018-06-17 12:10:26 +00:00
winIco : './src/images/bf_icon.ico' ,
zip : false
2018-01-09 00:44:13 +00:00
} ;
2018-05-13 19:00:56 +00:00
var nwArmVersion = '0.27.6' ;
2018-01-10 14:36:12 +00:00
//-----------------
//Pre tasks operations
//-----------------
const SELECTED _PLATFORMS = getInputPlatforms ( ) ;
//-----------------
//Tasks
//-----------------
gulp . task ( 'clean' , gulp . parallel ( clean _dist , clean _apps , clean _debug , clean _release ) ) ;
gulp . task ( 'clean-dist' , clean _dist ) ;
gulp . task ( 'clean-apps' , clean _apps ) ;
gulp . task ( 'clean-debug' , clean _debug ) ;
gulp . task ( 'clean-release' , clean _release ) ;
gulp . task ( 'clean-cache' , clean _cache ) ;
2018-08-12 08:19:02 +00:00
gulp . task ( 'get-changeset-id' , getChangesetId ) ;
var distBuild = gulp . series ( dist _src , dist _locale , dist _libraries , dist _resources , getChangesetId ) ;
2018-08-01 09:22:12 +00:00
var distRebuild = gulp . series ( clean _dist , distBuild ) ;
gulp . task ( 'dist' , distRebuild ) ;
2018-01-10 14:36:12 +00:00
2018-08-01 09:22:12 +00:00
var appsBuild = gulp . series ( gulp . parallel ( clean _apps , distRebuild ) , apps , gulp . parallel ( listPostBuildTasks ( APPS _DIR ) ) ) ;
2018-01-10 14:36:12 +00:00
gulp . task ( 'apps' , appsBuild ) ;
2018-08-01 09:22:12 +00:00
var debugBuild = gulp . series ( distBuild , debug , gulp . parallel ( listPostBuildTasks ( DEBUG _DIR ) ) , start _debug )
2018-01-10 14:36:12 +00:00
gulp . task ( 'debug' , debugBuild ) ;
var releaseBuild = gulp . series ( gulp . parallel ( clean _release , appsBuild ) , gulp . parallel ( listReleaseTasks ( ) ) ) ;
gulp . task ( 'release' , releaseBuild ) ;
gulp . task ( 'default' , debugBuild ) ;
2018-01-09 00:44:13 +00:00
2017-11-22 20:19:34 +00:00
// -----------------
// Helper functions
// -----------------
// Get platform from commandline args
// #
2018-05-13 19:00:56 +00:00
// # gulp <task> [<platform>]+ Run only for platform(s) (with <platform> one of --linux64, --linux32, --armv7, --osx64, --win32, --win64, or --chromeos)
// #
2018-01-10 14:36:12 +00:00
function getInputPlatforms ( ) {
2018-05-13 19:00:56 +00:00
var supportedPlatforms = [ 'linux64' , 'linux32' , 'armv7' , 'osx64' , 'win32' , 'win64' , 'chromeos' ] ;
2017-11-22 20:19:34 +00:00
var platforms = [ ] ;
2017-11-24 03:40:02 +00:00
var regEx = /--(\w+)/ ;
2018-05-13 19:00:56 +00:00
console . log ( process . argv ) ;
2017-11-24 03:40:02 +00:00
for ( var i = 3 ; i < process . argv . length ; i ++ ) {
var arg = process . argv [ i ] . match ( regEx ) [ 1 ] ;
if ( supportedPlatforms . indexOf ( arg ) > - 1 ) {
platforms . push ( arg ) ;
} else {
console . log ( 'Unknown platform: ' + arg ) ;
process . exit ( ) ;
2017-11-22 20:19:34 +00:00
}
2018-05-13 19:00:56 +00:00
}
2017-11-24 03:40:02 +00:00
if ( platforms . length === 0 ) {
2017-12-07 15:00:13 +00:00
var defaultPlatform = getDefaultPlatform ( ) ;
if ( supportedPlatforms . indexOf ( defaultPlatform ) > - 1 ) {
platforms . push ( defaultPlatform ) ;
} else {
2018-01-08 10:37:32 +00:00
console . error ( ` Your current platform ( ${ os . platform ( ) } ) is not a supported build platform. Please specify platform to build for on the command line. ` ) ;
2017-12-07 15:00:13 +00:00
process . exit ( ) ;
2017-11-24 03:40:02 +00:00
}
}
2018-01-08 10:37:32 +00:00
if ( platforms . length > 0 ) {
console . log ( 'Building for platform(s): ' + platforms + '.' ) ;
} else {
console . error ( 'No suitables platforms found.' ) ;
process . exit ( ) ;
}
2017-11-24 03:40:02 +00:00
return platforms ;
2017-11-22 20:19:34 +00:00
}
2017-12-07 15:00:13 +00:00
// Gets the default platform to be used
function getDefaultPlatform ( ) {
var defaultPlatform ;
2017-12-03 20:18:03 +00:00
switch ( os . platform ( ) ) {
case 'darwin' :
2017-12-07 15:00:13 +00:00
defaultPlatform = 'osx64' ;
2017-12-03 20:18:03 +00:00
break ;
2017-12-07 15:00:13 +00:00
case 'linux' :
defaultPlatform = 'linux64' ;
2017-12-03 20:18:03 +00:00
break ;
2017-12-07 15:00:13 +00:00
case 'win32' :
defaultPlatform = 'win32' ;
break ;
2018-05-13 19:00:56 +00:00
2017-12-07 15:00:13 +00:00
default :
defaultPlatform = '' ;
2018-05-13 19:00:56 +00:00
2017-12-07 15:00:13 +00:00
break ;
}
return defaultPlatform ;
}
2018-01-10 14:36:12 +00:00
function getPlatforms ( ) {
return SELECTED _PLATFORMS . slice ( ) ;
}
2018-01-08 10:37:32 +00:00
function removeItem ( platforms , item ) {
var index = platforms . indexOf ( item ) ;
if ( index >= 0 ) {
platforms . splice ( index , 1 ) ;
}
}
2017-12-07 15:00:13 +00:00
function getRunDebugAppCommand ( arch ) {
switch ( arch ) {
case 'osx64' :
2018-01-10 14:36:12 +00:00
return 'open ' + path . join ( DEBUG _DIR , pkg . name , arch , pkg . name + '.app' ) ;
2017-12-07 15:00:13 +00:00
break ;
case 'linux64' :
2017-12-10 20:25:16 +00:00
case 'linux32' :
2018-05-13 19:00:56 +00:00
case 'armv7' :
2018-01-10 14:36:12 +00:00
return path . join ( DEBUG _DIR , pkg . name , arch , pkg . name ) ;
2017-12-10 20:25:16 +00:00
break ;
2017-12-03 20:18:03 +00:00
case 'win32' :
2017-12-07 15:00:13 +00:00
case 'win64' :
2018-01-10 14:36:12 +00:00
return path . join ( DEBUG _DIR , pkg . name , arch , pkg . name + '.exe' ) ;
2017-12-03 20:18:03 +00:00
break ;
default :
2017-12-04 10:03:35 +00:00
return '' ;
2017-12-03 20:18:03 +00:00
break ;
}
}
2018-01-10 14:36:12 +00:00
function getReleaseFilename ( platform , ext ) {
return 'betaflight-configurator_' + pkg . version + '_' + platform + '.' + ext ;
2017-10-20 00:36:33 +00:00
}
2018-05-13 19:00:56 +00:00
function clean _dist ( ) {
return del ( [ DIST _DIR + '**' ] , { force : true } ) ;
2018-01-10 14:36:12 +00:00
} ;
2017-11-22 20:19:34 +00:00
2018-05-13 19:00:56 +00:00
function clean _apps ( ) {
return del ( [ APPS _DIR + '**' ] , { force : true } ) ;
2018-01-10 14:36:12 +00:00
} ;
2017-11-22 20:19:34 +00:00
2018-05-13 19:00:56 +00:00
function clean _debug ( ) {
return del ( [ DEBUG _DIR + '**' ] , { force : true } ) ;
2018-01-10 14:36:12 +00:00
} ;
2017-11-22 20:19:34 +00:00
2018-05-13 19:00:56 +00:00
function clean _release ( ) {
return del ( [ RELEASE _DIR + '**' ] , { force : true } ) ;
2018-01-10 14:36:12 +00:00
} ;
2017-10-20 00:36:33 +00:00
2018-05-13 19:00:56 +00:00
function clean _cache ( ) {
return del ( [ './cache/**' ] , { force : true } ) ;
2018-01-10 14:36:12 +00:00
} ;
2017-12-08 12:48:55 +00:00
2017-10-20 00:36:33 +00:00
// Real work for dist task. Done in another task to call it via
// run-sequence.
2018-01-24 23:37:07 +00:00
function dist _src ( ) {
2017-10-20 00:36:33 +00:00
var distSources = [
2018-01-29 14:40:04 +00:00
'./src/**/*' ,
'!./src/css/dropdown-lists/LICENSE' ,
'!./src/css/font-awesome/css/font-awesome.css' ,
'!./src/css/opensans_webfontkit/*.{txt,html}' ,
'!./src/support/**'
2017-10-20 00:36:33 +00:00
] ;
2018-01-24 23:37:07 +00:00
2018-01-21 16:09:36 +00:00
return gulp . src ( distSources , { base : 'src' } )
. pipe ( gulp . src ( 'manifest.json' , { passthrougth : true } ) )
. pipe ( gulp . src ( 'package.json' , { passthrougth : true } ) )
2018-01-24 23:37:07 +00:00
. pipe ( gulp . src ( 'changelog.html' , { passthrougth : true } ) )
2018-01-25 23:52:10 +00:00
. pipe ( gulp . dest ( DIST _DIR ) )
. pipe ( install ( {
npm : '--production --ignore-scripts'
} ) ) ;
2018-01-10 14:36:12 +00:00
} ;
2017-10-20 00:36:33 +00:00
2018-01-24 23:37:07 +00:00
function dist _locale ( ) {
return gulp . src ( './locales/**/*' , { base : 'locales' } )
. pipe ( gulp . dest ( DIST _DIR + '_locales' ) ) ;
}
function dist _libraries ( ) {
return gulp . src ( './libraries/**/*' , { base : '.' } )
. pipe ( gulp . dest ( DIST _DIR + 'js' ) ) ;
}
function dist _resources ( ) {
return gulp . src ( './resources/**/*' , { base : '.' } )
. pipe ( gulp . dest ( DIST _DIR ) ) ;
}
2017-11-22 20:19:34 +00:00
// Create runable app directories in ./apps
2018-01-10 14:36:12 +00:00
function apps ( done ) {
2017-11-24 03:40:02 +00:00
var platforms = getPlatforms ( ) ;
2018-01-08 10:37:32 +00:00
removeItem ( platforms , 'chromeos' ) ;
2018-05-13 19:00:56 +00:00
buildNWAppsWrapper ( platforms , 'normal' , APPS _DIR , done ) ;
}
2017-11-11 14:00:18 +00:00
2018-01-10 14:36:12 +00:00
function listPostBuildTasks ( folder , done ) {
2018-01-05 17:58:27 +00:00
var platforms = getPlatforms ( ) ;
2018-01-10 14:36:12 +00:00
var postBuildTasks = [ ] ;
2018-01-05 17:58:27 +00:00
if ( platforms . indexOf ( 'linux32' ) != - 1 ) {
2018-05-20 01:11:36 +00:00
postBuildTasks . push ( function post _build _linux32 ( done ) {
return post _build ( 'linux32' , folder , done ) ;
} ) ;
2018-01-05 17:58:27 +00:00
}
if ( platforms . indexOf ( 'linux64' ) != - 1 ) {
2018-05-20 01:11:36 +00:00
postBuildTasks . push ( function post _build _linux64 ( done ) {
return post _build ( 'linux64' , folder , done ) ;
} ) ;
2018-01-10 14:36:12 +00:00
}
2018-05-13 19:00:56 +00:00
if ( platforms . indexOf ( 'armv7' ) != - 1 ) {
2018-05-20 01:11:36 +00:00
postBuildTasks . push ( function post _build _armv7 ( done ) {
return post _build ( 'armv7' , folder , done ) ;
} ) ;
2018-05-13 19:00:56 +00:00
}
2018-01-10 14:36:12 +00:00
// We need to return at least one task, if not gulp will throw an error
if ( postBuildTasks . length == 0 ) {
2018-05-20 01:11:36 +00:00
postBuildTasks . push ( function post _build _none ( done ) {
done ( ) ;
} ) ;
2018-01-10 14:36:12 +00:00
}
return postBuildTasks ;
}
function post _build ( arch , folder , done ) {
2018-05-13 19:00:56 +00:00
if ( ( arch === 'linux32' ) || ( arch === 'linux64' ) ) {
2018-01-05 17:58:27 +00:00
// Copy Ubuntu launcher scripts to destination dir
2018-01-10 14:36:12 +00:00
var launcherDir = path . join ( folder , pkg . name , arch ) ;
console . log ( 'Copy Ubuntu launcher scripts to ' + launcherDir ) ;
return gulp . src ( 'assets/linux/**' )
. pipe ( gulp . dest ( launcherDir ) ) ;
2018-01-05 17:58:27 +00:00
}
2018-05-13 19:00:56 +00:00
if ( arch === 'armv7' ) {
console . log ( 'Moving ARMv7 build from "linux32" to "armv7" directory...' ) ;
fse . moveSync ( path . join ( folder , pkg . name , 'linux32' ) , path . join ( folder , pkg . name , 'armv7' ) ) ;
}
2018-01-10 14:36:12 +00:00
return done ( ) ;
}
2017-11-11 14:00:18 +00:00
// Create debug app directories in ./debug
2018-01-10 14:36:12 +00:00
function debug ( done ) {
2017-11-24 03:40:02 +00:00
var platforms = getPlatforms ( ) ;
2018-01-08 10:37:32 +00:00
removeItem ( platforms , 'chromeos' ) ;
2018-01-10 14:36:12 +00:00
2018-05-13 19:00:56 +00:00
buildNWAppsWrapper ( platforms , 'sdk' , DEBUG _DIR , done ) ;
2018-01-10 14:36:12 +00:00
}
2018-05-13 19:00:56 +00:00
function injectARMCache ( flavor , callback ) {
var flavorPostfix = ` - ${ flavor } ` ;
var flavorDownloadPostfix = flavor !== 'normal' ? ` - ${ flavor } ` : '' ;
clean _cache ( ) . then ( function ( ) {
2018-05-20 00:16:50 +00:00
if ( ! fs . existsSync ( './cache' ) ) {
fs . mkdirSync ( './cache' ) ;
}
2018-05-13 19:00:56 +00:00
fs . closeSync ( fs . openSync ( './cache/_ARMv7_IS_CACHED' , 'w' ) ) ;
var versionFolder = ` ./cache/ ${ nwBuilderOptions . version } ${ flavorPostfix } ` ;
2018-05-20 00:16:50 +00:00
if ( ! fs . existsSync ( versionFolder ) ) {
fs . mkdirSync ( versionFolder ) ;
}
if ( ! fs . existsSync ( versionFolder + '/linux32' ) ) {
fs . mkdirSync ( ` ${ versionFolder } /linux32 ` ) ;
}
2018-05-13 19:00:56 +00:00
var downloadedArchivePath = ` ${ versionFolder } /nwjs ${ flavorPostfix } -v ${ nwArmVersion } -linux-arm.tar.gz ` ;
var downloadUrl = ` https://github.com/LeonardLaszlo/nw.js-armv7-binaries/releases/download/v ${ nwArmVersion } /nwjs ${ flavorDownloadPostfix } -v ${ nwArmVersion } -linux-arm.tar.gz ` ;
if ( fs . existsSync ( downloadedArchivePath ) ) {
console . log ( 'Prebuilt ARMv7 binaries found in /tmp' ) ;
downloadDone ( flavorDownloadPostfix , downloadedArchivePath , versionFolder ) ;
} else {
console . log ( ` Downloading prebuilt ARMv7 binaries from " ${ downloadUrl } "... ` ) ;
process . stdout . write ( '> Starting download...\r' ) ;
var armBuildBinary = fs . createWriteStream ( downloadedArchivePath ) ;
var request = https . get ( downloadUrl , function ( res ) {
var totalBytes = res . headers [ 'content-length' ] ;
var downloadedBytes = 0 ;
res . pipe ( armBuildBinary ) ;
res . on ( 'data' , function ( chunk ) {
downloadedBytes += chunk . length ;
process . stdout . write ( ` > ${ parseInt ( ( downloadedBytes * 100 ) / totalBytes ) } % done \r ` ) ;
} ) ;
armBuildBinary . on ( 'finish' , function ( ) {
process . stdout . write ( '> 100% done \n' ) ;
armBuildBinary . close ( function ( ) {
downloadDone ( flavorDownloadPostfix , downloadedArchivePath , versionFolder ) ;
} ) ;
} ) ;
} ) ;
}
} ) ;
function downloadDone ( flavorDownloadPostfix , downloadedArchivePath , versionFolder ) {
console . log ( 'Injecting prebuilt ARMv7 binaries into Linux32 cache...' ) ;
targz . decompress ( {
src : downloadedArchivePath ,
dest : versionFolder ,
2018-05-20 00:16:50 +00:00
} , function ( err ) {
2018-05-13 19:00:56 +00:00
if ( err ) {
console . log ( err ) ;
clean _debug ( ) ;
process . exit ( 1 ) ;
} else {
fs . rename (
` ${ versionFolder } /nwjs ${ flavorDownloadPostfix } -v ${ nwArmVersion } -linux-arm ` ,
` ${ versionFolder } /linux32 ` ,
( err ) => {
if ( err ) {
console . log ( err ) ;
clean _debug ( ) ;
process . exit ( 1 ) ;
}
callback ( ) ;
}
) ;
}
} ) ;
}
}
2017-11-22 20:19:34 +00:00
2018-05-13 19:00:56 +00:00
function buildNWAppsWrapper ( platforms , flavor , dir , done ) {
function buildNWAppsCallback ( ) {
buildNWApps ( platforms , flavor , dir , done ) ;
}
if ( platforms . indexOf ( 'armv7' ) !== - 1 ) {
if ( platforms . indexOf ( 'linux32' ) !== - 1 ) {
console . log ( 'Cannot build ARMv7 and Linux32 versions at the same time!' ) ;
clean _debug ( ) ;
process . exit ( 1 ) ;
}
removeItem ( platforms , 'armv7' ) ;
platforms . push ( 'linux32' ) ;
if ( ! fs . existsSync ( './cache/_ARMv7_IS_CACHED' , 'w' ) ) {
console . log ( 'Purging cache because it needs to be overwritten...' ) ;
clean _cache ( ) . then ( ( ) => {
injectARMCache ( flavor , buildNWAppsCallback ) ;
} )
} else {
buildNWAppsCallback ( ) ;
}
} else {
if ( platforms . indexOf ( 'linux32' ) !== - 1 && fs . existsSync ( './cache/_ARMv7_IS_CACHED' ) ) {
console . log ( 'Purging cache because it was previously overwritten...' ) ;
clean _cache ( ) . then ( buildNWAppsCallback ) ;
} else {
buildNWAppsCallback ( ) ;
}
}
}
function buildNWApps ( platforms , flavor , dir , done ) {
2018-01-08 10:37:32 +00:00
if ( platforms . length > 0 ) {
2018-01-09 00:44:13 +00:00
var builder = new NwBuilder ( Object . assign ( {
2018-01-10 14:36:12 +00:00
buildDir : dir ,
2018-01-08 10:37:32 +00:00
platforms : platforms ,
2018-01-10 14:36:12 +00:00
flavor : flavor
2018-01-09 00:44:13 +00:00
} , nwBuilderOptions ) ) ;
2018-01-08 10:37:32 +00:00
builder . on ( 'log' , console . log ) ;
builder . build ( function ( err ) {
if ( err ) {
console . log ( 'Error building NW apps: ' + err ) ;
2018-01-10 14:36:12 +00:00
clean _debug ( ) ;
process . exit ( 1 ) ;
2018-01-08 10:37:32 +00:00
}
done ( ) ;
} ) ;
} else {
2018-01-10 14:36:12 +00:00
console . log ( 'No platform suitable for NW Build' )
2017-10-20 00:36:33 +00:00
done ( ) ;
2018-01-08 10:37:32 +00:00
}
2018-01-10 14:36:12 +00:00
}
2018-08-12 08:19:02 +00:00
function getChangesetId ( done ) {
git . exec ( { args : 'log -1 --format="%h"' } , function ( err , stdout ) {
if ( err ) {
throw err ;
}
var versionData = { gitChangesetId : stdout . trim ( ) }
var destFile = path . join ( DIST _DIR , 'version.json' ) ;
fs . writeFile ( destFile , JSON . stringify ( versionData ) , function ( ) {
done ( ) ;
} ) ;
} ) ;
}
2018-01-10 14:36:12 +00:00
function start _debug ( done ) {
var platforms = getPlatforms ( ) ;
2018-05-13 19:00:56 +00:00
var exec = require ( 'child_process' ) . exec ;
2018-01-10 14:36:12 +00:00
if ( platforms . length === 1 ) {
var run = getRunDebugAppCommand ( platforms [ 0 ] ) ;
console . log ( 'Starting debug app (' + run + ')...' ) ;
exec ( run ) ;
} else {
console . log ( 'More than one platform specified, not starting debug app' ) ;
}
done ( ) ;
}
2017-10-20 00:36:33 +00:00
2017-12-29 13:57:45 +00:00
// Create installer package for windows platforms
2018-01-10 14:36:12 +00:00
function release _win ( arch , done ) {
2017-12-29 13:57:45 +00:00
2018-01-29 15:14:24 +00:00
// Check if makensis exists
if ( ! commandExistsSync ( 'makensis' ) ) {
console . warn ( 'makensis command not found, not generating win package for ' + arch ) ;
return done ( ) ;
}
2018-01-17 15:38:41 +00:00
// The makensis does not generate the folder correctly, manually
createDirIfNotExists ( RELEASE _DIR ) ;
2018-01-10 14:36:12 +00:00
2017-12-29 13:57:45 +00:00
// Parameters passed to the installer script
const options = {
verbose : 2 ,
define : {
'VERSION' : pkg . version ,
'PLATFORM' : arch ,
2018-01-10 14:36:12 +00:00
'DEST_FOLDER' : RELEASE _DIR
2017-12-29 13:57:45 +00:00
}
}
2018-01-10 14:36:12 +00:00
2017-12-29 13:57:45 +00:00
var output = makensis . compileSync ( './assets/windows/installer.nsi' , options ) ;
2018-01-10 14:36:12 +00:00
if ( output . status !== 0 ) {
2017-12-29 13:57:45 +00:00
console . error ( 'Installer for platform ' + arch + ' finished with error ' + output . status + ': ' + output . stderr ) ;
}
2018-01-10 14:36:12 +00:00
done ( ) ;
2017-12-29 13:57:45 +00:00
}
// Create distribution package (zip) for windows and linux platforms
2018-01-10 14:36:12 +00:00
function release _zip ( arch ) {
var src = path . join ( APPS _DIR , pkg . name , arch , '**' ) ;
var output = getReleaseFilename ( arch , 'zip' ) ;
var base = path . join ( APPS _DIR , pkg . name , arch ) ;
return compressFiles ( src , base , output , 'Betaflight Configurator' ) ;
}
// Create distribution package for chromeos platform
function release _chromeos ( ) {
var src = path . join ( DIST _DIR , '**' ) ;
var output = getReleaseFilename ( 'chromeos' , 'zip' ) ;
var base = DIST _DIR ;
return compressFiles ( src , base , output , '.' ) ;
}
// Compress files from srcPath, using basePath, to outputFile in the RELEASE_DIR
function compressFiles ( srcPath , basePath , outputFile , zipFolder ) {
return gulp . src ( srcPath , { base : basePath } )
2018-05-20 01:11:36 +00:00
. pipe ( rename ( function ( actualPath ) {
actualPath . dirname = path . join ( zipFolder , actualPath . dirname ) ;
} ) )
2018-01-10 14:36:12 +00:00
. pipe ( zip ( outputFile ) )
. pipe ( gulp . dest ( RELEASE _DIR ) ) ;
2018-01-05 17:58:27 +00:00
}
2018-01-29 15:14:24 +00:00
function release _deb ( arch , done ) {
2018-01-10 14:36:12 +00:00
2018-01-29 15:14:24 +00:00
// Check if dpkg-deb exists
if ( ! commandExistsSync ( 'dpkg-deb' ) ) {
console . warn ( 'dpkg-deb command not found, not generating deb package for ' + arch ) ;
return done ( ) ;
2018-01-05 17:58:27 +00:00
}
2018-01-10 14:36:12 +00:00
return gulp . src ( [ path . join ( APPS _DIR , pkg . name , arch , '*' ) ] )
2018-01-05 17:58:27 +00:00
. pipe ( deb ( {
package : pkg . name ,
version : pkg . version ,
section : 'base' ,
priority : 'optional' ,
2018-01-29 15:14:24 +00:00
architecture : getLinuxPackageArch ( 'deb' , arch ) ,
2018-01-05 17:58:27 +00:00
maintainer : pkg . author ,
description : pkg . description ,
2018-01-25 14:15:58 +00:00
postinst : [ 'xdg-desktop-menu install /opt/betaflight/betaflight-configurator/betaflight-configurator.desktop' ] ,
prerm : [ 'xdg-desktop-menu uninstall betaflight-configurator.desktop' ] ,
2018-01-05 17:58:27 +00:00
depends : 'libgconf-2-4' ,
changelog : [ ] ,
_target : 'opt/betaflight/betaflight-configurator' ,
2018-01-10 14:36:12 +00:00
_out : RELEASE _DIR ,
2018-01-17 14:30:44 +00:00
_copyright : 'assets/linux/copyright' ,
2018-01-05 17:58:27 +00:00
_clean : true
} ) ) ;
2017-12-10 20:25:16 +00:00
}
2018-01-29 15:14:24 +00:00
function release _rpm ( arch , done ) {
// Check if dpkg-deb exists
if ( ! commandExistsSync ( 'rpmbuild' ) ) {
console . warn ( 'rpmbuild command not found, not generating rpm package for ' + arch ) ;
return done ( ) ;
}
2018-02-02 19:23:09 +00:00
// The buildRpm does not generate the folder correctly, manually
2018-01-29 15:14:24 +00:00
createDirIfNotExists ( RELEASE _DIR ) ;
var options = {
name : pkg . name ,
version : pkg . version ,
buildArch : getLinuxPackageArch ( 'rpm' , arch ) ,
vendor : pkg . author ,
summary : pkg . description ,
license : 'GNU General Public License v3.0' ,
requires : 'libgconf-2-4' ,
prefix : '/opt' ,
files :
[ { cwd : path . join ( APPS _DIR , pkg . name , arch ) ,
2018-02-02 19:23:09 +00:00
src : '*' ,
2018-01-29 15:14:24 +00:00
dest : '/opt/betaflight/betaflight-configurator' } ] ,
postInstallScript : [ 'xdg-desktop-menu install /opt/betaflight/betaflight-configurator/betaflight-configurator.desktop' ] ,
preUninstallScript : [ 'xdg-desktop-menu uninstall betaflight-configurator.desktop' ] ,
tempDir : path . join ( RELEASE _DIR , 'tmp-rpm-build-' + arch ) ,
keepTemp : false ,
verbose : false ,
rpmDest : RELEASE _DIR
} ;
buildRpm ( options , function ( err , rpm ) {
if ( err ) {
console . error ( "Error generating rpm package: " + err ) ;
}
done ( ) ;
} ) ;
}
function getLinuxPackageArch ( type , arch ) {
var packArch ;
switch ( arch ) {
case 'linux32' :
packArch = 'i386' ;
break ;
case 'linux64' :
if ( type == 'rpm' ) {
packArch = 'x86_64' ;
} else {
packArch = 'amd64' ;
}
break ;
default :
console . error ( "Package error, arch: " + arch ) ;
process . exit ( 1 ) ;
break ;
}
return packArch ;
}
2017-11-22 20:19:34 +00:00
// Create distribution package for macOS platform
function release _osx64 ( ) {
var appdmg = require ( 'gulp-appdmg' ) ;
2017-10-20 00:36:33 +00:00
2018-01-17 15:38:41 +00:00
// The appdmg does not generate the folder correctly, manually
createDirIfNotExists ( RELEASE _DIR ) ;
// The src pipe is not used
return gulp . src ( [ '.' ] )
2017-11-22 20:19:34 +00:00
. pipe ( appdmg ( {
2018-01-10 14:36:12 +00:00
target : path . join ( RELEASE _DIR , getReleaseFilename ( 'macOS' , 'dmg' ) ) ,
basepath : path . join ( APPS _DIR , pkg . name , 'osx64' ) ,
2017-11-22 20:19:34 +00:00
specification : {
2017-11-25 12:53:28 +00:00
title : 'Betaflight Configurator' ,
contents : [
2017-11-22 20:19:34 +00:00
{ 'x' : 448 , 'y' : 342 , 'type' : 'link' , 'path' : '/Applications' } ,
{ 'x' : 192 , 'y' : 344 , 'type' : 'file' , 'path' : pkg . name + '.app' , 'name' : 'Betaflight Configurator.app' }
2017-11-25 12:53:28 +00:00
] ,
2018-01-21 16:09:36 +00:00
background : path . join ( _ _dirname , 'assets/osx/dmg-background.png' ) ,
2017-11-25 12:53:28 +00:00
format : 'UDZO' ,
window : {
size : {
width : 638 ,
height : 479
}
}
2017-11-25 07:47:32 +00:00
} ,
2017-11-22 20:19:34 +00:00
} )
) ;
}
2018-01-17 15:38:41 +00:00
// Create the dir directory, with write permissions
function createDirIfNotExists ( dir ) {
fs . mkdir ( dir , '0775' , function ( err ) {
if ( err ) {
if ( err . code !== 'EEXIST' ) {
throw err ;
}
}
} ) ;
}
2018-01-10 14:36:12 +00:00
// Create a list of the gulp tasks to execute for release
function listReleaseTasks ( done ) {
2017-11-21 10:40:39 +00:00
2018-01-08 10:37:32 +00:00
var platforms = getPlatforms ( ) ;
2017-11-24 03:40:02 +00:00
2018-01-10 14:36:12 +00:00
var releaseTasks = [ ] ;
2017-12-04 10:03:35 +00:00
if ( platforms . indexOf ( 'chromeos' ) !== - 1 ) {
2018-01-10 14:36:12 +00:00
releaseTasks . push ( release _chromeos ) ;
2017-12-04 10:03:35 +00:00
}
2017-11-24 03:40:02 +00:00
if ( platforms . indexOf ( 'linux64' ) !== - 1 ) {
2018-05-20 01:11:36 +00:00
releaseTasks . push ( function release _linux64 _zip ( ) {
return release _zip ( 'linux64' ) ;
} ) ;
releaseTasks . push ( function release _linux64 _deb ( done ) {
return release _deb ( 'linux64' , done ) ;
} ) ;
releaseTasks . push ( function release _linux64 _rpm ( done ) {
return release _rpm ( 'linux64' , done ) ;
} ) ;
2017-11-25 03:38:26 +00:00
}
2017-12-10 20:25:16 +00:00
if ( platforms . indexOf ( 'linux32' ) !== - 1 ) {
2018-05-20 01:11:36 +00:00
releaseTasks . push ( function release _linux32 _zip ( ) {
return release _zip ( 'linux32' ) ;
} ) ;
releaseTasks . push ( function release _linux32 _deb ( done ) {
return release _deb ( 'linux32' , done ) ;
} ) ;
releaseTasks . push ( function release _linux32 _rpm ( done ) {
return release _rpm ( 'linux32' , done ) ;
} ) ;
2017-12-10 20:25:16 +00:00
}
2018-01-10 14:36:12 +00:00
2018-05-13 19:00:56 +00:00
if ( platforms . indexOf ( 'armv7' ) !== - 1 ) {
2018-05-20 01:11:36 +00:00
releaseTasks . push ( function release _armv7 _zip ( ) {
return release _zip ( 'armv7' ) ;
} ) ;
2018-05-13 19:00:56 +00:00
}
2017-11-25 03:38:26 +00:00
if ( platforms . indexOf ( 'osx64' ) !== - 1 ) {
2018-01-10 14:36:12 +00:00
releaseTasks . push ( release _osx64 ) ;
2017-11-25 03:38:26 +00:00
}
if ( platforms . indexOf ( 'win32' ) !== - 1 ) {
2018-05-20 01:11:36 +00:00
releaseTasks . push ( function release _win32 ( done ) {
return release _win ( 'win32' , done ) ;
} ) ;
2017-12-07 15:00:13 +00:00
}
2018-01-29 15:14:24 +00:00
2017-12-07 15:00:13 +00:00
if ( platforms . indexOf ( 'win64' ) !== - 1 ) {
2018-05-20 01:11:36 +00:00
releaseTasks . push ( function release _win64 ( done ) {
return release _win ( 'win64' , done ) ;
} ) ;
2017-11-22 20:19:34 +00:00
}
2017-10-20 00:36:33 +00:00
2018-01-10 14:36:12 +00:00
return releaseTasks ;
}