Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 19c80bd

Browse files
committed
Use gulp to release new versions
1 parent c5e5e72 commit 19c80bd

File tree

3 files changed

+84
-53
lines changed

3 files changed

+84
-53
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ The karma task will try to open Firefox and Chrome as browser in which to run th
4747

4848
### How to release
4949

50-
Use npm to update version and create a tag, then push to GitHub:
50+
Use gulp to bump version, build and create a tag. Then push to GitHub:
5151

5252
````sh
53-
gulp && git commit . # if necessary, build everything and commit latest changes
54-
npm version [major | minor | patch] # let npm update package.json and create a tag
53+
gulp release [--patch|--minor|--major]
5554
git push --tags origin master # push everything to GitHub
5655
````
5756

gulpfile.js

+75-46
Original file line numberDiff line numberDiff line change
@@ -10,70 +10,99 @@ var es = require('event-stream');
1010
var del = require('del');
1111
var uglify = require('gulp-uglify');
1212
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;
1317

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']);
2619
gulp.task('build', ['scripts']);
2720
gulp.task('test', ['build', 'karma']);
2821

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']);
3124
});
3225

3326
gulp.task('clean', function(cb) {
34-
del(['dist'], cb);
27+
del(['dist'], cb);
3528
});
3629

3730
gulp.task('scripts', ['clean'], function() {
3831

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+
};
5053

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'));
6366

6467
});
6568

6669
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();
6972
});
7073

7174
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);
74106
});
75107

76-
var handleError = function (err) {
77-
console.log(err.toString());
78-
this.emit('end');
79-
};
108+
gulp.task('release', ['release:tag']);

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@
99
"del": "~1.2.0",
1010
"event-stream": "~3.3.1",
1111
"gulp": "~3.9.0",
12+
"gulp-bump": "^0.3.1",
1213
"gulp-concat": "~2.6.0",
13-
"gulp-header": "~1.2.2",
1414
"gulp-footer": "~1.0.5",
15+
"gulp-git": "^1.4.0",
16+
"gulp-header": "~1.2.2",
1517
"gulp-jshint": "1.11.2",
1618
"gulp-plumber": "^1.0.1",
1719
"gulp-rename": "~1.2.2",
1820
"gulp-uglify": "~1.2.0",
21+
"jasmine-core": "^2.3.4",
1922
"jshint-stylish": "~2.0.1",
2023
"karma": "^0.13.9",
2124
"karma-chrome-launcher": "^0.2.0",
25+
"karma-coverage": "~0.5",
2226
"karma-firefox-launcher": "~0.1",
2327
"karma-jasmine": "~0.3",
2428
"karma-ng-html2js-preprocessor": "^0.1.0",
2529
"karma-phantomjs-launcher": "~0.2.1",
26-
"karma-coverage": "~0.5",
27-
"jasmine-core": "^2.3.4",
28-
"phantomjs": "^1.9.18"
30+
"phantomjs": "^1.9.18",
31+
"run-sequence": "^1.1.2"
2932
},
3033
"scripts": {},
3134
"main": "./dist/scrollpoint.js",

0 commit comments

Comments
 (0)