index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. var pumpify = require('pumpify');
  3. var lead = require('lead');
  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 linkFile = require('./link-file');
  9. var folderConfig = {
  10. outFolder: {
  11. type: 'string',
  12. },
  13. };
  14. function symlink(outFolder, opt) {
  15. if (!outFolder) {
  16. throw new Error('Invalid symlink() folder argument.' +
  17. ' Please specify a non-empty string or a function.');
  18. }
  19. var optResolver = createResolver(config, opt);
  20. var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
  21. function dirpath(file, callback) {
  22. var dirMode = optResolver.resolve('dirMode', file);
  23. callback(null, file.dirname, dirMode);
  24. }
  25. var stream = pumpify.obj(
  26. prepare(folderResolver, optResolver),
  27. mkdirpStream.obj(dirpath),
  28. linkFile(optResolver)
  29. );
  30. // Sink the stream to start flowing
  31. return lead(stream);
  32. }
  33. module.exports = symlink;