Skip to content

Commit

Permalink
Add cli usage information (#423)
Browse files Browse the repository at this point in the history
* add cli usage: `next init`

* add cli usage: `next --help`

* add cli usage: `next build --help`

* add cli usage: `next dev --help`

* add cli usage: `next init --help`

* add cli usage: `next start --help`

* use set

* build, start and dev all accept a directory

* typo and conciseness
  • Loading branch information
stephensauceda authored and rauchg committed Dec 18, 2016
1 parent d12502e commit 955f681
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bin/next
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@ import { watchFile } from 'fs'

const defaultCommand = 'dev'
const commands = new Set([
defaultCommand,
'init',
'build',
'start'
'start',
defaultCommand
])

let cmd = process.argv[2]
let args

if (new Set(['--help', '-h']).has(cmd)) {
console.log(`
Usage
$ next <command>
Available commands
${Array.from(commands).join(', ')}
For more information run a command with the --help flag
$ next init --help
`)
process.exit(0)
}

if (commands.has(cmd)) {
args = process.argv.slice(3)
} else {
Expand Down
14 changes: 14 additions & 0 deletions bin/next-build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const argv = parseArgs(process.argv.slice(2), {
boolean: ['h']
})

if (argv.help) {
console.log(`
Description
Compiles the application for production deployment
Usage
$ next build <dir>
<dir> represents where the compiled .next folder should go.
If no directory is provided, .next will be created in the current directory
`)
process.exit(0)
}

const dir = resolve(argv._[0] || '.')

build(dir)
Expand Down
19 changes: 19 additions & 0 deletions bin/next-dev
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ const argv = parseArgs(process.argv.slice(2), {
}
})

if (argv.help) {
console.log(`
Description
Starts the application in development mode (hot-code reloading, error
reporting, etc)
Usage
$ next dev <dir> -p <port number>
<dir> represents where the compiled .next folder should go.
If no directory is provided, .next will be created in the current directory
Options
--port, -p A port number on which to start the application
--help, -p Displays this message
`)
process.exit(0)
}

const dir = resolve(argv._[0] || '.')

const srv = new Server({ dir, dev: true })
Expand Down
17 changes: 17 additions & 0 deletions bin/next-init
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ const argv = parseArgs(process.argv.slice(2), {
boolean: ['h']
})

if (argv.help) {
console.log(`
Description
Scaffolds a simple project structure to get started quickly
Usage
$ next init <dir>
If no directory is provided the current directory will be used.
Options
--help, -p Displays this message
`)

process.exit(0)
}

const dir = resolve(argv._[0] || '.')

if (basename(dir) === 'pages') {
Expand Down
20 changes: 20 additions & 0 deletions bin/next-start
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ const argv = parseArgs(process.argv.slice(2), {
}
})

if (argv.help) {
console.log(`
Description
Starts the application in production mode.
The application should be compiled with \`next build\` first.
Usage
$ next start <dir> -p <port>
<dir> is the directory that contains the compiled .next folder
created by running \`next build\`.
If no directory is provided, the current directory will be assumed.
Options
--port, -p A port number on which to start the application
--help, -p Displays this message
`)
process.exit(0)
}

const dir = resolve(argv._[0] || '.')

const srv = new Server({ dir })
Expand Down

0 comments on commit 955f681

Please sign in to comment.