@antora/cli 3.0.0-beta.1 → 3.0.0-beta.5
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 +6 -4
- package/lib/cli.js +35 -36
- package/lib/index.js +14 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Antora CLI
|
|
2
2
|
|
|
3
3
|
The command line interface (CLI) for Antora.
|
|
4
|
+
This package provides the `antora` command (i.e., bin script) to run Antora.
|
|
5
|
+
It does not include the site generator, which must be installed separately.
|
|
4
6
|
|
|
5
7
|
[Antora](https://antora.org) is a modular static site generator designed for creating documentation sites from AsciiDoc documents.
|
|
6
8
|
Its site generator aggregates documents from versioned content repositories and processes them using [Asciidoctor](https://asciidoctor.org).
|
|
@@ -13,7 +15,7 @@ Once these packages are installed, you can use the `antora` command to generate
|
|
|
13
15
|
Let's start by installing the CLI.
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
|
-
npm
|
|
18
|
+
npm i -g @antora/cli
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
This package adds the `antora` command to your PATH.
|
|
@@ -24,10 +26,10 @@ antora -v
|
|
|
24
26
|
```
|
|
25
27
|
|
|
26
28
|
Next, install a site generator.
|
|
27
|
-
The
|
|
29
|
+
The site generator provided by Antora will be sufficient for most users.
|
|
28
30
|
|
|
29
31
|
```sh
|
|
30
|
-
npm
|
|
32
|
+
npm i -g @antora/site-generator
|
|
31
33
|
```
|
|
32
34
|
|
|
33
35
|
The `antora` command (specifically the implicit `generate` subcommand) will look for this package by default.
|
|
@@ -37,7 +39,7 @@ The `antora` command (specifically the implicit `generate` subcommand) will look
|
|
|
37
39
|
To run Antora, you'll need a playbook file and at least one content (source) repository.
|
|
38
40
|
Consult the [quickstart](https://docs.antora.org/antora/latest/install-and-run-quickstart/) to find an example.
|
|
39
41
|
|
|
40
|
-
Once you have your content sources set up,
|
|
42
|
+
Once you have your content sources set up, point the `antora` command at your playbook file:
|
|
41
43
|
|
|
42
44
|
```sh
|
|
43
45
|
antora antora-playbook.yml
|
package/lib/cli.js
CHANGED
|
@@ -1,53 +1,41 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
'use strict'
|
|
4
2
|
|
|
5
3
|
const buildPlaybook = require('@antora/playbook-builder')
|
|
6
4
|
const cli = require('./commander')
|
|
7
5
|
const convict = require('@antora/playbook-builder/lib/solitary-convict')
|
|
8
|
-
const { configureLogger, getLogger, finalizeLogger } = require('@antora/logger')
|
|
9
6
|
const ospath = require('path')
|
|
10
7
|
const userRequire = require('@antora/user-require-helper')
|
|
11
8
|
|
|
12
9
|
const { version: VERSION } = require('../package.json')
|
|
13
10
|
|
|
14
11
|
async function run (argv = process.argv) {
|
|
15
|
-
|
|
16
|
-
return cli.parseAsync(args.length ? args : ['help'], { from: 'user' })
|
|
12
|
+
return cli.parseAsync((argv = argv.slice(2)).length ? argv : ['help'], { from: 'user' })
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
function exitWithError (err, opts, msg = undefined) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
27
|
if (opts.stacktrace) {
|
|
26
|
-
|
|
27
|
-
if ((stack = err.backtrace)) {
|
|
28
|
-
err = Object.assign(new Error(msg), { stack: ['Error', ...stack.slice(1)].join('\n') })
|
|
29
|
-
} else if ((stack = err.stack)) {
|
|
30
|
-
if (err instanceof SyntaxError && stack.includes('\nSyntaxError: ')) {
|
|
31
|
-
;[loc, stack] = stack.split(/\n+SyntaxError: [^\n]+/)
|
|
32
|
-
err = Object.assign(new SyntaxError(msg), { stack: stack.replace('\n', `SyntaxError\n at ${loc}\n`) })
|
|
33
|
-
} else if (stack.startsWith(`${err.name}: ${msg}`)) {
|
|
34
|
-
stack = stack.replace(`${err.name}: ${msg}`, '').replace(/^\n/, '')
|
|
35
|
-
err = Object.assign(new err.constructor(msg), { stack: stack ? `${err.name}\n${stack}` : undefined })
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
err = Object.assign(new Error(msg), { stack: undefined })
|
|
39
|
-
}
|
|
40
|
-
if ({}.propertyIsEnumerable.call(err, 'name')) Object.defineProperty(err, 'name', { enumerable: false })
|
|
41
|
-
err.stack = `Cause: ${err.stack || '(no stacktrace)'}`
|
|
42
|
-
logger.fatal(err, msg)
|
|
28
|
+
getLogger(name).fatal(err, msg)
|
|
43
29
|
} else {
|
|
44
|
-
|
|
30
|
+
getLogger(name).fatal({ hint: 'Add the --stacktrace option to see the cause of the error.' }, msg)
|
|
45
31
|
}
|
|
46
32
|
return exit()
|
|
47
33
|
}
|
|
48
34
|
|
|
49
35
|
function exit () {
|
|
50
|
-
return
|
|
36
|
+
return requireLogger()
|
|
37
|
+
.finalizeLogger()
|
|
38
|
+
.then((failOnExit) => process.exit(process.exitCode || (failOnExit ? 1 : 0)))
|
|
51
39
|
}
|
|
52
40
|
|
|
53
41
|
function getTTYColumns () {
|
|
@@ -58,6 +46,17 @@ function outputError (str, write) {
|
|
|
58
46
|
write(str.replace(/^error: /, cli.name() + ': '))
|
|
59
47
|
}
|
|
60
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
|
+
) // require('@antora/logger')
|
|
55
|
+
} catch {
|
|
56
|
+
return fromPath && (requireLogger.cache = require(moduleName))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
61
60
|
cli
|
|
62
61
|
.allowExcessArguments(false)
|
|
63
62
|
.configureOutput({ getOutHelpWidth: getTTYColumns, getErrHelpWidth: getTTYColumns, outputError })
|
|
@@ -118,21 +117,23 @@ cli
|
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
119
|
const args = command.optionArgs.concat('--playbook', playbookFile)
|
|
121
|
-
let playbook
|
|
120
|
+
let generator, generatorPath, playbook
|
|
122
121
|
try {
|
|
123
122
|
playbook = buildPlaybook(args, process.env, buildPlaybook.defaultSchema, (config) => {
|
|
124
123
|
try {
|
|
125
|
-
|
|
124
|
+
generatorPath = userRequire.resolve((generator = config.get('antora.generator')), userRequireContext)
|
|
125
|
+
} catch {}
|
|
126
|
+
try {
|
|
127
|
+
requireLogger(generatorPath).configureLogger(config.getModel('runtime.log'), playbookDir)
|
|
126
128
|
} catch {}
|
|
127
129
|
})
|
|
128
130
|
} catch (err) {
|
|
129
131
|
return exitWithError(err, errorOpts)
|
|
130
132
|
}
|
|
131
|
-
const generator = playbook.antora.generator
|
|
132
133
|
let generateSite
|
|
133
134
|
try {
|
|
134
135
|
generateSite =
|
|
135
|
-
(generateSite = userRequire(generator, userRequireContext)).length === 1
|
|
136
|
+
(generateSite = require(generatorPath || userRequire.resolve(generator, userRequireContext))).length === 1
|
|
136
137
|
? generateSite.bind(null, playbook)
|
|
137
138
|
: generateSite.bind(null, args, process.env)
|
|
138
139
|
} catch (err) {
|
|
@@ -140,9 +141,7 @@ cli
|
|
|
140
141
|
if (generator && generator.charAt() !== '.') msg += ` Try installing the '${generator}' package.`
|
|
141
142
|
return exitWithError(err, errorOpts, msg)
|
|
142
143
|
}
|
|
143
|
-
return generateSite()
|
|
144
|
-
.then(exit)
|
|
145
|
-
.catch((err) => exitWithError(err, errorOpts))
|
|
144
|
+
return generateSite().then(exit, (err) => exitWithError(err, errorOpts))
|
|
146
145
|
})
|
|
147
146
|
.options.sort((a, b) => a.long.localeCompare(b.long))
|
|
148
147
|
|
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-beta.
|
|
3
|
+
"version": "3.0.0-beta.5",
|
|
4
4
|
"description": "The command line interface for Antora.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -13,18 +13,19 @@
|
|
|
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-beta.
|
|
22
|
-
"@antora/playbook-builder": "3.0.0-beta.
|
|
21
|
+
"@antora/logger": "3.0.0-beta.5",
|
|
22
|
+
"@antora/playbook-builder": "3.0.0-beta.5",
|
|
23
23
|
"@antora/user-require-helper": "~2.0",
|
|
24
24
|
"commander": "~8.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@antora/site-publisher": "3.0.0-beta.
|
|
27
|
+
"@antora/site-publisher": "3.0.0-beta.5",
|
|
28
|
+
"@asciidoctor/core": "~2.2",
|
|
28
29
|
"convict": "~6.2",
|
|
29
30
|
"kapok-js": "~0.10"
|
|
30
31
|
},
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"static site",
|
|
44
45
|
"web publishing"
|
|
45
46
|
],
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a13d03df41654d4deb78211a5a54953ce2a35fb8"
|
|
47
48
|
}
|