-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (74 loc) · 2.11 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
const {Transform} = require('stream');
const babel = require('gulp-babel');
const gulp = require('gulp');
const path = require('path');
const {rimraf} = require('rimraf');
const babelConfig = require('./babel.config.json');
const IGNORED_PACKAGES = [
'!packages/examples/**',
'!packages/core/integration-tests/**',
'!packages/core/workers/test/integration/**',
'!packages/core/test-utils/**',
'!packages/core/types/**',
'!packages/core/types-internal/**',
// These packages are bundled.
'!packages/core/codeframe/**',
'!packages/core/fs/**',
'!packages/core/package-manager/**',
'!packages/core/utils/**',
'!packages/reporters/cli/**',
'!packages/reporters/dev-server/**',
];
const paths = {
packageSrc: [
'packages/*/*/src/**/*.js',
'!**/dev-prelude.js',
...IGNORED_PACKAGES,
],
packageOther: ['packages/*/*/src/**/dev-prelude.js'],
packages: 'packages/',
};
/*
* "Taps" into the contents of a flowing stream, yielding chunks to the passed
* callback. Continues to pass data chunks down the stream.
*/
class TapStream extends Transform {
constructor(tap, options) {
super({...options, objectMode: true});
this._tap = tap;
}
_transform(chunk, encoding, callback) {
try {
this._tap(chunk);
callback(null, chunk);
} catch (err) {
callback(err);
}
}
}
exports.clean = function clean(cb) {
rimraf('packages/*/*/lib/**').then(
() => cb(),
(err) => cb(err),
);
};
exports.default = exports.build = gulp.parallel(buildBabel, copyOthers);
function buildBabel() {
return gulp
.src(paths.packageSrc)
.pipe(babel({...babelConfig, babelrcRoots: [__dirname + '/packages/*/*']}))
.pipe(renameStream((relative) => relative.replace('src', 'lib')))
.pipe(gulp.dest(paths.packages));
}
function copyOthers() {
return gulp
.src(paths.packageOther)
.pipe(renameStream((relative) => relative.replace('src', 'lib')))
.pipe(gulp.dest(paths.packages));
}
function renameStream(fn) {
return new TapStream((vinyl) => {
let relative = path.relative(vinyl.base, vinyl.path);
vinyl.path = path.join(vinyl.base, fn(relative));
});
}