gulp-addDtsExport.js 736 B

1234567891011121314151617181920212223242526272829
  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 = '\nexport = ' + varName + ';\n';
  6. if (file.isNull()) {
  7. cb(null, file);
  8. return;
  9. }
  10. if (file.isStream()) {
  11. //streams not supported, no need for now.
  12. return;
  13. }
  14. try {
  15. file.contents = new Buffer(String(file.contents) + moduleExportsAddition);
  16. this.push(file);
  17. } catch (err) {
  18. this.emit('error', new gutil.PluginError('gulp-add-module-exports', err, { fileName: file.path }));
  19. }
  20. cb();
  21. });
  22. };