-
Notifications
You must be signed in to change notification settings - Fork 44
/
gulpfile.js
105 lines (91 loc) · 2.28 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
import gulp from 'gulp';
import gulpESlint from 'gulp-eslint';
import gulpMocha from 'gulp-mocha';
import runSequence from 'run-sequence';
const IGNOREDDIRS = ['!**/node_modules/**'];
const SRCDIR = 'modules';
const EXAMPLESDIR = 'examples';
const SPECDIR = 'spec';
const defaultLoader = require.extensions['.js'];
function transpilePath(path, babelConfig) {
/* eslint-disable global-require, no-underscore-dangle */
return () => {
require.extensions['.js'] = (module, filename) => {
if (filename.indexOf(path) < 0) {
defaultLoader(module, filename);
return;
}
const { code } = require('babel-core').transformFileSync(
filename,
babelConfig,
);
module._compile(code, filename);
return;
};
};
/* eslint-enable */
}
const transpile = {
'react-router': transpilePath(
'node_modules/react-router/es6',
{
// TODO use react-router .babelrc
}
),
};
gulp.task('load-require-hooks', (done) => {
/* eslint-disable global-require */
// Can't mock NavigationExperimental until lelandrichardson/react-native-mock#48 lands in
// react-native-mock
require('react-native-mock/mock');
/* eslint-enable */
// We are using react-router's es6 API via the provided es6 modules. This makes debugging much
// easier compared to using their transpiled counterparts.
transpile['react-router']();
done();
});
gulp.task('lint', () => gulp
.src([
`${SRCDIR}/**/*.js`,
`${SPECDIR}/**/*.js`,
`${EXAMPLESDIR}/**/*.js`,
'gulpfile.js',
...IGNOREDDIRS,
])
.pipe(gulpESlint())
.pipe(gulpESlint.format())
.pipe(gulpESlint.failAfterError())
);
gulp.task('spec', ['load-require-hooks'], () =>
gulp.src([
`${SPECDIR}/**/*.spec.js`,
])
.pipe(gulpMocha({
reporter: 'spec',
ui: 'bdd',
})));
gulp.task('copy', () =>
gulp.src([
`${SRCDIR}/**/*.js`,
])
.pipe(gulp.dest(
'examples/Aviato/node_modules/react-router-native/modules'
))
.pipe(gulp.dest(
'examples/Simple/node_modules/react-router-native/modules'
))
);
gulp.task('default', done => {
runSequence(
'spec',
'lint',
done
);
});
gulp.task('watch', () => {
gulp.watch([
`${SRCDIR}/**/*`,
`${SPECDIR}/**/*`,
'gulpfile.js',
], ['copy', 'default']);
});