Skip to content

Instantly share code, notes, and snippets.

@mmocny
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmocny/7e6348a8db201cbc6ef1 to your computer and use it in GitHub Desktop.
Save mmocny/7e6348a8db201cbc6ef1 to your computer and use it in GitHub Desktop.
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