mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
refactor(rest) currify -> wraptile
This commit is contained in:
parent
d54ba5e25f
commit
fe00e26cc7
2 changed files with 16 additions and 13 deletions
|
|
@ -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';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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!');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue