Skip to content

Commit 955f681

Browse files
stephensaucedarauchg
authored andcommitted
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
1 parent d12502e commit 955f681

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

bin/next

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ import { watchFile } from 'fs'
66

77
const defaultCommand = 'dev'
88
const commands = new Set([
9-
defaultCommand,
109
'init',
1110
'build',
12-
'start'
11+
'start',
12+
defaultCommand
1313
])
1414

1515
let cmd = process.argv[2]
1616
let args
1717

18+
if (new Set(['--help', '-h']).has(cmd)) {
19+
console.log(`
20+
Usage
21+
$ next <command>
22+
23+
Available commands
24+
${Array.from(commands).join(', ')}
25+
26+
For more information run a command with the --help flag
27+
$ next init --help
28+
`)
29+
process.exit(0)
30+
}
31+
1832
if (commands.has(cmd)) {
1933
args = process.argv.slice(3)
2034
} else {

bin/next-build

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ const argv = parseArgs(process.argv.slice(2), {
1111
boolean: ['h']
1212
})
1313

14+
if (argv.help) {
15+
console.log(`
16+
Description
17+
Compiles the application for production deployment
18+
19+
Usage
20+
$ next build <dir>
21+
22+
<dir> represents where the compiled .next folder should go.
23+
If no directory is provided, .next will be created in the current directory
24+
`)
25+
process.exit(0)
26+
}
27+
1428
const dir = resolve(argv._[0] || '.')
1529

1630
build(dir)

bin/next-dev

+19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ const argv = parseArgs(process.argv.slice(2), {
1616
}
1717
})
1818

19+
if (argv.help) {
20+
console.log(`
21+
Description
22+
Starts the application in development mode (hot-code reloading, error
23+
reporting, etc)
24+
25+
Usage
26+
$ next dev <dir> -p <port number>
27+
28+
<dir> represents where the compiled .next folder should go.
29+
If no directory is provided, .next will be created in the current directory
30+
31+
Options
32+
--port, -p A port number on which to start the application
33+
--help, -p Displays this message
34+
`)
35+
process.exit(0)
36+
}
37+
1938
const dir = resolve(argv._[0] || '.')
2039

2140
const srv = new Server({ dir, dev: true })

bin/next-init

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ const argv = parseArgs(process.argv.slice(2), {
1111
boolean: ['h']
1212
})
1313

14+
if (argv.help) {
15+
console.log(`
16+
Description
17+
Scaffolds a simple project structure to get started quickly
18+
19+
Usage
20+
$ next init <dir>
21+
22+
If no directory is provided the current directory will be used.
23+
24+
Options
25+
--help, -p Displays this message
26+
`)
27+
28+
process.exit(0)
29+
}
30+
1431
const dir = resolve(argv._[0] || '.')
1532

1633
if (basename(dir) === 'pages') {

bin/next-start

+20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ const argv = parseArgs(process.argv.slice(2), {
1515
}
1616
})
1717

18+
if (argv.help) {
19+
console.log(`
20+
Description
21+
Starts the application in production mode.
22+
The application should be compiled with \`next build\` first.
23+
24+
Usage
25+
$ next start <dir> -p <port>
26+
27+
<dir> is the directory that contains the compiled .next folder
28+
created by running \`next build\`.
29+
If no directory is provided, the current directory will be assumed.
30+
31+
Options
32+
--port, -p A port number on which to start the application
33+
--help, -p Displays this message
34+
`)
35+
process.exit(0)
36+
}
37+
1838
const dir = resolve(argv._[0] || '.')
1939

2040
const srv = new Server({ dir })

0 commit comments

Comments
 (0)