Skip to content

Commit

Permalink
add open webpage flag, add open docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Feb 11, 2025
1 parent 14bf4f4 commit fe402aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/nuekit/src/cli-help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colors, openUrl, version } from './util.js'
import { colors, version } from './util.js'

const HELP = `
Usage
Expand All @@ -11,14 +11,16 @@ Commands
build Build the site under <root_dir>
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)
-p or --production Build production version / Show production stats
-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:
Expand All @@ -38,15 +40,15 @@ 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}
┃┃┃┃┗┛┃┃━┫ nuejs.org
┗┛┗┻━━┻━━┛
`

const commands = ['serve', 'build', 'init', 'create']
const commands = ['serve', 'build', 'init', 'create', 'docs']

function formatLine(line) {
const { gray, magenta, cyan, green } = colors
Expand Down
8 changes: 6 additions & 2 deletions packages/nuekit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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') : {}
Expand Down

0 comments on commit fe402aa

Please sign in to comment.