-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
162 lines (139 loc) · 3.75 KB
/
gulpfile.babel.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
/* eslint-disable no-undef, no-console */
import babel from 'gulp-babel';
import bg from 'gulp-bg';
import del from 'del';
import eslint from 'gulp-eslint';
import gulp from 'gulp';
import gulpIf from 'gulp-if';
import mochaRunCreator from './test/mochaRunCreator';
import path from 'path';
import postcss from 'gulp-postcss';
import runSequence from 'run-sequence';
import reporter from 'postcss-reporter';
import shell from 'gulp-shell';
import stylelint from 'stylelint';
import webpackBuild from './webpack/build';
import yargs from 'yargs';
const args = yargs
.alias('p', 'production')
.argv;
function isFixed(file) {
// Has ESLint fixed the file contents?
return file.eslint && file.eslint.fixed;
}
function runEslint() {
return gulp.src([
'gulpfile.babel.js',
'src/**/*.js',
'webpack/*.js'
])
.pipe(eslint({
fix: true
}))
.pipe(eslint.format());
}
/* eslint-disable */
function buildReact(minify) {
gulp
.src(['src/**/*.react.js', 'src/**/index.js'])
.pipe(babel())
.pipe(gulp.dest('dist'));
}
function buildSass() {
//Copy files and directory structure from /scss to /dist
gulp.src('src/**/*.scss').pipe(gulp.dest('dist'));
}
/* eslint-enable */
gulp.task('dist', () => {
del(['dist/*']);
buildReact(true);
buildSass();
});
gulp.task('lint-fix-src', () => {
return gulp.src('src/**/*.js')
.pipe(eslint({
fix: true
}))
.pipe(eslint.format())
// if fixed, write the file to dest
.pipe(gulpIf(isFixed, gulp.dest('src/')));
});
gulp.task('env', () => {
process.env.NODE_ENV = args.production ? 'production' : 'development';
});
gulp.task('clean', done => del('build/*', done));
gulp.task('build-webpack', ['env'], webpackBuild);
gulp.task('build', ['build-webpack']);
gulp.task('eslint', () => {
return runEslint();
});
gulp.task('eslint-ci', () => {
// Exit process with an error code (1) on lint error for CI build.
return runEslint().pipe(eslint.failAfterError());
});
function styleLint() {
return gulp.src(['src/**/*.scss', 'webpack/*.scss'])
.pipe(postcss(
[
stylelint({ configFile: path.join(__dirname, './.stylelintrc') }),
reporter({ clearMessages: true })
]
));
}
gulp.task('stylelint', styleLint);
gulp.task('mocha', () => {
mochaRunCreator('process')();
});
/* Enable to run single test file */
/* ex. gulp mocha-file --file app/browser/components/__test__/Button.js */
gulp.task('mocha-file', () => {
mochaRunCreator('process')({ path: path.join(__dirname, args.file) });
});
/* Run a test on a shared component */
/* ex. gulp test-shared-component -c Gallery */
gulp.task('test-shared-component', () => {
mochaRunCreator('process')({
path: path.join(
__dirname,
'app/browser/components/shared/',
args.c,
'__test__',
`${args.c}.spec.js`
)
});
});
gulp.task('test-component', () => {
mochaRunCreator('process')({
path: path.join(
__dirname,
'app/browser/components/',
args.c,
'__test__',
`${args.c}.spec.js`
)
});
});
/* Continuous test running */
gulp.task('mocha-watch', () => {
gulp.watch(
['app/browser/**', 'app/common/**', 'app/server/**'],
mochaRunCreator('log')
);
});
gulp.task('test', done => {
runSequence('stylelint', 'eslint-ci', 'mocha', 'build-webpack', done);
});
gulp.task('server-node', bg('node', './app/server'));
gulp.task('server-hot', bg('node', './webpack/server'));
gulp.task('server-nodemon', shell.task(
// Normalize makes path cross platform.
path.normalize('node_modules/.bin/nodemon app/server')
));
gulp.task('server', ['env'], done => {
if (args.production) {
runSequence('clean', 'build', 'server-node', done);
} else {
runSequence('server-hot', 'server-nodemon', done);
}
});
gulp.task('default', ['server']);