Skip to content

Commit

Permalink
feat(cli): add --include-urls option
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed May 10, 2023
1 parent 58f141f commit 8568a02
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
47 changes: 24 additions & 23 deletions docs/content/2.integrations/0.cli.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
_---
title: CLI
icon: carbon:terminal
description: Using the Unlighthouse CLI is the primary way to scan entire production sites.
Expand Down Expand Up @@ -52,27 +52,28 @@ See the [Configuration](#configuration) section for more details and the guides.

### CLI Options

| Options | |
|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-v, --version` | Display version number. |
| `--site <url>` | Host URL to scan. |
| `--root <path>` | Define the project root. |
| `--config-file <path>` | Path to config file. |
| `--output-path <path>` | Path to save the contents of the client and reports to. |
| `--cache` | Enable the caching. |
| `--no-cache` | Disable the caching. |
| `--desktop` | Simulate device as desktop. |
| `--mobile` | Simulate device as mobile. |
| `--throttle` | Enable the throttling. |
| `--samples` | Specify the amount of samples to run. |
| `--urls` | Specify explicit relative paths as a comma-seperated list.<br>e.g. `unlighthouse --site unlighthouse.dev --urls /guide,/api,/config` |
| `--disallow-urls` | Specify explicit relative paths (string or regex) to disallow as a comma-seperated list. <br>e.g. `unlighthouse --site unlighthouse.dev --exclude-urls /guide/.*,/api/.*` |
| `--enable-javascript` | When inspecting the HTML wait for the javascript to execute. Useful for SPAs. |
| `--disable-javascript` | When inspecting the HTML, don't wait for the javascript to execute. |
| `--enable-i18n-pages` | Enable scanning pages which use x-default. |
| `--disable-i18n-pages` | Disable scanning pages which use x-default. |
| `-d, --debug` | Debug. Enable debugging in the logger. |
| `-h, --help` | Display available CLI options |
| Options | |
|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-v, --version` | Display version number. |
| `--site <url>` | Host URL to scan. |
| `--root <path>` | Define the project root. |
| `--config-file <path>` | Path to config file. |
| `--output-path <path>` | Path to save the contents of the client and reports to. |
| `--cache` | Enable the caching. |
| `--no-cache` | Disable the caching. |
| `--desktop` | Simulate device as desktop. |
| `--mobile` | Simulate device as mobile. |
| `--throttle` | Enable the throttling. |
| `--samples` | Specify the amount of samples to run. |
| `--urls` | Specify explicit relative paths as a comma-seperated list.<br>e.g. `unlighthouse --site unlighthouse.dev --urls /guide,/api,/config` |
| `--exclude-urls` | Specify relative paths (string or regex) to exclude from scanning as a comma-seperated list. <br>e.g. `unlighthouse --site unlighthouse.dev --exclude-urls /guide/.*,/api/.*` |
| `--include-urls` | Specify relative paths (string or regex) to include as a comma-seperated list. <br>e.g. `unlighthouse --site unlighthouse.dev --include-urls /guide/.*` |
| `--enable-javascript` | When inspecting the HTML wait for the javascript to execute. Useful for SPAs. |
| `--disable-javascript` | When inspecting the HTML, don't wait for the javascript to execute. |
| `--enable-i18n-pages` | Enable scanning pages which use x-default. |
| `--disable-i18n-pages` | Disable scanning pages which use x-default. |
| `-d, --debug` | Debug. Enable debugging in the logger. |
| `-h, --help` | Display available CLI options |


### Config File
Expand All @@ -88,4 +89,4 @@ export default {
device: 'desktop'
}
}
```
```_
5 changes: 3 additions & 2 deletions packages/cli/src/createCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export default function createCli() {
cli.option('--disable-javascript', 'When inspecting the HTML, don\'t wait for the javascript to execute.')
cli.option('--enable-i18n-pages', 'Enable scanning pages which use x-default.')
cli.option('--disable-i18n-pages', 'Disable scanning pages which use x-default.')
cli.option('--urls <urls>', 'Specify explicit relative URLs as a comma-seperated list.')
cli.option('--disallow-urls <urls>', 'Specify explicit relative URLs to disallow as a comma-seperated list.')
cli.option('--urls <urls>', 'Specify explicit relative paths to scan as a comma-seperated list, disabling the link crawler.')
cli.option('--exclude-urls <urls>', 'Relative paths (string or regex) to exclude as a comma-separated list.')
cli.option('--include-urls <urls>', 'Relative paths (string or regex) to include as a comma-separated list.')
cli.option('--disable-robots-txt', 'Disables the robots.txt crawling.')
cli.option('--disable-sitemap', 'Disables the sitemap.xml crawling.')
cli.option('-d, --debug', 'Debug. Enable debugging in the logger.')
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ export interface CliOptions {
host?: string
help?: boolean
urls?: string
disallowUrls?: string
excludeUrls?: string
includeUrls?: string
site?: string
throttle?: boolean
desktop?: boolean
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ export function pickOptions(options: CiOptions | CliOptions): UserConfig {
if (options.urls)
picked.urls = options.urls.split(',')

if (options.disallowUrls)
picked.scanner.exclude = options.disallowUrls.split(',')
if (options.excludeUrls)
picked.scanner.exclude = options.excludeUrls.split(',')

if (options.includeUrls)
picked.scanner.include = options.includeUrls.split(',')

const config = pick(options, [
// root level options
Expand Down

0 comments on commit 8568a02

Please sign in to comment.