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 12, 2025
1 parent 7b9a9a5 commit 296e737
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,6 +11,7 @@ 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)
Expand All @@ -19,7 +20,8 @@ Options
-n or --dry-run Show what would be built. Does not create outputs
-b or --esbuild Use esbuild as JS bundler. Please install it manually
-l or --lcss Use lightningcss as CSS 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 @@ -39,15 +41,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 @@ -52,6 +52,7 @@ export function getArgs(argv) {
else if (['-l', '--lcss'].includes(arg)) args.lcss = 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 @@ -87,6 +88,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 @@ -105,6 +108,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 296e737

Please sign in to comment.