@antora/cli
Advanced tools
Comparing version 3.0.0-alpha.7 to 3.0.0-alpha.8
@@ -11,4 +11,5 @@ #!/usr/bin/env node | ||
const ospath = require('path') | ||
const userRequire = require('@antora/user-require-helper') | ||
const DOT_RELATIVE_RX = new RegExp(`^\\.{1,2}[/${ospath.sep.replace('/', '').replace('\\', '\\\\')}]`) | ||
const DEFAULT_GENERATOR = '@antora/site-generator-default' | ||
const { version: VERSION } = require('../package.json') | ||
@@ -28,3 +29,11 @@ | ||
} else if ((stack = err.stack)) { | ||
msg = stack.startsWith(`${err.name}: ${msg}\n`) ? stack : [msg, ...stack.split('\n').slice(1)].join('\n') | ||
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') | ||
} | ||
} else { | ||
@@ -44,18 +53,2 @@ msg = `error: ${msg} (no stack)` | ||
function requireLibraries (requirePaths) { | ||
if (requirePaths) requirePaths.forEach((requirePath) => requireLibrary(requirePath)) | ||
} | ||
function requireLibrary (requirePath, cwd = process.cwd()) { | ||
if (requirePath.charAt() === '.' && DOT_RELATIVE_RX.test(requirePath)) { | ||
// NOTE require resolves a dot-relative path relative to current file; resolve relative to cwd instead | ||
requirePath = ospath.resolve(requirePath) | ||
} else if (!ospath.isAbsolute(requirePath)) { | ||
// NOTE appending node_modules prevents require from looking elsewhere before looking in these paths | ||
const paths = [cwd, ospath.dirname(__dirname)].map((start) => ospath.join(start, 'node_modules')) | ||
requirePath = require.resolve(requirePath, { paths }) | ||
} | ||
return require(requirePath) | ||
} | ||
cli | ||
@@ -66,3 +59,22 @@ .allowExcessArguments(false) | ||
.name('antora') | ||
.version(VERSION, '-v, --version', 'Output the version number.') | ||
.version( | ||
{ | ||
toString () { | ||
const buffer = [`@antora/cli: ${VERSION}`] | ||
let generatorVersion | ||
const generatorPackageJson = DEFAULT_GENERATOR + '/package.json' | ||
try { | ||
generatorVersion = require(generatorPackageJson).version | ||
} catch { | ||
try { | ||
generatorVersion = require(require.resolve(generatorPackageJson, { paths: [''] })).version | ||
} catch {} | ||
} | ||
buffer.push(DEFAULT_GENERATOR + ': ' + (generatorVersion || 'not installed')) | ||
return buffer.join('\n') | ||
}, | ||
}, | ||
'-v, --version', | ||
'Output the version of the CLI and default site generator.' | ||
) | ||
.description('A modular, multi-repository documentation site generator for AsciiDoc.') | ||
@@ -82,4 +94,4 @@ .usage('[options] [[command] [args]]') | ||
) | ||
.option('-r, --require <library>', 'Require library (aka node module) or script before executing command.') | ||
.on('option:require', (requirePath) => (cli.requirePaths = [...(cli.requirePaths || []), requirePath])) | ||
.option('-r, --require <library>', 'Require library (aka node module) or script path before executing command.') | ||
.on('option:require', (requireRequest) => (cli.requireRequests = cli.requireRequests || []).push(requireRequest)) | ||
.option('--stacktrace', 'Print the stacktrace to the console if the application fails.') | ||
@@ -94,9 +106,13 @@ | ||
.createOption('--generator <library>', 'The site generator library.') | ||
.default('@antora/site-generator-default', '@antora/site-generator-default') | ||
.default(DEFAULT_GENERATOR, DEFAULT_GENERATOR) | ||
) | ||
.action(async (playbookFile, options, command) => { | ||
try { | ||
requireLibraries(cli.requirePaths) | ||
} catch (err) { | ||
exitWithError(err, cli.stacktrace) | ||
const dot = ospath.resolve(playbookFile, '..') | ||
const userRequireContext = { dot, paths: [dot, __dirname] } | ||
if (cli.requireRequests) { | ||
try { | ||
cli.requireRequests.forEach((requireRequest) => userRequire(requireRequest, userRequireContext)) | ||
} catch (err) { | ||
exitWithError(err, cli.stacktrace) | ||
} | ||
} | ||
@@ -106,3 +122,3 @@ const generator = options.generator | ||
try { | ||
generateSite = requireLibrary(generator, ospath.resolve(playbookFile, '..')) | ||
generateSite = userRequire(generator, userRequireContext) | ||
} catch (err) { | ||
@@ -109,0 +125,0 @@ let msg = 'Generator not found or failed to load.' |
@@ -35,3 +35,3 @@ 'use strict' | ||
option.form += ' <choice>' | ||
option.choices = Object.defineProperty(format.slice(0), 'map', { value: () => format }) | ||
option.choices = Object.defineProperty(format.slice(), 'map', { value: () => format }) | ||
} else if (format !== 'boolean') { | ||
@@ -38,0 +38,0 @@ option.form += ` <${arg.substr(arg.lastIndexOf('-') + 1, arg.length)}>` |
{ | ||
"name": "@antora/cli", | ||
"version": "3.0.0-alpha.7", | ||
"version": "3.0.0-alpha.8", | ||
"description": "The command line interface for Antora.", | ||
@@ -21,8 +21,9 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/logger": "3.0.0-alpha.7", | ||
"@antora/playbook-builder": "3.0.0-alpha.7", | ||
"@antora/logger": "3.0.0-alpha.8", | ||
"@antora/playbook-builder": "3.0.0-alpha.8", | ||
"@antora/user-require-helper": "~2.0", | ||
"commander": "~7.2" | ||
}, | ||
"devDependencies": { | ||
"@antora/site-publisher": "3.0.0-alpha.7", | ||
"@antora/site-publisher": "3.0.0-alpha.8", | ||
"convict": "~6.1", | ||
@@ -46,3 +47,3 @@ "kapok-js": "~0.10" | ||
], | ||
"gitHead": "fbd597b3680474f2083cda8a7facf1e2848c08e0" | ||
"gitHead": "2e5695bea11fb5719989c329c97e66d36e29659f" | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
26995
189
4
6
+ Added@antora/expand-path-helper@2.0.0(transitive)
+ Added@antora/logger@3.0.0-alpha.8(transitive)
+ Added@antora/playbook-builder@3.0.0-alpha.8(transitive)
+ Added@antora/user-require-helper@2.0.0(transitive)
- Removed@antora/expand-path-helper@1.0.0(transitive)
- Removed@antora/logger@3.0.0-alpha.7(transitive)
- Removed@antora/playbook-builder@3.0.0-alpha.7(transitive)
Updated@antora/logger@3.0.0-alpha.8