Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antora/cli

Package Overview
Dependencies
Maintainers
2
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/cli - npm Package Compare versions

Comparing version 3.0.0-alpha.9 to 3.0.0-alpha.10

lib/commander/track-options.js

70

lib/cli.js

@@ -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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc