This is an Express ESM-only module library - you are not able to import it with
require()
.
npm install @point-hub/express-cli
•
├── bin
│ └── cli.js
├── lib
└── src
├── commands
│ └── example-command.ts
└── index.ts
- create command file
src/commands/greet-command.ts
import { BaseCommand } from "@point-hub/express-cli";
export class GreetCommand extends BaseCommand {
constructor() {
super({
name: "greet",
summary: "Welcome someone",
description: "Welcome someone with particular words",
alias: ["gret", "say"],
arguments: [
{
name: "name",
description: "Your name",
},
],
options: [
{
type: "boolean",
flag: "--smile",
shorthand: "-s",
description: "Add smiley :)",
},
],
});
}
handle() {
// handle command here
}
}
- create an entry point file
src/ìndex.ts
import { ExpressCli } from "@point-hub/express-cli";
import { GreetCommand } from "./commands/greet.command.js";
/**
* Register the commands for the application.
*
* @example
* command.register(ExampleCommand);
*/
export function commands(command: ExpressCli): void {
command.register(new GreetCommand());
}
-
compile typescript to
"lib"
directory -
create an executeable file
bin/cli.js
and make it executeablechmod +x bin/cli.js
#!/usr/bin/env node
import { commands } from "../lib/index.js";
import { ExpressCli } from "@point-hub/express-cli";
const cli = new ExpressCli("cli");
commands(cli);
cli.run(process.argv);
- try your command using
node bin/cli.js greet John