some shit for module loading
parent
956ac726e1
commit
4e9debfa25
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
|
||||
export default function createExecutor(functions: any) {
|
||||
return function execute(...options: string[]) {
|
||||
return async function execute(...options: string[]) {
|
||||
// console.log('λ', line);
|
||||
const [cmd, ...args] = options;
|
||||
if(cmd in functions) {
|
||||
const toInvoke: (...args: any[]) => void = functions[cmd as keyof typeof functions];
|
||||
toInvoke(...args);
|
||||
const toInvoke: (...args: any[]) => void | Promise<void> = functions[cmd as keyof typeof functions];
|
||||
await toInvoke(...args);
|
||||
} else {
|
||||
console.log('Unknown command', cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
declare module "serverline";
|
||||
declare module "telnet";
|
||||
29
src/index.ts
29
src/index.ts
|
|
@ -20,9 +20,9 @@ const system = {
|
|||
handoff: ''
|
||||
}
|
||||
|
||||
export const exec = (s: string, echo = true) => {
|
||||
export const exec = async (s: string, echo = true) => {
|
||||
if(echo) console.log(chalk.cyan('@ ') + chalk.ansi256(242)(s));
|
||||
executor(...(s.split(' ')));
|
||||
await executor(...(s.split(' ')));
|
||||
};
|
||||
|
||||
serverline.init({
|
||||
|
|
@ -31,8 +31,14 @@ serverline.init({
|
|||
// serverline.setCompletion(['help', 'command1', 'command2', 'login', 'check', 'ping'])
|
||||
|
||||
const executor = createExecutor({
|
||||
create(module: string, name: string) {
|
||||
console.log(s);
|
||||
async create(module: string, name: string) {
|
||||
try {
|
||||
const functions = await import('./modules/' + module + '.js');
|
||||
console.log(functions)
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
e.trace();
|
||||
}
|
||||
},
|
||||
quit() {
|
||||
console.log('Shutting down');
|
||||
|
|
@ -74,10 +80,13 @@ serverline.on('SIGINT', () => {
|
|||
exec('quit');
|
||||
});
|
||||
|
||||
if(startupFile) {
|
||||
const fullPath = resolve(startupFile);
|
||||
const lines = readFileSync(fullPath).toString().split('\n').map(v => v.trim());
|
||||
for(const line of lines) {
|
||||
exec(line);
|
||||
|
||||
(async () => {
|
||||
if(startupFile) {
|
||||
const fullPath = resolve(startupFile);
|
||||
const lines = readFileSync(fullPath).toString().split('\n').map(v => v.trim());
|
||||
for(const line of lines) {
|
||||
await exec(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
@ -4,9 +4,9 @@ import { exec } from '@kernel';
|
|||
|
||||
export default {
|
||||
start() {
|
||||
var telnet = require('telnet')
|
||||
var telnet = require('telnet');
|
||||
|
||||
telnet.createServer(function (client) {
|
||||
telnet.createServer(function (client: any) {
|
||||
|
||||
// make unicode characters work properly
|
||||
client.do.transmit_binary()
|
||||
|
|
@ -15,14 +15,14 @@ export default {
|
|||
client.do.window_size()
|
||||
|
||||
// listen for the window size events from the client
|
||||
client.on('window size', function (e) {
|
||||
client.on('window size', function (e: any) {
|
||||
if (e.command === 'sb') {
|
||||
console.log('telnet window resized to %d x %d', e.width, e.height)
|
||||
}
|
||||
})
|
||||
|
||||
// listen for the actual data from the client
|
||||
client.on('data', function (b) {
|
||||
client.on('data', function (b: any) {
|
||||
exec(b);
|
||||
client.write(b)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
"downlevelIteration": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"baseUrl": "./",
|
||||
"baseUrl": "./src",
|
||||
"paths": {
|
||||
"@kernel": [ "src/index.ts" ]
|
||||
"@kernel": [ "./" ]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/index.ts"
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue