refactor(rest) currify -> wraptile

This commit is contained in:
coderaiser 2018-05-04 16:01:25 +03:00
parent d54ba5e25f
commit fe00e26cc7
2 changed files with 16 additions and 13 deletions

View file

@ -12,7 +12,7 @@ const markdown = require(DIR + 'markdown');
const jaguar = require('jaguar');
const onezip = require('onezip');
const inly = require('inly');
const currify = require('currify/legacy');
const wraptile = require('wraptile/legacy');
const pullout = require('pullout/legacy');
const json = require('jonny/legacy');
const ponse = require('ponse');
@ -21,7 +21,7 @@ const check = require('checkup');
const moveFiles = require('./move-files');
const swap = currify((fn, a, b) => fn(b, a));
const swap = wraptile((fn, a, b) => fn(b, a));
const isWin32 = process.platform === 'win32';
/**

View file

@ -2,39 +2,42 @@
const path = require('path');
const flop = require('flop');
const check = require('checkup');
const promisify = require('es6-promisify').promisify;
const move = promisify(flop.move);
module.exports = (files, callback) => {
check(files, callback);
if (!files.names)
return move(files.from, files.to)
.then(callback)
.catch(callback);
const names = files.names.slice();
const copy = () => {
const iterate = () => {
const isLast = !names.length;
if (isLast)
return callback(null);
return callback();
const name = names.shift();
const from = path.join(files.from, name);
const to = path.join(files.to, name);
move(from, to)
.then(copy)
.then(iterate)
.catch(callback);
};
check
.type('callback', callback, 'function')
.check({
files,
});
copy();
iterate();
};
function check(files, callback) {
if (typeof files !== 'object')
throw Error('files should be an object!');
if (typeof callback !== 'function')
throw Error('callback should be a function!');
}