Created
January 23, 2015 04:20
-
-
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)
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
#!/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