-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (89 loc) · 2.93 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
const gulp = require('gulp');
const child_process = require('child_process');
const fs = require('fs');
const browsersync = require('browser-sync');
gulp.task('build',()=>{
mergeShader();
build();
// child_process.exec('tsc',(error,stdout,stderr)=>{
// if(stdout != null && stdout != '') console.log(stdout);
// if(stderr != null && stderr != '') console.log(stderr);
// });
});
gulp.task('watch',()=>{
mergeShader();
build();
gulp.watch('./src/**/*.ts',null,()=>{
build();
});
child_process.exec('tsc --module esnext -w',(error,stdout,stderr)=>{
if(stdout != null && stdout != '') console.log(stdout);
if(stderr != null && stderr != '') console.log(stderr);
});
gulp.watch('./res/shaders/**/*.glsl',null,()=>{
mergeShader();
});
browsersync.init({
server: {
baseDir: './',
middleware: function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
}
},
port: 6644,
files: ['./res/*.js', './*.html']
})
})
var onBuild =false;
function build(){
if(onBuild == true) return;
onBuild = true;
console.log('[Compile Script]');
//--emitDeclarationOnly
//tsc &&
child_process.exec('rollup -c rollup.config.ts',(error,stdout,stderr)=>{
if(stdout != null && stdout != '') console.log(stdout);
if(stderr != null && stderr != '') console.log(stderr);
onBuild = false;
console.log('[build done]');
});
}
gulp.task('shader',mergeShader)
function mergeShader(){
console.log('[Compile Shader]');
let basepath = './res/shaders/';
let files = fs.readdirSync(basepath);
let sources = {};
files.forEach(f=>{
let sta =fs.statSync(basepath + f);
if(sta.isFile && f.endsWith('.glsl')){
let fname = f.substr(0,f.length - 5);
fname = fname.replace('.','_');
let src = fs.readFileSync(basepath + f).toString();
src= src.replace('\n',"\\n");
sources[fname] =src;
}
})
let includepath = basepath +'includes/';
let fileIncludes = fs.readdirSync(includepath);
let includes = {};
fileIncludes.forEach(f=>{
let sta = fs.statSync(includepath + f);
if(sta.isFile && f.endsWith('.inc.glsl')){
let fname = f.substr(0,f.length - '.inc.glsl'.length);
fname = fname.toUpperCase();
let src = fs.readFileSync(includepath + f).toString();
includes[fname] = src;
}
})
let shadergen = 'export class ShaderGen{ \n';
for(k in includes){
shadergen += `\tpublic static readonly ${k}:string = \`${includes[k]}\`;\n`;
}
for(k in sources){
shadergen += `\tpublic static readonly ${k}:string = \`${sources[k]}\`;\n`;
}
shadergen += '}'
fs.writeFileSync('src/shaderfx/ShaderGenerated.ts',shadergen);
}