-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion-bump.js
More file actions
52 lines (41 loc) · 1.08 KB
/
version-bump.js
File metadata and controls
52 lines (41 loc) · 1.08 KB
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
/**
* Automatically bump the version of the plugin.
*
* @package DPWD\HPOSCompatPlugin
*/
const fs = require( 'fs' );
const bumpType = process.argv[ 2 ];
function bumpPluginVersion( path ) {
const pluginVersion = /(\d+\.\d+\.\d+)/g;
let fileContent = fs.readFileSync( path, 'utf8' );
const versionStrings = fileContent.match( pluginVersion );
if ( ! versionStrings[ 0 ] ) {
return;
}
let versionParts = versionStrings[ 0 ].split( '.' );
if ( 'major' === bumpType ) {
versionParts[ 2 ] = 0;
if ( 9 > versionParts[ 1 ] ) {
versionParts[ 1 ]++;
} else {
versionParts[ 1 ] = 0;
versionParts[ 0 ]++;
}
} else {
if ( 9 > versionParts[ 2 ] ) {
versionParts[ 2 ]++;
} else {
versionParts[ 2 ] = 0;
if ( 9 > versionParts[ 1 ] ) {
versionParts[ 1 ]++;
} else {
versionParts[ 1 ] = 0;
versionParts[ 0 ]++;
}
}
}
const bumpedPluginVersion = versionParts.join( '.' );
fileContent = fileContent.replace( pluginVersion, bumpedPluginVersion );
fs.writeFileSync( path, fileContent );
}
bumpPluginVersion( './hpos-compatibility-scanner.php' );