Skip to main content

Running

Check how to run your CLI commands in different scenarios.

Introduction

To run the CLI application you have two options:

  1. Run using the node artisan.
  2. Link your CLI using npm link command and run it anywhere.

As running with node artisan is simple and has a lot of examples over Athenna documentation, we are going to focus in linking your CLI to run anywhere of your terminal.

Registering your CLI command name

To register your CLI command name, you need to add the bin object inside your package.json file and set the path to the entry point file of your CLI:

"bin": {
"yourCliCommand": "./bin/main.js"
}

Entrypoint file

In our example we defined the ./bin/main.js file as the entrypoint file of our CLI. By default, this file comes with the shebang line #!/usr/bin/env node in the top of the file. Without this line the npm link command will not work. So just in case you want to define a different entrypoint file, remember that #!/usr/bin/env node should be on the top of this file.

Linking the CLI

Now you need to run the following command in your project root:

npm link

And now the yourCliCommand will exist in your actual Node.js version:

yourCliCommand --help

Display CLI name

When running your CLI without any option and command, the display name will be rendered in the terminal using chalk-rainbow and figlet.

By default, Artisan always display the Artisan name, but you can change it for your own display name by setting the displayName property in Ignite.console() method:

Path.bin('main.ts')
import { Ignite } from '@athenna/core'

const ignite = await new Ignite().load(import.meta.url)

await ignite.console(process.argv, {
displayName: 'Your CLI Command', 👈
})
tip

If you wish to disable the display name, set the displayName as null:

Path.bin('main.ts')
import { Ignite } from '@athenna/core'

const ignite = await new Ignite().load(import.meta.url)

await ignite.console(process.argv, {
displayName: null, 👈
})