-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage_json_version_bump.js
46 lines (37 loc) · 1.24 KB
/
package_json_version_bump.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
const path = require('path');
const fs = require('fs');
const { exec } = require('child_process');
const args = process.argv;
const version = args[3];
const directory = args[2];
// Check the git config to see if versionbumping is enabled
exec('git config --get gitflow.versionbumping', (err, versionBumpingIsEnabled, stderr) => {
if (err) {
// Not defined in config, ignoring further actions
return;
}
try {
versionBumpingIsEnabled = JSON.parse(versionBumpingIsEnabled);
} catch (err) {
versionBumpingIsEnabled = false;
}
if (versionBumpingIsEnabled) {
// We check for a composer.json file first, if it does not exist, read package.json
if (fs.existsSync(path.join(directory, 'composer.json'))) {
bumpVersion('composer.json', 4);
} else if (fs.existsSync(path.join(directory, 'package.json'))) {
bumpVersion('package.json');
}
}
});
function bumpVersion(file, tabSize = 2) {
let content = fs.readFileSync(path.join(directory, file), 'utf-8');
try {
content = JSON.parse(content);
} catch (e) {
content = {};
}
content.version = version;
fs.writeFileSync(path.join(directory, file), JSON.stringify(content, null, tabSize));
console.log(`Bumped ${file} version to ${version}`);
}