-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
208 lines (168 loc) · 5.06 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const gulp = require('gulp');
const exec = require('child_process').exec,
fs = require('fs'),
path = require('path');
const AWS = require('aws-sdk'),
awspublish = require('gulp-awspublish'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
git = require('gulp-git'),
gitStatus = require('git-get-status'),
glob = require('glob'),
jasmine = require('gulp-jasmine'),
jshint = require('gulp-jshint'),
merge = require('merge-stream'),
prompt = require('gulp-prompt'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
run = require('gulp-run-command').default,
source = require('vinyl-source-stream');
function getVersionFromPackage() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
function getGitHubLink() {
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const link = pkg.bugs.url.replace(/\/issues.*/g, '');
return `Project GitHub: ${link}`;
}
gulp.task('ensure-clean-working-directory', (cb) => {
gitStatus((err, status) => {
if (err, !status.clean) {
throw new Error('Unable to proceed, your working directory is not clean.');
}
cb();
});
});
gulp.task('bump-choice', (cb) => {
const processor = prompt.prompt({
type: 'list',
name: 'bump',
message: 'What type of bump would you like to do?',
choices: ['patch', 'minor', 'major'],
}, (res) => {
global.bump = res.bump;
return cb();
});
return gulp.src(['./package.json']).pipe(processor);
});
gulp.task('bump-version', (cb) => {
exec(`npm version ${global.bump || 'patch'} --no-git-tag-version`, {
cwd: './'
}, (error) => {
if (error) {
cb(error);
}
cb();
});
});
gulp.task('embed-version', () => {
const version = getVersionFromPackage();
const meta = gulp.src(['./lib/index.js'])
.pipe(replace(/(version:\s*')([0-9]+\.[0-9]+\.[0-9]+)(')/g, '$1' + version + '$3'))
.pipe(gulp.dest('./lib/'));
const coverpage = gulp.src(['./docs/_coverpage.md'])
.pipe(replace(/[0-9]+\.[0-9]+\.[0-9]+/g, version))
.pipe(gulp.dest('./docs/'));
return merge(meta, coverpage);
});
gulp.task('build-example-bundle', run('npm run build'));
gulp.task('deploy-example', () => {
const publisher = awspublish.create({
region: 'us-east-1',
params: {
Bucket: 'barchart-examples'
},
credentials: new AWS.SharedIniFileCredentials({ profile: 'default' })
});
const headers = { 'Cache-Control': 'no-cache' };
const options = { };
return gulp.src(['./example/browser/index.html', './example/browser/bundle.js'])
.pipe(rename((path) => {
path.dirname = 'watchlist-client-js';
}))
.pipe(publisher.publish(headers, options))
.pipe(publisher.cache())
.pipe(awspublish.reporter());
});
gulp.task('upload-documentation-site-to-S3', () => {
let publisher = awspublish.create({
region: 'us-east-1',
params: {
Bucket: 'docs.barchart.com'
},
credentials: new AWS.SharedIniFileCredentials({profile: 'default'})
});
let headers = {'Cache-Control': 'no-cache'};
let options = {};
return gulp.src(['./docs/**'])
.pipe(rename((filePath) => {
filePath.dirname = path.join('watchlist', filePath.dirname);
}))
.pipe(publisher.publish(headers, options))
.pipe(publisher.cache())
.pipe(awspublish.reporter());
});
gulp.task('deploy-documentation', gulp.series('upload-documentation-site-to-S3'));
gulp.task('commit-changes', () => {
return gulp.src([ './', './test/', './package.json', './lib/index.js', './test/SpecRunner.js' ])
.pipe(git.add())
.pipe(git.commit('Release. Bump version number'));
});
gulp.task('push-changes', (cb) => {
git.push('origin', 'master', cb);
});
gulp.task('create-tag', (cb) => {
const version = getVersionFromPackage();
git.tag(version, 'Release ' + version, (error) => {
if (error) {
return cb(error);
}
git.push('origin', 'master', { args: '--tags' }, cb);
});
});
gulp.task('build-test-bundle', () => {
return browserify({ entries: glob.sync('test/specs/**/*.js') })
.bundle()
.pipe(source('SpecRunner.js'))
.pipe(buffer())
.pipe(gulp.dest('test'));
});
gulp.task('execute-browser-tests', () => {
return gulp.src('test/SpecRunner.js')
.pipe(jasmine());
});
gulp.task('execute-node-tests', () => {
return gulp.src(['test/specs/**/*.js'])
.pipe(jasmine());
});
gulp.task('print-github', () => {
return Promise.resolve().then(() => {
console.info(getGitHubLink());
});
});
gulp.task('execute-tests', gulp.series(
'build-test-bundle',
'execute-browser-tests',
'execute-node-tests'
));
gulp.task('test', gulp.series('execute-tests'));
gulp.task('release', gulp.series(
'ensure-clean-working-directory',
'execute-tests',
'bump-choice',
'bump-version',
'embed-version',
'build-example-bundle',
'commit-changes',
'push-changes',
'create-tag',
'deploy-documentation',
'print-github'
));
gulp.task('lint', () => {
return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./test/SpecRunner.js', '!./example/browser/bundle.js', '!./docs/**', '!./example/browser/webpack.config.js'])
.pipe(jshint({ esversion: 9 }))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('default', gulp.series('lint'));