Skip to content

Commit

Permalink
Support replacing versions defined with val by extra in kotlin build …
Browse files Browse the repository at this point in the history
…scripts
  • Loading branch information
kevcodez committed Mar 25, 2020
1 parent 019259e commit df7cc95
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ReplaceVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ module.exports = {
})
})
}

// val PUBG_API_WRAPPER by extra("0.8.1")
const regexKotlinValExtra = new RegExp(`${variableName}.+\(("|')${oldVersion}("|')\)`)
const regexKotlinValMatches = regexKotlinValExtra.exec(body)
if (regexKotlinValMatches && regexKotlinValMatches.length) {
regexKotlinValMatches.filter(it => it.includes(dependency.oldVersion)).forEach(match => {
replaceActions.push({
searchValue: match,
replaceValue: match.replace(dependency.oldVersion, dependency.version)
})
})
}
}

// compile 'de.kevcodez:pubg-api-wrapper:1.0.0'
Expand Down
22 changes: 22 additions & 0 deletions __tests__/ReplaceVersion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ test('Replace kotlin plugin version', () => {
const replacedVersion = replaceText(`id("com.github.ben-manes.versions") version "0.22.0"`, pluginDependency)
expect(replacedVersion).toBe(`id("com.github.ben-manes.versions") version "0.24.0"`)
})
test('Replace kotlin version with extra val without braces in reference', () => {
const replacedVersion = replaceText(`
val PUBG_API_WRAPPER by extra("0.8.1")
dependencies {
implementation("de.kevcodez:pubg-api-wrapper:$PUBG_API_WRAPPER")
}
`, dependency)

expect(replacedVersion).toContain(`val PUBG_API_WRAPPER by extra("1.0.0")`)
})
test('Replace kotlin version with extra val with braces in reference', () => {
const replacedVersion = replaceText(`
val PUBG_API_WRAPPER by extra("0.8.1")
dependencies {
implementation("de.kevcodez:pubg-api-wrapper:$\{PUBG_API_WRAPPER\}")
}
`, dependency)

expect(replacedVersion).toContain(`val PUBG_API_WRAPPER by extra("1.0.0")`)
})

function replaceText(source, dependency) {
const replaceVersionActions = ReplaceVersion.replace(source, dependency)
Expand Down

0 comments on commit df7cc95

Please sign in to comment.