SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const path = require('path');
  3. const pkg = require('./package');
  4. const convert = require('xml-js');
  5. const beautify = require('xml-beautifier');
  6. const plist = require('plist');
  7.  
  8. updateIOSPList();
  9. updateAndroidManifest();
  10.  
  11. /**
  12.  * Update iOS PList file with new version
  13.  */
  14. function updateIOSPList() {
  15.     const iosPListPath = path.resolve('./app/App_Resources/iOS/Info.plist');
  16.  
  17.     let iosPListFile = fs.readFileSync(iosPListPath, { encoding: 'utf-8' }).toString();
  18.  
  19.     if(!iosPListFile) {
  20.         throw new Error("Could not update iOS Plist file");
  21.     }
  22.  
  23.     let iosPList = plist.parse(iosPListFile);
  24.  
  25.     iosPList.CFBundleShortVersionString = pkg.version;
  26.     iosPList.CFBundleVersion = pkg.version;
  27.  
  28.     const newIOSPList = plist.build(iosPList);
  29.  
  30.     fs.writeFileSync(iosPListPath, newIOSPList, 'utf8');
  31. }
  32.  
  33. /**
  34.  * Update Android Manifest with new version
  35.  */
  36. function updateAndroidManifest() {
  37.     const androidManifestPath = path.resolve('./app/App_Resources/Android/src/main/AndroidManifest.xml');
  38.  
  39.     let androidManifest = fs.readFileSync(androidManifestPath, { encoding: 'utf-8' }).toString();
  40.  
  41.     let androidManifestXml = convert.xml2js(androidManifest, {
  42.         object: true,
  43.         reversible: true,
  44.         coerce: false,
  45.         sanitize: false,
  46.         trim: false,
  47.         arrayNotation: false,
  48.         alternateTextNode: false
  49.     });
  50.  
  51.     if(!androidManifestXml.elements[0].attributes['android:versionCode'] && !androidManifestXml.elements[0].attributes['android:versionName']) {
  52.         throw new Error("Could not update Android Manifest");
  53.     }
  54.  
  55.     androidManifestXml.elements[0].attributes['android:versionCode'] = pkg.version.replace(/\./g, '') + '000';
  56.     androidManifestXml.elements[0].attributes['android:versionName'] = pkg.version;
  57.  
  58.     const newAndroidManifest = convert.js2xml(androidManifestXml);
  59.  
  60.     fs.writeFileSync(androidManifestPath, beautify(newAndroidManifest), 'utf8');
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top