var gutil = require('gulp-util'); var through = require('through2'); /** * The parameters for this function has grown during development. * Eventually, this function will need to be reorganized. */ // subModule, extendsRoot, externalUsingBabylon, noBabylonInit module.exports = function (varName, config) { return through.obj(function (file, enc, cb) { var extendsAddition = `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)}}(); `; 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}; `; if (file.isNull()) { cb(null, file); return; } if (file.isStream()) { //streams not supported, no need for now. return; } try { file.contents = Buffer.from(decorateAddition.concat(extendsAddition).concat(file.contents)); this.push(file); } catch (err) { this.emit('error', new gutil.PluginError('gulp-decorate-and-extends', err, { fileName: file.path })); } cb(); }); };