mcmd
TypeScript icon, indicating that this package has built-in type declarations

0.0.93 • Public • Published

MCMD - A Meta framework for building CLIs

Enjoy the DX of File Based Routing (eg: NextJs) for CLI development.

Usage

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

Folder Structure

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

Coding

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

Final Build

bun run build

# or
# bunx mcmd build

Publish CLI

// package.json
{
    "name": "my-cli",
    "version": "0.0.0",
    "bin": "./dist/cli.js",
    "files": ["dist/**/*"],
    ...
}
bun publish

Enjoy CLI

bunx my-cli --name Rajat

TypeScript Support

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);
});

Package Sidebar

Install

npm i mcmd

Weekly Downloads

4

Version

0.0.93

License

none

Unpacked Size

41 kB

Total Files

17

Last publish

Collaborators

  • rajatsandeepsen