@d-zero/print 2.2.0 → 2.3.0
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/dist/cli.js +5 -0
- package/dist/modules/print-pdf.d.ts +2 -1
- package/dist/modules/print-pdf.js +4 -2
- package/dist/modules/print-png.d.ts +2 -1
- package/dist/modules/print-png.js +3 -1
- package/dist/print-child-process.d.ts +1 -0
- package/dist/print-child-process.js +3 -3
- package/dist/print-main-process.d.ts +1 -0
- package/dist/print-main-process.js +1 -0
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ const { options, args, hasConfigFile } = createCLI({
|
|
|
8
8
|
f: 'listfile',
|
|
9
9
|
t: 'type',
|
|
10
10
|
d: 'devices',
|
|
11
|
+
T: 'timeout',
|
|
11
12
|
},
|
|
12
13
|
usage: [
|
|
13
14
|
'Usage:',
|
|
@@ -18,6 +19,7 @@ const { options, args, hasConfigFile } = createCLI({
|
|
|
18
19
|
'\t-f, --listfile <file> File containing URLs to print',
|
|
19
20
|
'\t-t, --type <type> Output type: png|pdf|note (default: png)',
|
|
20
21
|
'\t-d, --devices <devices> Device presets (comma-separated, default: desktop-compact,mobile)',
|
|
22
|
+
'\t-T, --timeout <ms> Request timeout in milliseconds (default: 30000)',
|
|
21
23
|
'\t--limit <number> Limit concurrent processes',
|
|
22
24
|
'\t--debug Enable debug mode',
|
|
23
25
|
'\t--verbose Enable verbose logging',
|
|
@@ -35,6 +37,7 @@ const { options, args, hasConfigFile } = createCLI({
|
|
|
35
37
|
listfile: cli.listfile,
|
|
36
38
|
type: cli.type,
|
|
37
39
|
devices: cli.devices,
|
|
40
|
+
timeout: cli.timeout ? Number(cli.timeout) : undefined,
|
|
38
41
|
}),
|
|
39
42
|
validateArgs: (options, cli) => {
|
|
40
43
|
return !!(options.listfile?.length || cli._.length > 0);
|
|
@@ -52,6 +55,7 @@ if (hasConfigFile) {
|
|
|
52
55
|
verbose: options.verbose,
|
|
53
56
|
hooks,
|
|
54
57
|
devices,
|
|
58
|
+
timeout: options.timeout,
|
|
55
59
|
});
|
|
56
60
|
process.exit(0);
|
|
57
61
|
}
|
|
@@ -62,6 +66,7 @@ if (args.length > 0) {
|
|
|
62
66
|
verbose: options.verbose,
|
|
63
67
|
debug: options.debug,
|
|
64
68
|
devices,
|
|
69
|
+
timeout: options.timeout,
|
|
65
70
|
});
|
|
66
71
|
process.exit(0);
|
|
67
72
|
}
|
|
@@ -8,5 +8,6 @@ import type { Page } from 'puppeteer';
|
|
|
8
8
|
* @param update
|
|
9
9
|
* @param hooks
|
|
10
10
|
* @param devices
|
|
11
|
+
* @param timeout
|
|
11
12
|
*/
|
|
12
|
-
export declare function printPdf(page: Page, url: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes): Promise<void>;
|
|
13
|
+
export declare function printPdf(page: Page, url: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes, timeout?: number): Promise<void>;
|
|
@@ -7,8 +7,9 @@ import { beforePageScan, pageScanListener, devicePresets, } from '@d-zero/puppet
|
|
|
7
7
|
* @param update
|
|
8
8
|
* @param hooks
|
|
9
9
|
* @param devices
|
|
10
|
+
* @param timeout
|
|
10
11
|
*/
|
|
11
|
-
export async function printPdf(page, url, filePath, update, hooks, devices) {
|
|
12
|
+
export async function printPdf(page, url, filePath, update, hooks, devices, timeout) {
|
|
12
13
|
// Use the first desktop device or fallback to desktop preset
|
|
13
14
|
const defaultWidth = devicePresets.desktop.width;
|
|
14
15
|
let pdfWidth = defaultWidth;
|
|
@@ -30,11 +31,12 @@ export async function printPdf(page, url, filePath, update, hooks, devices) {
|
|
|
30
31
|
width: pdfWidth,
|
|
31
32
|
listener: pageScanListener(update),
|
|
32
33
|
hooks,
|
|
34
|
+
timeout,
|
|
33
35
|
});
|
|
34
36
|
update('📄 Save as PDF');
|
|
35
37
|
await page.pdf({
|
|
36
38
|
path: filePath,
|
|
37
|
-
timeout: 30_000 * 10,
|
|
39
|
+
timeout: timeout ?? 30_000 * 10,
|
|
38
40
|
format: 'A4',
|
|
39
41
|
printBackground: true,
|
|
40
42
|
displayHeaderFooter: false,
|
|
@@ -10,5 +10,6 @@ import type { Page } from 'puppeteer';
|
|
|
10
10
|
* @param update
|
|
11
11
|
* @param hooks
|
|
12
12
|
* @param devices
|
|
13
|
+
* @param timeout
|
|
13
14
|
*/
|
|
14
|
-
export declare function printPng(page: Page, url: string, fileId: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes): Promise<Record<string, import("@d-zero/puppeteer-screenshot").Screenshot>>;
|
|
15
|
+
export declare function printPng(page: Page, url: string, fileId: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes, timeout?: number): Promise<Record<string, import("@d-zero/puppeteer-screenshot").Screenshot>>;
|
|
@@ -9,8 +9,9 @@ import { screenshot, screenshotListener } from '@d-zero/puppeteer-screenshot';
|
|
|
9
9
|
* @param update
|
|
10
10
|
* @param hooks
|
|
11
11
|
* @param devices
|
|
12
|
+
* @param timeout
|
|
12
13
|
*/
|
|
13
|
-
export function printPng(page, url, fileId, filePath, update, hooks, devices) {
|
|
14
|
+
export function printPng(page, url, fileId, filePath, update, hooks, devices, timeout) {
|
|
14
15
|
const defaultSizes = {
|
|
15
16
|
'desktop-compact': devicePresets['desktop-compact'],
|
|
16
17
|
mobile: devicePresets.mobile,
|
|
@@ -21,5 +22,6 @@ export function printPng(page, url, fileId, filePath, update, hooks, devices) {
|
|
|
21
22
|
sizes: devices ?? defaultSizes,
|
|
22
23
|
listener: screenshotListener(update),
|
|
23
24
|
hooks,
|
|
25
|
+
timeout,
|
|
24
26
|
});
|
|
25
27
|
}
|
|
@@ -4,18 +4,18 @@ import { pngToPdf } from './modules/png-to-pdf.js';
|
|
|
4
4
|
import { printPdf } from './modules/print-pdf.js';
|
|
5
5
|
import { printPng } from './modules/print-png.js';
|
|
6
6
|
createChildProcess((param) => {
|
|
7
|
-
const { dir, type, hooks, devices } = param;
|
|
7
|
+
const { dir, type, hooks, devices, timeout } = param;
|
|
8
8
|
return {
|
|
9
9
|
async eachPage({ page, id, url }, logger) {
|
|
10
10
|
const ext = type === 'pdf' ? 'pdf' : 'png';
|
|
11
11
|
const fileName = `${id}.${ext}`;
|
|
12
12
|
const filePath = path.resolve(dir, fileName);
|
|
13
13
|
if (type === 'pdf') {
|
|
14
|
-
await printPdf(page, url, filePath, logger, hooks, devices);
|
|
14
|
+
await printPdf(page, url, filePath, logger, hooks, devices, timeout);
|
|
15
15
|
logger('🔚 Closing');
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const result = await printPng(page, url, id, filePath, logger, hooks, devices);
|
|
18
|
+
const result = await printPng(page, url, id, filePath, logger, hooks, devices, timeout);
|
|
19
19
|
if (type === 'png') {
|
|
20
20
|
logger('🔚 Closing');
|
|
21
21
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/print",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Print web pages to PDF or image files.",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@d-zero/cli-core": "1.1.1",
|
|
28
28
|
"@d-zero/html-distiller": "2.0.1",
|
|
29
29
|
"@d-zero/puppeteer-dealer": "0.5.4",
|
|
30
|
-
"@d-zero/puppeteer-page-scan": "4.
|
|
31
|
-
"@d-zero/puppeteer-screenshot": "3.
|
|
30
|
+
"@d-zero/puppeteer-page-scan": "4.2.0",
|
|
31
|
+
"@d-zero/puppeteer-screenshot": "3.2.0",
|
|
32
32
|
"@d-zero/readtext": "1.1.8",
|
|
33
33
|
"@d-zero/shared": "0.9.2",
|
|
34
34
|
"ansi-colors": "4.1.3",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"minimist": "1.2.8",
|
|
38
38
|
"puppeteer": "24.18.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "00ab4d99dc17e8f09f1a84e3a02f702629b642fc"
|
|
41
41
|
}
|