|
1 | 1 | module.exports = function (config) {
|
2 |
| - var gulp = require('gulp'); |
3 |
| - var conventionalChangelog = require('gulp-conventional-changelog'); |
4 |
| - var bump = require('gulp-bump'); |
5 |
| - var gutil = require('gulp-util'); |
6 |
| - var git = require('gulp-git'); |
7 |
| - var fs = require('fs'); |
8 |
| - var minimist = require('minimist'); |
| 2 | + var gulp = require('gulp'); |
| 3 | + var conventionalChangelog = require('gulp-conventional-changelog'); |
| 4 | + var bump = require('gulp-bump'); |
| 5 | + var gutil = require('gulp-util'); |
| 6 | + var git = require('gulp-git'); |
| 7 | + var fs = require('fs'); |
| 8 | + var minimist = require('minimist'); |
9 | 9 |
|
10 |
| - config = config || {}; |
| 10 | + config = config || {}; |
11 | 11 |
|
12 |
| - var defaultOptions = { |
13 |
| - string: 'env', |
14 |
| - default: { |
15 |
| - env: process.env.NODE_ENV || 'production', |
16 |
| - sources: config.sources || ['./bower.json', './package.json'], |
17 |
| - branch: config.branch || 'master', |
18 |
| - bump: config.bump || 'patch', |
19 |
| - message: config.message || 'Release %VERSION%', |
20 |
| - tag: config.tag |
21 |
| - } |
22 |
| - }; |
| 12 | + var defaultOptions = { |
| 13 | + string: 'env', |
| 14 | + default: { |
| 15 | + env: process.env.NODE_ENV || 'production', |
| 16 | + sources: config.sources || ['./bower.json', './package.json'], |
| 17 | + branch: config.branch || 'master', |
| 18 | + bump: config.bump || 'patch', |
| 19 | + message: config.message || 'Release %VERSION%', |
| 20 | + tag: config.tag |
| 21 | + } |
| 22 | + }; |
23 | 23 |
|
24 |
| - // Parse arguments options, if any: |
25 |
| - var options = minimist(process.argv.slice(2), defaultOptions); |
| 24 | + // Parse arguments options, if any: |
| 25 | + var options = minimist(process.argv.slice(2), defaultOptions); |
26 | 26 |
|
27 |
| - /** |
28 |
| - * A task to create a changelog |
29 |
| - **/ |
30 |
| - gulp.task('build:changelog', function () { |
31 |
| - return gulp.src('CHANGELOG.md', { |
32 |
| - buffer: false |
33 |
| - }) |
34 |
| - .pipe(conventionalChangelog({ |
35 |
| - preset: 'eslint' |
36 |
| - })) |
37 |
| - .pipe(gulp.dest('./')); |
38 |
| - }); |
| 27 | + /** |
| 28 | + * A task to create a changelog |
| 29 | + **/ |
| 30 | + gulp.task('build:changelog', function () { |
| 31 | + return gulp.src('CHANGELOG.md', { |
| 32 | + buffer: false, |
| 33 | + allowEmpty: true |
| 34 | + }) |
| 35 | + .pipe(conventionalChangelog({ |
| 36 | + preset: 'eslint' |
| 37 | + })) |
| 38 | + .pipe(gulp.dest('./')); |
| 39 | + }); |
39 | 40 |
|
40 |
| - /** |
41 |
| - * A task to bump package.json version |
42 |
| - **/ |
43 |
| - gulp.task('build:bump-version', function () { |
44 |
| - return gulp.src(options.sources) |
45 |
| - .pipe(bump(options.tag ? {version: options.tag} : {type: options.bump}).on('error', gutil.log)) |
46 |
| - .pipe(gulp.dest('./')); |
47 |
| - }); |
| 41 | + /** |
| 42 | + * A task to bump package.json version |
| 43 | + **/ |
| 44 | + gulp.task('build:bump-version', function () { |
| 45 | + return gulp.src( |
| 46 | + options.sources, {allowEmpty: true} |
| 47 | + ).pipe( |
| 48 | + bump(options.tag ? {version: options.tag} : {type: options.bump}).on('error', gutil.log) |
| 49 | + ).pipe( |
| 50 | + gulp.dest('./') |
| 51 | + ); |
| 52 | + }); |
48 | 53 |
|
49 |
| - /** |
50 |
| - * A task to commit all changes in current workspace. |
51 |
| - **/ |
52 |
| - gulp.task('build:commit-changes', function () { |
53 |
| - return gulp.src('.') |
54 |
| - .pipe(git.add()) |
55 |
| - .pipe(git.commit(options.message.replace('%VERSION%', getPackageJsonVersion()))); |
56 |
| - }); |
| 54 | + /** |
| 55 | + * A task to commit all changes in current workspace. |
| 56 | + **/ |
| 57 | + gulp.task('build:commit-changes', function () { |
| 58 | + return gulp.src('.') |
| 59 | + .pipe(git.add()) |
| 60 | + .pipe(git.commit(options.message.replace('%VERSION%', getPackageJsonVersion()))); |
| 61 | + }); |
57 | 62 |
|
58 |
| - /** |
59 |
| - * A task to push all commits to master branch |
60 |
| - **/ |
61 |
| - gulp.task('build:push-changes', function (cb) { |
62 |
| - git.push('origin', options.branch, cb); |
63 |
| - }); |
| 63 | + /** |
| 64 | + * A task to push all commits to master branch |
| 65 | + **/ |
| 66 | + gulp.task('build:push-changes', function (cb) { |
| 67 | + git.push('origin', options.branch, cb); |
| 68 | + }); |
64 | 69 |
|
65 |
| - /** |
66 |
| - * Create a tag for the current version where version is taken from the package.json file |
67 |
| - **/ |
68 |
| - gulp.task('build:create-new-tag', function (cb) { |
69 |
| - var version = options.tag || getPackageJsonVersion(); |
70 |
| - git.tag(version, options.message.replace('%VERSION%', getPackageJsonVersion()), function (error) { |
71 |
| - if (error) { |
72 |
| - return cb(error); |
73 |
| - } |
74 |
| - git.push('origin', options.branch, {args: '--tags'}, cb); |
75 |
| - }); |
76 |
| - }); |
| 70 | + /** |
| 71 | + * Create a tag for the current version where version is taken from the package.json file |
| 72 | + **/ |
| 73 | + gulp.task('build:create-new-tag', function (cb) { |
| 74 | + var version = options.tag || getPackageJsonVersion(); |
| 75 | + git.tag(version, options.message.replace('%VERSION%', getPackageJsonVersion()), function (error) { |
| 76 | + if (error) { |
| 77 | + return cb(error); |
| 78 | + } |
| 79 | + git.push('origin', options.branch, {args: '--tags'}, cb); |
| 80 | + }); |
| 81 | + }); |
77 | 82 |
|
78 |
| - gulp.task('build:release', function (callback) { |
79 |
| - gulp.series( |
80 |
| - 'build:bump-version', |
81 |
| - 'build:changelog', |
82 |
| - 'build:commit-changes', |
83 |
| - 'build:push-changes', |
84 |
| - 'build:create-new-tag', |
85 |
| - function (error) { |
86 |
| - if (error) { |
87 |
| - console.log(error.message); |
88 |
| - } else { |
89 |
| - console.log('RELEASE FINISHED SUCCESSFULLY'); |
90 |
| - } |
91 |
| - callback(error); |
92 |
| - }); |
93 |
| - }); |
| 83 | + gulp.task( |
| 84 | + 'build:release', |
| 85 | + gulp.series( |
| 86 | + 'build:bump-version', |
| 87 | + 'build:changelog', |
| 88 | + 'build:commit-changes', |
| 89 | + 'build:push-changes', |
| 90 | + 'build:create-new-tag' |
| 91 | + ) |
| 92 | + ); |
94 | 93 |
|
95 |
| - function getPackageJsonVersion() { |
96 |
| - // We parse the json file instead of using require because require caches |
97 |
| - // multiple calls so the version number won't be updated |
98 |
| - return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version; |
99 |
| - } |
| 94 | + function getPackageJsonVersion() { |
| 95 | + // We parse the json file instead of using require because require caches |
| 96 | + // multiple calls so the version number won't be updated |
| 97 | + return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version; |
| 98 | + } |
100 | 99 |
|
101 | 100 | };
|
0 commit comments