@antora/pdf-extension
Version:
An Antora extension that uses Assembler to merge pages into assembly files, export them to the PDF format, and publish them with the site.
37 lines (31 loc) • 1.26 kB
JavaScript
const fsp = require('node:fs/promises')
const ospath = require('node:path')
const DEFAULT_COMMAND = 'asciidoctor-pdf --sourcemap'
const PACKAGE_NAME = require('../package.json').name
async function convert (file, convertAttributes, buildConfig, { logCommand, runCommand }) {
const { command, cwd = process.cwd(), attributeOptionFlag, outputOptionFlag, stderr = 'print' } = buildConfig
if (!command) return null
const extraArgs = convertAttributes.toArgs(attributeOptionFlag || '-a')
const stdout =
outputOptionFlag === false
? 'buffer'
: extraArgs.push(outputOptionFlag || '-o', convertAttributes.outfile) && 'print'
logCommand?.(command, extraArgs, file, convertAttributes)
return runCommand(command, extraArgs.concat('-'), { parse: true, cwd, stdin: file.contents, stdout, stderr })
}
function getDefaultCommand (cwd, playbook) {
const defaultCommand = playbook?.runtime.stacktrace ? `${DEFAULT_COMMAND} --trace` : DEFAULT_COMMAND
return fsp.access(ospath.join(cwd, 'Gemfile.lock')).then(
() => `bundle exec ${defaultCommand}`,
() => defaultCommand
)
}
module.exports = {
convert,
backend: 'pdf',
getDefaultCommand,
extname: '.pdf',
mediaType: 'application/pdf',
loggerName: PACKAGE_NAME,
}