gulp-addDtsExport.js 804 B

1234567891011121314151617181920212223242526272829303132
  1. var gutil = require('gulp-util');
  2. var through = require('through2');
  3. module.exports = function (varName) {
  4. return through.obj(function (file, enc, cb) {
  5. var moduleExportsAddition =
  6. 'export = ' + varName + ';\n' +
  7. 'export as namespace ' + varName + ';\n\n';
  8. if (file.isNull()) {
  9. cb(null, file);
  10. return;
  11. }
  12. if (file.isStream()) {
  13. //streams not supported, no need for now.
  14. return;
  15. }
  16. try {
  17. file.contents = new Buffer(moduleExportsAddition + String(file.contents));
  18. this.push(file);
  19. } catch (err) {
  20. this.emit('error', new gutil.PluginError('gulp-add-module-exports', err, { fileName: file.path }));
  21. }
  22. cb();
  23. });
  24. };