@neo4j-antora/pdf-generator 0.1.14 → 0.1.15
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/extension.js +12 -1
- package/package.json +1 -1
- package/scripts/convert.js +8 -2
- package/scripts/setup-vendor.js +19 -0
package/extension.js
CHANGED
|
@@ -41,8 +41,19 @@ function limitLocalSourcesToHead ({ playbook }) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// When the renderer fails, the assembler logs nothing, adds no PDF and Antora still exits 0, so the
|
|
45
|
+
// failure only shows up later, when the workflow cannot find a PDF. Registered after
|
|
46
|
+
// @antora/pdf-extension, this runs once the assembler has added its PDFs to the content catalog,
|
|
47
|
+
// and fails the build if there are none.
|
|
48
|
+
function requirePdf ({ contentCatalog }) {
|
|
49
|
+
const pdfs = contentCatalog.findBy({ family: 'export' }).filter((file) => file.out?.path?.endsWith('.pdf'))
|
|
50
|
+
if (!pdfs.length) throw new Error('@neo4j-antora/pdf-generator: no PDF was generated (see the renderer output above)')
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
module.exports.register = function ({ config = {} } = {}) {
|
|
45
54
|
this.once('playbookBuilt', limitLocalSourcesToHead.bind(this))
|
|
46
55
|
const resolvedConfig = Object.assign({ configFile: DEFAULT_CONFIG_FILE }, config)
|
|
47
|
-
|
|
56
|
+
const result = pdfExtension.register.call(this, { config: resolvedConfig })
|
|
57
|
+
this.once('navigationBuilt', requirePdf)
|
|
58
|
+
return result
|
|
48
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-antora/pdf-generator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Generates a PDF export from an Antora docset, styled to match the real Neo4j docs site, via @antora/assembler + @antora/pdf-extension and asciidoctor-web-pdf",
|
|
5
5
|
"main": "extension.js",
|
|
6
6
|
"files": [
|
package/scripts/convert.js
CHANGED
|
@@ -218,10 +218,16 @@ function readStdin () {
|
|
|
218
218
|
// asciidoctor-web-pdf only reads these from the environment (no -a attribute or
|
|
219
219
|
// CLI flag equivalent - see lib/browser.js) and defaults to 30s, which a large
|
|
220
220
|
// docset can easily exceed. Give it more headroom here rather than relying on
|
|
221
|
-
// whoever runs the build to remember to export these.
|
|
221
|
+
// whoever runs the build to remember to export these. Rendering, printing and
|
|
222
|
+
// protocol calls (PUPPETEER_PROTOCOL_TIMEOUT, added by setup-vendor.js) all run
|
|
223
|
+
// for as long as the whole layout takes, about 40 minutes for the Cypher Manual,
|
|
224
|
+
// so they get 2 hours. Values already set in the environment win.
|
|
225
|
+
const TWO_HOURS = String(2 * 60 * 60 * 1000)
|
|
222
226
|
const PUPPETEER_TIMEOUT_ENV = {
|
|
223
227
|
PUPPETEER_NAVIGATION_TIMEOUT: '180000',
|
|
224
|
-
PUPPETEER_RENDERING_TIMEOUT:
|
|
228
|
+
PUPPETEER_RENDERING_TIMEOUT: TWO_HOURS,
|
|
229
|
+
PUPPETEER_PRINT_TIMEOUT: TWO_HOURS,
|
|
230
|
+
PUPPETEER_PROTOCOL_TIMEOUT: TWO_HOURS,
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
// antora-assembler-pdf.yml deliberately does NOT set a `stylesheet` attribute
|
package/scripts/setup-vendor.js
CHANGED
|
@@ -63,3 +63,22 @@ if (result.error || result.status !== 0) {
|
|
|
63
63
|
console.error('@neo4j-antora/pdf-generator: failed to install its isolated asciidoctor-pdf renderer (see vendor/package.json)')
|
|
64
64
|
process.exit(result.status || 1)
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
// asciidoctor-web-pdf launches Chromium without a protocolTimeout, so every call Puppeteer makes
|
|
68
|
+
// to the page is limited to the Puppeteer default of 180 seconds. While Vivliostyle lays out a
|
|
69
|
+
// large document, the page cannot answer the call that checks whether layout has finished, and
|
|
70
|
+
// the conversion fails with "Waiting failed" (the Cypher Manual needs about 40 minutes). None of
|
|
71
|
+
// the PUPPETEER_*_TIMEOUT variables that asciidoctor-web-pdf reads change this, so the launch
|
|
72
|
+
// options are patched here to read PUPPETEER_PROTOCOL_TIMEOUT as well.
|
|
73
|
+
const browserJs = path.join(vendorDir, 'node_modules/asciidoctor-pdf/lib/browser.js')
|
|
74
|
+
const LAUNCH_OPTION = ' headless: !preview,\n'
|
|
75
|
+
const PROTOCOL_TIMEOUT_OPTION =
|
|
76
|
+
' protocolTimeout: process.env.PUPPETEER_PROTOCOL_TIMEOUT ? Number(process.env.PUPPETEER_PROTOCOL_TIMEOUT) : undefined,\n'
|
|
77
|
+
const browserSource = fs.readFileSync(browserJs, 'utf8')
|
|
78
|
+
if (!browserSource.includes('protocolTimeout')) {
|
|
79
|
+
if (!browserSource.includes(LAUNCH_OPTION)) {
|
|
80
|
+
console.error(`@neo4j-antora/pdf-generator: cannot add protocolTimeout to ${browserJs}: launch options not found`)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(browserJs, browserSource.replace(LAUNCH_OPTION, LAUNCH_OPTION + PROTOCOL_TIMEOUT_OPTION))
|
|
84
|
+
}
|