@antora/cli
Advanced tools
Comparing version 3.0.0-alpha.9 to 3.0.0-alpha.10
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
const convict = require('@antora/playbook-builder/lib/solitary-convict') | ||
const { finalizeLogger } = require('@antora/logger') | ||
const { configureLogger, getLogger, finalizeLogger } = require('@antora/logger') | ||
const ospath = require('path') | ||
@@ -22,28 +22,36 @@ const userRequire = require('@antora/user-require-helper') | ||
function exitWithError (err, showStack, msg = undefined) { | ||
function exitWithError (err, opts, msg = undefined) { | ||
if (!msg) msg = err.message || err | ||
if (showStack) { | ||
let stack | ||
const name = msg.startsWith('asciidoctor: FAILED: ') ? (msg = msg.slice(21)) && 'asciidoctor' : cli.name() | ||
const logger = getLogger(null) | ||
? getLogger(name) | ||
: configureLogger({ format: 'pretty', level: opts.silent ? 'silent' : 'fatal', failureLevel: 'fatal' }).get(name) | ||
if (opts.stacktrace) { | ||
let loc, stack | ||
if ((stack = err.backtrace)) { | ||
msg = [`error: ${msg}`, ...stack.slice(1)].join('\n') | ||
err = Object.assign(new Error(msg), { stack: ['Error', ...stack.slice(1)].join('\n') }) | ||
} else if ((stack = err.stack)) { | ||
if (err instanceof SyntaxError) { | ||
let loc | ||
;[loc, stack] = stack.split(/\n+(?=SyntaxError: )/) | ||
msg = stack.replace('\n', `\n at ${loc}\n`) | ||
} else if (stack.startsWith(`${err.name}: ${msg}\n`)) { | ||
msg = stack | ||
} else { | ||
msg = [msg, ...stack.split('\n').slice(1)].join('\n') | ||
if (err instanceof SyntaxError && stack.includes('\nSyntaxError: ')) { | ||
;[loc, stack] = stack.split(/\n+SyntaxError: [^\n]+/) | ||
err = Object.assign(new SyntaxError(msg), { stack: stack.replace('\n', `SyntaxError\n at ${loc}\n`) }) | ||
} else if (stack.startsWith(`${err.name}: ${msg}`)) { | ||
stack = stack.replace(`${err.name}: ${msg}`, '').replace(/^\n/, '') | ||
err = Object.assign(new err.constructor(msg), { stack: stack ? `${err.name}\n${stack}` : undefined }) | ||
} | ||
} else { | ||
msg = `error: ${msg} (no stack)` | ||
err = Object.assign(new Error(msg), { stack: undefined }) | ||
} | ||
console.error(msg) | ||
if ({}.propertyIsEnumerable.call(err, 'name')) Object.defineProperty(err, 'name', { enumerable: false }) | ||
err.stack = `Cause: ${err.stack || '(no stacktrace)'}` | ||
logger.fatal(err, msg) | ||
} else { | ||
console.error(`error: ${msg}\nAdd the --stacktrace option to see the cause.`) | ||
logger.fatal(msg + '\nAdd the --stacktrace option to see the cause of the error.') | ||
} | ||
process.exit(1) | ||
return exit() | ||
} | ||
function exit () { | ||
return finalizeLogger().then((failOnExit) => process.exit(failOnExit ? 1 : process.exitCode)) | ||
} | ||
function getTTYColumns () { | ||
@@ -53,5 +61,9 @@ return process.env.COLUMNS || process.stdout.columns || 80 | ||
function outputError (str, write) { | ||
write(str.replace(/^error: /, `${cli.name()}: `)) | ||
} | ||
cli | ||
.allowExcessArguments(false) | ||
.configureOutput({ getOutHelpWidth: getTTYColumns, getErrHelpWidth: getTTYColumns }) | ||
.configureOutput({ getOutHelpWidth: getTTYColumns, getErrHelpWidth: getTTYColumns, outputError }) | ||
.storeOptionsAsProperties() | ||
@@ -99,3 +111,3 @@ .name('antora') | ||
.command('generate <playbook>', { isDefault: true }) | ||
.description('Generate a documentation site specified in <playbook>.') | ||
.description('Generate a documentation site as specified by <playbook>.') | ||
.optionsFromConvict(convict(configSchema), { exclude: 'playbook' }) | ||
@@ -107,4 +119,6 @@ .addOption( | ||
) | ||
.trackOptions() | ||
.action(async (playbookFile, options, command) => { | ||
const dot = ospath.resolve(playbookFile, '..') | ||
const errorOpts = { stacktrace: cli.stacktrace, silent: command.silent } | ||
const userRequireContext = { dot, paths: [dot, __dirname] } | ||
@@ -115,3 +129,3 @@ if (cli.requireRequests) { | ||
} catch (err) { | ||
exitWithError(err, cli.stacktrace) | ||
return exitWithError(err, errorOpts) | ||
} | ||
@@ -126,11 +140,9 @@ } | ||
if (generator && generator.charAt() !== '.') msg += ` Try installing the '${generator}' package.` | ||
exitWithError(err, cli.stacktrace, msg) | ||
return exitWithError(err, errorOpts, msg) | ||
} | ||
const args = cli.rawArgs.slice(cli.rawArgs.indexOf(command.name()) + 1) | ||
args.splice(args.indexOf(playbookFile), 0, '--playbook') | ||
const args = command.optionArgs.concat('--playbook', playbookFile) | ||
// TODO support passing a preloaded convict config as third option; gets new args and env | ||
return generateSite(args, process.env) | ||
.then(finalizeLogger) | ||
.then((failOnExit) => process.exit(failOnExit ? 1 : process.exitCode)) | ||
.catch((err) => finalizeLogger().then(() => exitWithError(err, cli.stacktrace))) | ||
.then(exit) | ||
.catch((err) => exitWithError(err, errorOpts)) | ||
}) | ||
@@ -145,6 +157,4 @@ .options.sort((a, b) => a.long.localeCompare(b.long)) | ||
} else { | ||
console.error( | ||
`'${name}' is not a valid command in ${cli.name()}. See '${cli.name()} --help' for a list of commands.` | ||
) | ||
process.exit(1) | ||
const message = `error: unknown command '${name}'. See '${cli.name()} --help' for a list of commands.` | ||
cli._displayError(1, 'commander.unknownCommand', message) | ||
} | ||
@@ -151,0 +161,0 @@ } else { |
@@ -5,3 +5,4 @@ 'use strict' | ||
require('./commander/options-from-convict') | ||
require('./commander/track-options') | ||
module.exports = commander |
{ | ||
"name": "@antora/cli", | ||
"version": "3.0.0-alpha.9", | ||
"version": "3.0.0-alpha.10", | ||
"description": "The command line interface for Antora.", | ||
@@ -21,4 +21,4 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/logger": "3.0.0-alpha.9", | ||
"@antora/playbook-builder": "3.0.0-alpha.9", | ||
"@antora/logger": "3.0.0-alpha.10", | ||
"@antora/playbook-builder": "3.0.0-alpha.10", | ||
"@antora/user-require-helper": "~2.0", | ||
@@ -28,4 +28,4 @@ "commander": "~7.2" | ||
"devDependencies": { | ||
"@antora/site-publisher": "3.0.0-alpha.9", | ||
"convict": "~6.1", | ||
"@antora/site-publisher": "3.0.0-alpha.10", | ||
"convict": "~6.2", | ||
"kapok-js": "~0.10" | ||
@@ -48,3 +48,3 @@ }, | ||
], | ||
"gitHead": "a504d6889819b548e8a5416a7194cbb6f9a93e93" | ||
"gitHead": "a9e10aacbc6fb0c4dc3a42dd7e4a5c763d153428" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28312
8
210
+ Added@antora/logger@3.0.0-alpha.10(transitive)
+ Added@antora/playbook-builder@3.0.0-alpha.10(transitive)
+ Addedcolorette@2.0.20(transitive)
+ Addedconvict@6.2.4(transitive)
+ Addedduplexify@4.1.3(transitive)
+ Addedpino-abstract-transport@0.4.0(transitive)
+ Addedpino-pretty@7.1.0(transitive)
+ Addedsecure-json-parse@2.7.0(transitive)
+ Addedsonic-boom@2.8.0(transitive)
+ Addedstream-shift@1.0.3(transitive)
+ Addedyargs-parser@20.2.9(transitive)
- Removed@antora/logger@3.0.0-alpha.9(transitive)
- Removed@antora/playbook-builder@3.0.0-alpha.9(transitive)
- Removed@hapi/bourne@2.1.0(transitive)
- Removedcolorette@1.4.0(transitive)
- Removedconvict@6.1.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedjmespath@0.15.0(transitive)
- Removedpino-pretty@6.0.0(transitive)
- Removedyargs-parser@18.1.3(transitive)