copyFile.js 797 B

12345678910111213141516171819202122232425262728
  1. const fsN = require("fs");
  2. const path = require("path");
  3. const mkdirp = require("mkdirp");
  4. module.exports = function(input, options) {
  5. return new Promise(function(resolve, reject) {
  6. Promise.all(
  7. input.currentJob.files.map(file => {
  8. return new Promise(function(resolve, reject) {
  9. const outputPath = path.join(options.outputDir, file.outputPath);
  10. mkdirp(path.dirname(outputPath), function(err) {
  11. if (err) {
  12. reject(err);
  13. }
  14. fsN.copyFile(file.path, outputPath, function(err) {
  15. if (err) {
  16. reject(err);
  17. }
  18. resolve(file);
  19. });
  20. });
  21. });
  22. })
  23. )
  24. .then(res => resolve(input))
  25. .catch(err => reject(err));
  26. });
  27. };