forked from expo/snack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
47 lines (40 loc) · 1.41 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
const path = require('path');
const gulp = require('gulp');
const babel = require('gulp-babel');
const changed = require('gulp-changed');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const del = require('del');
const shell = require('gulp-shell');
const sourcemaps = require('gulp-sourcemaps');
const paths = {
source: {
js: 'src/**/*.js',
},
build: {
node: 'dist',
esm: 'esm',
},
};
const transpile = (desitantion, config) =>
gulp
.src(paths.source.js)
.pipe(changed(desitantion))
.pipe(plumber())
.pipe(sourcemaps.init({ identityMap: true }))
.pipe(babel(config))
.pipe(sourcemaps.write('__sourcemaps__', { sourceRoot: '/snack-sdk/src' }))
.pipe(gulp.dest(desitantion));
const flow = desitantion =>
gulp
.src(paths.source.js)
.pipe(rename({ extname: '.js.flow' }))
.pipe(gulp.dest(desitantion));
const build = (desitantion, config) =>
gulp.parallel(() => transpile(desitantion, config), () => flow(desitantion));
gulp.task('build:node', build(paths.build.node));
gulp.task('build:esm', build(paths.build.esm, require('./.babelrc.esm.json')));
gulp.task('clean', () => del([paths.build.node, paths.build.esm]));
gulp.task('build', gulp.series('clean', gulp.parallel('build:node', 'build:esm')));
gulp.task('watch', gulp.series('build', () => gulp.watch(paths.source.js, gulp.series('build'))));
gulp.task('default', gulp.series('watch'));