-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
147 lines (128 loc) · 3.91 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
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const eslint = require('gulp-eslint');
const livereload = require('gulp-livereload');
const concat = require('gulp-concat');
const sass = require('gulp-sass');
const webpack = require('webpack-stream');
const babel = require('gulp-babel');
const Jasmine = require('jasmine');
const config = {
sassPath: 'src/styles/**/*.scss',
cssDestDir: 'public/css',
jsClientEntry: 'src/client/index.jsx',
jsClientDependencies: 'src/client/lib/**/*.js',
jsPath: 'src/**/*.js',
jsDependPath: 'src/client/lib/**/*.js',
jsDestDir: 'public/js',
jsSpecPath: 'src/**/*[sS]pec.js',
clientJsPath: [
'src/client/**/*.js',
'src/client/**/*.jsx',
'!src/**/*.spec.js'
],
sharedJsPath: 'src/shared/**/*.js',
serverJsPath: ['src/server/**/*.js', 'src/client/game/**/*.js'],
serverJsEntry: 'src/server/index.js',
serverJsDestDir: './'
};
const webpackConfig = {
output: {
path: __dirname + config.jsDestDir,
filename: 'build.js'
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
}
};
gulp.task('testDev', ['test'], function() {
// Watch for changes in the test files and test accordingly.
gulp.watch([config.jsSpecPath], ['test']);
});
gulp.task('test', function() {
const jasmine = new Jasmine();
jasmine.loadConfig({
spec_dir: '/',
spec_files: [
config.jsSpecPath,
],
helpers: [
'helpers/**/*.js'
]
});
// Run the jasmine tests (Tests all files that end in [sS]pec.js).
jasmine.execute();
});
gulp.task('dev', function() {
gulp.watch([config.jsPath, 'index.jsx', 'gulpfile.js' /* That's me! */], ['lint']);
// Watch for clientside changes and run building tasks.
gulp.watch([config.clientJsPath, config.sharedJsPath], ['js']);
// Watch for changes in the dependencies for clientside and build accordingly.
gulp.watch([config.jsDependPath], ['jsClientDependencies']);
gulp.watch([config.sassPath],['style']);
// Watch for any changes on public files and live reload.
gulp.watch('public/**', function(file) {
livereload.changed(file.path);
});
});
// JSLint
gulp.task('lint', function () {
gulp.src([
'**/*.js',
'**/*.jsx',
'!node_modules/**' /* Ignore modules. */,
'!**/lib/**' /* Ignore external libraries. */,
'!public/**' /* Ignore built files. */
])
// 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());
});
// SASS -> CSS
gulp.task('style', function() {
gulp.src([config.sassPath])
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(config.cssDestDir));
});
gulp.task('jsClientDependencies', function() {
// First build in the dependencies.
gulp.src(config.jsClientDependencies)
.pipe(concat('dependencies.js'))
.pipe(gulp.dest(config.jsDestDir));
});
// Build the js using webpack and pipe it into a build.js file in the public folder.
gulp.task('js', function() {
// Build in the client code starting from the entry point.
gulp.src(config.jsClientEntry)
.pipe(webpack(webpackConfig))
.on('error', function handleError() {
this.emit('end'); // Recover from errors.
})
.pipe(concat('build.js'))
.pipe(gulp.dest(config.jsDestDir));
});
gulp.task('server', function() {
// Watch for changes in server code and restart the server.
nodemon({
script: 'index.js',
ext: 'js html',
watch: [config.serverJsPath, config.sharedJsPath]
})
.on('restart', function() {
setTimeout(function() {
livereload.reload();
}, 1000);
});
});
gulp.task('default', ['js', 'dev', 'server', 'style', 'jsClientDependencies']);