-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
127 lines (115 loc) · 3.44 KB
/
gulpfile.js
File metadata and controls
127 lines (115 loc) · 3.44 KB
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
const { dest, parallel, series, src, watch } = require('gulp');
const PluginError = require('plugin-error');
const webpack = require('webpack');
const webpackConfig = require('./config/webpack.config.js');
const webpackRoomsConfig = require('./config/webpack.rooms.config.js');
const webpackConfigDev = require('./config/webpack-dev.config.js');
const webpackRoomsConfigDev = require('./config/webpack-dev.rooms.config.js');
const del = require('del');
const { spawn } = require('child_process');
let node;
// Ensure all processing stops on Ctrl-C
process.once('SIGINT', function () {
process.exit(0);
});
function vendor() {
return src([
'./node_modules/three/build/three.min.js',
'./node_modules/stats.js/build/stats.min.js',
'./node_modules/three/examples/js/loaders/OBJLoader.js',
'./node_modules/webvr-polyfill/build/webvr-polyfill.js',
'./node_modules/webrtc-adapter/out/adapter.js'
], { buffer: true })
.pipe(dest('dist/vendor'));
}
function staticClient() {
return src(['client/static/**/*'], { buffer: true })
.pipe(dest('dist'));
}
function webpackClient(callback) {
webpack(webpackConfig,
function(err, stats) {
if(err) throw new PluginError('webpack', err);
console.log('[webpack]', stats.toString({
chunks: false,
color: true
}));
callback();
}
);
}
function webpackRooms(callback) {
webpack(webpackRoomsConfig,
function(err, stats) {
if(err) throw new PluginError('webpack', err);
console.log('[webpack rooms]', stats.toString({
chunks: false,
color: true
}));
callback();
}
);
}
async function webpackDev() {
const compiler = webpack(webpackConfigDev);
compiler.watch({
aggregateTimeout: 300
},function(err, stats) {
if(err) throw new PluginError('webpack', err);
console.log('[webpack]', stats.toString({
chunks: false,
color: true
}));
});
}
async function webpackRoomsDev() {
const compiler = webpack(webpackRoomsConfigDev);
compiler.watch({
aggregateTimeout: 300
}, function(err, stats) {
if(err) throw new PluginError('webpack', err);
console.log('[webpack rooms]', stats.toString({
chunks: false,
color: true
}));
});
}
const watchClient = parallel(vendor, staticClient, webpackDev, webpackRoomsDev, function watchStaticClient() {
watch('client/static/**/*', function(callback) {
staticClient();
callback();
});
});
function watchServer() {
startServer();
watch('server/**/*.js', function(callback) {
console.log('Reloading server...');
startServer();
callback();
})
}
function startServer() {
if(node) {
node.kill();
}
node = spawn('node', ['server/index.js'], {
stdio: 'inherit',
env: {
PATH: process.env.PATH,
NODE_ENV: 'development'
}
});
node.on('close', function (code) {
if (code === 8) {
console.log('Error with server, waiting...');
}
});
}
exports.clean = function() {
return del([
'dist/**',
'node_modules/**'
]);
}
exports.dev = parallel(watchClient, watchServer);
exports.default = series(vendor, staticClient, webpackClient, webpackRooms);