mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature(server) convert to ESM
This commit is contained in:
parent
990fbde90f
commit
d475790257
43 changed files with 327 additions and 420 deletions
|
|
@ -18,7 +18,6 @@ import prefixer from '../server/prefixer.js';
|
||||||
import minimist from 'minimist';
|
import minimist from 'minimist';
|
||||||
|
|
||||||
const Info = await readjson(new URL('../package.json', import.meta.url));
|
const Info = await readjson(new URL('../package.json', import.meta.url));
|
||||||
console.log(Info);
|
|
||||||
|
|
||||||
const {argv} = process;
|
const {argv} = process;
|
||||||
|
|
||||||
|
|
@ -29,8 +28,6 @@ const choose = (a, b) => {
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('---->', env);
|
|
||||||
|
|
||||||
process.on('unhandledRejection', exit);
|
process.on('unhandledRejection', exit);
|
||||||
|
|
||||||
const args = minimist(argv.slice(2), {
|
const args = minimist(argv.slice(2), {
|
||||||
|
|
@ -245,7 +242,7 @@ async function start(options, config) {
|
||||||
if (!args.server)
|
if (!args.server)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const server = await import('../server/server.js');
|
const {default: server} = await import('../server/server.js');
|
||||||
server(options, config);
|
server(options, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@
|
||||||
"optimize-css-assets-webpack-plugin": "^5.0.0",
|
"optimize-css-assets-webpack-plugin": "^5.0.0",
|
||||||
"philip": "^2.0.0",
|
"philip": "^2.0.0",
|
||||||
"place": "^1.1.4",
|
"place": "^1.1.4",
|
||||||
"readjson": "^2.0.1",
|
"readjson": "^2.1.0",
|
||||||
"request": "^2.76.0",
|
"request": "^2.76.0",
|
||||||
"rimraf": "^3.0.0",
|
"rimraf": "^3.0.0",
|
||||||
"scroll-into-view-if-needed": "^2.2.5",
|
"scroll-into-view-if-needed": "^2.2.5",
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
'use strict';
|
import httpAuth from 'http-auth';
|
||||||
|
import criton from 'criton';
|
||||||
const httpAuth = require('http-auth');
|
import currify from 'currify';
|
||||||
const criton = require('criton');
|
|
||||||
const currify = require('currify');
|
|
||||||
const middle = currify(_middle);
|
const middle = currify(_middle);
|
||||||
const check = currify(_check);
|
const check = currify(_check);
|
||||||
|
|
||||||
module.exports = (config) => {
|
export default (config) => {
|
||||||
const auth = httpAuth.basic({
|
const auth = httpAuth.basic({
|
||||||
realm: 'Cloud Commander',
|
realm: 'Cloud Commander',
|
||||||
}, check(config));
|
}, check(config));
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,42 @@
|
||||||
'use strict';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
|
import {apiURL} from './../common/cloudfunc.js';
|
||||||
|
import authentication from './auth.js';
|
||||||
|
import {createConfig, configPath} from './config.js';
|
||||||
|
|
||||||
|
export {
|
||||||
|
createConfig,
|
||||||
|
configPath,
|
||||||
|
};
|
||||||
|
|
||||||
|
import modulas from './modulas.js';
|
||||||
|
import userMenu from './user-menu.js';
|
||||||
|
import rest from './rest/index.js';
|
||||||
|
import route from './route.js';
|
||||||
|
import * as validate from './validate.js';
|
||||||
|
import prefixer from './prefixer.js';
|
||||||
|
import terminal from './terminal.js';
|
||||||
|
import distributeExport from './distribute/export.js';
|
||||||
|
|
||||||
|
import currify from 'currify';
|
||||||
|
import apart from 'apart';
|
||||||
|
import ponse from 'ponse';
|
||||||
|
import restafary from 'restafary';
|
||||||
|
import restbox from 'restbox';
|
||||||
|
import konsole from 'console-io';
|
||||||
|
import edward from 'edward';
|
||||||
|
import dword from 'dword';
|
||||||
|
import deepword from 'deepword';
|
||||||
|
import nomine from 'nomine';
|
||||||
|
import fileop from '@cloudcmd/fileop';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const DIR = __dirname + '/';
|
const DIR = __dirname + '/';
|
||||||
const DIR_ROOT = DIR + '../';
|
const DIR_ROOT = DIR + '../';
|
||||||
const DIR_COMMON = DIR + '../common/';
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const cloudfunc = require(DIR_COMMON + 'cloudfunc');
|
|
||||||
const authentication = require(DIR + 'auth');
|
|
||||||
const {
|
|
||||||
createConfig,
|
|
||||||
configPath,
|
|
||||||
} = require(DIR + 'config');
|
|
||||||
|
|
||||||
const modulas = require(DIR + 'modulas');
|
|
||||||
const userMenu = require(DIR + 'user-menu');
|
|
||||||
const rest = require(DIR + 'rest');
|
|
||||||
const route = require(DIR + 'route');
|
|
||||||
const validate = require(DIR + 'validate');
|
|
||||||
const prefixer = require(DIR + 'prefixer');
|
|
||||||
const terminal = require(DIR + 'terminal');
|
|
||||||
const distribute = require(DIR + 'distribute');
|
|
||||||
|
|
||||||
const currify = require('currify');
|
|
||||||
const apart = require('apart');
|
|
||||||
const ponse = require('ponse');
|
|
||||||
const restafary = require('restafary');
|
|
||||||
const restbox = require('restbox');
|
|
||||||
const konsole = require('console-io');
|
|
||||||
const edward = require('edward');
|
|
||||||
const dword = require('dword');
|
|
||||||
const deepword = require('deepword');
|
|
||||||
const nomine = require('nomine');
|
|
||||||
const fileop = require('@cloudcmd/fileop');
|
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const isDev = process.env.NODE_ENV === 'development';
|
||||||
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
||||||
|
|
@ -45,7 +48,7 @@ const initAuth = currify(_initAuth);
|
||||||
const notEmpty = (a) => a;
|
const notEmpty = (a) => a;
|
||||||
const clean = (a) => a.filter(notEmpty);
|
const clean = (a) => a.filter(notEmpty);
|
||||||
|
|
||||||
module.exports = (params) => {
|
export default (params) => {
|
||||||
const p = params || {};
|
const p = params || {};
|
||||||
const options = p.config || {};
|
const options = p.config || {};
|
||||||
const config = p.configManager || createConfig({
|
const config = p.configManager || createConfig({
|
||||||
|
|
@ -89,10 +92,9 @@ module.exports = (params) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.createConfigManager = createConfig;
|
export const createConfigManager = createConfig;
|
||||||
module.exports.configPath = configPath;
|
|
||||||
|
|
||||||
module.exports._getIndexPath = getIndexPath;
|
export const _getIndexPath = getIndexPath;
|
||||||
|
|
||||||
function defaultValue(config, name, options) {
|
function defaultValue(config, name, options) {
|
||||||
const value = options[name];
|
const value = options[name];
|
||||||
|
|
@ -104,7 +106,7 @@ function defaultValue(config, name, options) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._getPrefix = getPrefix;
|
export const _getPrefix = getPrefix;
|
||||||
function getPrefix(prefix) {
|
function getPrefix(prefix) {
|
||||||
if (typeof prefix === 'function')
|
if (typeof prefix === 'function')
|
||||||
return prefix() || '';
|
return prefix() || '';
|
||||||
|
|
@ -112,8 +114,7 @@ function getPrefix(prefix) {
|
||||||
return prefix || '';
|
return prefix || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._initAuth = _initAuth;
|
export function _initAuth(config, accept, reject, username, password) {
|
||||||
function _initAuth(config, accept, reject, username, password) {
|
|
||||||
if (!config('auth'))
|
if (!config('auth'))
|
||||||
return accept();
|
return accept();
|
||||||
|
|
||||||
|
|
@ -169,7 +170,7 @@ function listen({prefixSocket, socket, config}) {
|
||||||
autoRestart: config('terminalAutoRestart'),
|
autoRestart: config('terminalAutoRestart'),
|
||||||
});
|
});
|
||||||
|
|
||||||
distribute.export(config, socket);
|
distributeExport(config, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloudcmd({modules, config}) {
|
function cloudcmd({modules, config}) {
|
||||||
|
|
@ -233,13 +234,13 @@ function cloudcmd({modules, config}) {
|
||||||
modules && modulas(modules),
|
modules && modulas(modules),
|
||||||
|
|
||||||
config('dropbox') && restbox({
|
config('dropbox') && restbox({
|
||||||
prefix: cloudfunc.apiURL,
|
prefix: apiURL,
|
||||||
root,
|
root,
|
||||||
token: dropboxToken,
|
token: dropboxToken,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
restafary({
|
restafary({
|
||||||
prefix: cloudfunc.apiURL + '/fs',
|
prefix: apiURL + '/fs',
|
||||||
root,
|
root,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
@ -265,7 +266,7 @@ function logout(req, res, next) {
|
||||||
res.sendStatus(401);
|
res.sendStatus(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._replaceDist = replaceDist;
|
export const _replaceDist = replaceDist;
|
||||||
function replaceDist(url) {
|
function replaceDist(url) {
|
||||||
if (!isDev)
|
if (!isDev)
|
||||||
return url;
|
return url;
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
'use strict';
|
import path from 'path';
|
||||||
|
|
||||||
const path = require('path');
|
import test from 'supertape';
|
||||||
|
import stub from '@cloudcmd/stub';
|
||||||
const test = require('supertape');
|
import {reRequire} from 'mock-require';
|
||||||
const stub = require('@cloudcmd/stub');
|
|
||||||
const {reRequire} = require('mock-require');
|
|
||||||
|
|
||||||
const DIR = './';
|
const DIR = './';
|
||||||
const cloudcmdPath = DIR + 'cloudcmd';
|
const cloudcmdPath = DIR + 'cloudcmd';
|
||||||
|
|
||||||
const cloudcmd = require(cloudcmdPath);
|
import cloudcmd from './cloudcmd.js';
|
||||||
const {
|
const {
|
||||||
createConfigManager,
|
createConfigManager,
|
||||||
_getPrefix,
|
_getPrefix,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
'use strict';
|
import {join, dirname} from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import readFilesSync from '@cloudcmd/read-files-sync';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
const readFilesSync = require('@cloudcmd/read-files-sync');
|
|
||||||
const isMap = (a) => /\.map$/.test(a);
|
const isMap = (a) => /\.map$/.test(a);
|
||||||
const not = (fn) => (a) => !fn(a);
|
const not = (fn) => (a) => !fn(a);
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
const defaultColumns = {
|
const defaultColumns = {
|
||||||
'': '',
|
'': '',
|
||||||
|
|
@ -15,14 +16,14 @@ const isDev = process.env.NODE_ENV === 'development';
|
||||||
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
||||||
|
|
||||||
const dist = getDist(isDev);
|
const dist = getDist(isDev);
|
||||||
const columnsDir = path.join(__dirname, '..', dist, 'columns');
|
const columnsDir = join(__dirname, '..', dist, 'columns');
|
||||||
|
|
||||||
const names = fs.readdirSync(columnsDir)
|
const names = fs.readdirSync(columnsDir)
|
||||||
.filter(not(isMap));
|
.filter(not(isMap));
|
||||||
|
|
||||||
const columns = readFilesSync(columnsDir, names, 'utf8');
|
const columns = readFilesSync(columnsDir, names, 'utf8');
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
...columns,
|
...columns,
|
||||||
...defaultColumns,
|
...defaultColumns,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,26 @@
|
||||||
'use strict';
|
import {join, dirname} from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import Emitter from 'events';
|
||||||
|
import {homedir} from 'os';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
const DIR_SERVER = __dirname + '/';
|
import exit from './exit.js';
|
||||||
const DIR_COMMON = '../common/';
|
import * as CloudFunc from '../common/cloudfunc.js';
|
||||||
const DIR = DIR_SERVER + '../';
|
|
||||||
|
|
||||||
const path = require('path');
|
import currify from 'currify';
|
||||||
const fs = require('fs');
|
import wraptile from 'wraptile';
|
||||||
const Emitter = require('events');
|
import tryToCatch from 'try-to-catch';
|
||||||
const {homedir} = require('os');
|
import pullout from 'pullout';
|
||||||
|
import ponse from 'ponse';
|
||||||
|
import jonny from 'jonny';
|
||||||
|
import jju from 'jju';
|
||||||
|
import writejson from 'writejson';
|
||||||
|
import tryCatch from 'try-catch';
|
||||||
|
import criton from 'criton';
|
||||||
|
import readjson from 'readjson';
|
||||||
|
|
||||||
const exit = require(DIR_SERVER + 'exit');
|
|
||||||
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
|
|
||||||
|
|
||||||
const currify = require('currify');
|
|
||||||
const wraptile = require('wraptile');
|
|
||||||
const tryToCatch = require('try-to-catch');
|
|
||||||
const pullout = require('pullout');
|
|
||||||
const ponse = require('ponse');
|
|
||||||
const jonny = require('jonny');
|
|
||||||
const jju = require('jju');
|
|
||||||
const writejson = require('writejson');
|
|
||||||
const tryCatch = require('try-catch');
|
|
||||||
const criton = require('criton');
|
|
||||||
const HOME = homedir();
|
const HOME = homedir();
|
||||||
|
const DIR = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
const resolve = Promise.resolve.bind(Promise);
|
const resolve = Promise.resolve.bind(Promise);
|
||||||
const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b));
|
const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b));
|
||||||
|
|
@ -31,26 +29,19 @@ const {apiURL} = CloudFunc;
|
||||||
|
|
||||||
const key = (a) => Object.keys(a).pop();
|
const key = (a) => Object.keys(a).pop();
|
||||||
|
|
||||||
const ConfigPath = path.join(DIR, 'json/config.json');
|
const ConfigPath = join(DIR, '..', 'json/config.json');
|
||||||
const ConfigHome = path.join(HOME, '.cloudcmd.json');
|
|
||||||
|
|
||||||
const connection = currify(_connection);
|
const connection = currify(_connection);
|
||||||
const connectionWraped = wraptile(_connection);
|
const connectionWraped = wraptile(_connection);
|
||||||
const middle = currify(_middle);
|
const middle = currify(_middle);
|
||||||
|
|
||||||
const readjsonSync = (name) => {
|
const rootConfig = readjson.sync(ConfigPath);
|
||||||
return jju.parse(fs.readFileSync(name, 'utf8'), {
|
|
||||||
mode: 'json',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const rootConfig = readjsonSync(ConfigPath);
|
|
||||||
|
|
||||||
function read(filename) {
|
function read(filename) {
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return rootConfig;
|
return rootConfig;
|
||||||
|
|
||||||
const [error, configHome] = tryCatch(readjsonSync, filename);
|
const [error, configHome] = tryCatch(readjson.sync, filename);
|
||||||
|
|
||||||
if (error && error.code !== 'ENOENT')
|
if (error && error.code !== 'ENOENT')
|
||||||
exit(`cloudcmd --config ${filename}: ${error.message}`);
|
exit(`cloudcmd --config ${filename}: ${error.message}`);
|
||||||
|
|
@ -61,8 +52,7 @@ function read(filename) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.createConfig = createConfig;
|
export const configPath = join(HOME, '.cloudcmd.json');
|
||||||
module.exports.configPath = ConfigHome;
|
|
||||||
|
|
||||||
const manageListen = currify((manage, socket, auth) => {
|
const manageListen = currify((manage, socket, auth) => {
|
||||||
if (!manage('configDialog'))
|
if (!manage('configDialog'))
|
||||||
|
|
@ -80,7 +70,7 @@ function initWrite(filename, configManager) {
|
||||||
return resolve;
|
return resolve;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createConfig({configPath} = {}) {
|
export function createConfig({configPath} = {}) {
|
||||||
const config = {};
|
const config = {};
|
||||||
const changeEmitter = new Emitter();
|
const changeEmitter = new Emitter();
|
||||||
|
|
||||||
|
|
@ -231,7 +221,7 @@ function traverse([manage, json]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._cryptoPass = cryptoPass;
|
export const _cryptoPass = cryptoPass;
|
||||||
function cryptoPass(manage, json) {
|
function cryptoPass(manage, json) {
|
||||||
const algo = manage('algo');
|
const algo = manage('algo');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,13 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import stub from '@cloudcmd/stub';
|
||||||
|
|
||||||
const test = require('supertape');
|
import {createConfig, _cryptoPass} from './config.js';
|
||||||
const stub = require('@cloudcmd/stub');
|
|
||||||
|
|
||||||
const root = '../';
|
|
||||||
const configPath = './config';
|
|
||||||
|
|
||||||
const {
|
|
||||||
createConfig,
|
|
||||||
_cryptoPass,
|
|
||||||
} = require(configPath);
|
|
||||||
const config = createConfig();
|
const config = createConfig();
|
||||||
|
|
||||||
const {apiURL} = require(root + 'common/cloudfunc');
|
import {apiURL} from '../common/cloudfunc.js';
|
||||||
|
|
||||||
const fixture = require('./config.fixture');
|
import fixture from './config.fixture.js';
|
||||||
const {connect} = require('../test/before');
|
import {connect} from '../test/before.js';
|
||||||
|
|
||||||
test('config: manage', (t) => {
|
test('config: manage', (t) => {
|
||||||
t.equal(undefined, config(), 'should return "undefined"');
|
t.equal(undefined, config(), 'should return "undefined"');
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
import currify from 'currify';
|
||||||
|
import wraptile from 'wraptile';
|
||||||
|
import squad from 'squad';
|
||||||
|
import omit from 'object.omit';
|
||||||
|
|
||||||
const currify = require('currify');
|
import log from './log.js';
|
||||||
const wraptile = require('wraptile');
|
|
||||||
const squad = require('squad');
|
|
||||||
const omit = require('object.omit');
|
|
||||||
|
|
||||||
const log = require('./log');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
exportStr,
|
exportStr,
|
||||||
|
|
@ -38,7 +36,7 @@ const omitList = [
|
||||||
|
|
||||||
const omitConfig = (config) => omit(config, omitList);
|
const omitConfig = (config) => omit(config, omitList);
|
||||||
|
|
||||||
module.exports = (config, socket) => {
|
export default (config, socket) => {
|
||||||
if (!config('export'))
|
if (!config('export'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
import {once} from 'events';
|
||||||
|
|
||||||
const {once} = require('events');
|
import test from 'supertape';
|
||||||
|
import io from 'socket.io-client';
|
||||||
|
|
||||||
const test = require('supertape');
|
import {connect} from '../../test/before.js';
|
||||||
const io = require('socket.io-client');
|
|
||||||
|
|
||||||
const {connect} = require('../../test/before');
|
|
||||||
const config = require('../config').createConfig();
|
const config = require('../config').createConfig();
|
||||||
|
|
||||||
test('distribute: export', async (t) => {
|
test('distribute: export', async (t) => {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
'use strict';
|
import currify from 'currify';
|
||||||
|
import wraptile from 'wraptile';
|
||||||
|
import squad from 'squad';
|
||||||
|
import fullstore from 'fullstore';
|
||||||
|
import _forEachKey from 'for-each-key';
|
||||||
|
|
||||||
const currify = require('currify');
|
import io from 'socket.io-client';
|
||||||
const wraptile = require('wraptile');
|
|
||||||
const squad = require('squad');
|
|
||||||
const fullstore = require('fullstore');
|
|
||||||
|
|
||||||
const io = require('socket.io-client');
|
import log from './log.js';
|
||||||
const forEachKey = currify(require('for-each-key'));
|
import env from '../env.js';
|
||||||
|
|
||||||
const log = require('./log');
|
const forEachKey = currify(_forEachKey);
|
||||||
const env = require('../env');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
importStr,
|
importStr,
|
||||||
|
|
@ -75,7 +75,7 @@ const updateConfig = currify((config, data) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = (config, options, fn) => {
|
export default (config, options, fn) => {
|
||||||
fn = fn || options;
|
fn = fn || options;
|
||||||
|
|
||||||
if (!config('import'))
|
if (!config('import'))
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import {promisify} from 'util';
|
||||||
|
import tryToCatch from 'try-to-catch';
|
||||||
|
|
||||||
const test = require('supertape');
|
import {connect} from '../../test/before.js';
|
||||||
const {promisify} = require('util');
|
import {createConfigManager} from '../cloudcmd.js';
|
||||||
const tryToCatch = require('try-to-catch');
|
|
||||||
|
|
||||||
const {connect} = require('../../test/before');
|
|
||||||
const {createConfigManager} = require('../cloudcmd');
|
|
||||||
|
|
||||||
const distribute = {
|
const distribute = {
|
||||||
import: promisify(require('./import')),
|
import: promisify(require('./import')),
|
||||||
|
|
@ -237,7 +235,7 @@ test('distribute: import: env', async (t) => {
|
||||||
const result = configManagerImport('editor');
|
const result = configManagerImport('editor');
|
||||||
const expected = 'deepword';
|
const expected = 'deepword';
|
||||||
|
|
||||||
t.equal(expected, result);
|
t.equal(result, expected);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -281,6 +279,6 @@ test('distribute: import: no env', async (t) => {
|
||||||
const result = configManagerImport('editor');
|
const result = configManagerImport('editor');
|
||||||
const expected = 'edward';
|
const expected = 'edward';
|
||||||
|
|
||||||
t.equal(expected, result);
|
t.equal(result, expected);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports.import = require('./import');
|
|
||||||
module.exports.export = require('./export');
|
|
||||||
|
|
@ -1,30 +1,24 @@
|
||||||
'use strict';
|
import wraptile from 'wraptile';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
|
||||||
const wraptile = require('wraptile');
|
import datetime from '../../common/datetime.js';
|
||||||
const chalk = require('chalk');
|
|
||||||
|
|
||||||
const datetime = require('../../common/datetime');
|
|
||||||
|
|
||||||
const log = (isLog, name, msg) => isLog && console.log(`${datetime()} -> ${name}: ${msg}`);
|
const log = (isLog, name, msg) => isLog && console.log(`${datetime()} -> ${name}: ${msg}`);
|
||||||
const makeColor = (a, color) => chalk.rgb(color || stringToRGB(a))(a);
|
export const makeColor = (a, color) => chalk.rgb(color || stringToRGB(a))(a);
|
||||||
const getMessage = (e) => e.message || e;
|
export const getMessage = (e) => e.message || e;
|
||||||
const getDescription = (e) => `${e.type}: ${e.description}`;
|
export const getDescription = (e) => `${e.type}: ${e.description}`;
|
||||||
|
|
||||||
module.exports = log;
|
export default log;
|
||||||
module.exports.logWraped = wraptile(log);
|
export const logWraped = wraptile(log);
|
||||||
module.exports.stringToRGB = stringToRGB;
|
|
||||||
module.exports.makeColor = makeColor;
|
|
||||||
module.exports.getMessage = getMessage;
|
|
||||||
module.exports.getDescription = getDescription;
|
|
||||||
|
|
||||||
module.exports.importStr = 'import';
|
export const importStr = 'import';
|
||||||
module.exports.exportStr = 'export';
|
export const exportStr = 'export';
|
||||||
module.exports.connectedStr = chalk.green('connected');
|
export const connectedStr = chalk.green('connected');
|
||||||
module.exports.disconnectedStr = chalk.red('disconnected');
|
export const disconnectedStr = chalk.red('disconnected');
|
||||||
module.exports.tokenRejectedStr = chalk.red('token rejected');
|
export const tokenRejectedStr = chalk.red('token rejected');
|
||||||
module.exports.authTryStr = chalk.yellow('try to auth');
|
export const authTryStr = chalk.yellow('try to auth');
|
||||||
|
|
||||||
function stringToRGB(a) {
|
export function stringToRGB(a) {
|
||||||
return [
|
return [
|
||||||
a.charCodeAt(0),
|
a.charCodeAt(0),
|
||||||
a.length,
|
a.length,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import log from './log.js';
|
||||||
const test = require('supertape');
|
import {createConfig} from '../config.js';
|
||||||
const log = require('./log');
|
|
||||||
const {createConfig} = require('../config');
|
|
||||||
|
|
||||||
test('distribute: log: getMessage', (t) => {
|
test('distribute: log: getMessage', (t) => {
|
||||||
const e = 'hello';
|
const e = 'hello';
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
'use strict';
|
import snake from 'just-snake-case';
|
||||||
|
|
||||||
const snake = require('just-snake-case');
|
|
||||||
|
|
||||||
const {env} = process;
|
const {env} = process;
|
||||||
const up = (a) => a.toUpperCase();
|
const up = (a) => a.toUpperCase();
|
||||||
|
|
||||||
module.exports = parse;
|
export default function parse(name) {
|
||||||
module.exports.bool = (name) => {
|
const small = `cloudcmd_${snake(name)}`;
|
||||||
|
const big = up(small);
|
||||||
|
|
||||||
|
return env[big] || env[small];
|
||||||
|
}
|
||||||
|
|
||||||
|
parse.bool = (name) => {
|
||||||
const value = parse(name);
|
const value = parse(name);
|
||||||
|
|
||||||
if (value === 'true')
|
if (value === 'true')
|
||||||
|
|
@ -16,10 +20,3 @@ module.exports.bool = (name) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
function parse(name) {
|
|
||||||
const small = `cloudcmd_${snake(name)}`;
|
|
||||||
const big = up(small);
|
|
||||||
|
|
||||||
return env[big] || env[small];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import env from './env.js';
|
||||||
const test = require('supertape');
|
|
||||||
const env = require('./env');
|
|
||||||
|
|
||||||
test('cloudcmd: server: env: bool: upper case first', (t) => {
|
test('cloudcmd: server: env: bool: upper case first', (t) => {
|
||||||
const {
|
const {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const getMessage = (a) => a && a.message || a;
|
const getMessage = (a) => a && a.message || a;
|
||||||
|
|
||||||
module.exports = (...args) => {
|
export default (...args) => {
|
||||||
const messages = args.map(getMessage);
|
const messages = args.map(getMessage);
|
||||||
|
|
||||||
console.error(...messages);
|
console.error(...messages);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import exit from './exit.js';
|
||||||
const test = require('supertape');
|
import stub from '@cloudcmd/stub';
|
||||||
const exit = require('./exit');
|
|
||||||
const stub = require('@cloudcmd/stub');
|
|
||||||
|
|
||||||
test('cloudcmd: exit: process.exit', (t) => {
|
test('cloudcmd: exit: process.exit', (t) => {
|
||||||
const {exit:exitOriginal} = process;
|
const {exit:exitOriginal} = process;
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
'use strict';
|
import {readFile} from 'fs/promises';
|
||||||
|
import {join, dirname} from 'path';
|
||||||
|
import {callbackify} from 'util';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
const {readFile} = require('fs').promises;
|
import pullout from 'pullout';
|
||||||
const {join} = require('path');
|
import ponse from 'ponse';
|
||||||
const {callbackify} = require('util');
|
import threadIt from 'thread-it';
|
||||||
|
|
||||||
const pullout = require('pullout');
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const ponse = require('ponse');
|
|
||||||
const threadIt = require('thread-it');
|
|
||||||
|
|
||||||
const parse = threadIt(join(__dirname, 'worker'));
|
const parse = threadIt(join(__dirname, 'worker.cjs'));
|
||||||
|
|
||||||
const root = require('../root');
|
import root from '../root.js';
|
||||||
|
|
||||||
threadIt.init();
|
threadIt.init();
|
||||||
|
|
||||||
|
|
@ -19,7 +20,7 @@ parse('');
|
||||||
|
|
||||||
const DIR_ROOT = __dirname + '/../../';
|
const DIR_ROOT = __dirname + '/../../';
|
||||||
|
|
||||||
module.exports = callbackify(async (name, rootDir, request) => {
|
export default callbackify(async (name, rootDir, request) => {
|
||||||
check(name, request);
|
check(name, request);
|
||||||
|
|
||||||
const {method} = request;
|
const {method} = request;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
'use strict';
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import test from 'supertape';
|
||||||
|
import {promisify} from 'util';
|
||||||
|
|
||||||
const fs = require('fs');
|
import tryToCatch from 'try-to-catch';
|
||||||
const path = require('path');
|
|
||||||
const test = require('supertape');
|
|
||||||
const {promisify} = require('util');
|
|
||||||
|
|
||||||
const tryToCatch = require('try-to-catch');
|
import markdown from '.';
|
||||||
|
|
||||||
const markdown = require('.');
|
|
||||||
|
|
||||||
const _markdown = promisify(markdown);
|
const _markdown = promisify(markdown);
|
||||||
const fixtureDir = path.join(__dirname, 'fixture');
|
const fixtureDir = path.join(__dirname, 'fixture');
|
||||||
const cloudcmd = require('../..');
|
import cloudcmd from '../...js';
|
||||||
const config = {
|
const config = {
|
||||||
auth: false,
|
auth: false,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,2 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const markdownIt = require('markdown-it')();
|
const markdownIt = require('markdown-it')();
|
||||||
module.exports = (a) => markdownIt.render(a);
|
module.exports = (a) => markdownIt.render(a);
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
import deepmerge from 'deepmerge';
|
||||||
|
import readjson from 'readjson';
|
||||||
|
|
||||||
const deepmerge = require('deepmerge');
|
const originalModules = await readjson(new URL('../json/modules.json', import.meta.url));
|
||||||
const originalModules = require('../json/modules');
|
|
||||||
|
|
||||||
module.exports = (modules) => {
|
export default (modules) => {
|
||||||
const result = deepmerge(originalModules, modules || {});
|
const result = deepmerge(originalModules, modules || {});
|
||||||
|
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
'use strict';
|
export default (value) => {
|
||||||
|
|
||||||
module.exports = (value) => {
|
|
||||||
if (typeof value !== 'string')
|
if (typeof value !== 'string')
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
|
||||||
const test = require('supertape');
|
import prefixer from './prefixer.js';
|
||||||
|
|
||||||
const prefixer = require('./prefixer');
|
|
||||||
|
|
||||||
test('prefixer: prefix without a slash', (t) => {
|
test('prefixer: prefix without a slash', (t) => {
|
||||||
t.equal(prefixer('hello'), '/hello', 'should add slash');
|
t.equal(prefixer('hello'), '/hello', 'should add slash');
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
'use strict';
|
import net from 'net';
|
||||||
|
import repl from 'repl';
|
||||||
|
|
||||||
const net = require('net');
|
export default net.createServer((socket) => {
|
||||||
const repl = require('repl');
|
|
||||||
|
|
||||||
module.exports = net.createServer((socket) => {
|
|
||||||
const {pid} = process;
|
const {pid} = process;
|
||||||
const addr = socket.remoteAddress;
|
const addr = socket.remoteAddress;
|
||||||
const port = socket.remotePort;
|
const port = socket.remotePort;
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,25 @@
|
||||||
'use strict';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
const DIR = '../';
|
import root from '../root.js';
|
||||||
const DIR_COMMON = DIR + '../common/';
|
import {apiURL, formatMsg} from '../../common/cloudfunc.js';
|
||||||
|
import markdown from '../markdown/index.js';
|
||||||
|
import info from './info.js';
|
||||||
|
|
||||||
const path = require('path');
|
import jaguar from 'jaguar';
|
||||||
const fs = require('fs');
|
import onezip from 'onezip';
|
||||||
|
import inly from 'inly';
|
||||||
|
import wraptile from 'wraptile';
|
||||||
|
import currify from 'currify';
|
||||||
|
import pullout from 'pullout';
|
||||||
|
import json from 'jonny';
|
||||||
|
import ponse from 'ponse';
|
||||||
|
|
||||||
const root = require(DIR + 'root');
|
import copymitter from 'copymitter';
|
||||||
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
|
import moveFiles from '@cloudcmd/move-files';
|
||||||
const markdown = require(DIR + 'markdown');
|
|
||||||
const info = require('./info');
|
|
||||||
|
|
||||||
const jaguar = require('jaguar');
|
|
||||||
const onezip = require('onezip');
|
|
||||||
const inly = require('inly');
|
|
||||||
const wraptile = require('wraptile');
|
|
||||||
const currify = require('currify');
|
|
||||||
const pullout = require('pullout');
|
|
||||||
const json = require('jonny');
|
|
||||||
const ponse = require('ponse');
|
|
||||||
|
|
||||||
const copymitter = require('copymitter');
|
|
||||||
const moveFiles = require('@cloudcmd/move-files');
|
|
||||||
|
|
||||||
const swap = wraptile((fn, a, b) => fn(b, a));
|
const swap = wraptile((fn, a, b) => fn(b, a));
|
||||||
const isWin32 = process.platform === 'win32';
|
const isWin32 = process.platform === 'win32';
|
||||||
const {apiURL} = CloudFunc;
|
|
||||||
|
|
||||||
const UserError = (msg) => {
|
const UserError = (msg) => {
|
||||||
const error = Error(msg);
|
const error = Error(msg);
|
||||||
|
|
@ -34,7 +28,7 @@ const UserError = (msg) => {
|
||||||
return error;
|
return error;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = currify((config, request, response, next) => {
|
export default currify((config, request, response, next) => {
|
||||||
const name = ponse.getPathName(request);
|
const name = ponse.getPathName(request);
|
||||||
const regExp = RegExp('^' + apiURL);
|
const regExp = RegExp('^' + apiURL);
|
||||||
const is = regExp.test(name);
|
const is = regExp.test(name);
|
||||||
|
|
@ -182,7 +176,7 @@ const getRenameMsg = (from, to) => {
|
||||||
return msg;
|
return msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports._onPUT = onPUT;
|
export const _onPUT = onPUT;
|
||||||
function onPUT({name, config, body}, callback) {
|
function onPUT({name, config, body}, callback) {
|
||||||
checkPut(name, body, callback);
|
checkPut(name, body, callback);
|
||||||
|
|
||||||
|
|
@ -360,14 +354,14 @@ const isRootWin32 = currify((root, path) => {
|
||||||
return isWin32 && isRoot && isConfig;
|
return isWin32 && isRoot && isConfig;
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports._isRootWin32 = isRootWin32;
|
export const _isRootWin32 = isRootWin32;
|
||||||
module.exports._isRootAll = isRootAll;
|
export const _isRootAll = isRootAll;
|
||||||
|
|
||||||
function isRootAll(root, names) {
|
function isRootAll(root, names) {
|
||||||
return names.some(isRootWin32(root));
|
return names.some(isRootWin32(root));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._getWin32RootMsg = getWin32RootMsg;
|
export const _getWin32RootMsg = getWin32RootMsg;
|
||||||
|
|
||||||
function getWin32RootMsg() {
|
function getWin32RootMsg() {
|
||||||
const message = 'Could not copy from/to root on windows!';
|
const message = 'Could not copy from/to root on windows!';
|
||||||
|
|
@ -385,11 +379,11 @@ function parseData(data) {
|
||||||
return json.stringify(data);
|
return json.stringify(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._formatMsg = formatMsg;
|
export const _formatMsg = formatRawMessage;
|
||||||
|
|
||||||
function formatMsg(msg, data, status) {
|
function formatRawMessage(msg, data, status) {
|
||||||
const value = parseData(data);
|
const value = parseData(data);
|
||||||
return CloudFunc.formatMsg(msg, value, status);
|
return formatMsg(msg, value, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPut(name, body, callback) {
|
function checkPut(name, body, callback) {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,7 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import tryToCatch from 'try-to-catch';
|
||||||
|
|
||||||
const test = require('supertape');
|
import {_formatMsg, _getWin32RootMsg, _isRootWin32, _isRootAll, _onPUT} from '.';
|
||||||
const tryToCatch = require('try-to-catch');
|
|
||||||
|
|
||||||
const {
|
|
||||||
_formatMsg,
|
|
||||||
_getWin32RootMsg,
|
|
||||||
_isRootWin32,
|
|
||||||
_isRootAll,
|
|
||||||
_onPUT,
|
|
||||||
} = require('.');
|
|
||||||
|
|
||||||
test('rest: formatMsg', (t) => {
|
test('rest: formatMsg', (t) => {
|
||||||
const result = _formatMsg('hello', 'world');
|
const result = _formatMsg('hello', 'world');
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
'use strict';
|
import format from 'format-io';
|
||||||
|
import readjson from 'readjson';
|
||||||
|
|
||||||
const format = require('format-io');
|
const infoPath = new URL('../../package.json', import.meta.url);
|
||||||
|
const {version} = await readjson(infoPath);
|
||||||
const {version} = require('../../package');
|
|
||||||
|
|
||||||
const getMemory = () => {
|
const getMemory = () => {
|
||||||
const {rss} = process.memoryUsage();
|
const {rss} = process.memoryUsage();
|
||||||
return format.size(rss);
|
return format.size(rss);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = (prefix) => ({
|
export default (prefix) => ({
|
||||||
version,
|
version,
|
||||||
prefix,
|
prefix,
|
||||||
memory: getMemory(),
|
memory: getMemory(),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import info from './info.js';
|
||||||
const test = require('supertape');
|
import stub from '@cloudcmd/stub';
|
||||||
const info = require('./info');
|
|
||||||
const stub = require('@cloudcmd/stub');
|
|
||||||
|
|
||||||
test('cloudcmd: rest: info', (t) => {
|
test('cloudcmd: rest: info', (t) => {
|
||||||
const {memoryUsage} = process;
|
const {memoryUsage} = process;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import mellow from 'mellow';
|
||||||
|
|
||||||
const mellow = require('mellow');
|
export default (dir, root) => {
|
||||||
|
|
||||||
module.exports = (dir, root) => {
|
|
||||||
return mellow.pathToWin(dir, root || '/');
|
return mellow.pathToWin(dir, root || '/');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import stub from '@cloudcmd/stub';
|
||||||
const test = require('supertape');
|
import mockRequire from 'mock-require';
|
||||||
const stub = require('@cloudcmd/stub');
|
|
||||||
const mockRequire = require('mock-require');
|
|
||||||
const {reRequire} = mockRequire;
|
const {reRequire} = mockRequire;
|
||||||
|
|
||||||
const pathConfig = './config';
|
const pathConfig = './config';
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,21 @@
|
||||||
'use strict';
|
import {realpath} from 'fs/promises';
|
||||||
|
import {createRequire} from 'module';
|
||||||
|
|
||||||
const DIR_SERVER = './';
|
import {read} from 'flop';
|
||||||
const DIR_COMMON = '../common/';
|
import ponse from 'ponse';
|
||||||
|
import rendy from 'rendy';
|
||||||
|
import format from 'format-io';
|
||||||
|
import currify from 'currify';
|
||||||
|
import tryToCatch from 'try-to-catch';
|
||||||
|
import once from 'once';
|
||||||
|
|
||||||
const {realpath} = require('fs').promises;
|
import root from './root.js';
|
||||||
|
import prefixer from './prefixer.js';
|
||||||
const {read} = require('flop');
|
import * as CloudFunc from '../common/cloudfunc.js';
|
||||||
const ponse = require('ponse');
|
|
||||||
const rendy = require('rendy');
|
|
||||||
const format = require('format-io');
|
|
||||||
const currify = require('currify');
|
|
||||||
const tryToCatch = require('try-to-catch');
|
|
||||||
const once = require('once');
|
|
||||||
|
|
||||||
const root = require(DIR_SERVER + 'root');
|
|
||||||
const prefixer = require(DIR_SERVER + 'prefixer');
|
|
||||||
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
|
|
||||||
|
|
||||||
const getPrefix = (config) => prefixer(config('prefix'));
|
const getPrefix = (config) => prefixer(config('prefix'));
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
const onceRequire = once(require);
|
const onceRequire = once(require);
|
||||||
|
|
||||||
const sendIndex = (params, data) => {
|
const sendIndex = (params, data) => {
|
||||||
|
|
@ -32,8 +29,8 @@ const sendIndex = (params, data) => {
|
||||||
|
|
||||||
const {FS} = CloudFunc;
|
const {FS} = CloudFunc;
|
||||||
|
|
||||||
const Columns = require(`${DIR_SERVER}/columns`);
|
import Columns from './/columns.js';
|
||||||
const Template = require(`${DIR_SERVER}/template`);
|
import Template from './/template.js';
|
||||||
|
|
||||||
const tokenize = (fn, a) => (b) => fn(a, b);
|
const tokenize = (fn, a) => (b) => fn(a, b);
|
||||||
const getReadDir = (config) => {
|
const getReadDir = (config) => {
|
||||||
|
|
@ -48,7 +45,7 @@ const getReadDir = (config) => {
|
||||||
/**
|
/**
|
||||||
* routing of server queries
|
* routing of server queries
|
||||||
*/
|
*/
|
||||||
module.exports = currify((config, options, request, response, next) => {
|
export default currify((config, options, request, response, next) => {
|
||||||
const name = ponse.getPathName(request);
|
const name = ponse.getPathName(request);
|
||||||
const isFS = RegExp('^/$|^' + FS).test(name);
|
const isFS = RegExp('^/$|^' + FS).test(name);
|
||||||
|
|
||||||
|
|
@ -59,7 +56,7 @@ module.exports = currify((config, options, request, response, next) => {
|
||||||
.catch(next);
|
.catch(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports._getReadDir = getReadDir;
|
export const _getReadDir = getReadDir;
|
||||||
|
|
||||||
async function route({config, options, request, response}) {
|
async function route({config, options, request, response}) {
|
||||||
const name = ponse.getPathName(request);
|
const name = ponse.getPathName(request);
|
||||||
|
|
@ -179,7 +176,7 @@ function buildIndex(config, html, data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports._hideKeysPanel = hideKeysPanel;
|
export const _hideKeysPanel = hideKeysPanel;
|
||||||
function hideKeysPanel(html) {
|
function hideKeysPanel(html) {
|
||||||
const keysPanel = '<div id="js-keyspanel" class="{{ className }}"';
|
const keysPanel = '<div id="js-keyspanel" class="{{ className }}"';
|
||||||
const keysPanelRegExp = '<div id="?js-keyspanel"? class="?{{ className }}"?';
|
const keysPanelRegExp = '<div id="?js-keyspanel"? class="?{{ className }}"?';
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
const path = require('path');
|
import tryToCatch from 'try-to-catch';
|
||||||
const fs = require('fs');
|
import test from 'supertape';
|
||||||
|
import mockRequire from 'mock-require';
|
||||||
const tryToCatch = require('try-to-catch');
|
|
||||||
const test = require('supertape');
|
|
||||||
const mockRequire = require('mock-require');
|
|
||||||
const {reRequire, stopAll} = mockRequire;
|
const {reRequire, stopAll} = mockRequire;
|
||||||
|
|
||||||
const fixtureDir = path.join(__dirname, '..', 'test', 'fixture');
|
const fixtureDir = path.join(__dirname, '..', 'test', 'fixture');
|
||||||
|
|
@ -13,9 +11,9 @@ const fixtureDir = path.join(__dirname, '..', 'test', 'fixture');
|
||||||
const routePath = './route';
|
const routePath = './route';
|
||||||
const cloudcmdPath = './cloudcmd';
|
const cloudcmdPath = './cloudcmd';
|
||||||
|
|
||||||
const cloudcmd = require(cloudcmdPath);
|
import cloudcmd from './cloudcmd.js';
|
||||||
const {createConfigManager} = cloudcmd;
|
const {createConfigManager} = cloudcmd;
|
||||||
const serveOnce = require('serve-once');
|
import serveOnce from 'serve-once';
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
auth: false,
|
auth: false,
|
||||||
dropbox: false,
|
dropbox: false,
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,32 @@
|
||||||
'use strict';
|
import cloudcmd from './cloudcmd.js';
|
||||||
|
|
||||||
const DIR_SERVER = './';
|
import http from 'http';
|
||||||
const cloudcmd = require(DIR_SERVER + 'cloudcmd');
|
import {createRequire} from 'module';
|
||||||
|
|
||||||
const http = require('http');
|
import {promisify} from 'util';
|
||||||
const {promisify} = require('util');
|
import currify from 'currify';
|
||||||
const currify = require('currify');
|
import squad from 'squad';
|
||||||
const squad = require('squad');
|
import tryToCatch from 'try-to-catch';
|
||||||
const tryToCatch = require('try-to-catch');
|
import wraptile from 'wraptile';
|
||||||
const wraptile = require('wraptile');
|
import compression from 'compression';
|
||||||
const compression = require('compression');
|
import threadIt from 'thread-it';
|
||||||
const threadIt = require('thread-it');
|
|
||||||
|
|
||||||
const two = currify((f, a, b) => f(a, b));
|
const two = currify((f, a, b) => f(a, b));
|
||||||
const exit = require(DIR_SERVER + 'exit');
|
import exit from './exit.js';
|
||||||
|
|
||||||
const exitPort = two(exit, 'cloudcmd --port: %s');
|
const exitPort = two(exit, 'cloudcmd --port: %s');
|
||||||
const bind = (f, self) => f.bind(self);
|
const bind = (f, self) => f.bind(self);
|
||||||
const promisifySelf = squad(promisify, bind);
|
const promisifySelf = squad(promisify, bind);
|
||||||
|
|
||||||
|
import opn from 'open';
|
||||||
|
import express from 'express';
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const io = require('socket.io');
|
||||||
|
|
||||||
|
import tryRequire from 'tryrequire';
|
||||||
|
const logger = tryRequire('morgan');
|
||||||
|
|
||||||
const shutdown = wraptile(async (promises) => {
|
const shutdown = wraptile(async (promises) => {
|
||||||
console.log('closing cloudcmd...');
|
console.log('closing cloudcmd...');
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
@ -26,14 +34,7 @@ const shutdown = wraptile(async (promises) => {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
const opn = require('open');
|
export default async (options, config) => {
|
||||||
const express = require('express');
|
|
||||||
const io = require('socket.io');
|
|
||||||
|
|
||||||
const tryRequire = require('tryrequire');
|
|
||||||
const logger = tryRequire('morgan');
|
|
||||||
|
|
||||||
module.exports = async (options, config) => {
|
|
||||||
const prefix = config('prefix');
|
const prefix = config('prefix');
|
||||||
const port = process.env.PORT || /* c9 */
|
const port = process.env.PORT || /* c9 */
|
||||||
config('port');
|
config('port');
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
'use strict';
|
import {table, getBorderCharacters} from 'table';
|
||||||
|
|
||||||
const {
|
export default (config) => {
|
||||||
table,
|
|
||||||
getBorderCharacters,
|
|
||||||
} = require('table');
|
|
||||||
|
|
||||||
module.exports = (config) => {
|
|
||||||
check(config);
|
check(config);
|
||||||
|
|
||||||
const data = Object.keys(config).map((name) => {
|
const data = Object.keys(config).map((name) => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
'use strict';
|
import {join, dirname} from 'path';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
import readFilesSync from '@cloudcmd/read-files-sync';
|
||||||
|
|
||||||
const path = require('path');
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const readFilesSync = require('@cloudcmd/read-files-sync');
|
const templatePath = join(__dirname, '..', 'tmpl/fs');
|
||||||
const templatePath = path.join(__dirname, '..', 'tmpl/fs');
|
|
||||||
|
|
||||||
module.exports = readFilesSync(templatePath, 'utf8');
|
export default readFilesSync(templatePath, 'utf8');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
import {createRequire} from 'module';
|
||||||
|
import tryCatch from 'try-catch';
|
||||||
|
|
||||||
const tryCatch = require('try-catch');
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const noop = (req, res, next) => {
|
const noop = (req, res, next) => {
|
||||||
next && next();
|
next && next();
|
||||||
|
|
@ -8,7 +9,7 @@ const noop = (req, res, next) => {
|
||||||
|
|
||||||
noop.listen = noop;
|
noop.listen = noop;
|
||||||
|
|
||||||
module.exports = (config, arg) => {
|
export default (config, arg) => {
|
||||||
if (!config('terminal'))
|
if (!config('terminal'))
|
||||||
return noop;
|
return noop;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import stub from '@cloudcmd/stub';
|
||||||
|
|
||||||
const test = require('supertape');
|
import mockRequire from 'mock-require';
|
||||||
const stub = require('@cloudcmd/stub');
|
|
||||||
|
|
||||||
const mockRequire = require('mock-require');
|
|
||||||
|
|
||||||
const terminalPath = './terminal';
|
const terminalPath = './terminal';
|
||||||
const terminal = require('./terminal');
|
import terminal from './terminal.js';
|
||||||
const {createConfigManager} = require('./cloudcmd');
|
import {createConfigManager} from './cloudcmd.js';
|
||||||
|
|
||||||
test('cloudcmd: terminal: disabled', (t) => {
|
test('cloudcmd: terminal: disabled', (t) => {
|
||||||
const config = createConfigManager();
|
const config = createConfigManager();
|
||||||
|
|
@ -29,13 +27,13 @@ test('cloudcmd: terminal: disabled: listen', (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: terminal: enabled', (t) => {
|
test('cloudcmd: terminal: enabled', async (t) => {
|
||||||
const term = stub();
|
const term = stub();
|
||||||
const arg = 'hello';
|
const arg = 'hello';
|
||||||
|
|
||||||
mockRequire(terminalPath, term);
|
mockRequire(terminalPath, term);
|
||||||
|
|
||||||
const terminal = require(terminalPath);
|
const terminal = await import(terminalPath);
|
||||||
terminal(arg);
|
terminal(arg);
|
||||||
|
|
||||||
t.calledWith(term, [arg], 'should call terminal');
|
t.calledWith(term, [arg], 'should call terminal');
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
'use strict';
|
import {homedir} from 'os';
|
||||||
|
import {readFile} from 'fs/promises';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
import {join, dirname} from 'path';
|
||||||
|
import {createRequire} from 'module';
|
||||||
|
|
||||||
const {homedir} = require('os');
|
import tryToCatch from 'try-to-catch';
|
||||||
const {readFile} = require('fs').promises;
|
import currify from 'currify';
|
||||||
|
import findUp from 'find-up';
|
||||||
|
import threadIt from 'thread-it';
|
||||||
|
import {codeframe} from 'putout';
|
||||||
|
|
||||||
const {join} = require('path');
|
const {resolve} = createRequire(import.meta.url);
|
||||||
|
const putout = threadIt(resolve('putout'));
|
||||||
const tryToCatch = require('try-to-catch');
|
|
||||||
const currify = require('currify');
|
|
||||||
const findUp = require('find-up');
|
|
||||||
const threadIt = require('thread-it');
|
|
||||||
const {codeframe} = require('putout');
|
|
||||||
const putout = threadIt(require.resolve('putout'));
|
|
||||||
|
|
||||||
threadIt.init();
|
threadIt.init();
|
||||||
|
|
||||||
|
|
@ -18,9 +19,10 @@ threadIt.init();
|
||||||
transpile('');
|
transpile('');
|
||||||
|
|
||||||
const URL = '/api/v1/user-menu';
|
const URL = '/api/v1/user-menu';
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const DEFAULT_MENU_PATH = join(__dirname, '../static/user-menu.js');
|
const DEFAULT_MENU_PATH = join(__dirname, '../static/user-menu.js');
|
||||||
|
|
||||||
module.exports = currify(async ({menuName}, req, res, next) => {
|
export default currify(async ({menuName}, req, res, next) => {
|
||||||
if (req.url.indexOf(URL))
|
if (req.url.indexOf(URL))
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
'use strict';
|
import fs from 'fs';
|
||||||
|
import {join} from 'path';
|
||||||
|
|
||||||
const fs = require('fs');
|
import test from 'supertape';
|
||||||
const {join} = require('path');
|
import serveOnce from 'serve-once';
|
||||||
|
import threadIt from 'thread-it';
|
||||||
|
import stub from '@cloudcmd/stub';
|
||||||
|
import {reRequire} from 'mock-require';
|
||||||
|
|
||||||
const test = require('supertape');
|
import userMenu from './user-menu.js';
|
||||||
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 {request} = serveOnce(userMenu);
|
||||||
|
|
||||||
const {readFileSync} = fs;
|
const {readFileSync} = fs;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
import tryCatch from 'try-catch';
|
||||||
|
|
||||||
const tryCatch = require('try-catch');
|
import exit from './exit.js';
|
||||||
|
import columnsData from './columns.js';
|
||||||
|
|
||||||
const exit = require('./exit');
|
export const root = async (dir, config) => {
|
||||||
const columns = require('./columns');
|
|
||||||
|
|
||||||
module.exports.root = (dir, config) => {
|
|
||||||
if (typeof dir !== 'string')
|
if (typeof dir !== 'string')
|
||||||
throw Error('dir should be a string');
|
throw Error('dir should be a string');
|
||||||
|
|
||||||
|
|
@ -15,31 +13,31 @@ module.exports.root = (dir, config) => {
|
||||||
if (config('dropbox'))
|
if (config('dropbox'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const {statSync} = require('fs');
|
const {statSync} = await import('fs');
|
||||||
const [error] = tryCatch(statSync, dir);
|
const [error] = tryCatch(statSync, dir);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return exit('cloudcmd --root: %s', error.message);
|
return exit('cloudcmd --root: %s', error.message);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.editor = (name) => {
|
export const editor = (name) => {
|
||||||
const reg = /^(dword|edward|deepword)$/;
|
const reg = /^(dword|edward|deepword)$/;
|
||||||
|
|
||||||
if (!reg.test(name))
|
if (!reg.test(name))
|
||||||
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
|
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.packer = (name) => {
|
export const packer = (name) => {
|
||||||
const reg = /^(tar|zip)$/;
|
const reg = /^(tar|zip)$/;
|
||||||
|
|
||||||
if (!reg.test(name))
|
if (!reg.test(name))
|
||||||
exit('cloudcmd --packer: could be "tar" or "zip" only');
|
exit('cloudcmd --packer: could be "tar" or "zip" only');
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.columns = (type) => {
|
export const columns = (type) => {
|
||||||
const addQuotes = (a) => `"${a}"`;
|
const addQuotes = (a) => `"${a}"`;
|
||||||
const all = Object
|
const all = Object
|
||||||
.keys(columns)
|
.keys(columnsData)
|
||||||
.concat('');
|
.concat('');
|
||||||
|
|
||||||
const names = all
|
const names = all
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
import fs from 'fs';
|
||||||
|
|
||||||
const fs = require('fs');
|
import test from 'supertape';
|
||||||
|
import stub from '@cloudcmd/stub';
|
||||||
const test = require('supertape');
|
import tryCatch from 'try-catch';
|
||||||
const stub = require('@cloudcmd/stub');
|
import mockRequire from 'mock-require';
|
||||||
const tryCatch = require('try-catch');
|
|
||||||
const mockRequire = require('mock-require');
|
|
||||||
const {reRequire} = mockRequire;
|
const {reRequire} = mockRequire;
|
||||||
|
|
||||||
const dir = '..';
|
const dir = '..';
|
||||||
|
|
@ -13,10 +11,9 @@ const dir = '..';
|
||||||
const validatePath = `${dir}/server/validate`;
|
const validatePath = `${dir}/server/validate`;
|
||||||
const exitPath = `${dir}/server/exit`;
|
const exitPath = `${dir}/server/exit`;
|
||||||
const columnsPath = `${dir}/server/columns`;
|
const columnsPath = `${dir}/server/columns`;
|
||||||
const cloudcmdPath = `${dir}/server/cloudcmd`;
|
|
||||||
|
|
||||||
const validate = require(validatePath);
|
import validate from '../server/validate.js';
|
||||||
const cloudcmd = require(cloudcmdPath);
|
import cloudcmd from '../server/cloudcmd.js';
|
||||||
|
|
||||||
test('validate: root: bad', (t) => {
|
test('validate: root: bad', (t) => {
|
||||||
const config = {
|
const config = {
|
||||||
|
|
@ -100,11 +97,11 @@ test('validate: editor: not valid', (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('validate: columns', (t) => {
|
test('validate: columns', async (t) => {
|
||||||
const fn = stub();
|
const fn = stub();
|
||||||
mockRequire(exitPath, fn);
|
mockRequire(exitPath, fn);
|
||||||
|
|
||||||
const {columns} = require(validatePath);
|
const {columns} = await import(validatePath);
|
||||||
|
|
||||||
columns('name-size-date');
|
columns('name-size-date');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue