#Documentations around CLI packages?

1 messages · Page 1 of 1 (latest)

fluid arch
#

How do I add CLI capabilities for my existing package?

For example when running deno run jsr:@foo/bar I would like to bring up an interactive installation for the package itself, possibly adding other subcommands for convenience.

Is there any special exports such as cli.ts, or is there a way to detect a deno run shell environment from the default export (mod.ts)?

Summaries

  1. ✅ Use import.meta.main for deno
  2. ❓ Interop for bin in package.json
cold acorn
#

Is there any special exports such as cli.ts, or is there a way to detect a deno run shell environment from the default export (mod.ts)?

Yup, the standard way to do so is import.meta.main.

if (import.meta.main) {
  console.log("I'm a CLI!");
}
fluid arch
#

@cold acorn Thanks a lot, it works!

fluid arch
#

Is it possible to also make the CLI work via npm interop?

npx jsr <package>
yarn dlx jsr <package>
pnpm dlx jsr <package>

I see that JSR will convert some of the fields from deno.json into package.json when downloaded through the jsr add subcommand, but adding bin field in deno.json does not expose the field.