-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
33 lines (30 loc) · 939 Bytes
/
gulpfile.babel.js
File metadata and controls
33 lines (30 loc) · 939 Bytes
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
import fs from 'fs';
import gulp from 'gulp';
import glob from 'glob';
import watch from 'gulp-watch';
gulp.task('build-shader-chunks', () => {
fs.writeFile('./src/shaders/chunks.js',
`// This file is autogenerated.
module.exports = {
${
glob.sync('./src/shaders/lib/chunks/**/*.vert')
.map(filename => filename.replace(/.*(lib\/chunks(.*)\/([aA-zZ]*)\..*)/, ' v_$3: require(\'./$1\'),'))
.join('\n')
}
${
glob.sync('./src/shaders/lib/chunks/**/*.frag')
.map(filename => filename.replace(/.*(lib\/chunks(.*)\/([aA-zZ]*)\..*)/, ' f_$3: require(\'./$1\'),'))
.join('\n').slice(0, -1)
}
};
`,
() => {
console.log('build-shader-chunks: done!');
}
);
});
gulp.task('watch-shader-chunks', () => {
const watcher = watch('./src/shaders/lib/chunks/**/*.{frag,vert}');
watcher.on('add', () => gulp.start('build-shader-chunks'));
watcher.on('unlink', () => gulp.start('build-shader-chunks'));
});