@d-zero/replicator 0.3.0 → 0.5.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 +56 -12
- package/dist/cli.js +27 -2
- package/dist/index.js +7 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,36 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@d-zero/replicator`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ウェブページとそのリソースをレスポンシブ画像対応でローカルディレクトリに複製するツールです。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## インストール
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @d-zero/replicator
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## 使い方
|
|
12
12
|
|
|
13
13
|
### CLI
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npx @d-zero/replicator <url> -o <output-directory>
|
|
16
|
+
npx @d-zero/replicator <url> -o <output-directory> [options]
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
#### オプション
|
|
20
|
+
|
|
21
|
+
- `-o, --output <dir>`: 出力ディレクトリ(必須)
|
|
22
|
+
- `-t, --timeout <ms>`: リクエストタイムアウト(ミリ秒、デフォルト: 30000)
|
|
23
|
+
- `-d, --devices <devices>`: デバイスプリセット(カンマ区切り、デフォルト: desktop-compact,mobile)
|
|
24
|
+
- `-v, --verbose`: 詳細ログモード
|
|
25
|
+
|
|
26
|
+
#### 利用可能なデバイスプリセット
|
|
27
|
+
|
|
28
|
+
- `desktop`: 1400px幅
|
|
29
|
+
- `tablet`: 768px幅
|
|
30
|
+
- `mobile`: 375px幅(2倍解像度)
|
|
31
|
+
- `desktop-hd`: 1920px幅
|
|
32
|
+
- `desktop-compact`: 1280px幅
|
|
33
|
+
- `mobile-large`: 414px幅(3倍解像度)
|
|
34
|
+
- `mobile-small`: 320px幅(2倍解像度)
|
|
35
|
+
|
|
36
|
+
#### 使用例
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# デフォルトデバイス(desktop-compact, mobile)
|
|
40
|
+
npx @d-zero/replicator https://example.com -o ./output
|
|
41
|
+
|
|
42
|
+
# カスタムデバイス指定
|
|
43
|
+
npx @d-zero/replicator https://example.com -o ./output --devices desktop,tablet,mobile
|
|
44
|
+
|
|
45
|
+
# タイムアウト指定
|
|
46
|
+
npx @d-zero/replicator https://example.com -o ./output --timeout 60000
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### プログラマティック使用
|
|
20
50
|
|
|
21
51
|
```typescript
|
|
22
52
|
import { replicate } from '@d-zero/replicator';
|
|
23
53
|
|
|
54
|
+
// デフォルトデバイス
|
|
24
55
|
await replicate('https://example.com', './output');
|
|
56
|
+
|
|
57
|
+
// カスタムデバイス
|
|
58
|
+
await replicate('https://example.com', './output', {
|
|
59
|
+
devices: {
|
|
60
|
+
desktop: { width: 1400 },
|
|
61
|
+
mobile: { width: 375, resolution: 2 },
|
|
62
|
+
},
|
|
63
|
+
timeout: 30000,
|
|
64
|
+
verbose: true,
|
|
65
|
+
});
|
|
25
66
|
```
|
|
26
67
|
|
|
27
|
-
##
|
|
68
|
+
## 機能
|
|
28
69
|
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
70
|
+
- **レスポンシブ画像対応**: 複数のデバイス幅で`<picture>`要素やメディアクエリのリソースを取得
|
|
71
|
+
- **遅延読み込み対応**: ページを自動スクロールして`loading=lazy`や`IntersectionObserver`ベースのコンテンツを取得
|
|
72
|
+
- **マルチデバイスシミュレーション**: 様々なデバイス幅と解像度をシミュレートして包括的なリソース取得を実現
|
|
73
|
+
- HTMLページのディレクトリ構造を保持してダウンロード
|
|
74
|
+
- 関連するすべてのリソース(CSS、JS、画像など)を取得
|
|
75
|
+
- リソース間の相対リンクを維持
|
|
76
|
+
- 同一ホストのリソースのみサポート
|
|
77
|
+
- 元のファイル拡張子とパスを保持
|
|
34
78
|
|
|
35
79
|
## License
|
|
36
80
|
|
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createCLI, parseCommonOptions } from '@d-zero/cli-core';
|
|
2
|
+
import { createCLI, parseCommonOptions, parseList } from '@d-zero/cli-core';
|
|
3
|
+
import { parseDevicesOption } from '@d-zero/puppeteer-page-scan';
|
|
3
4
|
import { replicate } from './index.js';
|
|
4
5
|
const { options, args } = createCLI({
|
|
5
6
|
aliases: {
|
|
6
7
|
o: 'output',
|
|
7
8
|
v: 'verbose',
|
|
9
|
+
t: 'timeout',
|
|
10
|
+
d: 'devices',
|
|
8
11
|
},
|
|
9
|
-
usage: [
|
|
12
|
+
usage: [
|
|
13
|
+
'Usage: replicator <url> -o <output-directory> [options]',
|
|
14
|
+
'',
|
|
15
|
+
'Options:',
|
|
16
|
+
' -o, --output <dir> Output directory (required)',
|
|
17
|
+
' -t, --timeout <ms> Request timeout in milliseconds (default: 30000)',
|
|
18
|
+
' -d, --devices <devices> Device presets (comma-separated, default: desktop-compact,mobile)',
|
|
19
|
+
' -v, --verbose Enable verbose logging',
|
|
20
|
+
'',
|
|
21
|
+
'Available device presets:',
|
|
22
|
+
' desktop, tablet, mobile, desktop-hd, desktop-compact, mobile-large, mobile-small',
|
|
23
|
+
'',
|
|
24
|
+
'Examples:',
|
|
25
|
+
' replicator https://example.com -o ./output',
|
|
26
|
+
' replicator https://example.com -o ./output --devices desktop,tablet',
|
|
27
|
+
' replicator https://example.com -o ./output --timeout 60000',
|
|
28
|
+
],
|
|
10
29
|
parseArgs: (cli) => ({
|
|
11
30
|
...parseCommonOptions(cli),
|
|
12
31
|
output: cli.output,
|
|
32
|
+
timeout: cli.timeout ? Number(cli.timeout) : undefined,
|
|
33
|
+
devices: cli.devices,
|
|
13
34
|
}),
|
|
14
35
|
validateArgs: (options, cli) => {
|
|
15
36
|
return !!(cli._.length > 0 && options.output);
|
|
@@ -23,8 +44,12 @@ if (!url || typeof url !== 'string') {
|
|
|
23
44
|
process.exit(1);
|
|
24
45
|
}
|
|
25
46
|
try {
|
|
47
|
+
const deviceNames = options.devices ? parseList(options.devices) : undefined;
|
|
48
|
+
const devices = parseDevicesOption(deviceNames);
|
|
26
49
|
await replicate(url, outputDir, {
|
|
27
50
|
verbose: options.verbose ?? false,
|
|
51
|
+
timeout: options.timeout,
|
|
52
|
+
devices,
|
|
28
53
|
});
|
|
29
54
|
// eslint-disable-next-line no-console
|
|
30
55
|
console.log(`✅ Successfully replicated ${url} to ${outputDir}`);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
|
-
import { beforePageScan } from '@d-zero/puppeteer-page-scan';
|
|
4
|
+
import { beforePageScan, devicePresets } from '@d-zero/puppeteer-page-scan';
|
|
5
5
|
import { launch } from 'puppeteer';
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -10,12 +10,12 @@ import { launch } from 'puppeteer';
|
|
|
10
10
|
* @param options
|
|
11
11
|
*/
|
|
12
12
|
export async function replicate(url, outputDir, options = {}) {
|
|
13
|
-
const { verbose = false, timeout = 30_000,
|
|
13
|
+
const { verbose = false, timeout = 30_000, devices } = options;
|
|
14
14
|
const defaultSizes = {
|
|
15
|
-
desktop:
|
|
16
|
-
mobile:
|
|
15
|
+
'desktop-compact': devicePresets['desktop-compact'],
|
|
16
|
+
mobile: devicePresets.mobile,
|
|
17
17
|
};
|
|
18
|
-
const targetSizes =
|
|
18
|
+
const targetSizes = devices ?? defaultSizes;
|
|
19
19
|
const log = (message) => {
|
|
20
20
|
if (verbose) {
|
|
21
21
|
// eslint-disable-next-line no-console
|
|
@@ -35,7 +35,6 @@ export async function replicate(url, outputDir, options = {}) {
|
|
|
35
35
|
progress(`🌐 Launching browser...`);
|
|
36
36
|
const browser = await launch({
|
|
37
37
|
headless: true,
|
|
38
|
-
timeout,
|
|
39
38
|
});
|
|
40
39
|
try {
|
|
41
40
|
// Process each device size
|
|
@@ -105,7 +104,7 @@ export async function replicate(url, outputDir, options = {}) {
|
|
|
105
104
|
* @param options.progress
|
|
106
105
|
*/
|
|
107
106
|
async function processPageForSize(page, url, baseUrl, resources, options) {
|
|
108
|
-
const { sizeName, width, resolution, log, progress } = options;
|
|
107
|
+
const { sizeName, width, resolution, timeout, log, progress } = options;
|
|
109
108
|
const requestPromises = [];
|
|
110
109
|
// Set up resource detection
|
|
111
110
|
page.on('request', (request) => {
|
|
@@ -161,6 +160,7 @@ async function processPageForSize(page, url, baseUrl, resources, options) {
|
|
|
161
160
|
name: sizeName,
|
|
162
161
|
width,
|
|
163
162
|
resolution,
|
|
163
|
+
timeout,
|
|
164
164
|
listener: (phase, data) => {
|
|
165
165
|
switch (phase) {
|
|
166
166
|
case 'setViewport': {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/replicator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Replicate web pages with all their resources to local directories",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@d-zero/cli-core": "1.1.1",
|
|
28
|
-
"@d-zero/puppeteer-page-scan": "4.0
|
|
29
|
-
"@d-zero/puppeteer-scroll": "3.0.
|
|
28
|
+
"@d-zero/puppeteer-page-scan": "4.2.0",
|
|
29
|
+
"@d-zero/puppeteer-scroll": "3.0.6",
|
|
30
30
|
"@d-zero/shared": "0.9.2",
|
|
31
31
|
"ansi-colors": "4.1.3",
|
|
32
32
|
"minimist": "1.2.8",
|
|
33
|
-
"puppeteer": "24.
|
|
33
|
+
"puppeteer": "24.18.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/minimist": "1.2.5"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "00ab4d99dc17e8f09f1a84e3a02f702629b642fc"
|
|
39
39
|
}
|