forked from vuejs/vuepress
/
registerCoreCommands.js
100 lines (88 loc) 路 3.46 KB
/
registerCoreCommands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict'
/**
* Module dependencies.
*/
const { chalk } = require('@vuepress/shared-utils')
const envinfo = require('envinfo')
const { dev, build, eject } = require('@vuepress/core')
const { path, logger, env } = require('@vuepress/shared-utils')
const { wrapCommand } = require('./util')
/**
* Expose registerCoreCommands function.
*/
module.exports = function (cli, options) {
cli
.command(`dev [targetDir]`, 'start development server')
.option('-p, --port <port>', 'use specified port (default: 8080)')
.option('-t, --temp <temp>', 'set the directory of the temporary file')
.option('-c, --cache [cache]', 'set the directory of cache')
.option('--host <host>', 'use specified host (default: 0.0.0.0)')
.option('--no-cache', 'clean the cache before build')
.option('--no-clear-screen', 'do not clear screen when dev server is ready')
.option('--debug', 'start development server in debug mode')
.option('--silent', 'start development server in silent mode')
.option('--open', 'open browser when ready')
.action((sourceDir = '.', commandOptions) => {
const { debug, silent } = commandOptions
logger.setOptions({ logLevel: silent ? 1 : debug ? 4 : 3 })
logger.debug('global_options', options)
logger.debug('dev_options', commandOptions)
env.setOptions({ isDebug: debug, isTest: process.env.NODE_ENV === 'test' })
wrapCommand(dev)({
sourceDir: path.resolve(sourceDir),
...options,
...commandOptions
})
})
cli
.command('build [targetDir]', 'build dir as static site')
.option('-d, --dest <dest>', 'specify build output dir (default: .vuepress/dist)')
.option('-t, --temp <temp>', 'set the directory of the temporary file')
.option('-c, --cache [cache]', 'set the directory of cache')
.option('--dest <dest>', 'the output directory for build process')
.option('--no-cache', 'clean the cache before build')
.option('--debug', 'build in development mode for debugging')
.option('--silent', 'build static site in silent mode')
.option('--max-concurrency', 'set the max docs concurrently processed when build static site')
.action((sourceDir = '.', commandOptions) => {
const { debug, silent } = commandOptions
logger.setOptions({ logLevel: silent ? 1 : debug ? 4 : 3 })
logger.debug('global_options', options)
logger.debug('build_options', commandOptions)
env.setOptions({ isDebug: debug, isTest: process.env.NODE_ENV === 'test' })
wrapCommand(build)({
sourceDir: path.resolve(sourceDir),
...options,
...commandOptions
})
})
cli
.command('eject [targetDir]', 'copy the default theme into .vuepress/theme for customization.')
.option('--debug', 'eject in debug mode')
.action((dir = '.') => {
wrapCommand(eject)(path.resolve(dir))
})
cli
.command('info', 'Shows debugging information about the local environment')
.action(() => {
console.log(chalk.bold('\nEnvironment Info:'))
envinfo.run(
{
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
npmGlobalPackages: ['vuepress'],
npmPackages: [
'vuepress',
'@vuepress/core',
'@vuepress/theme-default'
]
},
{
showNotFound: true,
duplicates: true,
fullTree: true
}
).then(console.log)
})
}