Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 42 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | const cp = require('child_process'); |
||
2 | const path = require('path'); |
||
3 | |||
4 | const appInfo = cp.execSync('grep -oPm1 "(?<=<version>)[^<]+" appinfo/info.xml').toString().trim(); |
||
5 | |||
6 | console.log('AppInfo: ' + appInfo); |
||
|
|||
7 | |||
8 | const appInfoFloat = withoutDot(appInfo); |
||
9 | |||
10 | let gitTagOld; |
||
11 | try { |
||
12 | gitTagOld = cp.execSync('git describe --tags $(git rev-list --tags --max-count=1)').toString().trim(); |
||
13 | } catch (e) { |
||
14 | gitTagOld = 0; |
||
15 | } |
||
16 | console.log('Current git tag:' + gitTagOld); |
||
17 | |||
18 | const gitTagOldFloat = withoutDot(gitTagOld); |
||
19 | |||
20 | if (appInfoFloat > gitTagOldFloat) { |
||
21 | // git tag with appInfo |
||
22 | console.log('major or minor version step'); |
||
23 | cp.execSync('git tag ' + appInfo); |
||
24 | } else { |
||
25 | console.log('they equal or git tag version is higher => patch version step'); |
||
26 | const newVersion = patch(gitTagOld); |
||
27 | // git tag with newVersion |
||
28 | console.log('New version: '+ newVersion); |
||
29 | cp.execSync('git tag ' + newVersion); |
||
30 | cp.execSync('sed -i \"s\/\\(<version.*>\\)[^<>]*\\(<\\\/version.*\\)\/\\1' + newVersion + '\\2\/\" ' + path.resolve(__dirname, '..\/appinfo\/info.xml')); |
||
31 | } |
||
32 | |||
33 | function patch(v) { |
||
34 | const parts = v.split('.'); |
||
35 | parts.push(Number.parseInt(parts.pop()) + 1); |
||
36 | return parts.join('.'); |
||
37 | } |
||
38 | |||
39 | function withoutDot(v) { |
||
40 | const parts = v.split('.'); |
||
41 | return Number.parseFloat(parts.shift() + '.' + parts.join('')); |
||
42 | } |