0.4.5 • Published 4 years ago

dieterm v0.4.5

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

DIE Terminal

Features

DIE Terminal is a back-end component written in pure JavaScript that helps write executable flexible modules quickly and easily

Installation

npm install dieterm --save

Requires

  • if nodejs older than 13.6.0 needs start with the parameter --experimental-modules
  • also need to use --es-module-specifier-resolution=node
node --es-module-specifier-resolution=node --experimental-modules ...

Quick Start

import Terminal from 'dieterm';

(async () => console.log(await new Terminal))();

Terminal Class

This is an initializing promise-like class with the following argument:

KeyDefault valueDescription
inputStreamprocess.stdininput stream
outputStreamprocess.stdoutoutput stream
hostfalseconsole username
storagefalsepath for logs, etc
repo[]Local moduls repositories

Simple module example

Run the module

use test

Code

export default Module => class Test extends Module {
    // Save state of the following methods
    stack = new Set(['execute', 'continue']);
    // Module name
    name = 'test';
    // Entry point
    async execute() {
        await this.log('execute');
        await this.continue({ ...(await this.getObject('param')), error: true });
    }
    // Some method with saved state
    async continue(params) {
        if(params.error)
            throw new Error('some uncaught error');

        /*
        *    To avoid this error, continue executing the code with --error=
        *    `use test --last --error=`
        * */

        await this.log({ type: 'success', message: 'ok!' });

        const exp = await this.getVar('exp');
        await this.log(`2 ^ ${exp} = ${2 ** exp}`);

        await this.kill();
    }

    // Optional method
    async kill() {
        await this.log('killing...');
    }
};
0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago