-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
146 lines (114 loc) · 4.25 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
gutil = require('gulp-util'),
colors = require('colors'),
fs = require('fs'),
stylish = require('jshint-stylish'),
runSequence = require('run-sequence'),
conventionalChangelog = require('gulp-conventional-changelog'),
conventionalGithubReleaser = require('conventional-github-releaser');
var DATE = new Date(),
SRC = 'src/qure.js',
DEST = 'dist/',
TESTS = 'tests/*.js',
HINTS = ['./src/*', './tests/*'],
PKG = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
var banner = ['/*',
' * <%= name %>.js [v<%= version %>]',
' * <%= homepage %> ',
' * Copyright (c) 2013-'+ DATE.getFullYear() +', <%= author.name %> <<%= author.email %>> \n' +
' * Licensed under the <%= license %> License',
' */',
''].join('\n');
// help instructions
gulp.task('help', function() {
console.log(' gulp tests'.cyan +'\t\tRun all tests'.grey);
console.log(' gulp test --file 01'.cyan +'\tRun specific file'.grey);
console.log(' gulp hint'.cyan +'\t\tJSHint source files'.grey);
console.log(' gulp minify'.cyan +'\t\tMinify and JSHint files'.grey);
console.log(' gulp commit'.cyan +'\t\tCommit and bump version'.grey);
console.log(' gulp release'.cyan +'\t\tCommit, bump, push and release version'.grey);
});
/*
* this task executes all tests -
* unless it is called with argument:
gulp tests --file 01
*/
gulp.task('tests', function() {
return gulp.src(TESTS, {read: false})
.pipe($.mocha({reporter: 'list'}));
});
gulp.task('test', function() {
var nr = process.argv.slice(2)[2],
src = nr.match(/\d\d/) === null ? nr : 'test-'+ nr ;
return gulp.src('tests/'+ src +'.js', {read: false})
.pipe($.mocha({reporter: 'list'}));
});
gulp.task('hint', function() {
return gulp.src(HINTS)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('minify', function() {
return gulp.src(SRC)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.header(banner, PKG))
.pipe(gulp.dest(DEST))
.pipe($.uglify())
.pipe($.header(banner, PKG))
.pipe($.rename({ extname: '.min.js' }))
.pipe(gulp.dest(DEST));
});
gulp.task('changelog', function() {
return gulp.src('CHANGELOG.md', {buffer: false})
.pipe(conventionalChangelog({preset: 'angular'}))
.pipe(gulp.dest('./'));
});
gulp.task('github-release', function(done) {
conventionalGithubReleaser({
type: "oauth",
token: '46e1c77d2e11dd7402f0346923fa53731a1f88a4'
}, {preset: 'angular'}, done);
});
gulp.task('bump-version', function() {
// We hardcode the version change type to 'patch' but it may be a good idea to
// use minimist (https://www.npmjs.com/package/minimist) to determine with a
// command argument whether you are doing a 'major', 'minor' or a 'patch' change.
return gulp.src(['./bower.json', './package.json'])
.pipe($.bump({type: "patch"}).on('error', gutil.log))
.pipe(gulp.dest('./'));
});
gulp.task('commit-changes', function() {
PKG = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
return gulp.src('.')
.pipe($.git.add())
.pipe($.git.commit('['+ PKG.version +'] Bumped version number'));
});
gulp.task('push-changes', function(cb) {
$.git.push('origin', 'master', cb);
});
gulp.task('create-new-tag', function(cb) {
var version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
$.git.tag(version, 'Created Tag for version: '+ version, function(error) {
if (error) return cb(error);
$.git.push('origin', 'master', {args: '--tags'}, cb);
});
});
gulp.task('commit', function(callback) {
runSequence('minify', 'bump-version', 'changelog', 'commit-changes',
function(error) {
if (error) console.log(error.message);
else console.log('COMMIT FINISHED SUCCESSFULLY');
callback(error);
});
});
gulp.task('release', function(callback) {
runSequence('minify', 'bump-version', 'changelog', 'commit-changes', 'push-changes', 'create-new-tag',
function(error) {
if (error) console.log(error.message);
else console.log('RELEASE FINISHED SUCCESSFULLY');
callback(error);
});
});