Forked from njleonzhang/append_8_to_version_code.js
Last active
January 27, 2020 17:05
-
-
Save ricardoapaes/66f07c0a46c3e7dadf488aa66b93fff7 to your computer and use it in GitHub Desktop.
append extend 8 to android code version.
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 | |
var path = require('path'); | |
var fs = require('fs'); | |
var xml2js = require('xml2js'); | |
var deferral; | |
function log(message) { | |
console.log(message); | |
} | |
function onError(error) { | |
log("ERROR: " + error); | |
deferral.resolve(); | |
} | |
function xmlFileToJs(filename, cb) { | |
var filepath = path.normalize(path.join(__dirname, filename)); | |
fs.readFile(filepath, 'utf8', function (err, xmlStr) { | |
if (err) throw (err); | |
xml2js.parseString(xmlStr, {}, cb); | |
}); | |
} | |
function jsToXmlFile(filename, obj, cb) { | |
try { | |
var filepath = path.normalize(path.join(__dirname, filename)); | |
var builder = new xml2js.Builder(); | |
var xml = builder.buildObject(obj); | |
fs.writeFile(filepath, xml, cb); | |
} catch (e) { | |
onError("EXCEPTION: " + e.toString()); | |
} | |
} | |
function run() { | |
var androidManifestRPath = '../platforms/android/app/src/main/AndroidManifest.xml'; | |
xmlFileToJs(androidManifestRPath, function(error, data) { | |
var config = data; | |
config.manifest.$['android:versionCode'] += '8'; | |
jsToXmlFile(androidManifestRPath, config, function() { | |
deferral.resolve(); | |
}); | |
}); | |
} | |
function attempt(fn) { | |
return function () { | |
try { | |
fn.apply(this, arguments); | |
} catch (e) { | |
onError("EXCEPTION: " + e.toString()); | |
} | |
} | |
} | |
module.exports = function (ctx) { | |
try{ | |
deferral = require('q').defer(); | |
}catch(e){ | |
e.message = 'Unable to load node module dependency \'q\': '+e.message; | |
log(e.message); | |
throw e; | |
} | |
attempt(run)(); | |
return deferral.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment