feature: cloudcmd: migrate to ESM

This commit is contained in:
coderiaser 2026-02-03 15:03:49 +02:00
parent e8a81c49ea
commit 4533a25c6f
184 changed files with 339 additions and 388 deletions

70
test/before.js Normal file
View file

@ -0,0 +1,70 @@
import process from 'node:process';
import http from 'node:http';
import os from 'node:os';
import {promisify} from 'node:util';
import {fileURLToPath} from 'node:url';
import {dirname} from 'node:path';
import express from 'express';
import {Server} from 'socket.io';
import writejson from 'writejson';
import readjson from 'readjson';
import cloudcmd from '../server/cloudcmd.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
process.env.NODE_ENV = 'development';
const {assign} = Object;
const pathConfig = os.homedir() + '/.cloudcmd.json';
const currentConfig = readjson.sync.try(pathConfig);
export default before;
function before(options, fn = options) {
const {
config,
plugins,
modules,
configManager,
} = options;
const app = express();
const server = http.createServer(app);
const after = (cb) => {
if (currentConfig)
writejson.sync(pathConfig, currentConfig);
server.close(cb);
};
const socket = new Server(server);
app.use(cloudcmd({
socket,
plugins,
config: assign(defaultConfig(), config),
configManager,
modules,
}));
server.listen(() => {
fn(server
.address().port, promisify(after));
});
}
export const connect = promisify((options, fn = options) => {
before(options, (port, done) => {
fn(null, {
port,
done,
});
});
});
const defaultConfig = () => ({
auth: false,
root: __dirname,
});