@@ -62,19 +62,8 @@ module.exports = function(grunt) {
62
62
'lint-commit-msg' , 'checks for commit message lint' , function ( ) {
63
63
var done = this . async ( ) ;
64
64
if ( semver . satisfies ( process . version , '>= 4.0.0' ) ) {
65
-
66
- var proc = spawn ( 'conventional-changelog-lint' , [ '--from' , 'master' ] ) ;
67
- proc . stderr . on ( 'data' , function ( data ) {
68
- grunt . log . write ( data ) ;
69
- } ) ;
70
- proc . stdout . on ( 'data' , function ( data ) {
71
- grunt . log . write ( data ) ;
72
- } ) ;
73
- proc . on ( 'close' , function ( code ) {
74
- var succeeded = code === 0 ;
75
- done ( succeeded ) ;
76
- } ) ;
77
-
65
+ gruntExec ( grunt , 'conventional-changelog-lint' , [ '--from' , 'master' ] ,
66
+ done ) ;
78
67
} else {
79
68
grunt . log . writeln (
80
69
'task skipped because this version of Node is too old' ) ;
@@ -103,107 +92,32 @@ module.exports = function(grunt) {
103
92
} ) ;
104
93
105
94
grunt . registerTask (
106
- 'changelog' , 'Create a changelog from commits' , function ( tag ) {
95
+ 'changelog' , 'Create a changelog from commits' , function ( ) {
107
96
// See https://github.com/mozilla/web-ext/blob/master/CONTRIBUTING.md#writing-commit-messages
108
- var done = this . async ( ) ;
109
- var results = { } ;
110
-
111
- if ( tag === undefined ) {
112
- grunt . log . writeln (
113
- 'Missing first agument: the current git release tag ' +
114
- '(before the next release)' ) ;
115
- return done ( false ) ;
116
- }
117
-
118
- function processLine ( line ) {
119
- // First, get the commit hash.
120
- var metaMatch = / c o m m i t : \{ ( [ ^ \} ] + ) \} ( .* ) / . exec ( line ) ;
121
- if ( ! metaMatch ) {
122
- throw new Error ( 'Could not find commit hash in ' + line ) ;
123
- }
124
- var commitHash = metaMatch [ 1 ] ;
125
- line = metaMatch [ 2 ] ; // strip off the commit hash part.
126
-
127
- // Parse the semantic commit message.
128
- // e.g. fix(): Fixed some stuff
129
- var match = / ^ ( [ a - z A - Z 0 - 9 ] + ) \( ? .* \) ? : ( .* ) $ / g. exec ( line ) ;
130
- var bucket ;
131
- var message = line ;
132
- if ( ! match ) {
133
- bucket = results . uncategorized = results . uncategorized || [ ] ;
134
- } else {
135
- var type = match [ 1 ] . toLowerCase ( ) ;
136
- bucket = results [ type ] = results [ type ] || [ ] ;
137
- message = match [ 2 ] ;
138
- }
139
-
140
- bucket . push ( { msg : message , commit : commitHash } ) ;
141
- }
142
-
143
- function commitLink ( commit ) {
144
- // Create a Markdown link to the commit.
145
- return '[' + commit + ']' +
146
- '(https://github.com/mozilla/web-ext/commit/' + commit + ')' ;
147
- }
148
-
149
- function bullet ( text ) {
150
- // Create a Markdown bullet point.
151
- return ' * ' + text ;
152
- }
153
-
154
- function writeChangelog ( ) {
155
- [
156
- [ 'New features:' , 'feat' ] ,
157
- [ 'Fixes:' , 'fix' ] ,
158
- [ 'Performance enhancements:' , 'perf' ] ,
159
- [ 'Uncategorized:' , 'uncategorized' ] ,
160
- ] . forEach ( function ( conf ) {
161
- var header = conf [ 0 ] ;
162
- var key = conf [ 1 ] ;
163
-
164
- if ( ( results [ key ] || [ ] ) . length ) {
165
- grunt . log . writeln ( header ) ;
166
- results [ key ] . forEach ( function ( data ) {
167
- grunt . log . writeln (
168
- bullet ( data . msg + ' (' + commitLink ( data . commit ) + ')' ) ) ;
169
- } ) ;
170
- grunt . log . writeln ( '' ) ;
171
- }
172
- } ) ;
173
- grunt . log . writeln ( 'General maintenance:' ) ;
174
- grunt . log . writeln ( bullet (
175
- results . chore . length + ' dependency updates (or other chores)' ) ) ;
176
- grunt . log . writeln ( bullet (
177
- results . docs . length + ' documentation updates' ) ) ;
178
- }
97
+ gruntExec ( grunt , 'conventional-changelog' , [ '-p' , 'angular' , '-u' ] ,
98
+ this . async ( ) ) ;
99
+ } ) ;
179
100
180
- var git = spawn (
181
- 'git' ,
182
- [ 'log' , '--no-merges' , '--format=commit:{%h} %s' , tag + '...master' ] ) ;
101
+ } ;
183
102
184
- git . stderr . on ( 'data' , function ( data ) {
185
- grunt . log . writeln ( data ) ;
186
- done ( false ) ;
187
- } ) ;
188
103
189
- git . stdout . on ( 'data' , function ( data ) {
190
- data . toString ( ) . split ( '\n' ) . forEach ( function ( line ) {
191
- if ( line !== '' ) {
192
- processLine ( line ) ;
193
- }
194
- } ) ;
195
- } ) ;
104
+ function gruntExec ( grunt , cmd , args , onCompletion ) {
105
+ var PATH = process . env . PATH || '' ;
106
+ // Make sure the script dir for local node modules is on the path.
107
+ process . env . PATH =
108
+ PATH + ':' + path . resolve ( __dirname ) + '/node_modules/.bin' ;
109
+ var proc = spawn ( cmd , args ) ;
196
110
197
- git . on ( 'close' , function ( code ) {
198
- if ( code !== 0 ) {
199
- grunt . log . writeln ( 'git exited: ' + code ) ;
200
- done ( false ) ;
201
- } else {
202
- writeChangelog ( ) ;
203
- done ( true ) ;
204
- }
205
- } ) ;
111
+ proc . stderr . on ( 'data' , function ( data ) {
112
+ grunt . log . write ( data ) ;
113
+ } ) ;
206
114
207
- } ) ;
115
+ proc . stdout . on ( 'data' , function ( data ) {
116
+ grunt . log . write ( data ) ;
117
+ } ) ;
208
118
209
- } ;
119
+ proc . on ( 'close' , function ( code ) {
120
+ var succeeded = code === 0 ;
121
+ onCompletion ( succeeded ) ;
122
+ } ) ;
123
+ }
0 commit comments