-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
139 lines (117 loc) · 3.56 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
'use strict';
var path = require('path');
var {task, src, dest, watch, series} = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
var coveralls = require('gulp-coveralls');
var rollup = require('rollup');
var json = require('rollup-plugin-json');
var babel = require('rollup-plugin-babel');
var fs = require('fs');
var del = require('del');
var merge = require('merge-stream');
var async = require('rollup-plugin-async');
let cache;
task('static', () => {
return src('src/*.js')
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
task('nsp', cb => {
nsp({package: path.resolve('package.json')}, cb);
});
task('pre-test', () => {
return src('bin/**/*.js')
.pipe(excludeGitignore())
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire());
});
task('test:after', cb => {
var mochaErr;
src('test/**/*.js')
.pipe(plumber())
.pipe(mocha({reporter: 'spec'}))
.on('error', err => {
mochaErr = err;
})
.pipe(istanbul.writeReports())
.on('end', () => {
cb(mochaErr);
});
});
task('test', series('pre-test', 'test:after'));
task('watch', () => {
watch(['bin/**/*.js', 'test/**'], ['test']);
});
task('coveralls:after', () => {
if (!process.env.CI) {
return;
}
return src(path.join(__dirname, 'coverage/lcov.info'))
.pipe(coveralls());
});
task('coveralls', series('test', 'coveralls:after'));
task('rollup:run', () => {
return rollup.rollup({
entry: 'src/backed.js',
// Use the previous bundle as starting point.
cache: cache,
acorn: {
allowReserved: true
},
plugins: [json(), async(), babel({runtimeHelpers: true})]
}).then(bundle => {
var result = bundle.generate({
format: 'cjs',
moduleName: 'Backed'
});
// Cache our bundle for later use (optional)
cache = bundle;
fs.writeFileSync('.tmp/backed.js', result.code);
});
});
task('rollup:before', cb => {
fs.mkdirSync('.tmp');
cb();
});
task('rollup:after', () => {
var string = fs.readFileSync('.tmp/backed.js').toString();
string = string.replace(`'use strict';`, `#!/usr/bin/env node`);
fs.unlinkSync('.tmp/backed.js');
fs.writeFileSync('.tmp/backed.js', string);
var cli = src('.tmp/backed.js').pipe(dest('bin'));
return merge(cli);
});
task('clean', cb => {
del.sync(['.tmp/', 'bin/**/*']);
cb();
});
task('copy', () => {
const workers = src('src/workers/*.js').pipe(dest('bin/workers'));
const asycRuntimeHelpers = src([
'node_modules/babel-runtime/helpers/{classCallCheck,createClass,regenerator,asyncGenerator}.js'
]).pipe(dest('bin/node_modules/babel-runtime/helpers'));
const asyncRegenerator = src([
'node_modules/babel-runtime/regenerator/*.js'
]).pipe(dest('bin/node_modules/babel-runtime/regenerator'));
const asyncRuntimeCore = src([
'node_modules/babel-runtime/core-js/object/define-property.js'
]).pipe(dest('bin/node_modules/babel-runtime/core-js/object'));
return merge(workers, asycRuntimeHelpers, asyncRegenerator, asyncRuntimeCore);
});
task('watch', () => {
watch('src/*.js', series('build'));
watch('src/workers/*.js', series('copy'));
});
task('rollup', series('rollup:before', 'rollup:run', 'rollup:after'));
task('build', series('clean', 'rollup', 'copy'));
task('prepublish', series('nsp', 'build'));
task('default', series('static', 'test', 'coveralls'));