|
1 | 1 | module.exports = { |
2 | | - replace: function replaceVersion (body, dependency) { |
3 | | - const oldVersion = dependency.oldVersion |
4 | | - const newVersion = dependency.version |
| 2 | + replace: function replaceVersion(body, dependency) { |
| 3 | + const oldVersion = dependency.oldVersion; |
| 4 | + const newVersion = dependency.version; |
5 | 5 |
|
6 | | - const replaceActions = [] |
| 6 | + const replaceActions = []; |
7 | 7 |
|
8 | | - const regexVersionVariable = new RegExp(dependency.group + ":" + dependency.name + ":\\${?(\\w+)}?", "ig") |
| 8 | + const regexVersionVariable = new RegExp(dependency.group + ":" + dependency.name + ":\\${?(\\w+)}?", "ig"); |
9 | 9 |
|
10 | 10 | // 'de.kevcodez:pubg-api-wrapper:$myVar' |
11 | 11 | // 'de.kevcodez:pubg-api-wrapper:${myVar}' |
12 | | - const versionWithVariableMatches = regexVersionVariable.exec(body) |
| 12 | + const versionWithVariableMatches = regexVersionVariable.exec(body); |
13 | 13 | if (versionWithVariableMatches && versionWithVariableMatches.length === 2) { |
14 | | - const variableName = versionWithVariableMatches[1] |
| 14 | + const variableName = versionWithVariableMatches[1]; |
15 | 15 |
|
16 | | - const regexVariableDefinition = new RegExp(`(${variableName}(\\s+)?=(\\s+)?('|")${oldVersion}('|"))`, "ig") |
17 | | - const regexVariableDefinitionMatches = regexVariableDefinition.exec(body) |
| 16 | + const regexVariableDefinition = new RegExp(`(${variableName}(\\s+)?=(\\s+)?('|")${oldVersion}('|"))`, "ig"); |
| 17 | + const regexVariableDefinitionMatches = regexVariableDefinition.exec(body); |
18 | 18 |
|
19 | 19 | if (regexVariableDefinitionMatches && regexVariableDefinitionMatches.length) { |
20 | | - regexVariableDefinitionMatches.filter(it => it.includes(dependency.oldVersion)).forEach(match => { |
21 | | - replaceActions.push({ |
22 | | - searchValue: match, |
23 | | - replaceValue: match.replace(dependency.oldVersion, dependency.version) |
24 | | - }) |
25 | | - }) |
| 20 | + regexVariableDefinitionMatches |
| 21 | + .filter((it) => it.includes(dependency.oldVersion)) |
| 22 | + .forEach((match) => { |
| 23 | + replaceActions.push({ |
| 24 | + searchValue: match, |
| 25 | + replaceValue: match.replace(dependency.oldVersion, dependency.version), |
| 26 | + }); |
| 27 | + }); |
26 | 28 | } |
27 | 29 |
|
28 | 30 | // val PUBG_API_WRAPPER by extra("0.8.1") |
29 | | - const regexKotlinValExtra = new RegExp(`${variableName}.+\(("|')${oldVersion}("|')\)`) |
30 | | - const regexKotlinValMatches = regexKotlinValExtra.exec(body) |
| 31 | + const regexKotlinValExtra = new RegExp(`${variableName}.+\(("|')${oldVersion}("|')\)`); |
| 32 | + const regexKotlinValMatches = regexKotlinValExtra.exec(body); |
31 | 33 | if (regexKotlinValMatches && regexKotlinValMatches.length) { |
32 | | - regexKotlinValMatches.filter(it => it.includes(dependency.oldVersion)).forEach(match => { |
33 | | - replaceActions.push({ |
34 | | - searchValue: match, |
35 | | - replaceValue: match.replace(dependency.oldVersion, dependency.version) |
36 | | - }) |
37 | | - }) |
| 34 | + regexKotlinValMatches |
| 35 | + .filter((it) => it.includes(dependency.oldVersion)) |
| 36 | + .forEach((match) => { |
| 37 | + replaceActions.push({ |
| 38 | + searchValue: match, |
| 39 | + replaceValue: match.replace(dependency.oldVersion, dependency.version), |
| 40 | + }); |
| 41 | + }); |
38 | 42 | } |
39 | 43 | } |
40 | 44 |
|
41 | 45 | // compile 'de.kevcodez:pubg-api-wrapper:1.0.0' |
42 | | - const regexVersionInline = new RegExp(`${dependency.group}:${dependency.name}:${dependency.oldVersion}`, "g") |
| 46 | + const regexVersionInline = new RegExp(`${dependency.group}:${dependency.name}:${dependency.oldVersion}`, "g"); |
43 | 47 | if (regexVersionInline.exec(body)) { |
44 | 48 | replaceActions.push({ |
45 | 49 | searchValue: regexVersionInline, |
46 | | - replaceValue: `${dependency.group}:${dependency.name}:${dependency.version}` |
47 | | - }) |
| 50 | + replaceValue: `${dependency.group}:${dependency.name}:${dependency.version}`, |
| 51 | + }); |
48 | 52 | } |
49 | 53 |
|
50 | 54 | // id 'com.github.ben-manes.versions' version "0.21.0" |
51 | 55 | // id("com.github.ben-manes.versions") version "0.22.0" |
52 | | - const regexPluginVersionWithPrefix = new RegExp(`${dependency.group}("|')\\)?(\\s+)?version(\\s+)?("|')${oldVersion}("|')`) |
53 | | - const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix.exec(body) |
| 56 | + const regexPluginVersionWithPrefix = new RegExp(`${dependency.group}("|')\\)?(\\s+)?version(\\s+)?("|')${oldVersion}("|')`); |
| 57 | + const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix.exec(body); |
54 | 58 | if (regexVersionWithPrefixMatches && regexVersionWithPrefixMatches.length) { |
55 | | - regexVersionWithPrefixMatches.filter(it => it.includes(oldVersion)).forEach(match => { |
56 | | - replaceActions.push({ |
57 | | - searchValue: match, |
58 | | - replaceValue: match.replace(oldVersion, newVersion) |
59 | | - }) |
60 | | - }) |
| 59 | + regexVersionWithPrefixMatches |
| 60 | + .filter((it) => it.includes(oldVersion)) |
| 61 | + .forEach((match) => { |
| 62 | + replaceActions.push({ |
| 63 | + searchValue: match, |
| 64 | + replaceValue: match.replace(oldVersion, newVersion), |
| 65 | + }); |
| 66 | + }); |
61 | 67 | } |
62 | 68 |
|
63 | 69 | // compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '0.8.1' |
64 | | - const regexDependencyWithVersionPrefix = new RegExp(`${dependency.name}('|"),(\\s+)?version:(\\s+)('|")${dependency.oldVersion}('|")`) |
65 | | - const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix.exec(body) |
| 70 | + const regexDependencyWithVersionPrefix = new RegExp(`${dependency.name}('|"),(\\s+)?version:(\\s+)('|")${dependency.oldVersion}('|")`); |
| 71 | + const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix.exec(body); |
66 | 72 | if (regexDependencyWithVersionPrefixMatches && regexDependencyWithVersionPrefixMatches.length) { |
67 | | - regexDependencyWithVersionPrefixMatches.filter(it => it.includes(oldVersion)).forEach(match => { |
68 | | - replaceActions.push({ |
69 | | - searchValue: match, |
70 | | - replaceValue: match.replace(oldVersion, newVersion) |
71 | | - }) |
72 | | - }) |
| 73 | + regexDependencyWithVersionPrefixMatches |
| 74 | + .filter((it) => it.includes(oldVersion)) |
| 75 | + .forEach((match) => { |
| 76 | + replaceActions.push({ |
| 77 | + searchValue: match, |
| 78 | + replaceValue: match.replace(oldVersion, newVersion), |
| 79 | + }); |
| 80 | + }); |
73 | 81 | } |
74 | 82 |
|
75 | | - return replaceActions |
76 | | - } |
77 | | -} |
| 83 | + return replaceActions; |
| 84 | + }, |
| 85 | +}; |
0 commit comments