-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
106 lines (83 loc) · 3.69 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
'use strict';
var gulp = require('gulp')
, mocha = require('gulp-mocha')
, minimist = require('minimist')
, cp = require('child_process')
, chalk = require('chalk')
, fs = require('fs')
, istanbul = require('gulp-istanbul')
, pkg = require('./package.json')
, knownOptions = {
string: 'type',
default: { type: 'patch' }
}
, incrementVersion = function (version, type) {
var versionArr = version.split('.');
if(type === 'major'){
versionArr[0] = parseInt(versionArr[0], 10) + 1;
} else if (type === 'minor') {
versionArr[1] = parseInt(versionArr[1], 10) + 1;
} else {
versionArr[2] = parseInt(versionArr[2], 10) + 1;
}
return versionArr.join('.');
}
, options = minimist(process.argv.slice(2), knownOptions);
gulp.task('default', function(){
});
gulp.task('pre-test', function () {
return gulp.src(['**/*.js', '!node_modules/**/*', '!**/*.test.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['pre-test'], function () {
return gulp.src(['**/**.test.js', '*.test.js', '!node_modules/**/*'])
.pipe(mocha({reporter: 'spec'}))
// Creating the reports after tests ran
.pipe(istanbul.writeReports())
// Enforce a coverage of at least 90%
.pipe(istanbul.enforceThresholds({ thresholds: { global: 100 } }));
});
// gulp.task('test', function(){
// return gulp.src(['**/**.test.js', '*.test.js', '!node_modules/**/*'], {read: false})
// .pipe(mocha({reporter: 'spec'}));
// });
gulp.task('dev', function () {
gulp.watch(['**/*_test.js', '**/*.js', '!node_modules/**/*'], ['test']);
});
gulp.task('release', ['test'], function(){
var newVersion = incrementVersion(pkg.version, options.type);
//this is the task to automat most of the release stuff... because it is lame and boring
console.log('\n\nPreparing for a ' + chalk.bgGreen.bold(options.type) + ' release...\n\n');
cp.exec('git log `git describe --tags --abbrev=0`..HEAD --pretty=format:" - %s"', function (err, stdout, stderr) {
var history = fs.readFileSync('./history.md');
console.log('Updating the history.md file');
fs.writeFile('./history.md', '### - ' + newVersion + ' *' + new Date().toLocaleString() + '*\n\n' + stdout + '\n\n\n' + history);
cp.exec('git log --all --format="%aN <%aE>" | sort -u', function (err, stdout, stderr) {
//write out the Authors file with all contributors
console.log('Updating the AUTHORS file');
fs.writeFile('./AUTHORS', stdout);
cp.exec('git add .', function () {
cp.exec('git commit -m "preparing for release of v' + newVersion + '"', function () {
console.log('commited the automated updates');
//run npm version
cp.exec('npm version ' + options.type, function(){
console.log('npm version to rev for release');
cp.exec('npm publish', function(){
console.log('pushing to origin');
cp.exec('git push origin master', function(){});
cp.exec('git push origin v' + newVersion, function(err){
if(err){
console.log(err);
}
console.log(chalk.green('DONE! Congrats on the Release!'));
});
});
});
});
});
});
});
});