index.js 568 B

12345678910111213141516171819202122
  1. var path = require('path');
  2. var through2 = require('through2');
  3. var flattenPath = require('./lib/flatten-path');
  4. var PluginError = require('plugin-error');
  5. module.exports = function(opts) {
  6. opts = opts || {};
  7. opts.newPath = opts.newPath || '';
  8. return through2.obj(function(file, enc, next) {
  9. if (!file.isDirectory()) {
  10. try {
  11. file.path = path.join(file.base, opts.newPath, flattenPath(file, opts));
  12. this.push(file);
  13. } catch (e) {
  14. this.emit('error', new PluginError('gulp-flatten', e));
  15. }
  16. }
  17. next();
  18. });
  19. };