feature(cloudcmd) IO.mv -> IO.move

This commit is contained in:
coderaiser 2020-08-14 15:58:35 +03:00
parent b081dc8b18
commit 13307f3861
11 changed files with 65 additions and 15 deletions

View file

@ -6,6 +6,7 @@ docker
docker-compose.yml
test
fixture
fixture-*
coverage
css
html

View file

@ -1,4 +1,7 @@
{
"ignore": [
"fixture*"
],
"match": {
"server": {
"remove-process-exit": true

View file

@ -87,11 +87,15 @@ module.exports.extract = async (data) => {
});
};
module.exports.mv = async (data) => {
module.exports.move = async (from, to, names) => {
return await sendRequest({
method: 'PUT',
url: '/mv',
data,
url: '/move',
data: {
from,
to,
names,
},
imgPosition,
});
};

View file

@ -29,7 +29,7 @@ module.exports.read = handleError(IO.read);
module.exports.cp = handleError(IO.cp);
module.exports.pack = handleError(IO.pack);
module.exports.extract = handleError(IO.extract);
module.exports.mv = handleError(IO.mv);
module.exports.move = handleError(IO.move);
module.exports.rename = handleError(IO.rename);
module.exports.Config = {

View file

@ -109,6 +109,7 @@
"@cloudcmd/fileop": "^4.0.0",
"@cloudcmd/move-files": "^3.0.0",
"@cloudcmd/read-files-sync": "^2.0.0",
"@putout/plugin-cloudcmd": "^1.0.0",
"apart": "^2.0.0",
"chalk": "^4.0.0",
"compression": "^1.7.4",

View file

@ -0,0 +1,2 @@
'use strict';
await IO.move(dirPath, mp3Dir, mp3Names);

View file

@ -0,0 +1,5 @@
await IO.mv({
from: dirPath,
to: mp3Dir,
names: mp3Names,
});

View file

@ -191,7 +191,7 @@ function onPUT({name, config, body}, callback) {
const rootDir = config('root');
switch(cmd) {
case 'mv': {
case 'move': {
const {
from,
to,

View file

@ -101,6 +101,7 @@ function transpile(source) {
plugins: [
'convert-esm-to-commonjs',
'strict-mode',
'cloudcmd',
],
});
}

View file

@ -6,12 +6,23 @@ const {join} = require('path');
const test = require('supertape');
const serveOnce = require('serve-once');
const threadIt = require('thread-it');
const stub = require('@cloudcmd/stub');
const {reRequire} = require('mock-require');
const userMenu = require('./user-menu');
const {request} = serveOnce(userMenu);
const {readFileSync} = fs;
const userMenuPath = join(__dirname, '..', '.cloudcmd.menu.js');
const userMenuFile = fs.readFileSync(userMenuPath, 'utf8');
const userMenuFile = readFileSync(userMenuPath, 'utf8');
const fixtureDir = join(__dirname, 'fixture-user-menu');
const fixtureMoveName = join(fixtureDir, 'io-mv.js');
const fixtureMoveFixName = join(fixtureDir, 'io-mv-fix.js');
const fixtureMove = readFileSync(fixtureMoveName, 'utf8');
const fixtureMoveFix = readFileSync(fixtureMoveFixName, 'utf8');
test('cloudcmd: user menu', async (t) => {
const options = {
@ -28,3 +39,25 @@ test('cloudcmd: user menu', async (t) => {
t.end();
});
test.only('cloudcmd: user menu: io.mv', async (t) => {
const options = {
menuName: '.cloudcmd.menu.js',
};
const {readFile} = fs.promises;
fs.promises.readFile = stub().returns(fixtureMove);
const userMenu = reRequire('./user-menu');
const {request} = serveOnce(userMenu);
const {body} = await request.get(`/api/v1/user-menu?dir=${__dirname}`, {
options,
});
threadIt.terminate();
fs.promises.readFile = readFile;
t.equal(fixtureMoveFix, body, 'should equal');
t.end();
});

View file

@ -16,9 +16,9 @@ const restPath = dir + 'rest';
const {assign} = Object;
test('cloudcmd: rest: mv', async (t) => {
test('cloudcmd: rest: move', async (t) => {
const volume = {
'/fixture/mv.txt': 'hello',
'/fixture/move.txt': 'hello',
'/fixture/tmp/a.txt': 'a',
};
@ -52,21 +52,21 @@ test('cloudcmd: rest: mv', async (t) => {
from: '/fixture/',
to: '/fixture/tmp/',
names: [
'mv.txt',
'move.txt',
],
};
const {body} = await request.put(`/api/v1/mv`, {
const {body} = await request.put(`/api/v1/move`, {
body: files,
});
mockRequire.stop('fs');
t.equal(body, 'move: ok("["mv.txt"]")', 'should move');
t.equal(body, 'move: ok("["move.txt"]")', 'should move');
t.end();
});
test('cloudcmd: rest: mv: no from', async (t) => {
test('cloudcmd: rest: move: no from', async (t) => {
const cloudcmd = reRequire(cloudcmdPath);
const {createConfigManager} = cloudcmd;
@ -80,7 +80,7 @@ test('cloudcmd: rest: mv: no from', async (t) => {
const files = {};
const {body} = await request.put(`/api/v1/mv`, {
const {body} = await request.put(`/api/v1/move`, {
body: files,
});
@ -90,7 +90,7 @@ test('cloudcmd: rest: mv: no from', async (t) => {
t.end();
});
test('cloudcmd: rest: mv: no to', async (t) => {
test('cloudcmd: rest: move: no to', async (t) => {
const cloudcmd = reRequire(cloudcmdPath);
const {createConfigManager} = cloudcmd;
@ -106,7 +106,7 @@ test('cloudcmd: rest: mv: no to', async (t) => {
from: '/',
};
const {body} = await request.put(`/api/v1/mv`, {
const {body} = await request.put(`/api/v1/move`, {
body: files,
});