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
|
|
@ -24,7 +24,7 @@ import route from './route.mjs';
|
|||
import * as validate from './validate.mjs';
|
||||
import prefixer from './prefixer.js';
|
||||
import terminal from './terminal.js';
|
||||
import distribute from './distribute/index.js';
|
||||
import {distributeExport} from './distribute/export.mjs';
|
||||
import {createDepStore} from './depstore.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
|
|
@ -175,7 +175,7 @@ function listen({prefixSocket, socket, config}) {
|
|||
autoRestart: config('terminalAutoRestart'),
|
||||
});
|
||||
|
||||
distribute.export(config, socket);
|
||||
distributeExport(config, socket);
|
||||
}
|
||||
|
||||
function cloudcmdMiddle({modules, config}) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
const currify = require('currify');
|
||||
const wraptile = require('wraptile');
|
||||
const squad = require('squad');
|
||||
const omit = require('object.omit');
|
||||
|
||||
const log = require('./log');
|
||||
|
||||
const {
|
||||
import currify from 'currify';
|
||||
import wraptile from 'wraptile';
|
||||
import squad from 'squad';
|
||||
import omit from 'object.omit';
|
||||
import log, {
|
||||
exportStr,
|
||||
connectedStr,
|
||||
disconnectedStr,
|
||||
|
|
@ -16,7 +11,7 @@ const {
|
|||
getMessage,
|
||||
getDescription,
|
||||
logWraped,
|
||||
} = log;
|
||||
} from './log.mjs';
|
||||
|
||||
const omitList = [
|
||||
'auth',
|
||||
|
|
@ -38,7 +33,7 @@ const omitList = [
|
|||
|
||||
const omitConfig = (config) => omit(config, omitList);
|
||||
|
||||
module.exports = (config, socket) => {
|
||||
export const distributeExport = (config, socket) => {
|
||||
if (!config('export'))
|
||||
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 forEachKey = currify(require('for-each-key'));
|
||||
const forEachKey = currify(_forEachKey);
|
||||
|
||||
const {
|
||||
importStr,
|
||||
|
|
@ -67,7 +65,7 @@ const updateConfig = currify((config, data) => {
|
|||
}
|
||||
});
|
||||
|
||||
module.exports = (config, options, fn) => {
|
||||
export const distributeImport = (config, options, fn) => {
|
||||
fn = fn || options;
|
||||
|
||||
if (!config('import'))
|
||||
|
|
@ -1,15 +1,13 @@
|
|||
import {createRequire} from 'node:module';
|
||||
import process from 'node:process';
|
||||
import test from 'supertape';
|
||||
import {promisify} from 'node:util';
|
||||
import tryToCatch from 'try-to-catch';
|
||||
import {connect} from '../../test/before.mjs';
|
||||
import {createConfigManager} from '../cloudcmd.mjs';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
import {distributeImport} from './import.mjs';
|
||||
|
||||
const distribute = {
|
||||
import: promisify(require('./import')),
|
||||
import: promisify(distributeImport),
|
||||
};
|
||||
|
||||
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';
|
||||
|
||||
const test = require('supertape');
|
||||
const log = require('./log');
|
||||
const {createConfig} = require('../config');
|
||||
import test from 'supertape';
|
||||
import log from './log.mjs';
|
||||
import {createConfig} from '../config.js';
|
||||
|
||||
test('distribute: log: getMessage', (t) => {
|
||||
const e = 'hello';
|
||||
Loading…
Add table
Add a link
Reference in a new issue