-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
139 lines (120 loc) · 3.13 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
var gulp = require("gulp");
var gutil = require("gulp-util");
var webpack = require('webpack');
var gulpWebpack = require('gulp-webpack');
var execFile = require('child_process').execFile;
var flow = require('flow-bin');
gulp.task('default', ['flow:check', 'copy'], function() {
doWebpack(webpackProdConfig);
});
gulp.task('dev', ['flow:start'], function() {
doWebpack(webpackDevConfig);
gulp.watch(['app/**/*.jsx?', 'model/**/*.js', 'tests/tests.js'],
['flow:status']);
gulp.watch(['app/*.html', 'app/*.css'],
['copy']);
});
gulp.task('copy', function() {
gulp.src([
'bower_components/pure/pure-min.css',])
.pipe(gulp.dest('build/css'));
gulp.src([
'node_modules/react-datepicker/dist/react-datepicker.min.css',])
.pipe(gulp.dest('build/css'));
// TODO: Clean this up, the entire tree of SASS etc. isn't required
// in the output
gulp.src('bower_components/fontawesome/**/*')
.pipe(gulp.dest('build/fontawesome'));
gulp.src('app/*.html')
.pipe(gulp.dest('build'));
gulp.src('app/*.css')
.pipe(gulp.dest('build'));
});
gulp.task('typecheck', function(callback) {
runFlow(['start'], function() {
runFlow(['status', '--no-auto-start'], callback);
})
});
gulp.task('flow:status', function(callback) {
runFlow(['status', '--no-auto-start'], callback);
});
gulp.task('flow:check', function(callback) {
runFlow(['check'], callback);
})
gulp.task('flow:start', function(callback) {
runFlow(['start'], callback);
});
gulp.task('flow:stop', function(callback) {
runFlow(['stop'], callback);
})
function runFlow(cmd, callback) {
execFile(flow, cmd, {
cwd: module.__dirname
}, function(err, stdout, stderr) {
if (err && stdout.length > 0) {
callback(new gutil.PluginError('flow', stdout));
}
else if (err) {
callback(err);
}
else {
callback();
}
});
}
var webpackConfig = {
entry: {
'tests/tests-bundle.js': './tests/tests.js',
'build/bundle.js': './app/jsx/index.js',
},
output: {
path: __dirname,
filename: '[name]'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: [/bower_components/, /node_modules/],
loader: 'babel-loader'
},
]
},
resolve: {
modulesDirectories: [
'model',
'bower_components/qunit/qunit',
'node_modules',
'app/jsx',
]
},
devtool: "#inline-source-map",
//noInfo: true
};
var webpackDevConfig = {
watch: true,
debug: true,
};
var webpackProdConfig = {
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"production"'
}
}),
new webpack.optimize.DedupePlugin(),
//new webpack.optimize.UglifyJsPlugin({minimize: true}),
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }),
]
}
function merge(obj1, obj2) {
var ret = {};
for (var attrname in obj1) { ret[attrname] = obj1[attrname]; }
for (var attrname in obj2) { ret[attrname] = obj2[attrname]; }
return ret;
}
function doWebpack(opts) {
return gulp.src(['app/jsx/index.js', 'tests/tests.js'])
.pipe(gulpWebpack(merge(webpackConfig, opts), webpack))
.pipe(gulp.dest('.'));
}