This repository has been archived by the owner on May 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
138 lines (113 loc) · 3.65 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
var gulp = require('gulp');
var babelify = require('babelify');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var bump = require('gulp-bump');
var git = require('gulp-git');
var gitStatus = require('git-get-status');
var glob = require('glob');
var helpers = require('babelify-external-helpers');
var jasmine = require('gulp-jasmine');
var jsdoc = require('gulp-jsdoc3');
var jshint = require('gulp-jshint');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var util = require('gulp-util');
var fs = require('fs');
function getVersionFromPackage() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
function getVersionForComponent() {
return getVersionFromPackage().split('.').slice(0, 2).join('.');
}
gulp.task('ensure-clean-working-directory', function() {
gitStatus(function(err, status) {
if (err, !status.clean) {
throw new Error('Unable to proceed, your working directory is not clean.');
}
});
});
gulp.task('bump-version', function () {
return gulp.src([ './package.json', './bower.json' ])
.pipe(bump({ type: 'patch' }).on('error', util.log))
.pipe(gulp.dest('./'));
});
gulp.task('document', function (cb) {
config = {
"opts": {
"destination": "./docs"
},
};
gulp.src(['README.md', './lib/**/*.js' ], {read: false})
.pipe(jsdoc(config, cb));
});
gulp.task('commit-changes', function () {
return gulp.src([ './', './test/dist/', './package.json', './bower.json' ])
.pipe(git.add())
.pipe(git.commit('Release. Bump version number'));
});
gulp.task('push-changes', function (cb) {
git.push('origin', 'master', cb);
});
gulp.task('create-tag', function (cb) {
var version = getVersionFromPackage();
git.tag(version, 'Release ' + version, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', { args: '--tags' }, cb);
});
});
gulp.task('build-browser-tests', function () {
return browserify({ entries: glob.sync('test/specs/**/*.js') }).bundle()
.pipe(source('barchart-marketdata-utilities-tests-' + getVersionForComponent() + '.js'))
.pipe(buffer())
.pipe(gulp.dest('test/dist'));
});
gulp.task('execute-browser-tests', function () {
return gulp.src('test/dist/barchart-marketdata-utilities-tests-' + getVersionForComponent() + '.js')
.pipe(jasmine());
});
gulp.task('execute-node-tests', function () {
return gulp.src(['lib/index.js', 'test/specs/**/*.js'])
.pipe(jasmine());
});
gulp.task('execute-tests', function (callback) {
runSequence(
'build-browser-tests',
'execute-node-tests',
function (error) {
if (error) {
console.log(error.message);
}
callback(error);
});
});
gulp.task('test', [ 'execute-tests' ]);
gulp.task('release', function (callback) {
runSequence(
'ensure-clean-working-directory',
'build-browser-tests',
'execute-tests',
'document',
'bump-version',
'commit-changes',
'push-changes',
'create-tag',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('Release complete');
}
callback(error);
});
});
gulp.task('lint', function() {
return gulp.src([ './lib/**/*.js', './test/specs/**/*.js' ])
.pipe(jshint({'esversion': 6}))
.pipe(jshint.reporter('default'));
});
gulp.task('default', [ 'lint' ]);