Skip to content

Commit

Permalink
fix: build number
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed May 3, 2022
1 parent 78d7f0a commit b03a62b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
10 changes: 7 additions & 3 deletions src/bin/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions src/bin/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit b03a62b

Please sign in to comment.