gulp-shaders.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var through = require('through');
  2. var gutil = require('gulp-util');
  3. var PluginError = gutil.PluginError;
  4. var File = gutil.File;
  5. var path = require('path');
  6. var shaders = function shaders() {
  7. var firstFile = null;
  8. var content = {};
  9. function bufferContents(file){
  10. if (file.isNull()) return; // ignore
  11. if (file.isStream()) return this.emit('error', new PluginError('gulp-shaders', 'Streaming not supported'));
  12. if (!firstFile) firstFile = file;
  13. var fileName = file.path
  14. .replace(file.base, '')
  15. .replace('.fragment', 'Pixel')
  16. .replace('.vertex', 'Vertex')
  17. .replace('.fx', 'Shader');
  18. content[fileName] = file.contents.toString('utf8').substring(1); //stript the BOM character
  19. }
  20. function endStream(){
  21. var joinedPath = path.join(firstFile.base, 'shaders.js');
  22. var joinedFile = new File({
  23. cwd: firstFile.cwd,
  24. base: firstFile.base,
  25. path: joinedPath,
  26. contents: new Buffer('BABYLON.Effect.ShadersStore='+JSON.stringify(content)+';')
  27. });
  28. this.emit('data', joinedFile);
  29. this.emit('end');
  30. }
  31. return through(bufferContents, endStream);
  32. }
  33. module.exports = shaders;