forked from elastic/generator-kibana-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.helpers.js
68 lines (60 loc) · 1.51 KB
/
gulpfile.helpers.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
import gulp from 'gulp';
import gulpif from 'gulp-if';
import { obj as combine } from 'stream-combiner2';
import { obj as through2 } from 'through2';
import sourcemaps from 'gulp-sourcemaps';
import babel from 'gulp-babel';
import { resolve, relative } from 'path';
import gutil from 'gulp-util';
import del from 'del';
export function ifJsSource(...then) {
return gulpif(
file => {
if (file.path.match(/[\\\/]templates[\\\/]/)) return false;
if (file.path.match(/\.jsx?$/)) return true;
return false;
},
...then
);
}
export function outputPath(file) {
return resolve(__dirname, 'lib', file.relative);
}
export function ifUnlinkEvent(...then) {
const unlinkEvent = ({ event }) => event === 'unlink' || event === 'unlinkDir';
return gulpif(unlinkEvent, ...then);
}
export function log(...preamble) {
return through2((file, enc, cb) => {
if (file.isDirectory()) return cb();
gutil.log(...preamble, relative(process.cwd(), outputPath(file)));
cb(null, file);
});
}
export function removeOutput() {
return combine([
through2((file, enc, cb) => {
del(outputPath(file))
.then(() => cb(null, file))
.catch(err => cb(err));
}),
log(gutil.colors.red('d'))
]);
}
export function transpile() {
return combine([
sourcemaps.init(),
babel(),
sourcemaps.write(),
toLib(),
]);
}
export function toLib() {
return gulp.dest('lib');
}
export function reTranspile() {
return combine([
transpile(),
log(gutil.colors.green('✔'))
]);
}