forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
277 lines (238 loc) · 7.19 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/**
* Copyright 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';
var gulp = require('gulp');
var babel = require('gulp-babel');
var flatten = require('gulp-flatten');
var del = require('del');
var merge = require('merge-stream');
var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
var stripProvidesModule = require('fbjs-scripts/gulp/strip-provides-module');
var extractErrors = require('./scripts/error-codes/gulp-extract-errors');
var devExpressionWithCodes = require('./scripts/error-codes/dev-expression-with-codes');
// Load all of the Gulp plugins.
var plugins = require('gulp-load-plugins')();
function getTask(name) {
return require(`./gulp/tasks/${name}`)(gulp, plugins);
}
var paths = {
react: {
src: [
'src/umd/ReactUMDEntry.js',
'src/umd/ReactWithAddonsUMDEntry.js',
'src/umd/shims/**/*.js',
'src/isomorphic/**/*.js',
'src/addons/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/shared/vendor/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react/lib',
},
reactDOM: {
src: [
'src/umd/ReactDOMUMDEntry.js',
'src/umd/ReactDOMServerUMDEntry.js',
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/shared/vendor/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-dom/lib',
},
reactNative: {
src: [
'src/renderers/native/**/*.js',
'src/renderers/shared/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/shared/vendor/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-native/lib',
},
reactTestRenderer: {
src: [
'src/renderers/testing/**/*.js',
'src/renderers/shared/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/shared/vendor/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-test-renderer/lib',
},
reactNoopRenderer: {
src: [
'src/renderers/noop/**/*.js',
'src/renderers/shared/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/shared/vendor/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-noop-renderer/lib',
},
};
var moduleMapBase = Object.assign(
{'object-assign': 'object-assign'},
require('fbjs/module-map')
);
var moduleMapReact = Object.assign(
{
// Addons needs to reach into DOM internals
ReactDOM: 'react-dom/lib/ReactDOM',
ReactInstanceMap: 'react-dom/lib/ReactInstanceMap',
ReactTestUtils: 'react-dom/lib/ReactTestUtils',
ReactPerf: 'react-dom/lib/ReactPerf',
getVendorPrefixedEventName: 'react-dom/lib/getVendorPrefixedEventName',
},
moduleMapBase
);
var rendererSharedState = {
// Alias
React: 'react/lib/React',
// Shared state
ReactCurrentOwner: 'react/lib/ReactCurrentOwner',
ReactComponentTreeHook: 'react/lib/ReactComponentTreeHook',
};
var moduleMapReactDOM = Object.assign(
{},
rendererSharedState,
moduleMapBase
);
var moduleMapReactNative = Object.assign(
{
// React Native Hooks
deepDiffer: 'react-native/lib/deepDiffer',
deepFreezeAndThrowOnMutationInDev: 'react-native/lib/deepFreezeAndThrowOnMutationInDev',
flattenStyle: 'react-native/lib/flattenStyle',
InitializeJavaScriptAppEngine: 'react-native/lib/InitializeJavaScriptAppEngine',
RCTEventEmitter: 'react-native/lib/RCTEventEmitter',
TextInputState: 'react-native/lib/TextInputState',
UIManager: 'react-native/lib/UIManager',
UIManagerStatTracker: 'react-native/lib/UIManagerStatTracker',
View: 'react-native/lib/View',
},
rendererSharedState,
moduleMapBase
);
var moduleMapReactTestRenderer = Object.assign(
{},
rendererSharedState,
moduleMapBase
);
var moduleMapReactNoopRenderer = Object.assign(
{},
rendererSharedState,
moduleMapBase
);
var errorCodeOpts = {
errorMapFilePath: 'scripts/error-codes/codes.json',
};
var babelOptsReact = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReact}],
],
};
var babelOptsReactDOM = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactDOM}],
],
};
var babelOptsReactNative = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactNative}],
],
};
var babelOptsReactTestRenderer = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactTestRenderer}],
],
};
var babelOptsReactNoopRenderer = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactNoopRenderer}],
],
};
gulp.task('eslint', getTask('eslint'));
gulp.task('lint', ['eslint']);
gulp.task('flow', getTask('flow'));
gulp.task('version-check', getTask('version-check'));
gulp.task('react:clean', function() {
return del([
paths.react.lib,
paths.reactDOM.lib,
paths.reactNative.lib,
paths.reactTestRenderer.lib,
paths.reactNoopRenderer.lib,
]);
});
gulp.task('react:modules', function() {
return merge(
gulp
.src(paths.react.src)
.pipe(babel(babelOptsReact))
.pipe(stripProvidesModule())
.pipe(flatten())
.pipe(gulp.dest(paths.react.lib)),
gulp
.src(paths.reactDOM.src)
.pipe(babel(babelOptsReactDOM))
.pipe(stripProvidesModule())
.pipe(flatten())
.pipe(gulp.dest(paths.reactDOM.lib)),
gulp
.src(paths.reactNative.src)
.pipe(babel(babelOptsReactNative))
.pipe(stripProvidesModule())
.pipe(flatten())
.pipe(gulp.dest(paths.reactNative.lib)),
gulp
.src(paths.reactTestRenderer.src)
.pipe(stripProvidesModule())
.pipe(babel(babelOptsReactTestRenderer))
.pipe(flatten())
.pipe(gulp.dest(paths.reactTestRenderer.lib)),
gulp
.src(paths.reactNoopRenderer.src)
.pipe(stripProvidesModule())
.pipe(babel(babelOptsReactNoopRenderer))
.pipe(flatten())
.pipe(gulp.dest(paths.reactNoopRenderer.lib))
);
});
gulp.task('react:extract-errors', function() {
return gulp.src([].concat(
paths.react.src,
paths.reactDOM.src,
paths.reactNative.src,
paths.reactTestRenderer.src
)).pipe(extractErrors(errorCodeOpts));
});
gulp.task('default', ['react:modules']);