Skip to content

Commit

Permalink
qmk docs: restore --port and --browser arguments (#24623)
Browse files Browse the repository at this point in the history
* `qmk docs`: restore `--port` and `--browser` arguments

* Make docs command args always a list
  • Loading branch information
fauxpark authored Feb 1, 2025
1 parent ff09b92 commit 273d8d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
15 changes: 9 additions & 6 deletions docs/cli_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,23 +723,26 @@ Now open your dev environment and live a squiggly-free life.

## `qmk docs`

This command starts a local HTTP server which you can use for browsing or improving the docs. Default port is 5173.
This command starts a local HTTP server which you can use for browsing or improving the docs, and provides live reload capability whilst editing. Default port is 8936.
Use the `-b`/`--browser` flag to automatically open the local webserver in your default browser.

This command requires `node` and `yarn` to be installed as prerequisites, and provides live reload capability whilst editing.
Requires `node` and `yarn` to be installed as prerequisites.

**Usage**:

```
usage: qmk docs [-h]
usage: qmk docs [-h] [-b] [-p PORT]
options:
-h, --help show this help message and exit
-h, --help show this help message and exit
-b, --browser Open the docs in the default browser.
-p, --port PORT Port number to use.
```

## `qmk generate-docs`

This command allows you to generate QMK documentation locally. It can be uses for general browsing or improving the docs.
Use the `-s`/`--serve` flag to also serve the static site once built. Default port is 4173.
This command generates QMK documentation for production.
Use the `-s`/`--serve` flag to also serve the static site on port 4173 once built. Note that this does not provide live reloading; use `qmk docs` instead for development purposes.

This command requires `node` and `yarn` to be installed as prerequisites, and requires the operating system to support symlinks.

Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ enum my_keycodes {
Before opening a pull request, you can preview your changes if you have set up the development environment by running this command from the `qmk_firmware/` folder:

```
qmk docs
qmk docs -b
```

and navigating to `http://localhost:5173/`.
Which should automatically open your browser; otherwise, navigate to `http://localhost:8936/`.

## Keyboards

Expand Down
9 changes: 6 additions & 3 deletions lib/python/qmk/cli/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from milc import cli


@cli.argument('-p', '--port', default=8936, type=int, help='Port number to use.')
@cli.argument('-b', '--browser', action='store_true', help='Open the docs in the default browser.')
@cli.subcommand('Run a local webserver for QMK documentation.', hidden=False if cli.config.user.developer else True)
def docs(cli):
"""Spin up a local HTTP server for the QMK docs.
Expand All @@ -22,6 +24,7 @@ def docs(cli):
if not prepare_docs_build_area(is_production=False):
return False

if not cli.config.general.verbose:
cli.log.info('Serving docs at http://localhost:5173/ (Ctrl+C to stop)')
run_docs_command('run', 'docs:dev')
cmd = ['docs:dev', '--port', f'{cli.args.port}']
if cli.args.browser:
cmd.append('--open')
run_docs_command('run', cmd)
6 changes: 2 additions & 4 deletions lib/python/qmk/cli/generate/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ def generate_docs(cli):
return False

cli.log.info('Building vitepress docs')
run_docs_command('run', 'docs:build')
run_docs_command('run', ['docs:build'])
cli.log.info('Successfully generated docs to %s.', BUILD_DOCS_PATH)

if cli.args.serve:
if not cli.config.general.verbose:
cli.log.info('Serving docs at http://localhost:4173/ (Ctrl+C to stop)')
run_docs_command('run', 'docs:preview')
run_docs_command('run', ['docs:preview'])
8 changes: 4 additions & 4 deletions lib/python/qmk/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
DOXYGEN_PATH = BUILD_DOCS_PATH / 'static' / 'doxygen'


def run_docs_command(verb, cmd=None):
def run_docs_command(verb, cmd_args=None):
environ['PATH'] += pathsep + str(NODE_MODULES_PATH / '.bin')

args = {'capture_output': False if cli.config.general.verbose else True, 'check': True, 'stdin': DEVNULL}
args = {'capture_output': False, 'check': True}
docs_env = environ.copy()
if cli.config.general.verbose:
docs_env['DEBUG'] = 'vitepress:*,vite:*'
args['env'] = docs_env

arg_list = ['yarn', verb]
if cmd:
arg_list.append(cmd)
if cmd_args:
arg_list.extend(cmd_args)

chdir(BUILDDEFS_PATH)
cli.run(arg_list, **args)
Expand Down

0 comments on commit 273d8d6

Please sign in to comment.