1
- module . exports = function ( gulp ) {
1
+ module . exports = function ( config ) {
2
2
var gulp = require ( 'gulp' ) ;
3
3
var runSequence = require ( 'run-sequence' ) ;
4
4
var conventionalChangelog = require ( 'gulp-conventional-changelog' ) ;
@@ -8,22 +8,21 @@ module.exports = function(gulp) {
8
8
var fs = require ( 'fs' ) ;
9
9
var minimist = require ( 'minimist' ) ;
10
10
11
- function getPackageJsonVersion ( ) {
12
- // We parse the json file instead of using require because require caches
13
- // multiple calls so the version number won't be updated
14
- return JSON . parse ( fs . readFileSync ( './package.json' , 'utf8' ) ) . version ;
15
- }
16
-
11
+ config = config || { } ;
12
+
17
13
var defaultOptions = {
18
14
string : 'env' ,
19
15
default : {
20
16
env : process . env . NODE_ENV || 'production' ,
21
- sources : [ './bower.json' , './package.json' ] ,
22
- bump : 'patch' ,
23
- version : null
17
+ sources : config . sources || [ './bower.json' , './package.json' ] ,
18
+ branch : config . branch || 'master' ,
19
+ bump : config . bump || 'patch' ,
20
+ message : config . message || 'Release %VERSION%' ,
21
+ version : config . version
24
22
}
25
23
} ;
26
24
25
+ // Parse arguments options, if any:
27
26
var options = minimist ( process . argv . slice ( 2 ) , defaultOptions ) ;
28
27
29
28
/**
@@ -70,26 +69,27 @@ module.exports = function(gulp) {
70
69
gulp . task ( 'build:commit-changes' , function ( ) {
71
70
return gulp . src ( '.' )
72
71
. pipe ( git . add ( ) )
73
- . pipe ( git . commit ( `Bumped version number: ${ getPackageJsonVersion ( ) } ` ) ) ;
72
+ . pipe ( git . commit ( options . message . replace ( '%VERSION%' , getPackageJsonVersion ( ) ) ) ) ;
74
73
} ) ;
75
74
76
75
/**
77
76
* A task to push all commits to master branch
78
77
**/
79
78
gulp . task ( 'build:push-changes' , function ( cb ) {
80
- git . push ( 'origin' , 'master' , cb ) ;
79
+ console . log ( options ) ;
80
+ git . push ( 'origin' , options . branch , cb ) ;
81
81
} ) ;
82
82
83
83
/**
84
84
* Create a tag for the current version where version is taken from the package.json file
85
85
**/
86
86
gulp . task ( 'build:create-new-tag' , function ( cb ) {
87
- var version = getPackageJsonVersion ( ) ;
88
- git . tag ( version , 'Created Tag for version: ' + version , function ( error ) {
87
+ var version = options . version || getPackageJsonVersion ( ) ;
88
+ git . tag ( version , options . message . replace ( '%VERSION%' , getPackageJsonVersion ( ) ) , function ( error ) {
89
89
if ( error ) {
90
90
return cb ( error ) ;
91
91
}
92
- git . push ( 'origin' , 'master' , { args : '--tags' } , cb ) ;
92
+ git . push ( 'origin' , options . branch , { args : '--tags' } , cb ) ;
93
93
} ) ;
94
94
} ) ;
95
95
@@ -110,4 +110,10 @@ module.exports = function(gulp) {
110
110
} ) ;
111
111
} ) ;
112
112
113
+ function getPackageJsonVersion ( ) {
114
+ // We parse the json file instead of using require because require caches
115
+ // multiple calls so the version number won't be updated
116
+ return JSON . parse ( fs . readFileSync ( './package.json' , 'utf8' ) ) . version ;
117
+ }
118
+
113
119
} ;
0 commit comments