Skip to content

lokesh-coder/lesyjs

 
 

Repository files navigation

The Lounge


> 𝙱𝚞𝚒𝚕𝚍 𝚖𝚘𝚍𝚎𝚛𝚗 𝚌𝚘𝚖𝚖𝚊𝚗𝚍-𝚕𝚒𝚗𝚎 𝚊𝚙𝚙𝚜_

WebsiteDocumentationPlaygroundTwitter


What is Lesy JS

Lesy is a simplified CLI framework build with NodeJS and Typescript. Main purpose of lesy is to enable web UI so that users can run commands from GUI dashboard without much complex. But lesy also shines in maintainability and flexibility focusing more on developer experience and performance.

Features

  • Language     - Javascript and Typescript with @types
  • Flexibility     - Able to change complete flow with middlewares
  • Boilerplate    - Write less code. whether it's a dead simple project or complex one
  • Extensions    - Add cool functionalities with plugins
  • Platform      - Write once and run in CLI or web UI. Desktop interface is coming soon
  • Performance  - It is faster than existing tools. Benchmarks inside
  • Testing       - Dedicated testing setup for unit test and integration test
  • Lot more      - Features, sub-commands, boilerplate generator...

Installation and setup

Lesy can be installed from Lesy CLI or manually.

  • Set it up from CLI

    Scaffold new project directly using npx command

    > npx lesy new my-cli

    Or, you can install lesy cli globally and generate a new project

    > npm i -g lesy
    > lesy new my-cli

    Once set up is done, follow the instructions that is displayed in the terminal.

    asciicast

    Also you can create your own project setup and run lesy. Learn more.


  • Manual setup

    Install @lesy/compiler via npm or yarn

    > mkdir my-cli && cd my-cli
    > npm install @lesy/compiler

    Then create a index file and add the below code

    #!/usr/bin/env node
    
    const lesy = require("@lesy/compiler");
    const commands = [{ name: "hello", run: () => console.log("hello world") }];
    
    lesy({ commands }).parse();
    > ./index hello

Lesy core parts

  • Commands

    Commands can be a simple object, or a function or a class. Also, you can provide a path to file or directory where lesy can discover all commands. There are lot of things you can do with commands like, deep nested sub commands, dynamic command execution, run asyncronous code, validate args and flags, etc.,

    const lesy = require("@lesy/compiler");
    
    const commands = [
      {
        name: "hello",
        run: () => console.log("Hello Buddy!"),
      },
    
      function hello(cmd) {
        cmd.name = "hello";
        cmd.run = () => console.log("Hello Buddy!");
      },
    
      class Hello {
        name = "hello";
        run() {
          console.log("Hello Buddy!");
        }
      },
    
      `${__dirname}/commands/welcome.ts`,
    
      `${__dirname}/commands`,
    ];
    
    lesy({ commands }).parse();

    To know more about formats, args, flags, context check here


  • Middlewares

    Middlewares are sort of hooks, you can plug a middleware at multiple stages of the flow. This way you can add, change and manipulate the flow.

    const lesy = require("@lesy/compiler");
    
    const commands = [{ name: "hello", run: () => console.log("hello world") }];
    const middlewares = [
      {
        on: "END",
        run: (ctx) => {
          console.log("this will be printed after hello world");
          return ctx;
        },
      },
    ];
    
    lesy({ commands, middlewares }).parse();

    To know more about hook points, async middlewares, parsing, context check here


  • Features

    Features are simple object, which are accesible in both commands and middlewares. It is super useful if you are dealing with third party libraries and want to share with all commands and middlewares.

    const lesy = require("@lesy/compiler");
    
    const commands = [
      { name: "hello", run: ({ feature }) => feature.sayHello() },
    ];
    const features = [
      (feature) => {
        feature.sayHello = () => console.log("hello");
      },
    ];
    
    lesy({ commands, features }).parse();

    To know more about features check here


  • Plugins

    Plugins are collection of commands, middlewares and features. Can be a local plugin or any lesy plugin that can be installed from npm. learn more

    const lesy = require("@lesy/compiler");
    
    const commands = [{ name: "hello", run: () => console.log("hello world") }];
    const plugins = [`${dirname}/plugins/my-custom-plugin`];
    
    lesy({ commands, plugins }).parse();

  • Even more

    To learn about global configuration, validators, testbed, performance check the documentation


Available Plugins

  • UI Pilot
    Run commands in Web UI. Supports input, console, workspace and more...
  • Artist
    Format and add state, dynamic elements like spinner, column, colorful text...
  • Store
    Key-value storage in the system
  • Config reader
    Setup config files like myapp.config.json, myapp.config.yml, myapp.config.js
  • Scaffold generator
    Generate projects with handlebars templating
  • Prompt
    Wrapper around inquirer plugin for prompts and questions
  • Help
    Automatically generate beautiful help with sub commands support. Highly customizable
  • Arg validator
    Prompt if required args are not supplied

Contribution

Any kind of contibutions are welcome. :)

Development

To run it in local, and to know in depth code login please check here

License

MIT

About

Node JS based CLI framework to build modern Command line applications (in Beta )

Topics

Resources

License

Stars

Watchers

Forks