cliframe
v3.0.0
Published
A simple CLI framework for building command-line applications in Node.js.
Maintainers
Readme
CLIFrame
A simple CLI framework for building command-line applications in Node.js.
GETTING STARTED
Follow the steps to get started:
npm init -ynpm i -D typescript tsx @types/nodemaking development easier.- Install cliFrame:
npm i cliframe - Run
npx cliframe init. This will generatecliframe.config.jsonfile, which is a configuration file for cliFrame, and a folder namedCLIby default. - In your root
index.tsjust importcliFramemethod and call it. - The setup is almost complete. The only missing thing is your code that is how your cli would responed to different commands. The
CLIfolder is where your code lives.- To help you understand what you should keep and how to strcuture it, it is better to show you an example. Run
npx cliframe generate-example
- To help you understand what you should keep and how to strcuture it, it is better to show you an example. Run
- Now try running:
node indexwhich will executeCLI/command.jsnode index startwhich will exectueCLI/start/command.jsnode index a b cwhich will executeCLI/a/b/c/command.js
Important to know:
cliframe.config.json,index.ts|jsandCLIfolder should live at a same level.
Obviously to make your project a cli, you have to add
"bin": {"mycli": "./index.js"}in yourpackage.json. This way you can run index.js file withmycliinstead ofnode index.node index start→mycli start
FILE SYSTEM CONVENTIONS
command.ts
It should export default a method. The method always get access to the props property, which is passed when it's called.
type Props = {
argument: Record<string, string>;
option: Record<string, boolean>;
values: (string | number)[];
};
const command = (props: Props) => {
console.log({
msg: "command runs successfully",
props,
});
};
export default command;