@@ -9,6 +9,7 @@ const readline = require('readline').createInterface({
9
9
const args = process . argv . slice ( 2 )
10
10
11
11
const version = validateVersion ( args )
12
+ const useForce = shouldUseForce ( args )
12
13
if ( ! version ) {
13
14
console . log ( `Please specify a valid version
14
15
Usage: npm run p -- [major|minor|patch] {message?}
@@ -17,29 +18,46 @@ const readline = require('readline').createInterface({
17
18
}
18
19
console . log ( `Publishing version: ${ version . toUpperCase ( ) } ` )
19
20
20
- const hasChangelog = await validateChangeLog ( )
21
- if ( ! hasChangelog ) {
22
- console . log ( "Please update the changelog" )
21
+ try {
22
+ await validateChangeLog ( useForce )
23
+ console . log ( "CHANGELOG update validated" )
24
+ } catch ( error ) {
25
+ console . log ( error )
23
26
process . exit ( 1 ) ;
24
27
}
25
28
26
29
runNpmVersionPatch ( version , args )
27
30
console . log ( execSync ( `npm run build` ) . toString ( ) )
28
31
console . log ( execSync ( `cd dist/angular4-paystack && npm publish` ) . toString ( ) )
32
+ console . log ( execSync ( `cd ../..` ) . toString ( ) )
33
+ process . exit ( 0 ) ;
29
34
} ) ( )
30
35
31
36
32
- function validateChangeLog ( ) {
33
- return new Promise ( ( resolve ) => {
34
- readline . question ( 'HAS CHANGELOG BEEN UPDATED?\n' , response => {
35
- if ( response . toLocaleLowerCase ( ) === "yes" || response . toLocaleLowerCase ( ) === "y" ) {
36
- readline . close ( )
37
- resolve ( true )
38
- } else {
39
- readline . close ( )
40
- resolve ( false )
37
+ function validateChangeLog ( force = false ) {
38
+ const modifiedFiles = execSync ( "git ls-files --modified" ) ;
39
+ const filesList = modifiedFiles . toString ( ) . split ( "\n" ) ;
40
+ return new Promise ( ( resolve , reject ) => {
41
+ if ( force ) {
42
+ readline . question ( 'HAS CHANGELOG BEEN UPDATED?\n' , response => {
43
+ if ( response . toLocaleLowerCase ( ) === "yes" || response . toLocaleLowerCase ( ) === "y" ) {
44
+ readline . close ( )
45
+ resolve ( true )
46
+ } else {
47
+ readline . close ( )
48
+ reject ( "Please update the changelog" )
49
+ }
50
+ } ) ;
51
+ } else {
52
+ if ( filesList ?. includes ( "projects/angular4-paystack/CHANGELOG.md" ) ) {
53
+ reject ( "Only CHANGELOG.md in root should be modified." )
41
54
}
42
- } ) ;
55
+ if ( filesList ?. includes ( "CHANGELOG.md" ) ) {
56
+ resolve ( true ) ;
57
+ return ;
58
+ }
59
+ reject ( "CHANGELOG.md not modified. Please update the changelog before publishing." ) ;
60
+ }
43
61
} )
44
62
}
45
63
@@ -58,3 +76,8 @@ function runNpmVersionPatch(version, args) {
58
76
`cd projects/angular4-paystack && npm version ${ version } ${ message ? ` -m "${ message } "` : "" } ` ) ;
59
77
console . log ( returnMessage . toString ( ) )
60
78
}
79
+
80
+ function shouldUseForce ( args ) {
81
+ return args . includes ( "-f" ) || args . includes ( "--force" )
82
+ }
83
+
0 commit comments