cloudcmd icon indicating copy to clipboard operation
cloudcmd copied to clipboard

ESM

Open coderaiser opened this issue 3 years ago • 0 comments

To convert Cloud Commander to ESM same changes in API should be made:

According to base usage example:

import http from 'http';
import cloudcmd from 'cloudcmd';
import {Server} from 'socket.io';
import express from 'express';

const app = express();
const port = 1337;
const prefix = '/';

const server = http.createServer(app);
const socket = new Server(server, {
    path: `${prefix}socket.io`,
});

const config = {
    name: 'cloudcmd :)',
};

const filePicker = {
    data: {
        FilePicker: {
            key: 'key',
        },
    },
};

// override option from json/modules.json
const modules = {
    filePicker,
};

const {
    createConfigManager,
    configPath,
} = cloudcmd;

const configManager = createConfigManager({
    configPath,
});

app.use(prefix, cloudcmd({
    socket, // used by Config, Edit (optional) and Console (required)
    config, // config data (optional)
    modules, // optional
    configManager, // optional
}));

server.listen(port);

this part:

app.use(prefix, cloudcmd({
    socket, // used by Config, Edit (optional) and Console (required)
    config, // config data (optional)
    modules, // optional
    configManager, // optional
}));

Should be changed to have ability to import Terminal. Right now it uses require, but in ESM in will be async, so we will have ability init cloudcmd this way:

app.use(prefix, await cloudcmd({
    socket, // used by Config, Edit (optional) and Console (required)
    config, // config data (optional)
    modules, // optional
    configManager, // optional
}));

It looks little bit awkward, and this is a good place for bugs to occur. Any ideas, about how convenient this change will be, and is it worth it?

According to https://github.com/coderaiser/spawnify/pull/3, @wll8, what do you think? have you tried API?

coderaiser avatar Jun 24 '22 13:06 coderaiser