-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.js
65 lines (48 loc) · 1.4 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const path = require('path');
const fs = require('fs');
function getVersionFilePath(directory) {
if (fs.existsSync(path.join(directory, 'composer.json'))) {
return path.join(directory, 'composer.json');
}
if (fs.existsSync(path.join(directory, 'package.json'))) {
return path.join(directory, 'package.json');
}
return null;
}
function writeVersionNumber(filePath, version) {
let contents = fs.readFileSync(filePath, 'utf-8');
let tabSize = 2;
if (filePath.indexOf('composer.json') !== -1) {
tabSize = 4;
}
try {
contents = JSON.parse(contents);
} catch (e) {
contents = {};
}
contents.version = version;
fs.writeFileSync(filePath, JSON.stringify(contents, null, tabSize));
}
/*
* Tries to determine the next version number that should be used, based on the previous
* version number and which git flow type that is being used (hotfix or release).
*/
function determineNextVersion(previousVersionNumber, flowType) {
const parts = previousVersionNumber.split('.');
if (flowType === 'hotfix') {
let hotfixNumber = parseInt(parts[2]);
hotfixNumber++;
return `${parts[0]}.${parts[1]}.${hotfixNumber}`;
}
if (flowType === 'release') {
let minorNumber = parseInt(parts[1]);
minorNumber++;
return `${parts[0]}.${minorNumber}.0`;
}
return null;
}
module.exports = {
getVersionFilePath,
writeVersionNumber,
determineNextVersion,
};