@d-zero/print 1.2.0 → 2.0.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 +1 -1
- package/dist/{png-to-pdf.d.ts → modules/png-to-pdf.d.ts} +1 -1
- package/dist/{print-pdf-with-note.d.ts → modules/print-pdf-with-note.d.ts} +1 -1
- package/dist/{print-pdf.d.ts → modules/print-pdf.d.ts} +1 -1
- package/dist/{print-png.d.ts → modules/print-png.d.ts} +1 -1
- package/dist/print-child-process.d.ts +7 -0
- package/dist/print-child-process.js +27 -0
- package/dist/{print.d.ts → print-main-process.d.ts} +2 -1
- package/dist/print-main-process.js +30 -0
- package/package.json +9 -11
- package/dist/print.js +0 -44
- /package/dist/{png-to-pdf.js → modules/png-to-pdf.js} +0 -0
- /package/dist/{print-pdf-with-note.js → modules/print-pdf-with-note.js} +0 -0
- /package/dist/{print-pdf.js → modules/print-pdf.js} +0 -0
- /package/dist/{print-png.js → modules/print-png.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createChildProcess } from '@d-zero/puppeteer-dealer';
|
|
3
|
+
import { pngToPdf } from './modules/png-to-pdf.js';
|
|
4
|
+
import { printPdf } from './modules/print-pdf.js';
|
|
5
|
+
import { printPng } from './modules/print-png.js';
|
|
6
|
+
createChildProcess((param) => {
|
|
7
|
+
const { dir, type, hooks } = param;
|
|
8
|
+
return {
|
|
9
|
+
async eachPage({ page, id, url }, logger) {
|
|
10
|
+
const ext = type === 'pdf' ? 'pdf' : 'png';
|
|
11
|
+
const fileName = `${id}.${ext}`;
|
|
12
|
+
const filePath = path.resolve(dir, fileName);
|
|
13
|
+
if (type === 'pdf') {
|
|
14
|
+
await printPdf(page, url, filePath, logger, hooks);
|
|
15
|
+
logger('🔚 Closing');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const result = await printPng(page, url, id, filePath, logger, hooks);
|
|
19
|
+
if (type === 'png') {
|
|
20
|
+
logger('🔚 Closing');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await pngToPdf(page, result, logger);
|
|
24
|
+
logger('🔚 Closing');
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PrintType } from './types.js';
|
|
2
2
|
import type { PageHook } from '@d-zero/puppeteer-page-scan';
|
|
3
|
+
import type { LaunchOptions } from 'puppeteer';
|
|
3
4
|
export interface PrintOptions {
|
|
4
5
|
readonly type?: PrintType;
|
|
5
6
|
readonly limit?: number;
|
|
@@ -15,4 +16,4 @@ export interface PrintOptions {
|
|
|
15
16
|
export declare function print(urlList: readonly (string | {
|
|
16
17
|
id: string | null;
|
|
17
18
|
url: string;
|
|
18
|
-
})[], options?: PrintOptions): Promise<void>;
|
|
19
|
+
})[], options?: PrintOptions & LaunchOptions): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createProcess, deal } from '@d-zero/puppeteer-dealer';
|
|
4
|
+
import c from 'ansi-colors';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param urlList
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
10
|
+
export async function print(urlList, options) {
|
|
11
|
+
const dir = path.resolve(process.cwd(), '.print');
|
|
12
|
+
await mkdir(dir, { recursive: true }).catch(() => { });
|
|
13
|
+
const type = options?.type ?? 'png';
|
|
14
|
+
await deal(urlList.map((url) => {
|
|
15
|
+
if (typeof url === 'string') {
|
|
16
|
+
return { id: null, url };
|
|
17
|
+
}
|
|
18
|
+
return url;
|
|
19
|
+
}), (_, done, total) => {
|
|
20
|
+
return `${c.bold.magenta('🎨 Print pages')} ${c.bgBlueBright(` ${type} `)} ${done}/${total}`;
|
|
21
|
+
}, () => {
|
|
22
|
+
return createProcess(path.resolve(import.meta.dirname, 'print-child-process.js'), {
|
|
23
|
+
dir,
|
|
24
|
+
type,
|
|
25
|
+
hooks: options?.hooks,
|
|
26
|
+
}, {
|
|
27
|
+
...options,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/print",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Print web pages to PDF or image files.",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,18 +27,16 @@
|
|
|
27
27
|
"clean": "tsc --build --clean"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@d-zero/html-distiller": "1.0.
|
|
31
|
-
"@d-zero/puppeteer-dealer": "0.
|
|
32
|
-
"@d-zero/puppeteer-page-scan": "
|
|
33
|
-
"@d-zero/puppeteer-screenshot": "3.0.
|
|
34
|
-
"@d-zero/readtext": "1.1.
|
|
30
|
+
"@d-zero/html-distiller": "1.0.3",
|
|
31
|
+
"@d-zero/puppeteer-dealer": "0.4.0",
|
|
32
|
+
"@d-zero/puppeteer-page-scan": "4.0.0",
|
|
33
|
+
"@d-zero/puppeteer-screenshot": "3.0.1",
|
|
34
|
+
"@d-zero/readtext": "1.1.3",
|
|
35
35
|
"ansi-colors": "4.1.3",
|
|
36
36
|
"dayjs": "1.11.13",
|
|
37
37
|
"front-matter": "4.0.2",
|
|
38
|
-
"minimist": "1.2.8"
|
|
38
|
+
"minimist": "1.2.8",
|
|
39
|
+
"puppeteer": "24.9.0"
|
|
39
40
|
},
|
|
40
|
-
"
|
|
41
|
-
"@d-zero/puppeteer-page": "0.3.0"
|
|
42
|
-
},
|
|
43
|
-
"gitHead": "e4fd17857e31022d121527b00fd7f009dbdb2142"
|
|
41
|
+
"gitHead": "4e9cc7b87e0fef91b6f2d4edfb66ca9134b2491b"
|
|
44
42
|
}
|
package/dist/print.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { mkdir } from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { deal } from '@d-zero/puppeteer-dealer';
|
|
4
|
-
import c from 'ansi-colors';
|
|
5
|
-
import { pngToPdf } from './png-to-pdf.js';
|
|
6
|
-
import { printPdf } from './print-pdf.js';
|
|
7
|
-
import { printPng } from './print-png.js';
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param urlList
|
|
11
|
-
* @param options
|
|
12
|
-
*/
|
|
13
|
-
export async function print(urlList, options) {
|
|
14
|
-
const dir = path.resolve(process.cwd(), '.print');
|
|
15
|
-
await mkdir(dir, { recursive: true }).catch(() => { });
|
|
16
|
-
const type = options?.type ?? 'png';
|
|
17
|
-
const hooks = options?.hooks;
|
|
18
|
-
await deal(urlList.map((url) => {
|
|
19
|
-
if (typeof url === 'string') {
|
|
20
|
-
return { id: null, url };
|
|
21
|
-
}
|
|
22
|
-
return url;
|
|
23
|
-
}), (_, done, total) => {
|
|
24
|
-
return `${c.bold.magenta('🎨 Print pages')} ${c.bgBlueBright(` ${type} `)} ${done}/${total}`;
|
|
25
|
-
}, {
|
|
26
|
-
async deal(page, id, url, logger) {
|
|
27
|
-
const ext = type === 'pdf' ? 'pdf' : 'png';
|
|
28
|
-
const fileName = `${id}.${ext}`;
|
|
29
|
-
const filePath = path.resolve(dir, fileName);
|
|
30
|
-
if (type === 'pdf') {
|
|
31
|
-
await printPdf(page, url, filePath, logger, hooks);
|
|
32
|
-
logger('🔚 Closing');
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const result = await printPng(page, url, id, filePath, logger, hooks);
|
|
36
|
-
if (type === 'png') {
|
|
37
|
-
logger('🔚 Closing');
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
await pngToPdf(page, result, logger);
|
|
41
|
-
logger('🔚 Closing');
|
|
42
|
-
},
|
|
43
|
-
}, options);
|
|
44
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|