forked from Narazaka/xlsx2seed.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
113 lines (97 loc) · 2.64 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
const path = require('path');
const gulp = require('gulp');
const rimraf = require('rimraf');
const $ = (require('gulp-load-plugins'))();
const isparta = require('isparta');
const files = {
bin: {
js: 'src/bin/**/*.js',
},
lib: {
js: 'src/lib/**/*.js',
},
test: {
js: 'test/**/*.js',
},
mock: {
js: 'mock/**/*.js',
},
conf: {
js: '*.js',
},
doc: 'doc/**/*',
};
const dirs = {
src: 'src',
dst: '.',
doc: 'doc',
};
gulp.task('default', ['build']);
gulp.task('bin', function() {
return gulp.src(files.bin.js, {base: dirs.src})
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.header('#!/usr/bin/env node\n'))
// .pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dirs.dst));
});
gulp.task('lib', function() {
return gulp.src(files.lib.js, {base: dirs.src})
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.header(
"if(typeof exports === 'undefined' && typeof window !== 'undefined')"
+ ' var exports = window;\n'
))
// .pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dirs.dst));
});
gulp.task('js', ['lib', 'bin']);
gulp.task('build', ['js', 'test', 'lint', 'doc']);
gulp.task('test', ['test-node']);
gulp.task('test-cli', ['test-node']);
gulp.task('pre-test', function() {
return gulp.src(files.lib.js)
.pipe($.istanbul({instrumenter: isparta.Instrumenter}))
.pipe($.istanbul.hookRequire())
.pipe(gulp.dest('test-tmp'));
});
gulp.task('test-node', ['pre-test'], function() {
return gulp.src(files.test.js, {read: false})
.pipe($.mocha({ui: 'mocha-lazy-bdd'}))
.pipe($.istanbul.writeReports());
});
gulp.task('lint', function() {
return gulp.src(
[files.bin.js, files.lib.js, files.test.js, files.mock.js, files.conf.js],
{base: '.'}
)
.pipe($.eslint({useEslintrc: true}))
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
});
gulp.task('lint-fix', function() {
return gulp.src(
[files.bin.js, files.lib.js, files.test.js, files.mock.js, files.conf.js],
{base: '.'}
)
.pipe($.eslint({useEslintrc: true, fix: true}))
.pipe($.eslint.format())
.pipe($.eslint.failAfterError())
.pipe(gulp.dest('.'));
});
gulp.task('clean-doc', function(done) {
return rimraf(files.doc, done);
});
gulp.task('doc', ['clean-doc'], function() {
return gulp.src(dirs.src, {read: false, base: dirs.src})
.pipe($.esdoc({destination: dirs.doc}));
});
gulp.task('watch', function() {
gulp.start(['js', 'test-node', 'lint', 'doc']);
return $.watch([files.bin.js, files.lib.js, files.test.js], function() {
return gulp.start(['js', 'test-node', 'lint', 'doc']);
});
});