diff --git a/package.json b/package.json index 3a0c009..43841c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "capacitor-standard-version", - "version": "1.0.11", + "version": "1.0.12", "description": "Default standard-version config for capacitor app", "main": "dist/index.js", "bin": { diff --git a/src/bin/android.ts b/src/bin/android.ts index 4362e3a..a66f79c 100644 --- a/src/bin/android.ts +++ b/src/bin/android.ts @@ -4,8 +4,12 @@ export const readVersion = (contents) => { } export const writeVersion = (contents, version) => { - const newContent = contents.replace(/(.*(?:versionName[ \t]+).*)/g, ` versionName "${version}"`) - const versionCode = Number(version.split('.').map(v => v.length === 1 ? `0${v}` : v).join('').replace(/\D/g, '')) - const finalContent = newContent.replace(/(.*(?:versionCode[ \t]+).*)/g, ` versionCode ${versionCode}`) + const versionPure = version.split('-')[0] + const newContent = contents.replace(/(.*(?:versionName[ \t]+).*)/g, `\t\tversionName "${versionPure}"`) + let versionCode = Number(version.replace(/-.*?\./g, '').split('.').map(v => v.length === 1 ? `0${v}` : v).join('')) + if (versionCode < 1000000) { + versionCode *= 100 + } + const finalContent = newContent.replace(/(.*(?:versionCode[ \t]+).*)/g, `\t\tversionCode ${versionCode}`) return finalContent } diff --git a/src/bin/ios.ts b/src/bin/ios.ts index de009c0..3f1981e 100644 --- a/src/bin/ios.ts +++ b/src/bin/ios.ts @@ -5,7 +5,13 @@ export const readVersion = (contents) => { } export const writeVersion = (contents, version) => { - const newContent = contents.replace(/(.*(?:MARKETING_VERSION[ \t]+).*)/g, ` MARKETING_VERSION = "${version}";`) - const finalContent = newContent.replace(/(.*(?:CURRENT_PROJECT_VERSION[ \t]+).*)/g, ` CURRENT_PROJECT_VERSION = "${version}";`) + const versionPure = version.split('-')[0] + const newContent = contents.replace(/(.*(?:MARKETING_VERSION[ \t]+).*)/g, `\t\t\t\tMARKETING_VERSION = "${versionPure}";`) + let versionCode = Number(version.replace(/-.*?\./g, '').split('.').map(v => v.length === 1 ? `0${v}` : v).join('')) + if (versionCode < 1000000) { + versionCode *= 100 + } + const finalContent = newContent + .replace(/(.*(?:CURRENT_PROJECT_VERSION[ \t]+).*)/g, `\t\t\t\tCURRENT_PROJECT_VERSION = "${versionPure}";`) return finalContent }