-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
88 lines (76 loc) · 2.17 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
/* eslint-disable import/no-nodejs-modules, import/no-commonjs, no-use-before-define */
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const file = require('gulp-file');
const karma = require('karma');
const path = require('path');
const {exec} = require('child_process');
const pkg = require('./package.json');
const argv = require('yargs')
.option('output', {alias: 'o', default: 'dist'})
.option('docs-dir', {default: 'docs'})
.option('www-dir', {default: 'www'})
.argv;
function run(bin, args) {
return new Promise((resolve, reject) => {
const exe = '"' + process.execPath + '"';
const src = require.resolve(bin);
const ps = exec([exe, src].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', () => run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']));
gulp.task('test', (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
}
},
(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('lint', () => {
const files = [
'src/**/*.js',
'test/**/*.js',
'*.js'
];
return gulp.src(files)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('docs', () => {
const mode = argv.watch ? 'dev' : 'build';
const out = path.join(argv.output, argv.docsDir);
const args = argv.watch ? '' : '--dest ' + out;
return run('vuepress', [mode, 'docs', args]);
});
gulp.task('bower', () => {
const 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'));