diff --git a/packages/nuekit/src/cli-help.js b/packages/nuekit/src/cli-help.js index 4091a9d3..1a3d1588 100644 --- a/packages/nuekit/src/cli-help.js +++ b/packages/nuekit/src/cli-help.js @@ -1,4 +1,4 @@ -import { colors, openUrl, version } from './util.js' +import { colors, version } from './util.js' const HELP = ` Usage @@ -11,6 +11,7 @@ Commands build Build the site under create Use a project starter template init Re-generate /@nue system files + docs Open Nue's docs Options -r or --root Source directory. Default "." (current working dir) @@ -18,7 +19,8 @@ Options -e or --environment Read extra options to override defaults in site.yaml -n or --dry-run Show what would be built. Does not create outputs -b or --esbuild Use esbuild as bundler. Please install it manually - -P or --port Port to serve the site on + -P or --port Serves the site on the specified port + -o or --open Opens the local site in the browser File matches Only build files that match the rest of the arguments. For example: @@ -38,7 +40,7 @@ Examples nue build .md .css # more examples - https://nuejs.org/docs/command-line-interface.html + Visit https://nuejs.org/docs/command-line-interface.html ┏━┓┏┓┏┳━━┓ ┃┏┓┫┃┃┃┃━┫ ${version} @@ -46,7 +48,7 @@ Examples ┗┛┗┻━━┻━━┛ ` -const commands = ['serve', 'build', 'init', 'create'] +const commands = ['serve', 'build', 'init', 'create', 'docs'] function formatLine(line) { const { gray, magenta, cyan, green } = colors diff --git a/packages/nuekit/src/cli.js b/packages/nuekit/src/cli.js index 37d2542d..684c9521 100755 --- a/packages/nuekit/src/cli.js +++ b/packages/nuekit/src/cli.js @@ -4,7 +4,7 @@ import { sep } from 'node:path' import esMain from 'es-main' -import { log, colors, version, getEngine } from './util.js' +import { log, colors, version, getEngine, openUrl } from './util.js' // [-npe] --> [-n, -p, -e] @@ -22,7 +22,7 @@ export function expandArgs(args) { // TODO: tests export function getArgs(argv) { - const commands = ['serve', 'build', 'init', 'create'] + const commands = ['serve', 'build', 'init', 'create', 'docs'] const args = { paths: [], root: null } const checkExecutable = /[\\\/]nue(\.(cmd|ps1|bunx|exe))?$/ let opt @@ -51,6 +51,7 @@ export function getArgs(argv) { else if (['-b', '--esbuild'].includes(arg)) args.esbuild = true else if (['-d', '--deploy'].includes(arg)) args.deploy = args.is_prod = true else if (['-I', '--incremental'].includes(arg)) args.incremental = true + else if (['-o', '--open'].includes(arg)) args.open = true // string values else if (['-e', '--environment'].includes(arg)) opt = 'env' @@ -86,6 +87,8 @@ async function printVersion() { } async function runCommand(args) { + if (args.cmd == 'docs') return openUrl('https://nuejs.org/docs/') + const { createKit } = await import('./nuekit.js') const { cmd = 'serve', dryrun, deploy, root = null, port } = args const init = cmd == 'init' @@ -104,6 +107,7 @@ async function runCommand(args) { const nue = await createKit(args) if (!nue) return + if (args.open) openUrl(`http://localhost:${nue.port}/`) // deployer (private repo) const { deploy: deployer } = deploy ? await import('nue-deployer') : {}