1
- const versionExtractRegex = / v e r s i o n [ " ] * = [ ] * [ " ' ] ( .* ) [ " ' ] / i
1
+ const versionExtractRegex = / v e r s i o n [ " ] * = [ ] * [ " ' ] ( .* ) [ " ' ] / i;
2
2
3
3
const getVersionIndex = function ( lines ) {
4
- let version
5
- const lineNumber = lines . findIndex ( line => {
6
- const versionMatcher = line . match ( versionExtractRegex )
4
+ let version ;
5
+ const lineNumber = lines . findIndex ( ( line ) => {
6
+ const versionMatcher = line . match ( versionExtractRegex ) ;
7
7
// if version not found in lines provided, return false
8
8
if ( versionMatcher == null ) {
9
- return false
9
+ return false ;
10
10
}
11
- version = versionMatcher [ 1 ]
12
- return true
13
- } )
14
- return { version, lineNumber }
15
- }
11
+ version = versionMatcher [ 1 ] ;
12
+ return true ;
13
+ } ) ;
14
+ return { version, lineNumber } ;
15
+ } ;
16
16
17
17
module . exports . readVersion = function ( contents ) {
18
- const lines = contents . split ( '\n' )
19
- const versionIndex = getVersionIndex ( lines )
20
- return versionIndex . version
21
- }
18
+ const lines = contents . split ( '\n' ) ;
19
+ const versionIndex = getVersionIndex ( lines ) ;
20
+ return versionIndex . version ;
21
+ } ;
22
22
23
23
module . exports . writeVersion = function ( contents , version ) {
24
- const lines = contents . split ( '\n' )
25
- const versionIndex = getVersionIndex ( lines )
26
- const versionLine = lines [ versionIndex . lineNumber ]
27
- const newVersionLine = versionLine . replace ( versionIndex . version , version )
28
- lines [ versionIndex . lineNumber ] = newVersionLine
29
- return lines . join ( '\n' )
30
- }
24
+ const lines = contents . split ( '\n' ) ;
25
+ const versionIndex = getVersionIndex ( lines ) ;
26
+ const versionLine = lines [ versionIndex . lineNumber ] ;
27
+ const newVersionLine = versionLine . replace ( versionIndex . version , version ) ;
28
+ lines [ versionIndex . lineNumber ] = newVersionLine ;
29
+ return lines . join ( '\n' ) ;
30
+ } ;
0 commit comments