UNPKG

@holisticon/nativescript-buildhelper

Version:

Basic NPM package for helping on automate releasing of NativeScript Apps

53 lines (52 loc) 2.31 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs"); var xml2js = require("xml2js"); var path = require("path"); var util = require("util"); var child_process_1 = require("child_process"); // Adds the build number to app versioning // e.g. release_notes.js 42 -> uses 42 as build number var ARGS = process.argv.slice(2); var DEBUG_ENV = 'holisticon_tns'; var debugLog = util.debuglog(DEBUG_ENV); var xmlParser = new xml2js.Parser(), builder = new xml2js.Builder(), manifestPath = process.env['MANIFEST_PATH'] || 'app/App_Resources/Android/AndroidManifest.xml', plistPath = process.env['PLIST_PATH'] || 'app/App_Resources/iOS/Info.plist', buildNo = ARGS[0] || process.env['BUILD_NUMBER'] || 1, packageJSON = require(path.resolve('.', 'package.json')), version = packageJSON.version; console.log('Updating with build number: ' + buildNo); fs.stat(manifestPath, function (error) { if (!error) { var manifestXML_1 = fs.readFileSync(manifestPath); debugLog('Using following manifest: ', manifestXML_1); xmlParser.parseString(manifestXML_1, function (err, manifestData) { var appId = packageJSON.nativescript.id; manifestData.manifest.$['android:versionCode'] = buildNo; manifestData.manifest.$['android:versionName'] = version; var updatedManifest = builder.buildObject(manifestData); debugLog('Updating manifest with: ', manifestXML_1); fs.writeFile(manifestPath, updatedManifest, function (err) { if (err) throw err; }); }); } else { console.log('Skipping platform Android'); } }); fs.stat(plistPath, function (error) { if (!error) { child_process_1.exec('/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ' + buildNo + '" ' + path.resolve('.', plistPath), function (err) { if (err) { throw err; } }); child_process_1.exec('/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ' + version + '" ' + path.resolve('.', plistPath), function (err) { if (err) { throw err; } }); } else { console.log('Skipping platform iOS'); } });