From 92e784629bdf4659a1b1cd6a3ab0a627ef81bafc Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 19 Sep 2024 20:16:03 +0800 Subject: [PATCH] fix(sample): bug --- packages/sample/lib/lib/pdf.mjs | 18 +++++++++++++----- packages/sample/lib/lib/sample.mjs | 4 +++- packages/sample/lib/lib/template.txt | 20 +++++++++++--------- packages/sample/package.json | 2 +- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/sample/lib/lib/pdf.mjs b/packages/sample/lib/lib/pdf.mjs index 8845d6e..5dac333 100644 --- a/packages/sample/lib/lib/pdf.mjs +++ b/packages/sample/lib/lib/pdf.mjs @@ -35,11 +35,11 @@ export async function pdf(data, config) { const browser = await instance.launch(); const page = await browser.newPage(); - const mock = JSON.stringify({ ...config, data }); + const raw = { ...config, data }; - await page.setContent( - template.replace('/*inject*/', `window.mock = ${mock}`), - ); + await page.exposeFunction('mock', () => raw, raw); + + await page.setContent(template); const options = { headerTemplate: @@ -50,7 +50,15 @@ export async function pdf(data, config) { footerTemplate: ' ', }; - await page.waitForFunction(() => globalThis.document.title, 50 * 1000); + await page.waitForFunction( + () => { + return globalThis.document.title; + }, + null, + { + timeout: 3 * 60 * 1000, + }, + ); await page.pdf({ path: join( diff --git a/packages/sample/lib/lib/sample.mjs b/packages/sample/lib/lib/sample.mjs index 48fcd38..0999192 100644 --- a/packages/sample/lib/lib/sample.mjs +++ b/packages/sample/lib/lib/sample.mjs @@ -16,7 +16,9 @@ export async function action() { const files = await scan(config); const code = await picker(files, config); - await pdf(code, config); + const { title, version } = config; + + await pdf(code, { title, version }); logger.task('Generated'); } } diff --git a/packages/sample/lib/lib/template.txt b/packages/sample/lib/lib/template.txt index b62957e..afb231c 100644 --- a/packages/sample/lib/lib/template.txt +++ b/packages/sample/lib/lib/template.txt @@ -40,20 +40,22 @@
- diff --git a/packages/sample/package.json b/packages/sample/package.json index d7d844e..f438d7b 100644 --- a/packages/sample/package.json +++ b/packages/sample/package.json @@ -1,6 +1,6 @@ { "name": "@bring-it/sample", - "version": "0.4.10", + "version": "0.4.12", "description": "Generate code sample files", "license": "MIT", "author": {