mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 10:14:13 +00:00
chore: lint
This commit is contained in:
parent
f1279666b5
commit
4717e035ee
173 changed files with 1388 additions and 1627 deletions
|
|
@ -20,7 +20,8 @@ function _middle(config, authentication, req, res, next) {
|
|||
if (!is)
|
||||
return next();
|
||||
|
||||
const success = () => next(/* success */);
|
||||
const success = () => next();
|
||||
|
||||
return authentication.check(success)(req, res);
|
||||
}
|
||||
|
||||
|
|
@ -38,4 +39,3 @@ function _check(config, username, password, callback) {
|
|||
|
||||
callback(sameName && samePass);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ const fs = require('fs');
|
|||
const cloudfunc = require(`${DIR_COMMON}cloudfunc`);
|
||||
|
||||
const authentication = require(`${DIR}auth`);
|
||||
const {
|
||||
createConfig,
|
||||
configPath,
|
||||
} = require(`${DIR}config`);
|
||||
const {createConfig, configPath} = require(`${DIR}config`);
|
||||
|
||||
const modulas = require(`${DIR}modulas`);
|
||||
|
||||
const userMenu = require(`${DIR}user-menu`);
|
||||
|
|
@ -111,7 +109,7 @@ module.exports._getPrefix = getPrefix;
|
|||
function getPrefix(prefix) {
|
||||
if (isFn(prefix))
|
||||
return prefix() || '';
|
||||
|
||||
|
||||
return prefix || '';
|
||||
}
|
||||
|
||||
|
|
@ -194,9 +192,7 @@ function cloudcmd({modules, config}) {
|
|||
config('console') && konsole({
|
||||
online,
|
||||
}),
|
||||
|
||||
config('terminal') && terminal(config, {}),
|
||||
|
||||
edward({
|
||||
root,
|
||||
online,
|
||||
|
|
@ -205,7 +201,6 @@ function cloudcmd({modules, config}) {
|
|||
dropbox,
|
||||
dropboxToken,
|
||||
}),
|
||||
|
||||
dword({
|
||||
root,
|
||||
online,
|
||||
|
|
@ -214,7 +209,6 @@ function cloudcmd({modules, config}) {
|
|||
dropbox,
|
||||
dropboxToken,
|
||||
}),
|
||||
|
||||
deepword({
|
||||
root,
|
||||
online,
|
||||
|
|
@ -223,38 +217,30 @@ function cloudcmd({modules, config}) {
|
|||
dropbox,
|
||||
dropboxToken,
|
||||
}),
|
||||
|
||||
fileop(),
|
||||
nomine(),
|
||||
|
||||
setUrl,
|
||||
setSW,
|
||||
logout,
|
||||
authentication(config),
|
||||
config.middle,
|
||||
|
||||
modules && modulas(modules),
|
||||
|
||||
config('dropbox') && restbox({
|
||||
prefix: cloudfunc.apiURL,
|
||||
root,
|
||||
token: dropboxToken,
|
||||
}),
|
||||
|
||||
restafary({
|
||||
prefix: cloudfunc.apiURL + '/fs',
|
||||
root,
|
||||
}),
|
||||
|
||||
userMenu({
|
||||
menuName: '.cloudcmd.menu.js',
|
||||
}),
|
||||
|
||||
rest(config),
|
||||
route(config, {
|
||||
html,
|
||||
}),
|
||||
|
||||
ponseStatic,
|
||||
]);
|
||||
|
||||
|
|
@ -272,7 +258,7 @@ module.exports._replaceDist = replaceDist;
|
|||
function replaceDist(url) {
|
||||
if (!isDev)
|
||||
return url;
|
||||
|
||||
|
||||
return url.replace(/^\/dist\//, '/dist-dev/');
|
||||
}
|
||||
|
||||
|
|
@ -294,4 +280,3 @@ function setSW(req, res, next) {
|
|||
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const {reRequire} = require('mock-require');
|
||||
|
||||
const DIR = './';
|
||||
|
|
@ -78,6 +76,7 @@ test('cloudcmd: getPrefix: function: empty', (t) => {
|
|||
|
||||
test('cloudcmd: replaceDist', (t) => {
|
||||
const {NODE_ENV} = process.env;
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
const {_replaceDist} = reRequire(cloudcmdPath);
|
||||
|
|
@ -188,6 +187,7 @@ test('cloudcmd: sw', async (t) => {
|
|||
|
||||
function cleanNodeEnv() {
|
||||
const {NODE_ENV} = process.env;
|
||||
|
||||
process.env.NODE_ENV = '';
|
||||
|
||||
const reset = () => {
|
||||
|
|
@ -196,4 +196,3 @@ function cleanNodeEnv() {
|
|||
|
||||
return reset;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
|||
const dist = getDist(isDev);
|
||||
const columnsDir = path.join(__dirname, '..', dist, 'columns');
|
||||
|
||||
const names = fs.readdirSync(columnsDir)
|
||||
const names = fs
|
||||
.readdirSync(columnsDir)
|
||||
.filter(not(isMap));
|
||||
|
||||
const columns = readFilesSync(columnsDir, names, 'utf8');
|
||||
|
|
@ -26,4 +27,3 @@ module.exports = {
|
|||
...columns,
|
||||
...defaultColumns,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ const manageListen = currify((manage, socket, auth) => {
|
|||
function initWrite(filename, configManager) {
|
||||
if (filename)
|
||||
return write.bind(null, filename, configManager);
|
||||
|
||||
|
||||
return resolve;
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,9 @@ function createConfig({configPath} = {}) {
|
|||
}
|
||||
|
||||
const write = (filename, config) => {
|
||||
return writejson(filename, config('*'), {mode: 0o600});
|
||||
return writejson(filename, config('*'), {
|
||||
mode: 0o600,
|
||||
});
|
||||
};
|
||||
|
||||
function _connection(manage, socket) {
|
||||
|
|
@ -136,7 +138,8 @@ function _connection(manage, socket) {
|
|||
socket.emit('log', data);
|
||||
};
|
||||
|
||||
manage.write()
|
||||
manage
|
||||
.write()
|
||||
.then(send)
|
||||
.catch(emit(socket, 'err'));
|
||||
});
|
||||
|
|
@ -145,11 +148,12 @@ function _connection(manage, socket) {
|
|||
function listen(manage, sock, auth) {
|
||||
const prefix = manage('prefixSocket');
|
||||
|
||||
sock.of(`${prefix}/config`)
|
||||
sock
|
||||
.of(`${prefix}/config`)
|
||||
.on('connection', (socket) => {
|
||||
if (!manage('auth'))
|
||||
return connection(manage, socket);
|
||||
|
||||
|
||||
const reject = () => socket.emit('reject');
|
||||
socket.on('auth', auth(connectionWraped(manage, socket), reject));
|
||||
});
|
||||
|
|
@ -243,4 +247,3 @@ function cryptoPass(manage, json) {
|
|||
password,
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const root = '../';
|
||||
const configPath = './config';
|
||||
|
||||
const {
|
||||
createConfig,
|
||||
_cryptoPass,
|
||||
} = require(configPath);
|
||||
const {createConfig, _cryptoPass} = require(configPath);
|
||||
|
||||
const {apiURL} = require(`${root}common/cloudfunc`);
|
||||
|
||||
const fixture = require('./config.fixture');
|
||||
|
|
@ -29,7 +24,9 @@ test('config: manage: get', async (t) => {
|
|||
const configManager = createConfig();
|
||||
|
||||
const {done} = await connect({
|
||||
config: {editor},
|
||||
config: {
|
||||
editor,
|
||||
},
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
|
@ -45,7 +42,9 @@ test('config: manage: get: config', async (t) => {
|
|||
editor,
|
||||
};
|
||||
|
||||
const {done} = await connect({config: conf});
|
||||
const {done} = await connect({
|
||||
config: conf,
|
||||
});
|
||||
|
||||
config('editor', 'dword');
|
||||
done();
|
||||
|
|
@ -98,6 +97,7 @@ test('config: middle: no', (t) => {
|
|||
const res = null;
|
||||
const url = `${apiURL}/config`;
|
||||
const method = 'POST';
|
||||
|
||||
const req = {
|
||||
url,
|
||||
method,
|
||||
|
|
@ -108,4 +108,3 @@ test('config: middle: no', (t) => {
|
|||
t.ok(next.calledWith(), 'should call next');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -46,14 +46,12 @@ module.exports = (config, socket) => {
|
|||
const distributePrefix = `${prefix}/distribute`;
|
||||
const isLog = config('log');
|
||||
|
||||
const onError = squad(
|
||||
logWraped(isLog, exportStr),
|
||||
getMessage,
|
||||
);
|
||||
const onError = squad(logWraped(isLog, exportStr), getMessage);
|
||||
|
||||
const onConnectError = squad(logWraped(isLog, exportStr), getDescription);
|
||||
|
||||
socket.of(distributePrefix)
|
||||
socket
|
||||
.of(distributePrefix)
|
||||
.on('connection', onConnection(push, config))
|
||||
.on('error', onError)
|
||||
.on('connect_error', onConnectError);
|
||||
|
|
@ -90,7 +88,11 @@ const connectPush = wraptile((push, config, socket) => {
|
|||
const host = getHost(socket);
|
||||
const subscription = push(socket);
|
||||
|
||||
socket.on('disconnect', onDisconnect(subscription, config, host));
|
||||
socket.on('disconnect', onDisconnect(
|
||||
subscription,
|
||||
config,
|
||||
host,
|
||||
));
|
||||
|
||||
log(isLog, exportStr, `${connectedStr} to ${host}`);
|
||||
socket.emit('config', omitConfig(config('*')));
|
||||
|
|
@ -125,4 +127,3 @@ const onDisconnect = wraptile((subscription, config, host) => {
|
|||
config.unsubscribe(subscription);
|
||||
log(isLog, exportStr, `${disconnectedStr} from ${host}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -68,4 +68,3 @@ test('distribute: export: config', async (t) => {
|
|||
t.equal(typeof data, 'object', 'should emit object');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ const {entries} = Object;
|
|||
|
||||
const equal = (a, b) => `${a}=${b}`;
|
||||
const append = currify((obj, a, b) => obj.value += b && equal(a, b) + '&');
|
||||
|
||||
const wrapApply = (f, disconnect) => (status) => () => f(null, {
|
||||
status,
|
||||
disconnect,
|
||||
|
|
@ -85,6 +86,7 @@ module.exports = (config, options, fn) => {
|
|||
});
|
||||
|
||||
const url = `${importUrl}/distribute?${query}`;
|
||||
|
||||
const socket = io.connect(url, {
|
||||
...options,
|
||||
rejectUnauthorized: false,
|
||||
|
|
@ -97,48 +99,42 @@ module.exports = (config, options, fn) => {
|
|||
const statusStore = fullstore();
|
||||
const statusStoreWraped = wraptile(statusStore);
|
||||
|
||||
const onConfig = squad(
|
||||
close,
|
||||
logWraped(isLog, importStr, `config received from ${colorUrl}`),
|
||||
statusStoreWraped('received'),
|
||||
updateConfig(config),
|
||||
);
|
||||
const onConfig = squad(close, logWraped(isLog, importStr, `config received from ${colorUrl}`), statusStoreWraped('received'), updateConfig(config));
|
||||
|
||||
const onError = squad(
|
||||
superFn('error'),
|
||||
logWraped(isLog, config, importStr),
|
||||
addUrl(colorUrl),
|
||||
getMessage,
|
||||
);
|
||||
const onError = squad(superFn('error'), logWraped(isLog, config, importStr), addUrl(colorUrl), getMessage);
|
||||
|
||||
const onConnectError = squad(
|
||||
superFn('connect_error'),
|
||||
logWraped(isLog, importStr),
|
||||
addUrl(colorUrl),
|
||||
getDescription,
|
||||
);
|
||||
const onConnectError = squad(superFn('connect_error'), logWraped(isLog, importStr), addUrl(colorUrl), getDescription);
|
||||
|
||||
const onConnect = emitAuth(importUrl, config, socket);
|
||||
const onAccept = logWraped(isLog, importStr, `${connectedStr} to ${colorUrl}`);
|
||||
|
||||
const onDisconnect = squad(
|
||||
done(fn, statusStore),
|
||||
logWraped(isLog, importStr, `${disconnectedStr} from ${colorUrl}`),
|
||||
rmListeners(socket, {
|
||||
onError,
|
||||
onConnect,
|
||||
onConfig,
|
||||
}),
|
||||
done(
|
||||
fn,
|
||||
statusStore,
|
||||
),
|
||||
logWraped(
|
||||
isLog,
|
||||
importStr,
|
||||
`${disconnectedStr} from ${colorUrl}`,
|
||||
),
|
||||
rmListeners(
|
||||
socket,
|
||||
{
|
||||
onError,
|
||||
onConnect,
|
||||
onConfig,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const onChange = squad(
|
||||
logWraped(isLog, importStr),
|
||||
config,
|
||||
);
|
||||
const onChange = squad(logWraped(isLog, importStr), config);
|
||||
|
||||
const onReject = squad(
|
||||
superFn('reject'),
|
||||
logWraped(isLog, importStr, tokenRejectedStr),
|
||||
);
|
||||
const onReject = squad(superFn('reject'), logWraped(
|
||||
isLog,
|
||||
importStr,
|
||||
tokenRejectedStr,
|
||||
));
|
||||
|
||||
socket.on('connect', onConnect);
|
||||
socket.on('accept', onAccept);
|
||||
|
|
@ -165,4 +161,3 @@ function toLine(obj) {
|
|||
|
||||
return result.value.slice(start, backward * end);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,4 +39,3 @@ function crc(a) {
|
|||
.split('')
|
||||
.reduce(add, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,16 +8,16 @@ const up = (a) => a.toUpperCase();
|
|||
module.exports = parse;
|
||||
module.exports.bool = (name) => {
|
||||
const value = parse(name);
|
||||
|
||||
|
||||
if (value === 'true')
|
||||
return true;
|
||||
|
||||
|
||||
if (value === '1')
|
||||
return true;
|
||||
|
||||
|
||||
if (value === 'false')
|
||||
return false;
|
||||
|
||||
|
||||
if (value === '0')
|
||||
return false;
|
||||
};
|
||||
|
|
@ -28,4 +28,3 @@ function parse(name) {
|
|||
|
||||
return env[big] || env[small];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ test('cloudcmd: server: env: bool: number', (t) => {
|
|||
const result = env.bool('terminal');
|
||||
|
||||
process.env.CLOUDCMD_TERMINAL = cloudcmd_terminal;
|
||||
|
||||
|
||||
t.ok(result);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -51,7 +51,7 @@ test('cloudcmd: server: env: bool: number: 0', (t) => {
|
|||
const result = env.bool('terminal');
|
||||
|
||||
process.env.cloudcmd_terminal = cloudcmd_terminal;
|
||||
|
||||
|
||||
t.notOk(result);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,4 +8,3 @@ module.exports = (...args) => {
|
|||
console.error(...messages);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const exit = require('./exit');
|
||||
|
||||
test('cloudcmd: exit: process.exit', (t) => {
|
||||
const {exit: exitOriginal} = process;
|
||||
|
||||
process.exit = stub();
|
||||
|
||||
exit();
|
||||
|
|
@ -48,4 +47,3 @@ test('cloudcmd: exit.error: console.error: error', (t) => {
|
|||
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ const root = require('../root');
|
|||
const parse = threadIt(join(__dirname, 'worker'));
|
||||
|
||||
threadIt.init();
|
||||
|
||||
// warm up
|
||||
parse('');
|
||||
|
||||
|
|
@ -63,4 +62,3 @@ function check(name, request) {
|
|||
if (!request)
|
||||
throw Error('request could not be empty!');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ const cloudcmd = require('../..');
|
|||
const config = {
|
||||
auth: false,
|
||||
};
|
||||
|
||||
const configManager = cloudcmd.createConfigManager();
|
||||
|
||||
const {request} = require('serve-once')(cloudcmd, {
|
||||
config,
|
||||
configManager,
|
||||
|
|
@ -101,6 +103,7 @@ test('cloudcmd: markdown', async (t) => {
|
|||
config,
|
||||
configManager,
|
||||
});
|
||||
|
||||
const {body} = await request.get('/api/v1/markdown/markdown.md');
|
||||
|
||||
t.equal(body, '<h1>hello</h1>\n');
|
||||
|
|
@ -119,6 +122,7 @@ test('cloudcmd: markdown: zip', async (t) => {
|
|||
config,
|
||||
configManager,
|
||||
});
|
||||
|
||||
const {body} = await request.get('/api/v1/markdown/markdown.zip/markdown.md');
|
||||
|
||||
t.equal(body, '<h1>hello</h1>\n');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const markdownIt = require('markdown-it')();
|
||||
|
||||
module.exports = (a) => markdownIt.render(a);
|
||||
|
|
|
|||
|
|
@ -13,4 +13,3 @@ module.exports = (modules) => {
|
|||
res.send(result);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,4 +12,3 @@ module.exports = (value) => {
|
|||
|
||||
return value;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,23 +3,24 @@
|
|||
const net = require('net');
|
||||
const repl = require('repl');
|
||||
|
||||
module.exports = net.createServer((socket) => {
|
||||
const {pid} = process;
|
||||
const addr = socket.remoteAddress;
|
||||
const port = socket.remotePort;
|
||||
module.exports = net
|
||||
.createServer((socket) => {
|
||||
const {pid} = process;
|
||||
const addr = socket.remoteAddress;
|
||||
const port = socket.remotePort;
|
||||
|
||||
const r = repl.start({
|
||||
prompt: `[${pid} ${addr}:${port}>`,
|
||||
input: socket,
|
||||
output: socket,
|
||||
terminal: true,
|
||||
useGlobal: false,
|
||||
});
|
||||
const r = repl.start({
|
||||
prompt: `[${pid} ${addr}:${port}>`,
|
||||
input: socket,
|
||||
output: socket,
|
||||
terminal: true,
|
||||
useGlobal: false,
|
||||
});
|
||||
|
||||
r.on('exit', () => {
|
||||
socket.end();
|
||||
});
|
||||
r.on('exit', () => {
|
||||
socket.end();
|
||||
});
|
||||
|
||||
r.context.socket = socket;
|
||||
}).listen(1337);
|
||||
|
||||
r.context.socket = socket;
|
||||
})
|
||||
.listen(1337);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ const {apiURL} = CloudFunc;
|
|||
|
||||
const UserError = (msg) => {
|
||||
const error = Error(msg);
|
||||
|
||||
error.code = 'EUSER';
|
||||
|
||||
return error;
|
||||
|
|
@ -100,7 +101,8 @@ function sendData(params, config, callback) {
|
|||
return onGET(params, config, callback);
|
||||
|
||||
case 'PUT':
|
||||
return pullout(p.request)
|
||||
return pullout(p
|
||||
.request)
|
||||
.then((body) => {
|
||||
onPUT({
|
||||
name: p.name,
|
||||
|
|
@ -147,7 +149,7 @@ function onGET(params, config, callback) {
|
|||
function getPackReg(packer) {
|
||||
if (packer === 'zip')
|
||||
return /\.zip$/;
|
||||
|
||||
|
||||
return /\.tar\.gz$/;
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +157,7 @@ function streamPack(cmd, response, packer) {
|
|||
const noop = () => {};
|
||||
const filename = cmd.replace(getPackReg(packer), '');
|
||||
const dir = path.dirname(filename);
|
||||
|
||||
const names = [
|
||||
path.basename(filename),
|
||||
];
|
||||
|
|
@ -165,7 +168,7 @@ function streamPack(cmd, response, packer) {
|
|||
function getCMD(cmd) {
|
||||
if (cmd[0] === '/')
|
||||
return cmd.slice(1);
|
||||
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +220,9 @@ function onPUT({name, config, body}, callback) {
|
|||
return moveFiles(fromRooted, toRooted, names)
|
||||
.on('error', fn)
|
||||
.on('end', fn);
|
||||
} case 'rename':
|
||||
}
|
||||
|
||||
case 'rename':
|
||||
return rename(rootDir, files.from, files.to, callback);
|
||||
|
||||
case 'copy':
|
||||
|
|
@ -329,7 +334,7 @@ function operation(op, packer, from, to, names, fn) {
|
|||
|
||||
const [name] = names;
|
||||
pack.on('progress', (count) => {
|
||||
process.stdout.write(`\r${ op } "${ name }": ${ count }%`);
|
||||
process.stdout.write(`\r${op} "${name}": ${count}%`);
|
||||
});
|
||||
|
||||
pack.on('end', () => {
|
||||
|
|
@ -403,4 +408,3 @@ function checkPut(name, body, callback) {
|
|||
if (typeof callback !== 'function')
|
||||
throw Error('callback should be a function!');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,4 +73,3 @@ test('rest: onPUT: no callback', async (t) => {
|
|||
t.equal(e.message, 'callback should be a function!', 'should throw when no callback');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -14,4 +14,3 @@ module.exports = (prefix) => ({
|
|||
prefix,
|
||||
memory: getMemory(),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const info = require('./info');
|
||||
|
||||
test('cloudcmd: rest: info', (t) => {
|
||||
const {memoryUsage} = process;
|
||||
|
||||
const _memoryUsage = stub()
|
||||
.returns({});
|
||||
const _memoryUsage = stub().returns({});
|
||||
|
||||
process.memoryUsage = _memoryUsage;
|
||||
|
||||
|
|
@ -21,4 +18,3 @@ test('cloudcmd: rest: info', (t) => {
|
|||
t.ok(_memoryUsage.calledWith(), 'should call memoryUsage');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,3 @@ const mellow = require('mellow');
|
|||
module.exports = (dir, root) => {
|
||||
return mellow.webToWin(dir, root || '/');
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const mockRequire = require('mock-require');
|
||||
const {reRequire, stopAll} = mockRequire;
|
||||
|
||||
|
|
@ -36,4 +34,3 @@ test('cloudcmd: root: mellow', (t) => {
|
|||
t.calledWith(webToWin, [dir, dirRoot], 'should call mellow');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -57,8 +57,12 @@ module.exports = currify((config, options, request, response, next) => {
|
|||
if (!isFS)
|
||||
return next();
|
||||
|
||||
route({config, options, request, response})
|
||||
.catch(next);
|
||||
route({
|
||||
config,
|
||||
options,
|
||||
request,
|
||||
response,
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
module.exports._getReadDir = getReadDir;
|
||||
|
|
@ -102,10 +106,7 @@ async function route({config, options, request, response}) {
|
|||
response.setHeader('Content-Length', contentLength);
|
||||
response.setHeader('Content-Type', contentType(extname(fullPath)));
|
||||
|
||||
await pipe([
|
||||
stream,
|
||||
response,
|
||||
]);
|
||||
await pipe([stream, response]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,20 +132,16 @@ function indexProcessing(config, options) {
|
|||
.replace('icon-copy', 'icon-copy none');
|
||||
|
||||
if (noContact)
|
||||
data = data
|
||||
.replace('icon-contact', 'icon-contact none');
|
||||
data = data.replace('icon-contact', 'icon-contact none');
|
||||
|
||||
if (noConfig)
|
||||
data = data
|
||||
.replace('icon-config', 'icon-config none');
|
||||
data = data.replace('icon-config', 'icon-config none');
|
||||
|
||||
if (noConsole)
|
||||
data = data
|
||||
.replace('icon-console', 'icon-console none');
|
||||
data = data.replace('icon-console', 'icon-console none');
|
||||
|
||||
if (noTerminal)
|
||||
data = data
|
||||
.replace('icon-terminal', 'icon-terminal none');
|
||||
data = data.replace('icon-terminal', 'icon-terminal none');
|
||||
|
||||
const left = rendy(Template.panel, {
|
||||
side: 'left',
|
||||
|
|
@ -204,4 +201,3 @@ function hideKeysPanel(html) {
|
|||
|
||||
return html.replace(RegExp(from), to);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@ const {createConfigManager} = cloudcmd;
|
|||
|
||||
const routePath = './route';
|
||||
const fixtureDir = path.join(__dirname, '..', 'test', 'fixture');
|
||||
const {
|
||||
reRequire,
|
||||
stopAll,
|
||||
} = mockRequire;
|
||||
|
||||
const {reRequire, stopAll} = mockRequire;
|
||||
|
||||
const defaultConfig = {
|
||||
auth: false,
|
||||
dropbox: false,
|
||||
|
|
@ -214,6 +213,7 @@ test('cloudcmd: route: sendIndex: encode', async (t) => {
|
|||
const name = '"><svg onload=alert(3);>';
|
||||
const nameEncoded = '"><svg onload=alert(3);>';
|
||||
const path = '/';
|
||||
|
||||
const files = [{
|
||||
name,
|
||||
}];
|
||||
|
|
@ -353,6 +353,7 @@ test('cloudcmd: route: no termianl: /fs', async (t) => {
|
|||
};
|
||||
|
||||
const {request} = serveOnce(cloudcmd);
|
||||
|
||||
const {body} = await request.get('/fs', {
|
||||
options,
|
||||
});
|
||||
|
|
@ -407,6 +408,7 @@ test('cloudcmd: route: buttons: contact', async (t) => {
|
|||
};
|
||||
|
||||
const {request} = serveOnce(cloudcmd);
|
||||
|
||||
const {body} = await request.get('/', {
|
||||
options,
|
||||
});
|
||||
|
|
@ -446,6 +448,7 @@ test('cloudcmd: route: content length', async (t) => {
|
|||
|
||||
test('cloudcmd: route: read: root', async (t) => {
|
||||
const stream = Readable.from('hello');
|
||||
|
||||
stream.contentLength = 5;
|
||||
|
||||
const read = stub().returns(stream);
|
||||
|
|
@ -468,15 +471,12 @@ test('cloudcmd: route: read: root', async (t) => {
|
|||
|
||||
await request.get('/fs/route.js');
|
||||
|
||||
const expected = [
|
||||
'/hello/route.js', {
|
||||
root,
|
||||
},
|
||||
];
|
||||
const expected = ['/hello/route.js', {
|
||||
root,
|
||||
}];
|
||||
|
||||
stopAll();
|
||||
|
||||
t.calledWith(read, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import cloudcmd from './cloudcmd.js';
|
||||
|
||||
import http from 'http';
|
||||
import {promisify} from 'util';
|
||||
import currify from 'currify';
|
||||
|
|
@ -8,10 +7,8 @@ import tryToCatch from 'try-to-catch';
|
|||
import wraptile from 'wraptile';
|
||||
import compression from 'compression';
|
||||
import threadIt from 'thread-it';
|
||||
|
||||
import exit from './exit.js';
|
||||
import opn from 'open';
|
||||
|
||||
import express from 'express';
|
||||
import {Server} from 'socket.io';
|
||||
import tryRequire from 'tryrequire';
|
||||
|
|
@ -25,6 +22,7 @@ const shutdown = wraptile(async (promises) => {
|
|||
threadIt.terminate();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
const promisifySelf = squad(promisify, bind);
|
||||
|
||||
const exitPort = two(exit, 'cloudcmd --port: %s');
|
||||
|
|
@ -32,12 +30,9 @@ const logger = tryRequire('morgan');
|
|||
|
||||
export default async (options, config) => {
|
||||
const prefix = config('prefix');
|
||||
const port = process.env.PORT /* c9 */
|
||||
|| config('port');
|
||||
const port = process.env.PORT /* c9 */ || config('port');
|
||||
|
||||
const ip = process.env.IP /* c9 */
|
||||
|| config('ip')
|
||||
|| '0.0.0.0';
|
||||
const ip = process.env.IP /* c9 */ || config('ip') || '0.0.0.0';
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
|
|
@ -87,4 +82,3 @@ export default async (options, config) => {
|
|||
if (openError)
|
||||
console.error('cloudcmd --open:', openError.message);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@ const {
|
|||
module.exports = (config) => {
|
||||
check(config);
|
||||
|
||||
const data = Object.keys(config).map((name) => [name, config[name]]);
|
||||
const data = Object
|
||||
.keys(config)
|
||||
.map((name) => [
|
||||
name,
|
||||
config[name],
|
||||
]);
|
||||
|
||||
if (!data.length)
|
||||
return '';
|
||||
|
|
@ -31,4 +36,3 @@ function check(config) {
|
|||
if (typeof config !== 'object')
|
||||
throw Error('config should be an object!');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,3 @@ const readFilesSync = require('@cloudcmd/read-files-sync');
|
|||
const templatePath = path.join(__dirname, '..', 'tmpl/fs');
|
||||
|
||||
module.exports = readFilesSync(templatePath, 'utf8');
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,3 @@ module.exports = (config, arg) => {
|
|||
|
||||
return noop;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const mockRequire = require('mock-require');
|
||||
|
||||
|
|
@ -84,4 +81,3 @@ test('cloudcmd: terminal: no arg', (t) => {
|
|||
t.equal(result, gritty);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ const {codeframe} = require('putout');
|
|||
const putout = threadIt(require.resolve('putout'));
|
||||
|
||||
threadIt.init();
|
||||
|
||||
// warm up worker cache
|
||||
transpile('');
|
||||
|
||||
|
|
@ -44,9 +43,10 @@ async function onGET({req, res, menuName}) {
|
|||
return sendDefaultMenu(res);
|
||||
|
||||
const {findUp} = await import('find-up');
|
||||
const [errorFind, currentMenuPath] = await tryToCatch(findUp, [
|
||||
menuName,
|
||||
], {cwd: dir});
|
||||
|
||||
const [errorFind, currentMenuPath] = await tryToCatch(findUp, [menuName], {
|
||||
cwd: dir,
|
||||
});
|
||||
|
||||
if (errorFind && errorFind.code !== 'ENOENT')
|
||||
return res
|
||||
|
|
@ -106,4 +106,3 @@ async function transpile(source) {
|
|||
],
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@
|
|||
const fs = require('fs');
|
||||
const {join} = require('path');
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const serveOnce = require('serve-once');
|
||||
const threadIt = require('thread-it');
|
||||
const {reRequire} = require('mock-require');
|
||||
|
|
@ -88,4 +86,3 @@ test('cloudcmd: user menu: io.cp', async (t) => {
|
|||
t.equal(fixtureCopyFix, body);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -50,4 +50,3 @@ module.exports.columns = (type) => {
|
|||
if (!all.includes(type))
|
||||
exit(`cloudcmd --columns: can be only one of: ${names}`);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
const fs = require('fs');
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const tryCatch = require('try-catch');
|
||||
const mockRequire = require('mock-require');
|
||||
const dir = '..';
|
||||
|
|
@ -25,7 +23,9 @@ test('validate: root: bad', (t) => {
|
|||
root: Math.random(),
|
||||
};
|
||||
|
||||
const [e] = tryCatch(cloudcmd, {config});
|
||||
const [e] = tryCatch(cloudcmd, {
|
||||
config,
|
||||
});
|
||||
|
||||
t.equal(e.message, 'dir should be a string', 'should throw');
|
||||
t.end();
|
||||
|
|
@ -53,6 +53,7 @@ test('validate: root: stat', (t) => {
|
|||
const {statSync} = fs;
|
||||
|
||||
const error = 'ENOENT';
|
||||
|
||||
fs.statSync = () => {
|
||||
throw Error(error);
|
||||
};
|
||||
|
|
@ -64,6 +65,7 @@ test('validate: root: stat', (t) => {
|
|||
root('hello', fn);
|
||||
|
||||
const msg = 'cloudcmd --root: %s';
|
||||
|
||||
fs.statSync = statSync;
|
||||
|
||||
stopAll();
|
||||
|
|
@ -137,4 +139,3 @@ test('validate: columns: wrong', (t) => {
|
|||
t.calledWith(fn, [msg], 'should call exit');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue