Created
May 5, 2016 15:36
-
-
Save lucianomlima/ac7a0fbc34f56002f3a423979001e5ea to your computer and use it in GitHub Desktop.
Cordova hook script to make a copy of an APK file after build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(context) { | |
// make sure android platform is part of build | |
if (context.opts.platforms.indexOf('android') < 0) { | |
return; | |
} | |
var fs = context.requireCordovaModule('fs'), | |
path = context.requireCordovaModule('path'), | |
ConfigParser = context.requireCordovaModule('cordova-lib').configparser; | |
var configFileLocation = path.join(context.opts.projectRoot, 'config.xml'); | |
var config = new ConfigParser(configFileLocation); | |
var platformRoot = path.join(context.opts.projectRoot, 'platforms/android'); | |
var buildType = 'debug'; | |
var buildOptions = context.opts.options || {}; | |
var apkFilename = String(config.name()).replace(/ /g, '_')+'_v'+config.version()+'-'+config.android_versionCode()+'.apk'; | |
if (buildOptions.hasOwnProperty('release')) { | |
buildType = 'release'; | |
apkFilename = String(config.name()).replace(/ /g, '_')+'_release.apk'; | |
}; | |
var apkFileLocation = path.join(platformRoot, 'build/outputs/apk/android-'+buildType+'.apk'); | |
var apkDestination = path.join(process.env.HOME, 'Downloads', apkFilename); | |
fs.createReadStream(apkFileLocation).pipe(fs.createWriteStream(apkDestination)); | |
console.log('Copy to', apkDestination); | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment