File tree 4 files changed +317
-15
lines changed
4 files changed +317
-15
lines changed Original file line number Diff line number Diff line change 1
1
node_modules /
2
2
docs /dist /
3
+ scripts /
Original file line number Diff line number Diff line change 22
22
"react-native-vector-icons" : " *"
23
23
},
24
24
"devDependencies" : {
25
+ "babel-cli" : " ^6.24.1" ,
25
26
"babel-eslint" : " ^7.2.3" ,
27
+ "babel-preset-flow" : " ^6.23.0" ,
26
28
"eslint" : " ^4.1.1" ,
27
29
"eslint-config-prettier" : " ^2.3.0" ,
28
30
"eslint-plugin-babel" : " ^4.1.1" ,
44
46
"react-native-drawer" : " ^2.3.0"
45
47
},
46
48
"scripts" : {
49
+ "commitmsg" : " babel-node ./scripts/validateCommitMessage.js $GIT_PARAMS --presets flow" ,
47
50
"precommit" : " npm run lint && npm run flow" ,
48
51
"flow" : " flow" ,
49
52
"lint" : " eslint ." ,
Original file line number Diff line number Diff line change
1
+ /* @flow */
2
+
3
+ const fs = require ( 'fs' ) ;
4
+ const util = require ( 'util' ) ;
5
+
6
+ const MAX_LENGTH = 100 ;
7
+ const PATTERN = / ^ (?: f i x u p ! \s * ) ? ( \w * ) ( \( ( [ \w \$ \. \* / - ] * ) \) ) ? \: ( .* ) $ / ;
8
+ const TYPES = {
9
+ feat : true ,
10
+ fix : true ,
11
+ docs : true ,
12
+ style : true ,
13
+ refactor : true ,
14
+ perf : true ,
15
+ test : true ,
16
+ chore : true ,
17
+ revert : true ,
18
+ breaking : true ,
19
+ } ;
20
+
21
+ function printError ( ) {
22
+ console . error ( 'INVALID COMMIT MSG: ' + util . format . apply ( null , arguments ) ) ;
23
+ }
24
+
25
+ function validateMessage ( message /*: string */ ) {
26
+ if ( message . length > MAX_LENGTH ) {
27
+ printError ( 'is longer than %d characters !' , MAX_LENGTH ) ;
28
+ return false ;
29
+ }
30
+
31
+ const match = PATTERN . exec ( message ) ;
32
+
33
+ if ( ! match ) {
34
+ printError ( 'does not match "<type>(<scope>): <subject>" ! was: ' + message ) ;
35
+ return false ;
36
+ }
37
+ const type = match [ 1 ] ;
38
+
39
+ if ( ! TYPES . hasOwnProperty ( type ) ) {
40
+ printError ( '"%s" is not allowed type !' , type ) ;
41
+ return false ;
42
+ }
43
+
44
+ return true ;
45
+ }
46
+
47
+ function firstLineFromBuffer ( buffer /*: Buffer */ ) {
48
+ return buffer . toString ( ) . split ( '\n' ) . shift ( ) ;
49
+ }
50
+
51
+ const commitMsgFile = process . argv [ 2 ] ;
52
+
53
+ try {
54
+ const buffer = fs . readFileSync ( commitMsgFile ) ;
55
+ const msg = firstLineFromBuffer ( buffer ) ;
56
+ if ( ! validateMessage ( msg ) ) {
57
+ process . exit ( 1 ) ;
58
+ } else {
59
+ process . exit ( 0 ) ;
60
+ }
61
+ } catch ( error ) {
62
+ process . exit ( 1 ) ;
63
+ }
You can’t perform that action at this time.
0 commit comments