mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: distribute: convert to ESM
This commit is contained in:
parent
faa2cb3f90
commit
d75818297b
9 changed files with 78 additions and 82 deletions
|
|
@ -241,8 +241,8 @@ async function main() {
|
||||||
if (args.showConfig)
|
if (args.showConfig)
|
||||||
await showConfig();
|
await showConfig();
|
||||||
|
|
||||||
const distribute = await simport('../server/distribute/index.js');
|
const {distributeImport} = await simport('../server/distribute/import.mjs');
|
||||||
const importConfig = promisify(distribute.import);
|
const importConfig = promisify(distributeImport);
|
||||||
|
|
||||||
await start(options, config);
|
await start(options, config);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import route from './route.mjs';
|
||||||
import * as validate from './validate.mjs';
|
import * as validate from './validate.mjs';
|
||||||
import prefixer from './prefixer.js';
|
import prefixer from './prefixer.js';
|
||||||
import terminal from './terminal.js';
|
import terminal from './terminal.js';
|
||||||
import distribute from './distribute/index.js';
|
import {distributeExport} from './distribute/export.mjs';
|
||||||
import {createDepStore} from './depstore.js';
|
import {createDepStore} from './depstore.js';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
|
@ -175,7 +175,7 @@ function listen({prefixSocket, socket, config}) {
|
||||||
autoRestart: config('terminalAutoRestart'),
|
autoRestart: config('terminalAutoRestart'),
|
||||||
});
|
});
|
||||||
|
|
||||||
distribute.export(config, socket);
|
distributeExport(config, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloudcmdMiddle({modules, config}) {
|
function cloudcmdMiddle({modules, config}) {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
'use strict';
|
import currify from 'currify';
|
||||||
|
import wraptile from 'wraptile';
|
||||||
const currify = require('currify');
|
import squad from 'squad';
|
||||||
const wraptile = require('wraptile');
|
import omit from 'object.omit';
|
||||||
const squad = require('squad');
|
import log, {
|
||||||
const omit = require('object.omit');
|
|
||||||
|
|
||||||
const log = require('./log');
|
|
||||||
|
|
||||||
const {
|
|
||||||
exportStr,
|
exportStr,
|
||||||
connectedStr,
|
connectedStr,
|
||||||
disconnectedStr,
|
disconnectedStr,
|
||||||
|
|
@ -16,7 +11,7 @@ const {
|
||||||
getMessage,
|
getMessage,
|
||||||
getDescription,
|
getDescription,
|
||||||
logWraped,
|
logWraped,
|
||||||
} = log;
|
} from './log.mjs';
|
||||||
|
|
||||||
const omitList = [
|
const omitList = [
|
||||||
'auth',
|
'auth',
|
||||||
|
|
@ -38,7 +33,7 @@ const omitList = [
|
||||||
|
|
||||||
const omitConfig = (config) => omit(config, omitList);
|
const omitConfig = (config) => omit(config, omitList);
|
||||||
|
|
||||||
module.exports = (config, socket) => {
|
export const distributeExport = (config, socket) => {
|
||||||
if (!config('export'))
|
if (!config('export'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
'use strict';
|
import currify from 'currify';
|
||||||
|
import wraptile from 'wraptile';
|
||||||
|
import squad from 'squad';
|
||||||
|
import fullstore from 'fullstore';
|
||||||
|
import io from 'socket.io-client';
|
||||||
|
import log from './log.mjs';
|
||||||
|
import env from '../env.js';
|
||||||
|
import _forEachKey from 'for-each-key';
|
||||||
|
|
||||||
const currify = require('currify');
|
|
||||||
const wraptile = require('wraptile');
|
|
||||||
const squad = require('squad');
|
|
||||||
const fullstore = require('fullstore');
|
|
||||||
|
|
||||||
const io = require('socket.io-client');
|
|
||||||
const log = require('./log');
|
|
||||||
|
|
||||||
const env = require('../env');
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
const forEachKey = currify(require('for-each-key'));
|
const forEachKey = currify(_forEachKey);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
importStr,
|
importStr,
|
||||||
|
|
@ -67,7 +65,7 @@ const updateConfig = currify((config, data) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = (config, options, fn) => {
|
export const distributeImport = (config, options, fn) => {
|
||||||
fn = fn || options;
|
fn = fn || options;
|
||||||
|
|
||||||
if (!config('import'))
|
if (!config('import'))
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
import {createRequire} from 'node:module';
|
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import test from 'supertape';
|
import test from 'supertape';
|
||||||
import {promisify} from 'node:util';
|
import {promisify} from 'node:util';
|
||||||
import tryToCatch from 'try-to-catch';
|
import tryToCatch from 'try-to-catch';
|
||||||
import {connect} from '../../test/before.mjs';
|
import {connect} from '../../test/before.mjs';
|
||||||
import {createConfigManager} from '../cloudcmd.mjs';
|
import {createConfigManager} from '../cloudcmd.mjs';
|
||||||
|
import {distributeImport} from './import.mjs';
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
|
|
||||||
const distribute = {
|
const distribute = {
|
||||||
import: promisify(require('./import')),
|
import: promisify(distributeImport),
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = createConfigManager();
|
const config = createConfigManager();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports.import = require('./import');
|
|
||||||
module.exports.export = require('./export');
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const wraptile = require('wraptile');
|
|
||||||
const chalk = require('chalk');
|
|
||||||
|
|
||||||
const datetime = require('../../common/datetime');
|
|
||||||
|
|
||||||
const log = (isLog, name, msg) => isLog && console.log(`${datetime()} -> ${name}: ${msg}`);
|
|
||||||
const makeColor = (a) => chalk.blue(a);
|
|
||||||
const getMessage = (e) => e.message || e;
|
|
||||||
const getDescription = (e) => e.message;
|
|
||||||
|
|
||||||
module.exports = log;
|
|
||||||
module.exports.logWraped = wraptile(log);
|
|
||||||
module.exports.stringToRGB = stringToRGB;
|
|
||||||
module.exports.makeColor = makeColor;
|
|
||||||
module.exports.getMessage = getMessage;
|
|
||||||
module.exports.getDescription = getDescription;
|
|
||||||
|
|
||||||
module.exports.importStr = 'import';
|
|
||||||
module.exports.exportStr = 'export';
|
|
||||||
module.exports.connectedStr = chalk.green('connected');
|
|
||||||
module.exports.disconnectedStr = chalk.red('disconnected');
|
|
||||||
module.exports.tokenRejectedStr = chalk.red('token rejected');
|
|
||||||
module.exports.authTryStr = chalk.yellow('try to auth');
|
|
||||||
|
|
||||||
function stringToRGB(a) {
|
|
||||||
return [
|
|
||||||
a.charCodeAt(0),
|
|
||||||
a.length,
|
|
||||||
crc(a),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
const add = (a, b) => a + b.charCodeAt(0);
|
|
||||||
|
|
||||||
function crc(a) {
|
|
||||||
return a
|
|
||||||
.split('')
|
|
||||||
.reduce(add, 0);
|
|
||||||
}
|
|
||||||
52
server/distribute/log.mjs
Normal file
52
server/distribute/log.mjs
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import wraptile from 'wraptile';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import datetime from '../../common/datetime.js';
|
||||||
|
|
||||||
|
const {assign} = Object;
|
||||||
|
|
||||||
|
const log = (isLog, name, msg) => isLog && console.log(`${datetime()} -> ${name}: ${msg}`);
|
||||||
|
|
||||||
|
export const makeColor = (a) => chalk.blue(a);
|
||||||
|
export const getMessage = (e) => e.message || e;
|
||||||
|
export const getDescription = (e) => e.message;
|
||||||
|
|
||||||
|
export default log;
|
||||||
|
|
||||||
|
export const logWraped = wraptile(log);
|
||||||
|
|
||||||
|
export const importStr = 'import';
|
||||||
|
export const exportStr = 'export';
|
||||||
|
export const connectedStr = chalk.green('connected');
|
||||||
|
export const disconnectedStr = chalk.red('disconnected');
|
||||||
|
export const tokenRejectedStr = chalk.red('token rejected');
|
||||||
|
export const authTryStr = chalk.yellow('try to auth');
|
||||||
|
|
||||||
|
export function stringToRGB(a) {
|
||||||
|
return [
|
||||||
|
a.charCodeAt(0),
|
||||||
|
a.length,
|
||||||
|
crc(a),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
const add = (a, b) => a + b.charCodeAt(0);
|
||||||
|
|
||||||
|
function crc(a) {
|
||||||
|
return a
|
||||||
|
.split('')
|
||||||
|
.reduce(add, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
assign(log, {
|
||||||
|
getMessage,
|
||||||
|
makeColor,
|
||||||
|
getDescription,
|
||||||
|
authTryStr,
|
||||||
|
stringToRGB,
|
||||||
|
logWraped,
|
||||||
|
importStr,
|
||||||
|
exportStr,
|
||||||
|
connectedStr,
|
||||||
|
disconnectedStr,
|
||||||
|
tokenRejectedStr,
|
||||||
|
});
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
import test from 'supertape';
|
||||||
|
import log from './log.mjs';
|
||||||
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';
|
||||||
Loading…
Add table
Add a link
Reference in a new issue