Omlet Docs
Search
K

CLI documentation

More details on Omlet CLI options & commands

CLI commands & options

Omlet CLI has two main commands init and analyze. Below we have details on available options for each command and when to use them.

init

This command will take you through a guided process to scan your repo(s) based on your setup. Some of the supported setups include…
  • A single repo which includes both your application and component library
  • A monorepo with multiple packages and your component library
  • Multiple application repos and a separate component library repo
☝️ Tip: If you need to restart the init setup process, you can delete scans that were created.
-r / --root
Set where Omlet CLI will run the analysis. This option will come in handy if you are running the CLI from a directory that is different from the directory of the project you are trying to scan.
By default, the project root is the current working directory of the terminal. If that directory doesn't contain a package.json, the CLI will attempt to find the closest package.json up in the directory hierarchy starting from the current directory to determine the project root.
The CLI will also display an output in the terminal which indicates the root where it is running the scan like this: Analyzing the project at <PATH>…
--log-level
Specify the log level for the CLI. Possible values your can pass: error, warn, info, debug, trace
-v / --verbose
By default set as false. By adding this option, you will get detailed log output in the CLI.
-h / --help
omlet init -h will provide all the available options you can use to run the analyze command with some explanations.

analyze

This command is used to scan additional repos to detect components and analyze their dependency after you have gone through initial setup using init.
-i / --include
By default analyze will take the current directory as the root and analyze everything. Supplying a glob pattern to -i will narrow and specify where to analyze for components. You can also pass multiple glob patterns like so… -i 'glob/one' -i 'glob/two'
--ignore
Pass a glob pattern to any directory, file or components that you would like Omlet CLI to ignore from scanning. You can pass multiple ignore glob patterns like so --ignore 'glob/one' --ignore 'glob/two'
-r / --root
Set where Omlet CLI will run the analysis. This option will come in handy if you are running the CLI from a directory that is different from the directory of the project you are trying to scan.
By default, the project root is the current working directory of the terminal. If that directory doesn't contain a package.json, the CLI will attempt to find the closest package.json up in the directory hierarchy starting from the current directory to determine the project root.
The CLI will also display an output in the terminal which indicates the root where it is running the scan like this: Analyzing the project at <PATH>…
--log-level
Specify log level for the CLI. Possible values your can pass: error, warn, info, debug, trace
-v / --verbose
By default set as false. By adding this option, you will get detailed log output in the CLI.
--dry-run
Scanned results will only be outputted locally to omlet.out.json. This will allow users to test results before uploading results to the Omlet web app.
-h / --help
omlet analyze -h will provide all the available options you can use to run the analyze command with some explanations.

login

This command is used to authenticate to the CLI, and also let it know where to upload the results from a scan.
--print-token
This flag is used to generate an access token which can be used to automate CLI runs by adding it to your CI/CD process.
  1. 1.
    Generate an access token by running: npx omlet login --print-token (or npx @omlet/cli login --print-token if you running it outside of your repository)
  2. 2.
    Set the access token to an environment variable named OMLET_TOKEN. Omlet CLI will automatically search for this specific environment variable.

Glob patterns

  • Glob patterns are applied against the file path relative to the project's root directory (see the -root, -r option for how to specify it).
  • * matches zero or more characters (excluding path separators).
  • ? matches any single character (excluding path separators).
  • ** recursively matches directories.

Omlet CLI config file

Omlet can read a config file with with parameters defined for options like include, ignore, tsconfigPath and aliases.

Config file name & location

The configuration for the cli can be placed in the following locations:
  • An omlet property in the package.json file.
  • An .omletrc file in JSON or YAML format.
  • An .omletrc.json, .omletrc.yaml, .omletrc.yml, .omletrc.js, .omletrc.mjs, or .omletrc.cjs file.
  • An omletrc, omletrc.json, omletrc.yaml, omletrc.yml, omletrc.js, or omletrc.cjs file inside a .config subdirectory.
  • An omletrc.config.js, omletrc.config.mjs, or omletrc.config.cjs file.
In addition to the above options, users can also specify a custom configuration file name and location using the --config option in the CLI command.

Configuration Properties

The configuration can include the following properties:
  • include: An array of strings that is equivalent to the -include parameter.
  • ignore: An array of strings that is equivalent to the -ignore parameter.
  • tsconfigPath: A string that is equivalent to the -tsconfig-path parameter.
  • aliases: An object consisting of key-value pairs to define custom aliases.
The properties include, ignore, and tsconfigPath can be set using either command-line arguments or the configuration file. If a property is provided as a command-line argument, the corresponding value in the configuration file will be ignored. If a property is not set via the configuration file or command-line argument, a default value will be used.

aliases Field

The aliases field allows users to define custom alias configurations that are used by bundlers such as webpack, Vite, or Babel. If users have a custom alias configuration for their bundler, it's important to configure it for Omlet as well.
The aliases property should be an object consisting of key-value pairs. The key represents the alias string used in the codebase, while the value should be an array of strings that specify the location(s) of the corresponding file or files. This structure is adopted from the paths property in tsconfig. For more in-depth information, please refer to the tsconfig documentation on paths.

Examples

Example 1: package.json
{
...
"omlet": {
"tsconfigPath": "tsconfig.frontend.json"
}
}
Example 2: JSON file
{
"ignore": ["**/another_test_folder/**"],
"aliases": {
"@components/*": ["src/components/*"],
"@icons": ["src/icons/index.tsx"]
}
}
Example 3: YAML file
include:
- "src/**/*.tsx"
aliases:
"@components/*":
- "src/components/*"
"@icons":
- "src/icons/index.tsx"