Skip to content

Commit 13e67ed

Browse files
committed
More default options (branch, message) and initial tasks config.
1 parent e9ad5c1 commit 13e67ed

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ Create a `gulpfile.js` in your project with:
2323
```js
2424
// add to gulpfile.js
2525
var gulp = require('gulp');
26-
// pass along gulp reference to have tasks imported
27-
require('gulp-release-flows')(gulp);
26+
27+
// pass along an *optional* config, if needed
28+
require('gulp-release-flows')({
29+
sources: ['./bower.json', './package.json'],
30+
branch: 'master',
31+
bump: 'patch',
32+
message: 'Release %VERSION%',
33+
version: null // If null or not specified, will be retrieved from './package.json'
34+
});
2835
```
2936

3037
To see all imported tasks, run:

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = function(gulp){
2-
require(__dirname + '/tasks/release')(gulp)
1+
module.exports = function(config){
2+
require(__dirname + '/tasks/release')(config)
33
};

tasks/release.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function(gulp) {
1+
module.exports = function(config) {
22
var gulp = require('gulp');
33
var runSequence = require('run-sequence');
44
var conventionalChangelog = require('gulp-conventional-changelog');
@@ -8,22 +8,21 @@ module.exports = function(gulp) {
88
var fs = require('fs');
99
var minimist = require('minimist');
1010

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+
1713
var defaultOptions = {
1814
string: 'env',
1915
default: {
2016
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
2422
}
2523
};
2624

25+
// Parse arguments options, if any:
2726
var options = minimist(process.argv.slice(2), defaultOptions);
2827

2928
/**
@@ -70,26 +69,27 @@ module.exports = function(gulp) {
7069
gulp.task('build:commit-changes', function () {
7170
return gulp.src('.')
7271
.pipe(git.add())
73-
.pipe(git.commit(`Bumped version number: ${getPackageJsonVersion()}`));
72+
.pipe(git.commit(options.message.replace('%VERSION%', getPackageJsonVersion())));
7473
});
7574

7675
/**
7776
* A task to push all commits to master branch
7877
**/
7978
gulp.task('build:push-changes', function (cb) {
80-
git.push('origin', 'master', cb);
79+
console.log(options);
80+
git.push('origin', options.branch, cb);
8181
});
8282

8383
/**
8484
* Create a tag for the current version where version is taken from the package.json file
8585
**/
8686
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) {
8989
if (error) {
9090
return cb(error);
9191
}
92-
git.push('origin', 'master', {args: '--tags'}, cb);
92+
git.push('origin', options.branch, {args: '--tags'}, cb);
9393
});
9494
});
9595

@@ -110,4 +110,10 @@ module.exports = function(gulp) {
110110
});
111111
});
112112

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

0 commit comments

Comments
 (0)