@@ -10,70 +10,99 @@ var es = require('event-stream');
10
10
var del = require ( 'del' ) ;
11
11
var uglify = require ( 'gulp-uglify' ) ;
12
12
var plumber = require ( 'gulp-plumber' ) ; //To prevent pipe breaking caused by errors at 'watch'
13
+ var git = require ( 'gulp-git' ) ;
14
+ var bump = require ( 'gulp-bump' ) ;
15
+ var runSequence = require ( 'run-sequence' ) ;
16
+ var versionAfterBump ;
13
17
14
- var config = {
15
- pkg : JSON . parse ( fs . readFileSync ( './package.json' ) ) ,
16
- banner :
17
- '/*!\n' +
18
- ' * <%= pkg.name %>\n' +
19
- ' * <%= pkg.homepage %>\n' +
20
- ' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
21
- ' * License: <%= pkg.license %>\n' +
22
- ' */\n\n\n'
23
- } ;
24
-
25
- gulp . task ( 'default' , [ 'build' , 'test' ] ) ;
18
+ gulp . task ( 'default' , [ 'build' , 'test' ] ) ;
26
19
gulp . task ( 'build' , [ 'scripts' ] ) ;
27
20
gulp . task ( 'test' , [ 'build' , 'karma' ] ) ;
28
21
29
- gulp . task ( 'watch' , [ 'build' , 'karma-watch' ] , function ( ) {
30
- gulp . watch ( [ 'src/**/*.{js,html}' ] , [ 'build' ] ) ;
22
+ gulp . task ( 'watch' , [ 'build' , 'karma-watch' ] , function ( ) {
23
+ gulp . watch ( [ 'src/**/*.{js,html}' ] , [ 'build' ] ) ;
31
24
} ) ;
32
25
33
26
gulp . task ( 'clean' , function ( cb ) {
34
- del ( [ 'dist' ] , cb ) ;
27
+ del ( [ 'dist' ] , cb ) ;
35
28
} ) ;
36
29
37
30
gulp . task ( 'scripts' , [ 'clean' ] , function ( ) {
38
31
39
- var buildLib = function ( ) {
40
- return gulp . src ( [ 'src/*.js' ] )
41
- . pipe ( plumber ( {
42
- errorHandler : handleError
43
- } ) )
44
- . pipe ( header ( '(function () { \n\'use strict\';\n' ) )
45
- . pipe ( footer ( '\n}());' ) )
46
- . pipe ( jshint ( ) )
47
- . pipe ( jshint . reporter ( 'jshint-stylish' ) )
48
- . pipe ( jshint . reporter ( 'fail' ) ) ;
49
- } ;
32
+ var buildLib = function ( ) {
33
+ return gulp . src ( [ 'src/*.js' ] )
34
+ . pipe ( plumber ( {
35
+ errorHandler : handleError
36
+ } ) )
37
+ . pipe ( header ( '(function () { \n\'use strict\';\n' ) )
38
+ . pipe ( footer ( '\n}());' ) )
39
+ . pipe ( jshint ( ) )
40
+ . pipe ( jshint . reporter ( 'jshint-stylish' ) )
41
+ . pipe ( jshint . reporter ( 'fail' ) ) ;
42
+ } ;
43
+ var config = {
44
+ pkg : JSON . parse ( fs . readFileSync ( './package.json' ) ) ,
45
+ banner :
46
+ '/*!\n' +
47
+ ' * <%= pkg.name %>\n' +
48
+ ' * <%= pkg.homepage %>\n' +
49
+ ' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
50
+ ' * License: <%= pkg.license %>\n' +
51
+ ' */\n\n\n'
52
+ } ;
50
53
51
- return es . merge ( buildLib ( ) )
52
- . pipe ( plumber ( {
53
- errorHandler : handleError
54
- } ) )
55
- . pipe ( concat ( 'scrollpoint.js' ) )
56
- . pipe ( header ( config . banner , {
57
- timestamp : ( new Date ( ) ) . toISOString ( ) , pkg : config . pkg
58
- } ) )
59
- . pipe ( gulp . dest ( 'dist' ) )
60
- . pipe ( uglify ( { preserveComments : 'some' } ) )
61
- . pipe ( rename ( { extname :'.min.js' } ) )
62
- . pipe ( gulp . dest ( 'dist' ) ) ;
54
+ return es . merge ( buildLib ( ) )
55
+ . pipe ( plumber ( {
56
+ errorHandler : handleError
57
+ } ) )
58
+ . pipe ( concat ( 'scrollpoint.js' ) )
59
+ . pipe ( header ( config . banner , {
60
+ timestamp : ( new Date ( ) ) . toISOString ( ) , pkg : config . pkg
61
+ } ) )
62
+ . pipe ( gulp . dest ( 'dist' ) )
63
+ . pipe ( uglify ( { preserveComments : 'some' } ) )
64
+ . pipe ( rename ( { extname : '.min.js' } ) )
65
+ . pipe ( gulp . dest ( 'dist' ) ) ;
63
66
64
67
} ) ;
65
68
66
69
gulp . task ( 'karma' , [ 'build' ] , function ( ) {
67
- var server = new Server ( { configFile : __dirname + '/karma.conf.js' , singleRun : true } ) ;
68
- server . start ( ) ;
70
+ var server = new Server ( { configFile : __dirname + '/karma.conf.js' , singleRun : true } ) ;
71
+ server . start ( ) ;
69
72
} ) ;
70
73
71
74
gulp . task ( 'karma-watch' , [ 'build' ] , function ( ) {
72
- var server = new Server ( { configFile : __dirname + '/karma.conf.js' , singleRun : false } ) ;
73
- server . start ( ) ;
75
+ var server = new Server ( { configFile : __dirname + '/karma.conf.js' , singleRun : false } ) ;
76
+ server . start ( ) ;
77
+ } ) ;
78
+
79
+ var handleError = function ( err ) {
80
+ console . log ( err . toString ( ) ) ;
81
+ this . emit ( 'end' ) ;
82
+ } ;
83
+
84
+ gulp . task ( 'release:bump' , function ( ) {
85
+ var type = process . argv [ 3 ] ? process . argv [ 3 ] . substr ( 2 ) : 'patch' ;
86
+ return gulp . src ( [ './package.json' ] )
87
+ . pipe ( bump ( { type : type } ) )
88
+ . pipe ( gulp . dest ( './' ) )
89
+ . on ( 'end' , function ( ) {
90
+ versionAfterBump = require ( './package.json' ) . version ;
91
+ } ) ;
92
+ } ) ;
93
+
94
+ gulp . task ( 'release:rebuild' , function ( cb ) {
95
+ runSequence ( 'release:bump' , 'build' , cb ) ; // bump will here be executed before build
96
+ } ) ;
97
+
98
+ gulp . task ( 'release:commit' , [ 'release:rebuild' ] , function ( ) {
99
+ return gulp . src ( [ './package.json' , 'dist/**/*' ] )
100
+ . pipe ( git . add ( ) )
101
+ . pipe ( git . commit ( versionAfterBump ) ) ;
102
+ } ) ;
103
+
104
+ gulp . task ( 'release:tag' , [ 'release:commit' ] , function ( ) {
105
+ git . tag ( versionAfterBump , versionAfterBump ) ;
74
106
} ) ;
75
107
76
- var handleError = function ( err ) {
77
- console . log ( err . toString ( ) ) ;
78
- this . emit ( 'end' ) ;
79
- } ;
108
+ gulp . task ( 'release' , [ 'release:tag' ] ) ;
0 commit comments