Enjoy the DX of File Based Routing (eg: NextJs) for CLI development.
Install MCMD package from NPM
Or clone the ready-made template from MCMD github repository
bun create mcmd-app --name my-cli
npx create mcmd-app --name my-cli
[!WARNING] MCMD plugin isn't available on node.js right now. Make sure to use Bun for building the CLI
root
├── .mcmd
├── node_modules
│
├─┬ app
│ ├── index.ts # npx my-cli
│ ├─┬ init
│ │ ├── something.ts # npx my-cli init something
│ │ └── index.ts # npx my-cli init
│ └── login.ts # npx my-cli login
│
├── package.json
├── build.ts
├── .gitignore
├── README.md
└── tsconfig.json
Don't need to import zod
or Command
, we'll handle everything for you.
// app/index.ts
export const options = z.object({
name: z.string()
});
export default Command((data) => {
const { name } = data;
console.log("Hi", name);
});
// npx my-cli --name Rajat
// app/init.ts
export default () => {
console.log("Done Init");
};
// npx my-cli init
bun run build
# or
# bunx mcmd build
// package.json
{
"name": "my-cli",
"version": "0.0.0",
"bin": "./dist/cli.js",
"files": ["dist/**/*"],
...
}
bun publish
bunx my-cli --name Rajat
Extends you tsconfig.json
with mcmd/base.json
{
// tsconfig.json
compilerOptions: {},
"include": ["."],
"exclude": [
"dist",
"node_modules"
],
"extends": [
"mcmd/base.json" // important
]
}
Or paste this code to ./type.d.ts
// Don't remove this.
// This helps for automatic type assigning for MCMD.
/// <reference types="mcmd/type" />
Follow this code to get full TypeScript support
// app/index.ts
export const options = z.object({
name: z.string()
});
export default Command<typeof options>((data) => {
const { name } = data;
console.log("Hi", name);
});