forked from facebook/fbjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (102 loc) · 2.89 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
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const del = require('del');
const flatten = require('gulp-flatten');
const gulp = require('gulp');
const gulpBabel = require('gulp-babel');
const mergeStream = require('merge-stream');
const rename = require('gulp-rename');
const runSequence = require('run-sequence');
const fbjsConfigurePreset = require('babel-preset-fbjs/configure');
const gulpModuleMap = require('fbjs-scripts/gulp/module-map');
const gulpStripProvidesModule = require('fbjs-scripts/gulp/strip-provides-module');
const gulpCheckDependencies = require('fbjs-scripts/gulp/check-dependencies');
const paths = {
lib: {
src: [
'src/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
dest: 'lib',
presetOptions: {
stripDEV: true,
rewriteModules: {
map: require('fbjs-scripts/third-party-module-map'),
},
},
},
mocks: {
src: [
'src/**/__mocks__/**/*.js',
],
dest: 'lib/__mocks__',
presetOptions: {
stripDEV: true,
rewriteModules: {
map: require('fbjs-scripts/third-party-module-map'),
prefix: '../',
},
},
},
};
const rewriteOptions = {
moduleMapFile: './module-map.json',
prefix: 'fbjs/lib/',
};
gulp.task('clean', function() {
return del([paths.lib.dest, paths.mocks.dest]);
});
gulp.task('lib', function() {
const libTask = gulp
.src(paths.lib.src)
.pipe(gulpModuleMap(rewriteOptions))
.pipe(gulpStripProvidesModule())
.pipe(gulpBabel(fbjsConfigurePreset(paths.lib.presetOptions)))
.pipe(flatten())
.pipe(gulp.dest(paths.lib.dest));
const mockTask = gulp
.src(paths.mocks.src)
.pipe(gulpBabel(fbjsConfigurePreset(paths.mocks.presetOptions)))
.pipe(flatten())
.pipe(gulp.dest(paths.mocks.dest));
return mergeStream(libTask, mockTask);
});
gulp.task('flow', function() {
return gulp
.src(paths.lib.src)
.pipe(gulpModuleMap(rewriteOptions))
.pipe(gulpBabel({
presets: [
fbjsConfigurePreset({
autoImport: false,
target: 'flow',
rewriteModules: {
map: require('fbjs-scripts/third-party-module-map'),
},
}),
],
}))
.pipe(flatten())
.pipe(rename({extname: '.js.flow'}))
.pipe(gulp.dest(paths.lib.dest));
});
gulp.task('check-dependencies', function() {
return gulp
.src('package.json')
.pipe(gulpCheckDependencies());
});
gulp.task('watch', function() {
gulp.watch(paths.src, ['lib', 'flow']);
});
gulp.task('build', function(cb) {
runSequence('check-dependencies', 'clean', ['lib', 'flow'], cb);
});
gulp.task('default', ['build']);