gulp-decorateAndExtends.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var gutil = require('gulp-util');
  2. var through = require('through2');
  3. /**
  4. * The parameters for this function has grown during development.
  5. * Eventually, this function will need to be reorganized.
  6. */
  7. // subModule, extendsRoot, externalUsingBabylon, noBabylonInit
  8. module.exports = function (varName, config) {
  9. return through.obj(function (file, enc, cb) {
  10. var extendsAddition =
  11. `var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  12. `;
  13. var decorateAddition = `var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  14. `;
  15. if (file.isNull()) {
  16. cb(null, file);
  17. return;
  18. }
  19. if (file.isStream()) {
  20. //streams not supported, no need for now.
  21. return;
  22. }
  23. try {
  24. file.contents = Buffer.from(decorateAddition.concat(extendsAddition).concat(file.contents));
  25. this.push(file);
  26. } catch (err) {
  27. this.emit('error', new gutil.PluginError('gulp-decorate-and-extends', err, { fileName: file.path }));
  28. }
  29. cb();
  30. });
  31. };