forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-shaders.js
More file actions
58 lines (44 loc) · 1.22 KB
/
bundle-shaders.js
File metadata and controls
58 lines (44 loc) · 1.22 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
let fs = require('fs-extra');
/*
BitmapMask.frag
BitmapMask.vert
DeferredDiffuse.frag
DeferredDiffuse.vert
ForwardDiffuse.frag
GBuffer.frag
TextureTint.frag
TextureTint.vert
*/
let srcdir = './src/renderer/webgl/shaders/src/';
let destdir = './src/renderer/webgl/shaders/';
let files = fs.readdirSync(srcdir);
files.forEach(function (file) {
let shaderSource = fs.readFileSync(srcdir + file, 'utf8');
let type = file.substr(-4);
let shaderFilename = file.substr(0, file.lastIndexOf('.')) + '-' + type + '.js';
let outputSource = 'module.exports = [\n';
let lines = shaderSource.split('\n');
for (var i = 0; i < lines.length; i++)
{
let line = lines[i].trimRight();
if (i < lines.length - 1)
{
outputSource = outputSource.concat(" '" + line + "',\n");
}
else
{
outputSource = outputSource.concat(" '" + line + "'\n");
}
}
outputSource = outputSource.concat('].join(\'\\n\');\n');
fs.writeFile(destdir + shaderFilename, outputSource, function (error) {
if (error)
{
throw error;
}
else
{
console.log('Saved', shaderFilename);
}
});
});