-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
50 lines (41 loc) · 1.09 KB
/
server.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
const path = require('path');
const sources = {};
const shaderFileRegex = /\.shader\.js$/i;
module.exports.updateShaderSource = function (file, opt) {
sources[file] = opt;
};
module.exports.isShaderReload = function (deps) {
return deps.length > 0 && deps.every(dep => shaderFileRegex.test(dep));
};
module.exports.isShaderError = function (err) {
return err.filename && shaderFileRegex.test(err.filename);
};
module.exports.getErrorEvent = function (error) {
return {
event: 'shader-error',
error: error.message
};
};
module.exports.getEvent = function (deps, cwd) {
cwd = cwd || process.cwd();
// Use the same format as "__filename" in the browser
const files = deps.map(dep => {
return path.join(path.sep, path.relative(process.cwd(), dep));
});
const updates = getUpdates(files);
return {
event: 'shader-reload',
updates: updates
};
};
function getUpdates (files) {
return files.map(file => {
if (file in sources) {
return Object.assign({}, sources[file], {
file
});
} else {
return null;
}
}).filter(Boolean);
}