site-mirror 1.0.0 → 1.0.2
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/LICENSE +21 -21
- package/README.md +101 -101
- package/bin/cli.mjs +314 -286
- package/bin/postinstall.mjs +15 -15
- package/lib/mirror.mjs +543 -463
- package/package.json +46 -46
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Mahesh
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mahesh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
# site-mirror
|
|
2
|
-
|
|
3
|
-
A CLI tool to mirror websites for offline browsing using Playwright.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Install globally
|
|
9
|
-
npm install -g site-mirror
|
|
10
|
-
|
|
11
|
-
# Or use directly via npx
|
|
12
|
-
npx site-mirror --help
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Quick Start
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
# Download a single page with all its assets (no config needed!)
|
|
19
|
-
site-mirror run --start https://www.apple.com/iphone/ --singlePage
|
|
20
|
-
|
|
21
|
-
# Crawl an entire site
|
|
22
|
-
site-mirror run --start https://example.com/
|
|
23
|
-
|
|
24
|
-
# Or use interactive config-based workflow:
|
|
25
|
-
site-mirror init # Interactive prompts to create site-mirror.config.json
|
|
26
|
-
site-mirror run # Runs the mirror using config
|
|
27
|
-
site-mirror serve # Serve locally on port 8080
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Commands
|
|
31
|
-
|
|
32
|
-
| Command | Description |
|
|
33
|
-
| ------------------------ | ----------------------------------------------------- |
|
|
34
|
-
| `site-mirror init` | Interactive setup - creates `site-mirror.config.json` |
|
|
35
|
-
| `site-mirror run` | Run the mirror (reads config + CLI overrides) |
|
|
36
|
-
| `site-mirror serve` | Serve the `./offline` folder locally |
|
|
37
|
-
| `site-mirror serve 3000` | Serve on a custom port |
|
|
38
|
-
|
|
39
|
-
## CLI Options (for `run`)
|
|
40
|
-
|
|
41
|
-
| Option | Description | Default |
|
|
42
|
-
| ------------------- | ---------------------------------------- | --------------- |
|
|
43
|
-
| `--start <url>` | Start URL (required if not in config) | - |
|
|
44
|
-
| `--out <dir>` | Output directory | `./offline` |
|
|
45
|
-
| `--maxPages <n>` | Max pages to crawl (0 = unlimited) | `0` |
|
|
46
|
-
| `--maxDepth <n>` | Max link depth (0 = unlimited) | `0` |
|
|
47
|
-
| `--sameOriginOnly` | Only crawl same-origin pages | `true` |
|
|
48
|
-
| `--seedSitemaps` | Seed URLs from sitemap.xml/robots.txt | `false` |
|
|
49
|
-
| `--singlePage` | Download only this page + all its assets | `false` |
|
|
50
|
-
|
|
51
|
-
## Config File (`site-mirror.config.json`)
|
|
52
|
-
|
|
53
|
-
Created via `site-mirror init` (interactive) or manually:
|
|
54
|
-
|
|
55
|
-
```json
|
|
56
|
-
{
|
|
57
|
-
"start": "https://example.com/",
|
|
58
|
-
"out": "./offline",
|
|
59
|
-
"singlePage": false,
|
|
60
|
-
"maxPages": 200,
|
|
61
|
-
"maxDepth": 6,
|
|
62
|
-
"sameOriginOnly": true,
|
|
63
|
-
"seedSitemaps": false
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
CLI options override config file settings.
|
|
68
|
-
|
|
69
|
-
## Output Structure
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
./offline/
|
|
73
|
-
├── index.html # Homepage
|
|
74
|
-
├── about/
|
|
75
|
-
│ └── index.html # /about/ page
|
|
76
|
-
├── _next/ # Same-origin assets
|
|
77
|
-
│ └── static/
|
|
78
|
-
├── _external/ # Cross-origin assets
|
|
79
|
-
│ └── cdn.example.com/
|
|
80
|
-
│ └── script.js
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## How It Works
|
|
84
|
-
|
|
85
|
-
1. Launches headless Chromium via Playwright
|
|
86
|
-
2. Navigates to each page, waits for network idle
|
|
87
|
-
3. Captures all static assets (CSS, JS, images, fonts, videos)
|
|
88
|
-
4. Rewrites absolute same-origin URLs to relative paths
|
|
89
|
-
5. Injects a script to handle SPA-style navigation offline
|
|
90
|
-
6. Discovers new pages via `<a href>` links
|
|
91
|
-
7. Saves everything to the output directory
|
|
92
|
-
|
|
93
|
-
## Notes
|
|
94
|
-
|
|
95
|
-
- XHR/fetch API responses are not saved (only rendered HTML + static assets)
|
|
96
|
-
- Some interactive features requiring live APIs won't work offline
|
|
97
|
-
- Be mindful of target site's Terms of Service and robots.txt
|
|
98
|
-
|
|
99
|
-
## License
|
|
100
|
-
|
|
101
|
-
MIT
|
|
1
|
+
# site-mirror
|
|
2
|
+
|
|
3
|
+
A CLI tool to mirror websites for offline browsing using Playwright.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install globally
|
|
9
|
+
npm install -g site-mirror
|
|
10
|
+
|
|
11
|
+
# Or use directly via npx
|
|
12
|
+
npx site-mirror --help
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Download a single page with all its assets (no config needed!)
|
|
19
|
+
site-mirror run --start https://www.apple.com/iphone/ --singlePage
|
|
20
|
+
|
|
21
|
+
# Crawl an entire site
|
|
22
|
+
site-mirror run --start https://example.com/
|
|
23
|
+
|
|
24
|
+
# Or use interactive config-based workflow:
|
|
25
|
+
site-mirror init # Interactive prompts to create site-mirror.config.json
|
|
26
|
+
site-mirror run # Runs the mirror using config
|
|
27
|
+
site-mirror serve # Serve locally on port 8080
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Commands
|
|
31
|
+
|
|
32
|
+
| Command | Description |
|
|
33
|
+
| ------------------------ | ----------------------------------------------------- |
|
|
34
|
+
| `site-mirror init` | Interactive setup - creates `site-mirror.config.json` |
|
|
35
|
+
| `site-mirror run` | Run the mirror (reads config + CLI overrides) |
|
|
36
|
+
| `site-mirror serve` | Serve the `./offline` folder locally |
|
|
37
|
+
| `site-mirror serve 3000` | Serve on a custom port |
|
|
38
|
+
|
|
39
|
+
## CLI Options (for `run`)
|
|
40
|
+
|
|
41
|
+
| Option | Description | Default |
|
|
42
|
+
| ------------------- | ---------------------------------------- | --------------- |
|
|
43
|
+
| `--start <url>` | Start URL (required if not in config) | - |
|
|
44
|
+
| `--out <dir>` | Output directory | `./offline` |
|
|
45
|
+
| `--maxPages <n>` | Max pages to crawl (0 = unlimited) | `0` |
|
|
46
|
+
| `--maxDepth <n>` | Max link depth (0 = unlimited) | `0` |
|
|
47
|
+
| `--sameOriginOnly` | Only crawl same-origin pages | `true` |
|
|
48
|
+
| `--seedSitemaps` | Seed URLs from sitemap.xml/robots.txt | `false` |
|
|
49
|
+
| `--singlePage` | Download only this page + all its assets | `false` |
|
|
50
|
+
|
|
51
|
+
## Config File (`site-mirror.config.json`)
|
|
52
|
+
|
|
53
|
+
Created via `site-mirror init` (interactive) or manually:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"start": "https://example.com/",
|
|
58
|
+
"out": "./offline",
|
|
59
|
+
"singlePage": false,
|
|
60
|
+
"maxPages": 200,
|
|
61
|
+
"maxDepth": 6,
|
|
62
|
+
"sameOriginOnly": true,
|
|
63
|
+
"seedSitemaps": false
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
CLI options override config file settings.
|
|
68
|
+
|
|
69
|
+
## Output Structure
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
./offline/
|
|
73
|
+
├── index.html # Homepage
|
|
74
|
+
├── about/
|
|
75
|
+
│ └── index.html # /about/ page
|
|
76
|
+
├── _next/ # Same-origin assets
|
|
77
|
+
│ └── static/
|
|
78
|
+
├── _external/ # Cross-origin assets
|
|
79
|
+
│ └── cdn.example.com/
|
|
80
|
+
│ └── script.js
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## How It Works
|
|
84
|
+
|
|
85
|
+
1. Launches headless Chromium via Playwright
|
|
86
|
+
2. Navigates to each page, waits for network idle
|
|
87
|
+
3. Captures all static assets (CSS, JS, images, fonts, videos)
|
|
88
|
+
4. Rewrites absolute same-origin URLs to relative paths
|
|
89
|
+
5. Injects a script to handle SPA-style navigation offline
|
|
90
|
+
6. Discovers new pages via `<a href>` links
|
|
91
|
+
7. Saves everything to the output directory
|
|
92
|
+
|
|
93
|
+
## Notes
|
|
94
|
+
|
|
95
|
+
- XHR/fetch API responses are not saved (only rendered HTML + static assets)
|
|
96
|
+
- Some interactive features requiring live APIs won't work offline
|
|
97
|
+
- Be mindful of target site's Terms of Service and robots.txt
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|