index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var lead = require('lead');
  3. var pumpify = require('pumpify');
  4. var mkdirpStream = require('fs-mkdirp-stream');
  5. var createResolver = require('resolve-options');
  6. var config = require('./options');
  7. var prepare = require('./prepare');
  8. var sourcemap = require('./sourcemap');
  9. var writeContents = require('./write-contents');
  10. var folderConfig = {
  11. outFolder: {
  12. type: 'string',
  13. },
  14. };
  15. function dest(outFolder, opt) {
  16. if (!outFolder) {
  17. throw new Error('Invalid dest() folder argument.' +
  18. ' Please specify a non-empty string or a function.');
  19. }
  20. var optResolver = createResolver(config, opt);
  21. var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
  22. function dirpath(file, callback) {
  23. var dirMode = optResolver.resolve('dirMode', file);
  24. callback(null, file.dirname, dirMode);
  25. }
  26. var saveStream = pumpify.obj(
  27. prepare(folderResolver, optResolver),
  28. sourcemap(optResolver),
  29. mkdirpStream.obj(dirpath),
  30. writeContents(optResolver)
  31. );
  32. // Sink the output stream to start flowing
  33. return lead(saveStream);
  34. }
  35. module.exports = dest;