-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
44 lines (37 loc) · 1.42 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
#!/usr/bin/env node
const path = require('path')
const fs = require('fs')
const sao = require('sao')
const cac = require('cac')
const chalk = require('chalk')
const { version } = require('../package.json')
const generator = path.resolve(__dirname, './')
const cli = cac('create-nuxt-netlify-cms-docs')
cli
.command('[out-dir]', 'Generate in a custom directory or current directory')
.option('--verbose', 'Show debug logs')
// eslint-disable-next-line default-param-last
.action((outDir = '.', cliOptions) => {
const files = fs.existsSync(outDir) ? fs.readdirSync(outDir) : []
// eslint-disable-next-line no-console
console.log(chalk`{cyan create-nuxt-netlify-cms-docs v${version}}`)
if (files.length) {
// eslint-disable-next-line no-console
return console.log(chalk.red(`Can't create ${outDir} because there's already a non-empty directory ${outDir} existing in path.`))
}
// eslint-disable-next-line no-console
console.log(chalk`✨ Generating @nuxt/netlify-cms-docs documentation in {cyan ${outDir}}`)
const { verbose, answers } = cliOptions
const logLevel = verbose ? 4 : 2
// See https://saojs.org/api.html#standalone-cli
sao({ generator, outDir, logLevel, answers, cliOptions })
.run()
.catch((err) => {
// eslint-disable-next-line no-console
console.trace(err)
process.exit(1)
})
})
cli.help()
cli.version(version)
cli.parse()