-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
59 lines (55 loc) · 1.69 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
const gulp = require('gulp');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const typescript = require('gulp-typescript').createProject('tsconfig.json');
const rename = require('gulp-rename');
const merge2 = require('merge2');
const del = require('del');
// This deletes all file from the lib folder
gulp.task('clear', () => {
return del('packages/*/lib/*');
});
// This listens to changes, and re-runs the build task
gulp.task('default', ['build'], () =>
gulp.watch('packages/*/src/**', ['build']),
);
// This uses both typescript and babel to transpile /src to /lib files.
gulp.task('build', ['clear'], () => {
// Get all files as described in tsconfig.js
const tsResult = typescript
.src()
// We start tracking all rewrites for the sourcemaps
.pipe(sourcemaps.init())
// Transpile to es2015 with the Typescript compiler
.pipe(typescript());
return (
merge2(
// Pass the declaration files as-is
tsResult.dts,
// Babel-ify the javascript files
tsResult.js.pipe(
babel({
plugins: ['transform-runtime'],
presets: ['env'],
}),
),
)
// Rename */src to */lib
.pipe(
rename(path => {
const newDirName = path.dirname.replace(
/^([a-z-]+)\/src/,
(_, p) => `${p}/lib`,
);
if (path.dirname === newDirName) {
throw new Error('Tried to compile ' + JSON.stringify(path));
}
path.dirname = newDirName;
}),
)
// Write the sourcemaps
.pipe(sourcemaps.write('.', { sourceRoot: '.' }))
// Write everything to the filesystem
.pipe(gulp.dest('packages'))
);
});