Skip to content

Instantly share code, notes, and snippets.

@rogerlsmith
Created January 23, 2015 04:20
Show Gist options
  • Save rogerlsmith/d0e0068c4e1c591832a7 to your computer and use it in GitHub Desktop.
Save rogerlsmith/d0e0068c4e1c591832a7 to your computer and use it in GitHub Desktop.
cordova hook for incrementing build number in config.xml (hooks/before_build/incrementVersion.js)
#!/usr/bin/env node
console.log ( 'incrementing version' );
var fs = require ( 'fs' ),
xml2js = require ( 'xml2js' );
var parser = new xml2js.Parser ( );
fs.readFile ( "config.xml", function ( err, data ) {
parser.parseString ( data, function ( err, result ) {
var buildArray = result['widget']['$']['version'].split ( '.' );
buildArray[2] = Number ( buildArray[2] ) + 1;
result['widget']['$']['version'] = buildArray.join ( '.' );
var builder = new xml2js.Builder ( );
var xml = builder.buildObject ( result );
fs.writeFile ( 'config.xml', xml, 0, xml.length, function ( err, written, buffer ) {
if ( err ) {
console.log ( "Error: " + written );
} else {
console.log ( 'config.xml updated' );
}
});
console.log ( 'Done' );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment