Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Mar 20, 2024
1 parent 98d3a4c commit 95c36b0
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .webpack/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
2 changes: 1 addition & 1 deletion .webpack/html.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
21 changes: 5 additions & 16 deletions .webpack/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
};
Expand Down Expand Up @@ -66,6 +64,10 @@ const splitChunks = {
module.exports = {
resolve: {
symlinks: false,
alias: {
'node:process': 'process',
'node:path': 'path',
},
},
devtool,
optimization: {
Expand Down Expand Up @@ -101,7 +103,6 @@ module.exports = {
devtoolModuleFilenameTemplate,
publicPath: '/dist/',
},
externals: [convertToWebpack5Externals(externals)],
module: {
rules,
noParse,
Expand All @@ -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}`;
Expand Down
2 changes: 1 addition & 1 deletion common/callbackify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
6 changes: 3 additions & 3 deletions server/cloudcmd.js
Original file line number Diff line number Diff line change
@@ -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`);
Expand Down
10 changes: 5 additions & 5 deletions server/columns.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -23,7 +23,7 @@ module.exports.isDev = _isDev;

module.exports.getColumns = ({isDev = _isDev()} = {}) => {
const columns = readFilesSyncMemo(isDev);

return {
...columns,
...defaultColumns,
Expand All @@ -36,6 +36,6 @@ const readFilesSyncMemo = nanomemoize((isDev) => {
const names = fs
.readdirSync(columnsDir)
.filter(not(isMap));

return readFilesSync(columnsDir, names, 'utf8');
});
12 changes: 6 additions & 6 deletions server/columns.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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 changes: 1 addition & 1 deletion server/distribute/import.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion server/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
64 changes: 32 additions & 32 deletions server/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const sendIndex = (params, data) => {
...params,
name: 'index.html',
};

ponse.send(data, ponseParams);
};

Expand All @@ -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'));
};

Expand All @@ -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,
Expand All @@ -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]);
}

Expand All @@ -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,
Expand All @@ -165,7 +165,7 @@ function indexProcessing(config, options) {
config: stringify(config('*')),
columns: getColumns()[config('columns')],
});

return data;
}

Expand All @@ -175,7 +175,7 @@ function buildIndex(config, html, data) {
prefix: getPrefix(config),
template: Template,
});

return indexProcessing(config, {
panel,
data: html,
Expand All @@ -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);
}
6 changes: 3 additions & 3 deletions server/user-menu.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down

0 comments on commit 95c36b0

Please sign in to comment.