@antora/pdf-extension
Version:
An Antora extension that uses Assembler to merge pages into assembly files, export them to the PDF format, and publishe them with the site.
32 lines (26 loc) • 950 B
JavaScript
const fsp = require('node:fs/promises')
const ospath = require('node:path')
const DEFAULT_COMMAND = 'asciidoctor-pdf'
async function convert (runCommand, file, convertAttributes, buildConfig) {
const { command, cwd = process.cwd(), stderr = 'print' } = buildConfig
const args = convertAttributes.toArgs('-a', command).concat('-o', convertAttributes.outfile, '-')
return runCommand(command, args, { parse: true, cwd, stdin: file.contents, stdout: 'print', stderr })
}
function getDefaultCommand (cwd) {
return fsp.access(ospath.join(cwd, 'Gemfile.lock')).then(
() => `bundle exec ${DEFAULT_COMMAND}`,
() => DEFAULT_COMMAND
)
}
module.exports = {
bind (thisArg, runCommand) {
return Object.assign({}, this, { convert: convert.bind(thisArg, runCommand) })
},
convert,
backend: 'pdf',
getDefaultCommand,
extname: '.pdf',
mediaType: 'application/pdf',
loggerName: require('../package.json').name,
}