index.js 593 B

1234567891011121314151617181920212223242526272829303132
  1. var through2 = require('through2')
  2. var File = require('vinyl')
  3. var path = require('path')
  4. module.exports = function (filename, baseDir) {
  5. var ins = through2()
  6. var out = false
  7. var opts = {
  8. contents: ins
  9. }
  10. if (filename) opts.path = path.resolve(baseDir || process.cwd(), filename)
  11. if (baseDir) opts.base = baseDir
  12. var file = new File(opts)
  13. return through2({
  14. objectMode: true
  15. }, function(chunk, enc, next) {
  16. if (!out) {
  17. this.push(file)
  18. out = true
  19. }
  20. ins.push(chunk)
  21. next()
  22. }, function() {
  23. ins.push(null)
  24. this.push(null)
  25. })
  26. }