@antora/pdf-extension 1.0.0-alpha.6 → 1.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,7 @@ antora:
21
21
  # ...
22
22
  ```
23
23
 
24
- You can configure the behavior of the extension using the optional *antora-assembler.yml* file.
24
+ You can configure the behavior of the extension using the optional _antora-assembler.yml_ file.
25
25
 
26
26
  ## Copyright and License
27
27
 
@@ -1,28 +1,23 @@
1
1
  'use strict'
2
2
 
3
- const { runCommand } = (() => {
4
- try {
5
- return require('@antora/assembler')
6
- } catch {
7
- return require('../../assembler')
8
- }
9
- })()
10
- const ospath = require('path')
3
+ const fsp = require('node:fs/promises')
4
+ const ospath = require('node:path')
11
5
 
12
6
  // Q: how can we simplify this to avoid redundant code?
13
7
  // Q: rename to convertDocumentToPDF?
14
- function convertDocumentToPdf (doc, buildConfig) {
8
+ async function convertDocumentToPdf (doc, buildConfig, runCommand) {
15
9
  const {
16
10
  asciidoc: { attributes: baseAttributes } = { attributes: {} },
17
11
  contents: input,
18
- src: { component, version, basename, extname: docfilesuffix },
12
+ src: { component, version, basename, extname = doc.extname },
19
13
  } = doc
20
- const { command = 'asciidoctor-pdf', cwd, dir } = buildConfig
14
+ const { cwd = process.cwd(), dir = cwd } = buildConfig
15
+ const command = buildConfig.command ?? (await scopeDefaultCommand(cwd))
21
16
  const docfile = `${version}@${component}::pdf$${basename}`
22
- const docname = basename.substr(0, basename.length - docfilesuffix.length)
17
+ const docname = basename.slice(0, basename.length - extname.length)
23
18
  const convertAttributes = Object.assign({}, baseAttributes, {
24
19
  docfile,
25
- docfilesuffix,
20
+ docfilesuffix: extname,
26
21
  'docname@': docname,
27
22
  imagesdir: dir,
28
23
  })
@@ -33,6 +28,8 @@ function convertDocumentToPdf (doc, buildConfig) {
33
28
  []
34
29
  )
35
30
  const output = ospath.join(dir, doc.path)
31
+ // Q: should mkdirs be the default behavior?
32
+ if (buildConfig.mkdirs) await fsp.mkdir(ospath.dirname(output), { recursive: true, force: true })
36
33
  argv.push('-o', output)
37
34
  // Q: should runCommand accept outputFlag and automatically append to argv?
38
35
  return runCommand(command, argv, { cwd, input, output }).then((contents) =>
@@ -40,4 +37,11 @@ function convertDocumentToPdf (doc, buildConfig) {
40
37
  )
41
38
  }
42
39
 
40
+ function scopeDefaultCommand (cwd, baseCommand = 'asciidoctor-pdf') {
41
+ return fsp.stat(ospath.join(cwd, 'Gemfile.lock')).then(
42
+ () => `bundle exec ${baseCommand}`,
43
+ () => baseCommand
44
+ )
45
+ }
46
+
43
47
  module.exports = convertDocumentToPdf
package/lib/index.js CHANGED
@@ -1,26 +1,13 @@
1
1
  'use strict'
2
2
 
3
3
  const convertDocumentToPdf = require('./convert-document-to-pdf')
4
- const { assembleContent } = (() => {
5
- try {
6
- return require('@antora/assembler')
7
- } catch {
8
- return require('../../assembler')
9
- }
10
- })()
11
4
 
12
5
  module.exports.register = function () {
13
- //this.on('beforeProcess', ({ asciidocConfig }) => {
14
- // asciidocConfig.keepSource = true
15
- //})
16
- this.on('contentClassified', ({ contentCatalog }) => {
17
- contentCatalog.getPages((page) => {
18
- if (!page.out) return
19
- page.src.contents = page.contents
20
- page.src = new Proxy(page.src, { deleteProperty: (o, p) => (p === 'contents' ? true : delete o[p]) })
21
- })
6
+ this.once('beforeProcess', ({ siteAsciiDocConfig }) => {
7
+ siteAsciiDocConfig.keepSource = true
8
+ })
9
+ this.once('beforePublish', ({ playbook, contentCatalog, siteCatalog }) => {
10
+ const { assembleContent } = this.require('@antora/assembler')
11
+ return assembleContent.call(this, playbook, contentCatalog, convertDocumentToPdf, { siteCatalog })
22
12
  })
23
- this.on('beforePublish', ({ playbook, contentCatalog, siteCatalog }) =>
24
- assembleContent.call(this, playbook, contentCatalog, convertDocumentToPdf, { siteCatalog })
25
- )
26
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/pdf-extension",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.8",
4
4
  "description": "An Antora extension that assembles content pages into PDF files by version and publishes them with the site.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "OpenDevise Inc. (https://opendevise.com)",
@@ -14,15 +14,19 @@
14
14
  "url": "https://gitlab.com/antora/antora-assembler/issues"
15
15
  },
16
16
  "scripts": {
17
- "prepublishOnly": "node $npm_config_local_prefix/npm/prepublishOnly.js",
18
- "postpublish": "node $npm_config_local_prefix/npm/postpublish.js"
17
+ "test": "_mocha test",
18
+ "prepublishOnly": "npx -y downdoc --prepublish",
19
+ "postpublish": "npx -y downdoc --postpublish"
19
20
  },
20
21
  "main": "lib/index.js",
21
22
  "exports": {
22
23
  ".": "./lib/index.js"
23
24
  },
25
+ "imports": {
26
+ "#convert-document-to-pdf": "./lib/convert-document-to-pdf.js"
27
+ },
24
28
  "dependencies": {
25
- "@antora/assembler": "1.0.0-alpha.6"
29
+ "@antora/assembler": "1.0.0-alpha.8"
26
30
  },
27
31
  "engines": {
28
32
  "node": ">=16.0.0"