-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathgulpfile.js
More file actions
143 lines (119 loc) · 3.57 KB
/
gulpfile.js
File metadata and controls
143 lines (119 loc) · 3.57 KB
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
(function() {
'use strict';
const bumper = require('gulp-bump');
const fs = require('fs');
const git = require('gulp-git');
const gulp = require('gulp');
const gzip = require('gulp-gzip');
const eslint = require('gulp-eslint-new');
const path = require('path');
const rimraf = require('gulp-rimraf');
const shell = require('gulp-shell');
const tar = require('gulp-tar');
const karma = require('karma');
// Banner is now handled by Rollup
function clean() {
return gulp.src('./dist/*', {read: false, allowEmpty: true})
.pipe(rimraf());
}
function lint() {
return gulp.src(['**/*.js', '!node_modules/**', '!dist/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function unit(done) {
new karma.Server({
configFile: path.join(__dirname, 'karma.conf.js'),
singleRun: true,
}, done).start();
}
function integration() {
return gulp.src('.', {read: false})
.pipe(shell(['npx playwright test']));
}
function bump(level) {
return function() {
return gulp.src(['./package.json'])
.pipe(bumper({type: level}))
.pipe(gulp.dest('./'));
};
}
function rollupTask() {
return gulp.src('.', {read: false})
.pipe(shell(['npx rollup -c']));
}
// js() task removed in favor of Rollup
function build() {
return gulp.src(['dist/*', '!./dist/*.tar.gz'])
.pipe(tar('angular-chart.js.tar'))
.pipe(gzip({gzipOptions: {level: 9}}))
.pipe(gulp.dest('dist/'));
}
function update(cb) {
fs.readFile('./examples/charts.html', 'utf8', function(err, file) {
if (err) {
return cb(err);
}
file = file.replace(/Download <small>\(.*\)<\/small>/,
'Download <small>(' + version() + ')</small>');
fs.writeFile('./examples/charts.html', file, cb);
});
}
function gitCommit() {
const v = version();
return gulp.src('.')
.pipe(git.add())
.pipe(git.commit(v));
}
function gitPush(cb) {
const v = version();
git.push('origin', 'main', function(err) {
if (err) {
return cb(err);
}
git.tag('v' + v, v, function(err) {
if (err) {
return cb(err);
}
git.push('origin', 'main', {args: '--tags'}, cb);
});
});
}
const npmPublish = shell.task([
'npm publish',
]);
function version() {
return JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
}
function serve() {
return gulp.src('.', {read: false})
.pipe(shell(['npx http-server -p 8080 -c-1']));
}
gulp.task('clean', clean);
gulp.task('lint', lint);
gulp.task('unit', unit);
gulp.task('integration', integration);
gulp.task('build', build);
gulp.task('update', update);
gulp.task('git-commit', gitCommit);
gulp.task('git-push', gitPush);
gulp.task('npm', npmPublish);
gulp.task('serve', serve);
gulp.task('bump-patch', bump('patch'));
gulp.task('bump-minor', bump('minor'));
gulp.task('bump-major', bump('major'));
gulp.task('assets', gulp.series(clean, rollupTask, build));
gulp.task('test', gulp.series(unit, integration));
gulp.task('check', gulp.series(lint, 'test'));
gulp.task('deploy-patch', gulp.series(
'check', 'bump-patch', 'assets', update, gitCommit, gitPush, npmPublish,
));
gulp.task('deploy-minor', gulp.series(
'check', 'bump-minor', 'assets', update, gitCommit, gitPush, npmPublish,
));
gulp.task('deploy-major', gulp.series(
'check', 'bump-major', 'assets', update, gitCommit, gitPush, npmPublish,
));
gulp.task('default', gulp.series('assets'));
})();