forked from chartjs/chartjs-plugin-datalabels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
135 lines (116 loc) · 3.6 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
/* global Promise */
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var file = require('gulp-file');
var replace = require('gulp-replace');
var streamify = require('gulp-streamify');
var zip = require('gulp-zip');
var karma = require('karma');
var merge = require('merge2');
var path = require('path');
var {exec} = require('child_process');
var pkg = require('./package.json');
var argv = require('yargs')
.option('output', {alias: 'o', default: 'dist'})
.option('samples-dir', {default: 'samples'})
.option('docs-dir', {default: 'docs'})
.option('www-dir', {default: 'www'})
.argv;
function run(bin, args) {
return new Promise((resolve, reject) => {
var exe = path.join('node_modules', '.bin', bin);
var ps = exec([exe].concat(args || []).join(' '));
ps.stdout.pipe(process.stdout);
ps.stderr.pipe(process.stderr);
ps.on('close', (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
gulp.task('build', function() {
return run('rollup', ['-c', argv.watch ? '--watch' : '']);
});
gulp.task('test-unit', function(done) {
new karma.Server({
configFile: path.join(__dirname, 'karma.config.js'),
singleRun: !argv.watch,
args: {
coverage: !!argv.coverage,
inputs: (argv.inputs || 'test/specs/**/*.js').split(';'),
watch: argv.watch
}
},
function(error) {
// https://github.com/karma-runner/gulp-karma/issues/18
error = error ? new Error('Karma returned with the error code: ' + error) : undefined;
done(error);
}).start();
});
gulp.task('test-types', function() {
return run('tsc', ['-p', 'types/test/']);
});
gulp.task('test', gulp.parallel('test-unit', 'test-types'));
gulp.task('lint', function() {
var files = [
'samples/**/*.js',
'samples/**/*.html',
'src/**/*.js',
'test/**/*.js',
'*.js'
];
return gulp.src(files)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('docs', function() {
var mode = argv.watch ? 'dev' : 'build';
var out = path.join(argv.output, argv.docsDir);
var args = argv.watch ? '' : '--dest ' + out;
return run('vuepress', [mode, 'docs', args]);
});
gulp.task('samples', function() {
// since we moved the dist files one folder up (package root), we need to rewrite
// samples src="../dist/ to src="../ and then copy them in the /samples directory.
var out = path.join(argv.output, argv.samplesDir);
return gulp.src('samples/**/*', {base: 'samples'})
.pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1', {skipBinary: true})))
.pipe(gulp.dest(out));
});
gulp.task('package', gulp.series(gulp.parallel('build', 'samples'), function() {
var out = argv.output;
var streams = merge(
gulp.src(path.join(out, argv.samplesDir, '**/*'), {base: out}),
gulp.src([path.join(out, '*.js'), 'LICENSE.md'])
);
return streams
.pipe(zip(pkg.name + '.zip'))
.pipe(gulp.dest(out));
}));
gulp.task('netlify', gulp.series(gulp.parallel('build', 'docs', 'samples'), function() {
var root = argv.output;
var out = path.join(root, argv.wwwDir);
var streams = merge(
gulp.src(path.join(root, argv.docsDir, '**/*'), {base: path.join(root, argv.docsDir)}),
gulp.src(path.join(root, argv.samplesDir, '**/*'), {base: root}),
gulp.src(path.join(root, '*.js'))
);
return streams.pipe(gulp.dest(out));
}));
gulp.task('bower', function() {
var json = JSON.stringify({
name: pkg.name,
description: pkg.description,
homepage: pkg.homepage,
license: pkg.license,
version: pkg.version,
main: argv.output + '/' + pkg.name + '.js'
}, null, 2);
return file('bower.json', json, {src: true})
.pipe(gulp.dest('./'));
});
gulp.task('default', gulp.parallel('build'));