website • documentation • playground • @lesyjs
A developer friendly Node js based CLI framework to build modern command line applications.
Whether you are building a tiny teeny app or large complex one, Lesy provides you all the necessary tools out of box. That means, write less and get more with no additional cost to you and your users.
- Typescript support
First class typescript support with types and compiler - Middleware architecture
Change the flow at any stage or competely alter the behaviour without touching your core code - Plugins system
Bring in more features on demand with official/community plugins. - Powerful commands
Smart args/flags parsing, multi level sub commands, validators, multiple types, programatically running commands - Reusable features
Global data that can be accessed everywhere, whether it is a simple piece of code or 3rd part module - Configuration
App level configuration object to customize the settings - Full-fledged Test suite
write simple unit level testing or complete app level integration testing with simple API - Lesy CLI
Scaffold new project with just one simple command - Performance
Lesy core is lightweight and smart enough to run just what it needs. Benchmark inside - Dynamic interface
Rewrite terminal screen content on data change with bunch of inbuilt elements - Web UI
Lesy's Pilot server brings all your commands to web ui, so your users can happily run commands from web UI - Desktop UI
installable desktop app, that runs all globally installed lesy projects, and users can run apps from their app - Utilities
Built-in lazy utilities to work with colors and spinner - Serverless mode
With Lesy's simple API, write a bot like app and run it in server
To ease the setup process, Lesy comes with own CLI which scaffolds the project with all necessary tools included.
In your terminal run this command:
npx lesy new my-cli
For detailed installation guide and manual set up refer this installation docs.
const lesy = require("@lesy/compiler");
const commands = [{ name: "greet", run: () => console.log("hello") }];
lesy({ commands }).parse();
$ ./my-cli greet
"hello"
Command is a simple object with a run
function which will be executed on running the command.
const lesy = require("@lesy/compiler");
const commands = [
{
name: "hello",
args: {
name: {
required: true,
},
},
run: ({ args }) => console.log(`Hello ${args.name}`),
},
];
lesy({ commands }).parse();
- Command can also be a
function
orclass
- You can also provide the command
file path
or thedirectory path
- Run multi-level sub commands
- Parse and validate args and flags
- Run command programmatically
- In-built lazy utilities that can be accessed from command context
- Execute synchronous and asynchronous code
Check out commands API guide to know more about it.
Middlewares are simple functions which will be executed during the lifecyle of command flow. With this, you will be able to add new functionallity, tweak and change the entire behaviour of the command at any point of the flow without changing the command logic.
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();
With middleware you can do:
- Async calls
- Programatically change running command
- Modify args and flags
- Terminate the flow
- Intercept and change the output
- Print additional info at any stages
- Capture and send logs to other services
- Include data in command context data
- And much more..
To know more about hook points, async operations, parsing, context check middleware docs
Features are simple global 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
Plugin is a collection of commands, middlewares, features and validators. 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/lesy-plugin-generator",
];
lesy({ commands, plugins }).parse();
- Pass config object to a plugin
- Support for plugins for a plugin
- Configuration - App level config object that can be accessed globally even with in plugins
- Validators - Args and flag validations
Generally commands, middlewares, features can be tested independently with Jest. But however, to test them with the app or to test a plugin testbed can be used
import { resolve } from "path";
import { LesyTestBed } from "@lesy/testbed";
const HelloCommand from "../src/commands/hello";
describe("CLI", () => {
let app;
beforeEach(() => {
app = new LesyTestBed({
root: resolve(__dirname, "./"),
commands: [HelloCommand],
});
});
it("should log proper output", async () => {
let response = await app.run(["greet"]);
expect(response).toContain("hello yoyo!");
});
});
Check out Testbed docs for more info.
Artist UI is an another cool plugin which helps you to render dynamic elements by updating the screen content on data change.
Artist can also be used independently without lesy, and it comes with commonly used interface elements like, spinner, progress bar, log, colors, layout, and much more. Also, Artist can be extended with plugins! View docs
Pilot Dashboard is one of the lesy plugins which allows you to view and run commands of any lesy projects from web UI. Pilot comes with inbuild customizable console panel, config viewer, prompt modal support, responsive layout and more. View docs
-
Pilot dashboard Run commands in Web UI. Supports input, console, workspace and more...
-
Artist UI Update console screen on data change with in build elements
-
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
There are few components which can be used without Lesy.
-
Artist Artist is an independent library which helps you to update console screen on data change. And not just that, Artist also comes bundled with all necessary elements like spinner, colums, tables, progress bar and more to spice up the visuals.
-
Object Validator A lightweight bare minimum core library to validate simple objects with your own custom rules and conditions. This also lets you to use async rules, custom response messages.
Any Contributions are welcome!
Refer this local setup guide for installing lesy in your local machine. And to know more indepth concepts check project overiew and concepts page.
This project is licensed under the MIT License