@d-zero/print 2.0.0 → 2.1.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/README.md +1 -1
- package/dist/cli.js +33 -18
- package/dist/read-config.js +2 -8
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ IDが指定されていない場合は、連番がIDとして使用されます
|
|
|
48
48
|
|
|
49
49
|
## ページフック
|
|
50
50
|
|
|
51
|
-
[Frontmatter](https://jekyllrb.com/docs/front-matter/)の`hooks`に配列としてスクリプトファイルのパスを渡すと、ページを開いた後(厳密には
|
|
51
|
+
[Frontmatter](https://jekyllrb.com/docs/front-matter/)の`hooks`に配列としてスクリプトファイルのパスを渡すと、ページを開いた後(厳密にはPuppeteerの`waitUntil: 'networkidle0'`のタイミング直後)にそれらのスクリプトを実行します。スクリプトは配列の順番通りに逐次実行されます。
|
|
52
52
|
|
|
53
53
|
```txt
|
|
54
54
|
---
|
package/dist/cli.js
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import { createCLI, parseCommonOptions } from '@d-zero/cli-core';
|
|
3
3
|
import { print } from './print-main-process.js';
|
|
4
4
|
import { readConfig } from './read-config.js';
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const { options, args, hasConfigFile } = createCLI({
|
|
6
|
+
aliases: {
|
|
7
7
|
f: 'listfile',
|
|
8
8
|
t: 'type',
|
|
9
9
|
},
|
|
10
|
+
usage: [
|
|
11
|
+
'Usage:',
|
|
12
|
+
'\tprint -f <listfile> [--type <png|pdf|note>] [--limit <number>] [--debug]',
|
|
13
|
+
'\tprint <url>... [--type <png|pdf|note>] [--limit <number>] [--debug]',
|
|
14
|
+
],
|
|
15
|
+
parseArgs: (cli) => ({
|
|
16
|
+
...parseCommonOptions(cli),
|
|
17
|
+
listfile: cli.listfile,
|
|
18
|
+
type: cli.type,
|
|
19
|
+
}),
|
|
20
|
+
validateArgs: (options, cli) => {
|
|
21
|
+
return !!(options.listfile?.length || cli._.length > 0);
|
|
22
|
+
},
|
|
10
23
|
});
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
const type = options.type === 'note' ? 'note' : options.type === 'pdf' ? 'pdf' : 'png';
|
|
25
|
+
if (hasConfigFile) {
|
|
26
|
+
const { urlList, hooks } = await readConfig(options.listfile);
|
|
27
|
+
await print(urlList, {
|
|
28
|
+
type,
|
|
29
|
+
limit: options.limit,
|
|
30
|
+
debug: options.debug,
|
|
31
|
+
verbose: options.verbose,
|
|
32
|
+
hooks,
|
|
33
|
+
});
|
|
18
34
|
process.exit(0);
|
|
19
35
|
}
|
|
20
|
-
if (
|
|
21
|
-
await print(
|
|
36
|
+
if (args.length > 0) {
|
|
37
|
+
await print(args, {
|
|
38
|
+
type,
|
|
39
|
+
limit: options.limit,
|
|
40
|
+
verbose: options.verbose,
|
|
41
|
+
debug: options.debug,
|
|
42
|
+
});
|
|
22
43
|
process.exit(0);
|
|
23
44
|
}
|
|
24
|
-
process.stderr.write([
|
|
25
|
-
'Usage:',
|
|
26
|
-
'\tprint -f <listfile> [--type <png|pdf|note>] [--limit <number>] [--debug]',
|
|
27
|
-
'\tprint <url>... [--type <png|pdf|note>] [--limit <number>] [--debug]',
|
|
28
|
-
].join('\n') + '\n');
|
|
29
|
-
process.exit(1);
|
package/dist/read-config.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
import { readPageHooks } from '@d-zero/puppeteer-page-scan';
|
|
4
2
|
import { toKvList } from '@d-zero/readtext/list';
|
|
5
|
-
import
|
|
3
|
+
import { readConfigFile } from '@d-zero/shared/config-reader';
|
|
6
4
|
/**
|
|
7
5
|
*
|
|
8
6
|
* @param filePath
|
|
9
7
|
*/
|
|
10
8
|
export async function readConfig(filePath) {
|
|
11
|
-
const
|
|
12
|
-
const content =
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
fm(fileContent);
|
|
9
|
+
const { content, baseDir } = await readConfigFile(filePath);
|
|
15
10
|
const urlList = toKvList(content.body).map((kv) => ({
|
|
16
11
|
id: kv.value ? kv.key : null,
|
|
17
12
|
url: kv.value || kv.key,
|
|
18
13
|
}));
|
|
19
|
-
const baseDir = path.dirname(filePath);
|
|
20
14
|
const hooks = await readPageHooks(content.attributes?.hooks ?? [], baseDir);
|
|
21
15
|
return {
|
|
22
16
|
urlList,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/print",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Print web pages to PDF or image files.",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,16 +27,18 @@
|
|
|
27
27
|
"clean": "tsc --build --clean"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@d-zero/cli-core": "1.1.0",
|
|
30
31
|
"@d-zero/html-distiller": "1.0.3",
|
|
31
|
-
"@d-zero/puppeteer-dealer": "0.
|
|
32
|
-
"@d-zero/puppeteer-page-scan": "4.0.
|
|
33
|
-
"@d-zero/puppeteer-screenshot": "3.0
|
|
34
|
-
"@d-zero/readtext": "1.1.
|
|
32
|
+
"@d-zero/puppeteer-dealer": "0.5.0",
|
|
33
|
+
"@d-zero/puppeteer-page-scan": "4.0.1",
|
|
34
|
+
"@d-zero/puppeteer-screenshot": "3.1.0",
|
|
35
|
+
"@d-zero/readtext": "1.1.4",
|
|
36
|
+
"@d-zero/shared": "0.9.0",
|
|
35
37
|
"ansi-colors": "4.1.3",
|
|
36
38
|
"dayjs": "1.11.13",
|
|
37
39
|
"front-matter": "4.0.2",
|
|
38
40
|
"minimist": "1.2.8",
|
|
39
|
-
"puppeteer": "24.
|
|
41
|
+
"puppeteer": "24.10.1"
|
|
40
42
|
},
|
|
41
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "04c6969564182c36ee38ef41e78130936dfa4863"
|
|
42
44
|
}
|