versioning-manager
Version:
Versioning manager is a helper to increment version on iOS and Android in Flutter or ReactNative projects
2 lines • 3.42 kB
JavaScript
(()=>{var e={519:(e,r,t)=>{const n=t(231);e.exports=class{constructor(e){this.path=e}read(){return n.readFileSync(this.path,"utf-8")}write(e){return n.writeFileSync(this.path,e,"utf-8")}}},114:(e,r,t)=>{const n=t(519),i=t(936);e.exports=class extends n{constructor(){super("android/app/build.gradle")}getCurrentVersion(){const e=this.read(),[r,t]=/versionName "(.*)"/.exec(e);return t}getCurrentBuildNumber(){const e=this.read(),[r,t]=/versionCode (\d+)/.exec(e);return Number(t)}getNextVersion(e){const r=new i(this.getCurrentVersion());return{major:r.incrementMajor(),minor:r.incrementMinor(),patch:r.incrementPatch()}[e]}incrementVersion(e="patch"){const r=this.read(),t=this.getNextVersion(e);this.write(r.replace(/versionName "(.*)"/,`versionName "${t}"`))}incrementBuildNumber(){const e=this.read(),r=this.getCurrentBuildNumber();this.write(e.replace(/versionCode (\d+)/,`versionCode ${r+1}`))}}},323:(e,r,t)=>{const n=t(519),i=t(936),s=t(230);e.exports=class extends n{constructor(){const[e]=s.sync("ios/*.xcodeproj/project.pbxproj");super(e)}getCurrentVersion(){const e=this.read(),[r,t]=/MARKETING_VERSION = (.*);/.exec(e);return t}getCurrentBuildNumber(){const e=this.read(),[r,t]=/CURRENT_PROJECT_VERSION = (\d+);/.exec(e);return Number(t)}getNextVersion(e){const r=new i(this.getCurrentVersion());return{major:r.incrementMajor(),minor:r.incrementMinor(),patch:r.incrementPatch()}[e]}incrementVersion(e="patch"){const r=this.read(),t=this.getNextVersion(e);this.write(r.replace(/MARKETING_VERSION = (.*);/g,`MARKETING_VERSION = ${t};`))}incrementBuildNumber(){const e=this.read(),r=this.getCurrentBuildNumber();this.write(e.replace(/CURRENT_PROJECT_VERSION = (\d+);/g,`CURRENT_PROJECT_VERSION = ${r+1};`))}}},936:e=>{e.exports=class{constructor(e){this.version=String(e)}incrementMajor(){const[e]=this.version.split(".").map(Number);return[e+1,0,0].join(".")}incrementMinor(){const[e,r]=this.version.split(".").map(Number);return[e,r+1,0].join(".")}incrementPatch(){const[e,r,t]=this.version.split(".").map(Number);return[e,r,(t??0)+1].join(".")}}},22:e=>{"use strict";e.exports=require("chalk")},231:e=>{"use strict";e.exports=require("fs")},230:e=>{"use strict";e.exports=require("glob")},760:e=>{"use strict";e.exports=require("yargs")}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var s=r[n]={exports:{}};return e[n](s,s.exports,t),s.exports}(()=>{const e=t(760),r=t(22),n=t(114),i=t(323),s=r.keyword("violet")("\nUsage: vm increment-version -t <type> -p <platform> \n"),o=e.usage(s).option("t",{alias:"type",describe:"[major|minor|patch] semver release type",default:"patch",type:"string",demandOption:!1}).option("p",{alias:"platform",describe:"[android|ios|both] specifies the platform",default:"both",type:"string",demandOption:!1}).help(!0).argv,{t:c,p:u}=o;let a=r.keyword("blue")(`\n-------------------------------------------------------\n---- Successfully incremented the ${c} version 🎉 ----\n-------------------------------------------------------\n\n`);if(["both","android"].some((e=>u===e))){const e=new n;e.incrementVersion(c),e.incrementBuildNumber(),a+=r.keyword("green")(`Android: ${e.getCurrentVersion()}(${e.getCurrentBuildNumber()})\n`)}if(["both","ios"].some((e=>u===e))){const e=new i;e.incrementVersion(c),e.incrementBuildNumber(),a+=r.keyword("green")(`iOS: ${e.getCurrentVersion()}(${e.getCurrentBuildNumber()})\n`)}console.log(a)})()})();