Created
July 13, 2016 06:35
-
-
Save YurySolovyov/b38c3b5422278cce1072b9e5bff83894 to your computer and use it in GitHub Desktop.
progressive-copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const copier = require('./index'); | |
copier('d:/Projects/streams/', 'd:/foo').then(function(res) { | |
console.log(res); | |
}).catch(function(e) { | |
console.log(e); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const Promise = require('bluebird'); | |
const minimatch = require('minimatch'); | |
const fs = Promise.promisifyAll(require('fs')); | |
const globby = require('globby'); | |
const mkdirp = Promise.promisify(require('mkdirp')); | |
const getStructure = function(from) { | |
const fromPattern = path.normalize(from) + '**\\*'; | |
return globby(fromPattern, { mark: true }).then(function(items) { | |
return items.map(path.normalize).reduce(function(res, item) { | |
const isDir = minimatch(item, '**/'); | |
if (isDir) { | |
res.directories.push(item); | |
} else { | |
res.files.push(item); | |
} | |
return res; | |
}, { files: [], directories: [] }); | |
}); | |
}; | |
module.exports = function(from, to, options) { | |
return getStructure(from).then(function(structure) { | |
return { | |
files: structure.files.map(function(filePath) { | |
const subPath = filePath.replace(path.normalize(from), ''); | |
return path.join(to, subPath); | |
}), | |
directories: structure.directories.map(function(dirPath) { | |
const subPath = dirPath.replace(path.normalize(from), ''); | |
return path.join(to, subPath); | |
}) | |
}; | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "progressive-copy", | |
"version": "0.1.0", | |
"description": "Copies files. And folders. Shows Progress", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [ | |
"copy", | |
"file", | |
"folder", | |
"directory", | |
"progress", | |
"promise" | |
], | |
"author": "YurySolovyov", | |
"license": "MIT", | |
"dependencies": { | |
"bluebird": "^3.4.1", | |
"globby": "^5.0.0", | |
"minimatch": "^3.0.2", | |
"mkdirp": "^0.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment