@antora/cli 3.0.0-alpha.8 → 3.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/cli.js +81 -66
- package/lib/commander/track-options.js +14 -0
- package/lib/commander.js +1 -0
- package/lib/index.js +14 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
The command line interface (CLI) for Antora.
|
|
4
4
|
|
|
5
5
|
[Antora](https://antora.org) is a modular static site generator designed for creating documentation sites from AsciiDoc documents.
|
|
6
|
-
Its site generator
|
|
6
|
+
Its site generator aggregates documents from versioned content repositories and processes them using [Asciidoctor](https://asciidoctor.org).
|
|
7
7
|
|
|
8
|
-
To run Antora, you need both the CLI and a site generator
|
|
8
|
+
To run Antora, you need both the CLI and a site generator.
|
|
9
9
|
Once these packages are installed, you can use the `antora` command to generate your site.
|
|
10
10
|
|
|
11
11
|
## How to Install
|
package/lib/cli.js
CHANGED
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
'use strict'
|
|
4
2
|
|
|
3
|
+
const buildPlaybook = require('@antora/playbook-builder')
|
|
5
4
|
const cli = require('./commander')
|
|
6
|
-
// Q: can we ask the playbook builder for the config schema?
|
|
7
|
-
const configSchema = require('@antora/playbook-builder/lib/config/schema')
|
|
8
5
|
const convict = require('@antora/playbook-builder/lib/solitary-convict')
|
|
9
|
-
const { finalizeLogger } = require('@antora/logger')
|
|
10
6
|
const ospath = require('path')
|
|
11
7
|
const userRequire = require('@antora/user-require-helper')
|
|
12
8
|
|
|
13
|
-
const DEFAULT_GENERATOR = '@antora/site-generator-default'
|
|
14
9
|
const { version: VERSION } = require('../package.json')
|
|
15
10
|
|
|
16
11
|
async function run (argv = process.argv) {
|
|
17
|
-
|
|
18
|
-
return cli.parseAsync(args.length ? args : ['help'], { from: 'user' })
|
|
12
|
+
return cli.parseAsync((argv = argv.slice(2)).length ? argv : ['help'], { from: 'user' })
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
function exitWithError (err,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
msg = [msg, ...stack.split('\n').slice(1)].join('\n')
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
msg = `error: ${msg} (no stack)`
|
|
39
|
-
}
|
|
40
|
-
console.error(msg)
|
|
15
|
+
function exitWithError (err, opts, msg = undefined) {
|
|
16
|
+
const { getLogger, configureLogger } = requireLogger()
|
|
17
|
+
let errMessage = String(
|
|
18
|
+
err instanceof Error ? err.message : Object.assign((err = new Error(String(err))), { stack: undefined }).message
|
|
19
|
+
)
|
|
20
|
+
const name = errMessage.startsWith('asciidoctor: FAILED: ')
|
|
21
|
+
? (errMessage = errMessage.slice(21)) && 'asciidoctor'
|
|
22
|
+
: cli.name()
|
|
23
|
+
if (!msg) msg = errMessage
|
|
24
|
+
if (!getLogger(null)) {
|
|
25
|
+
configureLogger({ format: 'pretty', level: opts.silent ? 'silent' : 'fatal', failureLevel: 'fatal' })
|
|
26
|
+
}
|
|
27
|
+
if (opts.stacktrace) {
|
|
28
|
+
getLogger(name).fatal(err, msg)
|
|
41
29
|
} else {
|
|
42
|
-
|
|
30
|
+
getLogger(name).fatal({ hint: 'Add the --stacktrace option to see the cause of the error.' }, msg)
|
|
43
31
|
}
|
|
44
|
-
|
|
32
|
+
return exit()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function exit () {
|
|
36
|
+
return requireLogger()
|
|
37
|
+
.finalizeLogger()
|
|
38
|
+
.then((failOnExit) => process.exit(process.exitCode || (failOnExit ? 1 : 0)))
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
function getTTYColumns () {
|
|
48
42
|
return process.env.COLUMNS || process.stdout.columns || 80
|
|
49
43
|
}
|
|
50
44
|
|
|
45
|
+
function outputError (str, write) {
|
|
46
|
+
write(str.replace(/^error: /, cli.name() + ': '))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function requireLogger (fromPath = undefined, moduleName = '@antora/logger') {
|
|
50
|
+
try {
|
|
51
|
+
return (
|
|
52
|
+
requireLogger.cache ||
|
|
53
|
+
(requireLogger.cache = fromPath ? userRequire(moduleName, { paths: [fromPath] }) : require(moduleName))
|
|
54
|
+
)
|
|
55
|
+
} catch {}
|
|
56
|
+
return fromPath && (requireLogger.cache = require(moduleName))
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
cli
|
|
52
60
|
.allowExcessArguments(false)
|
|
53
|
-
.configureOutput({ getOutHelpWidth: getTTYColumns, getErrHelpWidth: getTTYColumns })
|
|
61
|
+
.configureOutput({ getOutHelpWidth: getTTYColumns, getErrHelpWidth: getTTYColumns, outputError })
|
|
54
62
|
.storeOptionsAsProperties()
|
|
55
63
|
.name('antora')
|
|
56
64
|
.version(
|
|
57
65
|
{
|
|
58
66
|
toString () {
|
|
59
|
-
const
|
|
67
|
+
const generator = cli._findCommand('generate').getOptionValue('generator')
|
|
68
|
+
const buffer = ['@antora/cli: ' + VERSION]
|
|
60
69
|
let generatorVersion
|
|
61
|
-
const generatorPackageJson =
|
|
70
|
+
const generatorPackageJson = generator + '/package.json'
|
|
62
71
|
try {
|
|
63
72
|
generatorVersion = require(generatorPackageJson).version
|
|
64
73
|
} catch {
|
|
@@ -66,7 +75,7 @@ cli
|
|
|
66
75
|
generatorVersion = require(require.resolve(generatorPackageJson, { paths: [''] })).version
|
|
67
76
|
} catch {}
|
|
68
77
|
}
|
|
69
|
-
buffer.push(
|
|
78
|
+
buffer.push(generator + ': ' + (generatorVersion || 'not installed'))
|
|
70
79
|
return buffer.join('\n')
|
|
71
80
|
},
|
|
72
81
|
},
|
|
@@ -76,69 +85,75 @@ cli
|
|
|
76
85
|
.description('A modular, multi-repository documentation site generator for AsciiDoc.')
|
|
77
86
|
.usage('[options] [[command] [args]]')
|
|
78
87
|
.helpOption('-h, --help', 'Output usage information.')
|
|
79
|
-
.addHelpText(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
.addHelpText('after', () => {
|
|
89
|
+
const name = cli.name()
|
|
90
|
+
return cli
|
|
91
|
+
.createHelp()
|
|
92
|
+
.wrap(
|
|
84
93
|
` \nRun '${name} <command> --help' to see options and examples for a command (e.g., ${name} generate --help).`,
|
|
85
94
|
getTTYColumns(),
|
|
86
95
|
0
|
|
87
96
|
)
|
|
88
|
-
|
|
89
|
-
)
|
|
97
|
+
})
|
|
90
98
|
.option('-r, --require <library>', 'Require library (aka node module) or script path before executing command.')
|
|
91
99
|
.on('option:require', (requireRequest) => (cli.requireRequests = cli.requireRequests || []).push(requireRequest))
|
|
92
100
|
.option('--stacktrace', 'Print the stacktrace to the console if the application fails.')
|
|
93
101
|
|
|
94
102
|
cli
|
|
95
103
|
.command('generate <playbook>', { isDefault: true })
|
|
96
|
-
.description('Generate a documentation site specified
|
|
97
|
-
.optionsFromConvict(convict(
|
|
98
|
-
.
|
|
99
|
-
cli
|
|
100
|
-
.createOption('--generator <library>', 'The site generator library.')
|
|
101
|
-
.default(DEFAULT_GENERATOR, DEFAULT_GENERATOR)
|
|
102
|
-
)
|
|
104
|
+
.description('Generate a documentation site as specified by <playbook>.')
|
|
105
|
+
.optionsFromConvict(convict(buildPlaybook.defaultSchema), { exclude: 'playbook' })
|
|
106
|
+
.trackOptions()
|
|
103
107
|
.action(async (playbookFile, options, command) => {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
108
|
+
const errorOpts = { stacktrace: cli.stacktrace, silent: command.silent }
|
|
109
|
+
const playbookDir = ospath.resolve(playbookFile, '..')
|
|
110
|
+
const userRequireContext = { dot: playbookDir, paths: [playbookDir, __dirname] }
|
|
106
111
|
if (cli.requireRequests) {
|
|
107
112
|
try {
|
|
108
113
|
cli.requireRequests.forEach((requireRequest) => userRequire(requireRequest, userRequireContext))
|
|
109
114
|
} catch (err) {
|
|
110
|
-
exitWithError(err,
|
|
115
|
+
return exitWithError(err, errorOpts)
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
|
-
const
|
|
118
|
+
const args = command.optionArgs.concat('--playbook', playbookFile)
|
|
119
|
+
let generator, generatorPath, playbook
|
|
120
|
+
try {
|
|
121
|
+
playbook = buildPlaybook(args, process.env, buildPlaybook.defaultSchema, (config) => {
|
|
122
|
+
try {
|
|
123
|
+
generatorPath = userRequire.resolve((generator = config.get('antora.generator')), userRequireContext)
|
|
124
|
+
} catch {}
|
|
125
|
+
try {
|
|
126
|
+
requireLogger(generatorPath).configureLogger(config.getModel('runtime.log'), playbookDir)
|
|
127
|
+
} catch {}
|
|
128
|
+
})
|
|
129
|
+
} catch (err) {
|
|
130
|
+
return exitWithError(err, errorOpts)
|
|
131
|
+
}
|
|
114
132
|
let generateSite
|
|
115
133
|
try {
|
|
116
|
-
generateSite =
|
|
134
|
+
generateSite =
|
|
135
|
+
(generateSite = require(generatorPath || userRequire.resolve(generator, userRequireContext))).length === 1
|
|
136
|
+
? generateSite.bind(null, playbook)
|
|
137
|
+
: generateSite.bind(null, args, process.env)
|
|
117
138
|
} catch (err) {
|
|
118
139
|
let msg = 'Generator not found or failed to load.'
|
|
119
140
|
if (generator && generator.charAt() !== '.') msg += ` Try installing the '${generator}' package.`
|
|
120
|
-
exitWithError(err,
|
|
141
|
+
return exitWithError(err, errorOpts, msg)
|
|
121
142
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return generateSite(args, process.env)
|
|
126
|
-
.then(finalizeLogger)
|
|
127
|
-
.then((failOnExit) => process.exit(failOnExit ? 1 : process.exitCode))
|
|
128
|
-
.catch((err) => finalizeLogger().then(() => exitWithError(err, cli.stacktrace)))
|
|
143
|
+
return generateSite()
|
|
144
|
+
.then(exit)
|
|
145
|
+
.catch((err) => exitWithError(err, errorOpts))
|
|
129
146
|
})
|
|
130
147
|
.options.sort((a, b) => a.long.localeCompare(b.long))
|
|
131
148
|
|
|
132
149
|
cli.command('help [command]', { hidden: true }).action((name, options, command) => {
|
|
133
150
|
if (name) {
|
|
134
|
-
const helpCommand = cli.
|
|
151
|
+
const helpCommand = cli._findCommand(name)
|
|
135
152
|
if (helpCommand) {
|
|
136
153
|
helpCommand.help()
|
|
137
154
|
} else {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
)
|
|
141
|
-
process.exit(1)
|
|
155
|
+
const message = `error: unknown command '${name}'. See '${cli.name()} --help' for a list of commands.`
|
|
156
|
+
cli._displayError(1, 'commander.unknownCommand', message)
|
|
142
157
|
}
|
|
143
158
|
} else {
|
|
144
159
|
cli.help()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Command } = require('commander')
|
|
4
|
+
|
|
5
|
+
Command.prototype.trackOptions = function () {
|
|
6
|
+
const optionArgs = (this.optionArgs = [])
|
|
7
|
+
for (const eventName of this.eventNames().filter((name) => name.startsWith('option:'))) {
|
|
8
|
+
this.on(eventName, function () {
|
|
9
|
+
optionArgs.push(`--${eventName.slice(7)}`)
|
|
10
|
+
if (arguments.length) optionArgs.push(arguments[0])
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
return this
|
|
14
|
+
}
|
package/lib/commander.js
CHANGED
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The command line interface (CLI) for Antora.
|
|
5
|
+
*
|
|
6
|
+
* Provides a built-in set of commands to run Antora. The default command is
|
|
7
|
+
* generate. The generate command builds the specified playbook, configures the
|
|
8
|
+
* logger, then requires and invokes the generator function. When the generator
|
|
9
|
+
* function completes or fails, the generate command finalizes the logger and
|
|
10
|
+
* exits with the specified exit code.
|
|
11
|
+
*
|
|
12
|
+
* @namespace cli
|
|
13
|
+
*/
|
|
14
|
+
module.exports = require('./cli')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/cli",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.3",
|
|
4
4
|
"description": "The command line interface for Antora.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -13,23 +13,23 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://gitlab.com/antora/antora/issues"
|
|
15
15
|
},
|
|
16
|
-
"main": "lib/
|
|
16
|
+
"main": "lib/index.js",
|
|
17
17
|
"bin": {
|
|
18
18
|
"antora": "bin/antora"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@antora/logger": "3.0.0-
|
|
22
|
-
"@antora/playbook-builder": "3.0.0-
|
|
21
|
+
"@antora/logger": "3.0.0-beta.3",
|
|
22
|
+
"@antora/playbook-builder": "3.0.0-beta.3",
|
|
23
23
|
"@antora/user-require-helper": "~2.0",
|
|
24
|
-
"commander": "~
|
|
24
|
+
"commander": "~8.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@antora/site-publisher": "3.0.0-
|
|
28
|
-
"convict": "~6.
|
|
27
|
+
"@antora/site-publisher": "3.0.0-beta.3",
|
|
28
|
+
"convict": "~6.2",
|
|
29
29
|
"kapok-js": "~0.10"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
32
|
+
"node": ">=12.21.0"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"bin/",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"static site",
|
|
44
44
|
"web publishing"
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "45da95a2e2dea538379d2d9f42013d2208fb86c3"
|
|
47
47
|
}
|