The CLI (@better-auth-kit/cli)
Relevant source files
The following files were used as context for generating this wiki page:The @better-auth-kit/cli is a command-line interface designed to support development and management tasks within the Better Auth Kit ecosystem. It provides a set of tools for developers working with Better Auth plugins and adapters, streamlining common workflows.
Built with Node.js, the CLI leverages the commander library to offer a robust and extensible command structure. Its primary function, as evidenced by its usage in various plugins, is to assist with development-time operations, such as managing test databases for plugins.
Sources: packages/cli/README.md, packages/cli/package.json, packages/plugins/legal-consent/package.json
Architecture and Initialization
The CLI's entry point is packages/cli/src/index.ts, which is executed when a user runs the better-auth-kit command. The initialization process involves setting up a commander program instance, loading all available command modules, and parsing the command-line arguments provided by the user.
The following diagram illustrates the startup flow of the CLI:
This diagram shows the process from user execution to command dispatch.
The core logic for this initialization is concise:
// packages/cli/src/index.ts:10-18
async function main() {
const program = new Command("better-auth-kit");
for (const command of Object.values(commands)) {
program.addCommand(command);
}
program.version(version).description("Better Auth Kit CLI");
program.parse();
}
This structure allows for easy extension by adding new command files to the commands directory, which are then automatically registered with the CLI.
Sources: packages/cli/src/index.ts:3-18
Core Dependencies
The CLI utilizes several key Node.js packages to deliver its functionality. These dependencies are defined in its package.json file.
| Dependency | Purpose |
|---|---|
commander | The core framework for building the command-line interface, parsing arguments, and defining commands. |
chalk | Used for styling terminal output with colors to improve readability and user experience. |
prompts | Enables interactive command-line prompts for gathering user input when required by a command. |
fs-extra | Provides extended file system methods, likely for file and directory manipulation tasks. |
log-update | Used for creating persistent log messages that can be updated in place, useful for showing progress. |
open | Allows the CLI to open websites, files, and executables. |
Sources: packages/cli/package.json:23-40
Known Commands
While the full implementation of all commands is not present in the analyzed files, usage within other packages in the repository reveals the existence of certain commands.
The db Command
The db command is consistently referenced in the npm scripts of various plugins, such as @better-auth-kit/legal-consent and @better-auth-kit/reverify. Its purpose is to facilitate database operations during the testing phase of plugin development.
The following sequence diagram shows how a developer would use this command as part of their workflow:
This command is invoked via scripts in plugin package.json files, like so:
// packages/plugins/legal-consent/package.json:15-17
"scripts": {
"test:db": "cd tests && bunx @better-auth-kit/cli@latest db",
},
This indicates the db command is a crucial tool for setting up a consistent database environment for running plugin tests.
Sources: packages/plugins/legal-consent/package.json:16, packages/plugins/reverify/package.json:20
Build and Distribution
The CLI is designed to be published to the npm registry and used as a global or project-level executable. The package.json file contains the necessary configuration for building and distributing the tool.
package.json Field | Value | Description |
|---|---|---|
bin | ./dist/index.js | Specifies the entry point file that is linked as an executable (better-auth-kit) upon installation. |
files | ["dist"] | Defines that only the compiled dist directory will be included in the published npm package. |
scripts.build | bun build.ts | The command used to compile the TypeScript source code into JavaScript in the dist directory. |
publishConfig | { "access": "public", "executableFiles": ["./dist/index.js"] } | Configures the package for public access on npm and marks the main script as executable. |
This setup ensures that when a developer installs @better-auth-kit/cli, the better-auth-kit command becomes available in their shell environment, pointing to the compiled JavaScript entry point.
Sources: packages/cli/package.json:10-21
Conclusion
The @better-auth-kit/cli is an essential developer utility for the Better Auth Kit project. With its command-based architecture powered by commander, it provides developers with tools to manage and streamline development workflows, most notably for database setup during plugin testing. Its straightforward initialization and build process make it an extensible and maintainable component of the overall toolkit.