# new CLIUtils()
A static utility class that provides methods for loading modules, retrieving package information, and initializing CLI commands
Utility class for CLI operations
Example
// Initialize a Command object with package information
const command = new Command();
CLIUtils.initialize(command, './path/to/package');
// Load a CLI module from a file
const module = await CLIUtils.loadFromFile('./path/to/cli-module.js');
Methods
# static initialize(command, basePathopt) → {void}
Sets up a Commander Command object with the package name, description, and version from the package.json file
Initializes a Command object with package information
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
command |
Command
|
The Command object to initialize |
|
basePath |
string
|
<optional> |
The base path where the package.json file is located, defaults to the current working directory |
void
# async static loadFromFile(path) → {Promise.<CliModule>}
Loads a JavaScript file and returns it as a CliModule, handling both ESM and CommonJS formats
Dynamically imports a module file
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string
|
The file path to the module to load |
A promise that resolves to the loaded CliModule
Promise.<CliModule>
# static packageName(basePath) → {string}
Retrieves the name field from the package.json file at the specified path and extracts the package name without the scope
Returns the name from package.json
Parameters:
| Name | Type | Description |
|---|---|---|
basePath |
string
|
The base path where the package.json file is located |
The package name without the scope (e.g., "cli" from "@decaf-ts/cli")
string
# static packageVersion(basePath) → {string}
Retrieves the version field from the package.json file at the specified path
Returns the version from package.json
Parameters:
| Name | Type | Description |
|---|---|---|
basePath |
string
|
The base path where the package.json file is located |
The package version string
string