-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.babel.js
135 lines (118 loc) · 3.43 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
import gulp from 'gulp';
import babel from 'gulp-babel';
import eslint from 'gulp-eslint';
import install from 'gulp-install';
import mocha from 'gulp-mocha';
import flow from 'gulp-flowtype';
import gutil from 'gulp-util';
import react from 'gulp-react';
import sourcemaps from 'gulp-sourcemaps';
import webpack from 'webpack';
import webpackConfig from './webpack/webpack.config.babel';
const path = {
bootstrap: 'node_modules/bootstrap/dist/**/*.*',
images: [
'client/src/**/*.png'
],
sources: [
'client/src/**/*.js',
'client/src/**/*.jsx'
],
styles: [
'client/src/**/*.less',
'client/src/**/*.scss',
],
tests: [
'client/test/**/*.js'
],
lib: 'client/lib',
dest: 'client/lib',
assets: 'web/static/assets'
};
gulp.task('install', () => {
gulp.src('./package.json')
.pipe(install());
});
gulp.task('default', ['build']);
gulp.task('copy', ['copy-bootstrap', 'copy-images', 'copy-styles']);
gulp.task('copy-bootstrap', () => {
return gulp.src(path.bootstrap)
.pipe(gulp.dest(path.assets));
});
gulp.task('copy-images', () => {
return gulp.src(path.images)
.pipe(gulp.dest(path.dest));
});
gulp.task('copy-styles', () => {
return gulp.src(path.styles)
.pipe(gulp.dest(path.dest));
});
gulp.task('babel', ['copy'], () => {
return gulp.src(path.sources)
.pipe(sourcemaps.init())
.pipe(babel())
// .pipe(react({stripTypes: true}))
.pipe(sourcemaps.write('../../web/static/assets/js/maps', {
sourceMappingURL: (file) => {
return '/js/maps/' + file.relative + '.map';
}
}))
.pipe(gulp.dest(path.lib));
});
gulp.task('build', ['babel', 'lint', 'typecheck', 'webpack', 'test']);
gulp.task('lint', () => {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src([...path.sources, '!node_modules/**'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
gulp.task('test', ['babel'], () => {
return gulp.src(path.tests)
.pipe(mocha())
.on('error', () => {
gulp.emit('end');
});
});
gulp.task('typecheck', () => {
return gulp.src(path.sources)
.pipe(flow({
all: false,
weak: false,
declarations: './declarations',
killFlow: false,
beep: true,
abort: false
}));
});
gulp.task('watch-test', () => {
return gulp.watch([path.sources, path.tests], ['build']);
});
gulp.task('webpack', ['test'], (callback) => {
var myConfig = Object.create(webpackConfig);
myConfig.plugins = [
// new webpack.optimize.DedupePlugin(),
// new webpack.optimize.UglifyJsPlugin()
];
// run webpack
webpack(myConfig, (err, stats) => {
if (err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({
colors: true,
progress: true
}));
callback();
});
});
gulp.task('watch', ['build'], () => {
gulp.watch([...path.sources, ...path.styles, ...path.tests], ['build']);
});