forked from FormidableLabs/recipes-flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
191 lines (167 loc) · 5.07 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
// Gulpfile
var fs = require("fs");
// var _ = require("lodash");
var gulp = require("gulp");
var gutil = require("gulp-util");
var jsxcs = require("gulp-jsxcs");
var eslint = require("gulp-eslint");
var nodemon = require("gulp-nodemon");
var connect = require("gulp-connect");
var shell = require("gulp-shell");
var webpack = require("webpack");
var rimraf = require("gulp-rimraf");
var buildCfg = require("./webpack.config");
var buildDevCfg = require("./webpack.dev-config");
// ----------------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------------
var FRONTEND_FILES = [
"client/**/*.{js,jsx}"
];
var BACKEND_FILES = [
"scripts/**/*.js",
"server/**/*.js",
"test/**/*.js",
"*.js"
];
// ----------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------
// Strip comments from JsHint JSON files (naive).
var _jsonCfg = function (name) {
var raw = fs.readFileSync(name).toString();
return JSON.parse(raw.replace(/\/\/.*\n/g, ""));
};
// ----------------------------------------------------------------------------
// EsLint
// ----------------------------------------------------------------------------
gulp.task("eslint-frontend", function () {
return gulp
.src(FRONTEND_FILES)
.pipe(eslint({
envs: [
"browser"
]
}))
.pipe(eslint.formatEach("stylish", process.stderr))
.pipe(eslint.failOnError());
});
gulp.task("eslint-backend", function () {
return gulp
.src(BACKEND_FILES)
.pipe(eslint({
envs: [
"node"
]
}))
.pipe(eslint.formatEach("stylish", process.stderr))
.pipe(eslint.failOnError());
});
gulp.task("eslint", ["eslint-frontend", "eslint-backend"]);
// ----------------------------------------------------------------------------
// JsCs
// ----------------------------------------------------------------------------
gulp.task("jscs", function () {
return gulp
.src([].concat(
FRONTEND_FILES,
BACKEND_FILES
))
.pipe(jsxcs(_jsonCfg(".jscsrc")));
});
// ----------------------------------------------------------------------------
// Quality
// ----------------------------------------------------------------------------
gulp.task("check", ["jscs", "eslint"]);
gulp.task("check:ci", ["jscs", "eslint"]);
gulp.task("check:all", ["jscs", "eslint"]);
// ----------------------------------------------------------------------------
// Cleaning
// ----------------------------------------------------------------------------
gulp.task("clean:all", function () {
return gulp
.src([
"app/css-dist",
"app/js-dist"
], { read: false })
.pipe(rimraf());
});
gulp.task("clean:dist", function () {
return gulp
.src([
"app/css-dist",
"app/js-dist"
], { read: false })
.pipe(rimraf());
});
gulp.task("build:dev", function (done) {
webpack(buildDevCfg).run(function (err, stats) {
if (err) { throw new gutil.PluginError("webpack", err); }
gutil.log("[webpack]", stats.toString({
hash: true,
colors: true,
cached: false
}));
done();
});
});
gulp.task("watch:dev", function () {
gulp.watch([
"client/**/*.{js,jsx}"
], ["build:dev"]);
});
gulp.task("watch", ["watch:dev"]);
// ----------------------------------------------------------------------------
// Production
// ----------------------------------------------------------------------------
gulp.task("build:prod", function (done) {
webpack(buildCfg).run(function (err, stats) {
if (err) { throw new gutil.PluginError("webpack", err); }
gutil.log("[webpack]", stats.toString({
hash: true,
colors: true,
cached: false
}));
done();
});
});
gulp.task("build:prod-full", ["clean:dist"], function () {
return gulp.run("build:prod");
});
gulp.task("watch:prod", function () {
gulp.watch([
"client/**/*.{js,jsx}"
], ["build:prod"]);
});
// ----------------------------------------------------------------------------
// Servers
// ----------------------------------------------------------------------------
// Dev. server
gulp.task("server", function () {
nodemon({
script: "server/index.js",
ext: "js,jsx",
watch: [
"server",
"client"
]
});
});
// Hot reload webpack server
gulp.task("webpack-server", shell.task(["node ./hot/server"]));
// Source maps server
gulp.task("server:sources", function () {
connect.server({
root: __dirname,
port: 3001
});
});
// ----------------------------------------------------------------------------
// Aggregations
// ----------------------------------------------------------------------------
gulp.task("ls", ["build:ls", "watch:ls", "server:sources"]);
gulp.task("dev", ["build:dev", "watch:dev", "server", "server:sources"]);
gulp.task("hot", ["webpack-server"]);
gulp.task("prod", ["build:prod", "watch:prod", "server", "server:sources"]);
gulp.task("build", ["build:prod-full"]);
gulp.task("default", ["build:dev", "check"]);