1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add cli usage information (#423)

* 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
This commit is contained in:
Stephen Sauceda 2016-12-18 15:28:34 -05:00 committed by Guillermo Rauch
parent d12502ef24
commit 955f6817c4
5 changed files with 86 additions and 2 deletions

View file

@ -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 {

View file

@ -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)

View file

@ -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 })

View file

@ -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') {

View file

@ -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 })