-
Notifications
You must be signed in to change notification settings - Fork 19
/
cli.js
executable file
·56 lines (48 loc) · 1.65 KB
/
cli.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
#!/usr/bin/env node
const program = require('commander')
const chalk = require('chalk')
const esm = require('esm')
const { existsSync } = require('fs')
const { resolve } = require('path')
const pkg = require('./package.json')
const make = require('.')
program
.version(pkg.version)
.option('-H, --hostname <hostname>', 'website hostname')
.option(
'-F, --changefreq [daily|weekly|monthly]',
'page change frequency, defaults to daily'
)
.option('-c, --cache-time [n]', 'cache time in second', parseInt)
.option('-u, --urls [urls]', 'list of urls to be merged', (val) =>
val.split(',')
)
.option('-d, --dest [dest]', 'vuepress dest dir, defaults to process.cwd', process.cwd())
.option('-t, --temp [temp]', 'vuepress temporary dir')
.parse(process.argv)
if (!process.argv.slice(2).length) {
program.outputHelp(chalk.green)
process.exit()
}
try {
let tempDir = program.temp || ''
if (!tempDir) {
const legacyTempDir = resolve('node_modules/vuepress/lib/app/.temp')
tempDir = existsSync(legacyTempDir)
? legacyTempDir
: resolve('node_modules/@vuepress/core/.temp/internal')
} else {
const stableDir = resolve(tempDir, 'internal')
tempDir = existsSync(stableDir) ? stableDir : resolve(tempDir)
}
const siteDataFile = resolve(tempDir, 'siteData.js')
if (!existsSync(siteDataFile)) {
throw new Error('Can\'t find siteData on temp dir, please build first or supply temp dir manually')
}
const requires = esm(module)
const { siteData } = requires(siteDataFile)
make(program, siteData).generated()
} catch (error) {
console.error(chalk.bold.red(error.message || error.msg || error))
process.exit(1)
}