mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
chore: lint
This commit is contained in:
parent
98d3a4cc56
commit
95c36b0a37
15 changed files with 127 additions and 138 deletions
|
|
@ -10,7 +10,7 @@ const {
|
|||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||
|
||||
const {env} = require('process');
|
||||
const {env} = require('node:process');
|
||||
const isDev = env.NODE_ENV === 'development';
|
||||
|
||||
const extractCSS = (a) => new ExtractTextPlugin(`${a}.css`);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const {env} = require('process');
|
||||
const {env} = require('node:process');
|
||||
|
||||
const isDev = env.NODE_ENV === 'development';
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const WebpackBar = require('webpackbar');
|
|||
|
||||
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
|
||||
|
||||
const {env} = require('process');
|
||||
const {env} = require('node:process');
|
||||
const modules = './modules';
|
||||
const dirModules = './client/modules';
|
||||
const dir = './client';
|
||||
|
|
@ -27,8 +27,6 @@ const notEmpty = (a) => a;
|
|||
const clean = (array) => array.filter(notEmpty);
|
||||
|
||||
const noParse = (a) => /\.spec\.js$/.test(a);
|
||||
const convertToWebpack5Externals = (fn) => (context, request, cb) => fn({context, request}, cb);
|
||||
|
||||
const options = {
|
||||
babelrc: true,
|
||||
};
|
||||
|
|
@ -66,6 +64,10 @@ const splitChunks = {
|
|||
module.exports = {
|
||||
resolve: {
|
||||
symlinks: false,
|
||||
alias: {
|
||||
'node:process': 'process',
|
||||
'node:path': 'path',
|
||||
},
|
||||
},
|
||||
devtool,
|
||||
optimization: {
|
||||
|
|
@ -101,7 +103,6 @@ module.exports = {
|
|||
devtoolModuleFilenameTemplate,
|
||||
publicPath: '/dist/',
|
||||
},
|
||||
externals: [convertToWebpack5Externals(externals)],
|
||||
module: {
|
||||
rules,
|
||||
noParse,
|
||||
|
|
@ -113,18 +114,6 @@ module.exports = {
|
|||
},
|
||||
};
|
||||
|
||||
function externals({request}, fn) {
|
||||
if (!isDev)
|
||||
return fn();
|
||||
|
||||
const list = [];
|
||||
|
||||
if (list.includes(request))
|
||||
return fn(null, request);
|
||||
|
||||
fn();
|
||||
}
|
||||
|
||||
function devtoolModuleFilenameTemplate(info) {
|
||||
const resource = info.absoluteResourcePath.replace(rootDir + sep, '');
|
||||
return `file://cloudcmd/${resource}`;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const tryToCatch = require('try-to-catch');
|
|||
const {test, stub} = require('supertape');
|
||||
|
||||
const callbackify = require('./callbackify');
|
||||
const {promisify} = require('util');
|
||||
const {promisify} = require('node:util');
|
||||
|
||||
test('cloudcmd: common: callbackify: error', async (t) => {
|
||||
const promise = stub().rejects(Error('hello'));
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
const fullstore = require('fullstore');
|
||||
const process = require('process');
|
||||
const process = require('node:process');
|
||||
const DIR = `${__dirname}/`;
|
||||
const DIR_COMMON = `${DIR}../common/`;
|
||||
const path = require('path');
|
||||
const path = require('node:path');
|
||||
|
||||
const fs = require('fs');
|
||||
const fs = require('node:fs');
|
||||
const cloudfunc = require(`${DIR_COMMON}cloudfunc`);
|
||||
|
||||
const authentication = require(`${DIR}auth`);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const fullstore = require('fullstore');
|
||||
const process = require('process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const process = require('node:process');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const {nanomemoize} = require('nano-memoize');
|
||||
const readFilesSync = require('@cloudcmd/read-files-sync');
|
||||
|
|
@ -23,7 +23,7 @@ module.exports.isDev = _isDev;
|
|||
|
||||
module.exports.getColumns = ({isDev = _isDev()} = {}) => {
|
||||
const columns = readFilesSyncMemo(isDev);
|
||||
|
||||
|
||||
return {
|
||||
...columns,
|
||||
...defaultColumns,
|
||||
|
|
@ -36,6 +36,6 @@ const readFilesSyncMemo = nanomemoize((isDev) => {
|
|||
const names = fs
|
||||
.readdirSync(columnsDir)
|
||||
.filter(not(isMap));
|
||||
|
||||
|
||||
return readFilesSync(columnsDir, names, 'utf8');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('supertape');
|
||||
const fs = require('fs');
|
||||
const fs = require('node:fs');
|
||||
const {getColumns, isDev} = require('./columns');
|
||||
|
||||
test('columns: prod', (t) => {
|
||||
const columns = getColumns({
|
||||
isDev: false,
|
||||
});
|
||||
|
||||
|
||||
t.equal(columns[''], '');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -17,9 +17,9 @@ test('columns: dev', (t) => {
|
|||
const columns = getColumns({
|
||||
isDev: true,
|
||||
});
|
||||
|
||||
|
||||
const css = fs.readFileSync(`${__dirname}/../css/columns/name-size-date.css`, 'utf8');
|
||||
|
||||
|
||||
t.equal(columns['name-size-date'], css);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -28,10 +28,10 @@ test('columns: no args', (t) => {
|
|||
const currentIsDev = isDev();
|
||||
isDev(true);
|
||||
const columns = getColumns();
|
||||
|
||||
|
||||
const css = fs.readFileSync(`${__dirname}/../css/columns/name-size-date.css`, 'utf8');
|
||||
isDev(currentIsDev);
|
||||
|
||||
|
||||
t.equal(columns['name-size-date'], css);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const process = require('node:process');
|
||||
const test = require('supertape');
|
||||
const {promisify} = require('util');
|
||||
const {promisify} = require('node:util');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
|
||||
const {connect} = require('../../test/before');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const snake = require('just-snake-case');
|
||||
|
||||
const {env} = require('process');
|
||||
const {env} = require('node:process');
|
||||
const up = (a) => a.toUpperCase();
|
||||
|
||||
module.exports = parse;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ const sendIndex = (params, data) => {
|
|||
...params,
|
||||
name: 'index.html',
|
||||
};
|
||||
|
||||
|
||||
ponse.send(data, ponseParams);
|
||||
};
|
||||
|
||||
|
|
@ -37,9 +37,9 @@ const getPrefix = (config) => prefixer(config('prefix'));
|
|||
const getReadDir = (config) => {
|
||||
if (!config('dropbox'))
|
||||
return read;
|
||||
|
||||
|
||||
const {readDir} = onceRequire('@cloudcmd/dropbox');
|
||||
|
||||
|
||||
return wraptile(readDir, config('dropboxToken'));
|
||||
};
|
||||
|
||||
|
|
@ -49,10 +49,10 @@ const getReadDir = (config) => {
|
|||
module.exports = currify((config, options, request, response, next) => {
|
||||
const name = ponse.getPathName(request);
|
||||
const isFS = RegExp(`^/$|^${FS}`).test(name);
|
||||
|
||||
|
||||
if (!isFS)
|
||||
return next();
|
||||
|
||||
|
||||
route({
|
||||
config,
|
||||
options,
|
||||
|
|
@ -72,36 +72,36 @@ async function route({config, options, request, response}) {
|
|||
gzip,
|
||||
name,
|
||||
};
|
||||
|
||||
|
||||
config('prefix', prefixer(request.baseUrl));
|
||||
|
||||
|
||||
const rootName = name.replace(CloudFunc.FS, '') || '/';
|
||||
const fullPath = root(rootName, config('root'));
|
||||
|
||||
|
||||
const read = getReadDir(config);
|
||||
const [error, stream] = await tryToCatch(read, fullPath, {
|
||||
root: config('root'),
|
||||
});
|
||||
|
||||
|
||||
const {html} = options;
|
||||
|
||||
|
||||
if (error)
|
||||
return ponse.sendError(error, p);
|
||||
|
||||
|
||||
if (stream.type === 'directory') {
|
||||
const {files} = stream;
|
||||
|
||||
|
||||
return sendIndex(p, buildIndex(config, html, {
|
||||
files,
|
||||
path: format.addSlashToEnd(rootName),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
const {contentLength} = stream;
|
||||
|
||||
|
||||
response.setHeader('Content-Length', contentLength);
|
||||
response.setHeader('Content-Type', contentType(extname(fullPath)));
|
||||
|
||||
|
||||
await pipe([stream, response]);
|
||||
}
|
||||
|
||||
|
|
@ -116,46 +116,46 @@ function indexProcessing(config, options) {
|
|||
const noConsole = !config('console');
|
||||
const noTerminal = !config('terminal');
|
||||
const {panel} = options;
|
||||
|
||||
|
||||
let {data} = options;
|
||||
|
||||
|
||||
if (noKeysPanel)
|
||||
data = hideKeysPanel(data);
|
||||
|
||||
|
||||
if (oneFilePanel)
|
||||
data = data
|
||||
.replace('icon-move', 'icon-move none')
|
||||
.replace('icon-copy', 'icon-copy none');
|
||||
|
||||
|
||||
if (noContact)
|
||||
data = data.replace('icon-contact', 'icon-contact none');
|
||||
|
||||
|
||||
if (noConfig)
|
||||
data = data.replace('icon-config', 'icon-config none');
|
||||
|
||||
|
||||
if (noConsole)
|
||||
data = data.replace('icon-console', 'icon-console none');
|
||||
|
||||
|
||||
if (noTerminal)
|
||||
data = data.replace('icon-terminal', 'icon-terminal none');
|
||||
|
||||
|
||||
const left = rendy(Template.panel, {
|
||||
side: 'left',
|
||||
content: panel,
|
||||
className: !oneFilePanel ? '' : 'panel-single',
|
||||
});
|
||||
|
||||
|
||||
let right = '';
|
||||
|
||||
|
||||
if (!oneFilePanel)
|
||||
right = rendy(Template.panel, {
|
||||
side: 'right',
|
||||
content: panel,
|
||||
className: '',
|
||||
});
|
||||
|
||||
|
||||
const name = config('name');
|
||||
|
||||
|
||||
data = rendy(data, {
|
||||
title: CloudFunc.getTitle({
|
||||
name,
|
||||
|
|
@ -165,7 +165,7 @@ function indexProcessing(config, options) {
|
|||
config: stringify(config('*')),
|
||||
columns: getColumns()[config('columns')],
|
||||
});
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ function buildIndex(config, html, data) {
|
|||
prefix: getPrefix(config),
|
||||
template: Template,
|
||||
});
|
||||
|
||||
|
||||
return indexProcessing(config, {
|
||||
panel,
|
||||
data: html,
|
||||
|
|
@ -186,14 +186,14 @@ module.exports._hideKeysPanel = hideKeysPanel;
|
|||
function hideKeysPanel(html) {
|
||||
const keysPanel = '<div id="js-keyspanel" class="{{ className }}"';
|
||||
const keysPanelRegExp = '<div id="?js-keyspanel"? class="?{{ className }}"?';
|
||||
|
||||
|
||||
const from = rendy(keysPanelRegExp, {
|
||||
className: 'keyspanel',
|
||||
});
|
||||
|
||||
|
||||
const to = rendy(keysPanel, {
|
||||
className: 'keyspanel hidden',
|
||||
});
|
||||
|
||||
|
||||
return html.replace(RegExp(from), to);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const {homedir} = require('os');
|
||||
const {readFile} = require('fs/promises');
|
||||
const {homedir} = require('node:os');
|
||||
const {readFile} = require('node:fs/promises');
|
||||
|
||||
const {join} = require('path');
|
||||
const {join} = require('node:path');
|
||||
|
||||
const montag = require('montag');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
|
|
|
|||
|
|
@ -9,30 +9,30 @@ const isString = (a) => typeof a === 'string';
|
|||
module.exports.root = (dir, config) => {
|
||||
if (!isString(dir))
|
||||
throw Error('dir should be a string');
|
||||
|
||||
|
||||
if (dir === '/')
|
||||
return;
|
||||
|
||||
|
||||
if (config('dropbox'))
|
||||
return;
|
||||
|
||||
const {statSync} = require('fs');
|
||||
|
||||
const {statSync} = require('node:fs');
|
||||
const [error] = tryCatch(statSync, dir);
|
||||
|
||||
|
||||
if (error)
|
||||
return exit('cloudcmd --root: %s', error.message);
|
||||
};
|
||||
|
||||
module.exports.editor = (name) => {
|
||||
const reg = /^(dword|edward|deepword)$/;
|
||||
|
||||
|
||||
if (!reg.test(name))
|
||||
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
|
||||
};
|
||||
|
||||
module.exports.packer = (name) => {
|
||||
const reg = /^(tar|zip)$/;
|
||||
|
||||
|
||||
if (!reg.test(name))
|
||||
exit('cloudcmd --packer: could be "tar" or "zip" only');
|
||||
};
|
||||
|
|
@ -42,12 +42,12 @@ module.exports.columns = (type) => {
|
|||
const all = Object
|
||||
.keys(getColumns())
|
||||
.concat('');
|
||||
|
||||
|
||||
const names = all
|
||||
.filter(Boolean)
|
||||
.map(addQuotes)
|
||||
.join(', ');
|
||||
|
||||
|
||||
if (!all.includes(type))
|
||||
exit(`cloudcmd --columns: can be only one of: ${names}`);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,20 +22,20 @@ test('validate: root: bad', (t) => {
|
|||
const config = {
|
||||
root: Math.random(),
|
||||
};
|
||||
|
||||
|
||||
const [e] = tryCatch(cloudcmd, {
|
||||
config,
|
||||
});
|
||||
|
||||
|
||||
t.equal(e.message, 'dir should be a string', 'should throw');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('validate: root: config', (t) => {
|
||||
const config = stub().returns(true);
|
||||
|
||||
|
||||
validate.root('/hello', config);
|
||||
|
||||
|
||||
t.calledWith(config, ['dropbox'], 'should call config');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -43,7 +43,7 @@ test('validate: root: config', (t) => {
|
|||
test('validate: root: /', (t) => {
|
||||
const fn = stub();
|
||||
validate.root('/', fn);
|
||||
|
||||
|
||||
t.notCalled(fn, 'should not call fn');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -51,57 +51,57 @@ test('validate: root: /', (t) => {
|
|||
test('validate: root: stat', (t) => {
|
||||
const fn = stub();
|
||||
const {statSync} = fs;
|
||||
|
||||
|
||||
const error = 'ENOENT';
|
||||
|
||||
|
||||
fs.statSync = () => {
|
||||
throw Error(error);
|
||||
};
|
||||
|
||||
|
||||
mockRequire(exitPath, fn);
|
||||
|
||||
|
||||
const {root} = reRequire(validatePath);
|
||||
|
||||
|
||||
root('hello', fn);
|
||||
|
||||
|
||||
const msg = 'cloudcmd --root: %s';
|
||||
|
||||
|
||||
fs.statSync = statSync;
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.calledWith(fn, [msg, error], 'should call fn');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('validate: packer: not valid', (t) => {
|
||||
const fn = stub();
|
||||
|
||||
|
||||
mockRequire(exitPath, fn);
|
||||
|
||||
|
||||
const {packer} = reRequire(validatePath);
|
||||
const msg = 'cloudcmd --packer: could be "tar" or "zip" only';
|
||||
|
||||
|
||||
packer('hello');
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.calledWith(fn, [msg], 'should call fn');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('validate: editor: not valid', (t) => {
|
||||
const fn = stub();
|
||||
|
||||
|
||||
mockRequire(exitPath, fn);
|
||||
|
||||
|
||||
const {editor} = reRequire(validatePath);
|
||||
const msg = 'cloudcmd --editor: could be "dword", "edward" or "deepword" only';
|
||||
|
||||
|
||||
editor('hello');
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.calledWith(fn, [msg], 'should call fn');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -109,13 +109,13 @@ test('validate: editor: not valid', (t) => {
|
|||
test('validate: columns', (t) => {
|
||||
const fn = stub();
|
||||
mockRequire(exitPath, fn);
|
||||
|
||||
|
||||
const {columns} = require(validatePath);
|
||||
|
||||
|
||||
columns('name-size-date');
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.notCalled(fn, 'should not call exit');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -126,19 +126,19 @@ test('validate: columns: wrong', (t) => {
|
|||
'name-size-date': '',
|
||||
'name-size': '',
|
||||
});
|
||||
|
||||
|
||||
mockRequire(exitPath, fn);
|
||||
mockRequire(columnsPath, {
|
||||
getColumns,
|
||||
});
|
||||
|
||||
|
||||
const {columns} = reRequire(validatePath);
|
||||
const msg = 'cloudcmd --columns: can be only one of: "name-size-date", "name-size"';
|
||||
|
||||
|
||||
columns('hello');
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.calledWith(fn, [msg], 'should call exit');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const express = require('express');
|
|||
const io = require('socket.io');
|
||||
const writejson = require('writejson');
|
||||
const readjson = require('readjson');
|
||||
const {promisify} = require('util');
|
||||
const {promisify} = require('node:util');
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
|
|
|
|||
|
|
@ -19,45 +19,45 @@ test('cloudcmd: rest: rename', async (t) => {
|
|||
'/fixture/mv.txt': 'hello',
|
||||
'/fixture/tmp/a.txt': 'a',
|
||||
};
|
||||
|
||||
|
||||
const vol = Volume.fromJSON(volume, '/');
|
||||
|
||||
|
||||
const unionFS = ufs
|
||||
.use(vol)
|
||||
.use(fs);
|
||||
|
||||
|
||||
mockRequire('node:fs', unionFS);
|
||||
|
||||
|
||||
reRequire('@cloudcmd/rename-files');
|
||||
reRequire('@cloudcmd/move-files');
|
||||
reRequire(restPath);
|
||||
|
||||
|
||||
const cloudcmd = reRequire(cloudcmdPath);
|
||||
const {createConfigManager} = cloudcmd;
|
||||
const configManager = createConfigManager();
|
||||
|
||||
|
||||
configManager('auth', false);
|
||||
configManager('root', '/');
|
||||
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
||||
const files = {
|
||||
from: '/fixture/mv.txt',
|
||||
to: '/fixture/tmp/mv.txt',
|
||||
};
|
||||
|
||||
|
||||
const {body} = await request.put(`/api/v1/rename`, {
|
||||
body: files,
|
||||
});
|
||||
|
||||
|
||||
mockRequire.stopAll();
|
||||
|
||||
|
||||
const expected = 'rename: ok("{"from":"/fixture/mv.txt","to":"/fixture/tmp/mv.txt"}")';
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.equal(body, expected, 'should move');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -65,23 +65,23 @@ test('cloudcmd: rest: rename', async (t) => {
|
|||
test('cloudcmd: rest: rename: no from', async (t) => {
|
||||
const cloudcmd = reRequire(cloudcmdPath);
|
||||
const {createConfigManager} = cloudcmd;
|
||||
|
||||
|
||||
const configManager = createConfigManager();
|
||||
configManager('auth', false);
|
||||
configManager('root', '/');
|
||||
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
||||
const files = {};
|
||||
|
||||
|
||||
const {body} = await request.put(`/api/v1/rename`, {
|
||||
body: files,
|
||||
});
|
||||
|
||||
|
||||
const expected = '"from" should be filled';
|
||||
|
||||
|
||||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -89,25 +89,25 @@ test('cloudcmd: rest: rename: no from', async (t) => {
|
|||
test('cloudcmd: rest: rename: no to', async (t) => {
|
||||
const cloudcmd = reRequire(cloudcmdPath);
|
||||
const {createConfigManager} = cloudcmd;
|
||||
|
||||
|
||||
const configManager = createConfigManager();
|
||||
configManager('auth', false);
|
||||
configManager('root', '/');
|
||||
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
||||
const files = {
|
||||
from: '/',
|
||||
};
|
||||
|
||||
|
||||
const {body} = await request.put(`/api/v1/rename`, {
|
||||
body: files,
|
||||
});
|
||||
|
||||
|
||||
const expected = '"to" should be filled';
|
||||
|
||||
|
||||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue