Last active
August 29, 2015 14:15
-
-
Save mmocny/7e6348a8db201cbc6ef1 to your computer and use it in GitHub Desktop.
This file contains 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
var cordova = require('cordova-lib'); | |
var INPUT_WEBAPP = 'path/to/my/project/dist/app'; | |
var CDV_CONFIG = 'path/to/my/project/src/config.xml'; | |
var OUTPUT_CDVROOT = 'path/to/my/project/dist/cordova'; | |
var platforms = [ | |
require(‘cordova-android’), | |
require(‘cordova-ios’), | |
// ... | |
]; | |
var plugins = [ | |
require(‘cordova-plugin-device’), | |
require(‘cordova-plugin-contacts’), | |
// ... | |
]; | |
var cdv = cordova.Project(OUTPUT_CDVROOT); | |
function clean() { | |
shelljs.rm('-rf', OUTPUT_CDVROOT); | |
} | |
function create() { | |
// return Promise | |
return cdv.create({ | |
platforms: platforms, | |
plugins: plugins, | |
config: CDV_CONFIG, | |
}); | |
} | |
function buildFor(platform) { | |
// return Promise | |
return cdv.build({ | |
platforms: [ require('cordova-' + platform) ], | |
www: INPUT_WEBAPP, | |
}); | |
} | |
function runFor(platform) { | |
// return Promise | |
return cdv.run({ | |
platforms: [ require('cordova-' + platform) ], | |
opts: { | |
device: require('cordova-android-device-list').getDevices()[0], // This is not a part of core | |
} | |
}); | |
} | |
function main() { | |
var requiresRebuild = /* did you add plugins? did you change config.xml? etc */; | |
var work = Q.when(); | |
if (requiresRebuild) { | |
work = work | |
.then(clean) | |
.then(create); | |
} | |
work | |
.then(() => buildFor('android')) | |
.then(() => runFor('android')) | |
.done(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment