diff --git a/docs/cli_commands.md b/docs/cli_commands.md index 7d74d8e6177..c09af92604a 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md @@ -717,23 +717,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. diff --git a/docs/contributing.md b/docs/contributing.md index bbb1997a6f6..70a00b706d7 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -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 diff --git a/lib/python/qmk/cli/docs.py b/lib/python/qmk/cli/docs.py index d28dddf194e..da02ebf95e3 100644 --- a/lib/python/qmk/cli/docs.py +++ b/lib/python/qmk/cli/docs.py @@ -6,6 +6,8 @@ from qmk.docs import prepare_docs_build_area, run_docs_command 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. @@ -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) diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py index 5821d43b869..7abeca9d2ab 100644 --- a/lib/python/qmk/cli/generate/docs.py +++ b/lib/python/qmk/cli/generate/docs.py @@ -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']) diff --git a/lib/python/qmk/docs.py b/lib/python/qmk/docs.py index 56694cf6aeb..75d2d60bda1 100644 --- a/lib/python/qmk/docs.py +++ b/lib/python/qmk/docs.py @@ -17,18 +17,18 @@ BUILD_DOCS_PATH = BUILD_PATH / 'docs' 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)