portapack 0.2.1 โ 0.3.1
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/.github/workflows/ci.yml +5 -4
- package/CHANGELOG.md +20 -0
- package/README.md +81 -219
- package/dist/cli/{cli-entry.js โ cli-entry.cjs} +620 -513
- package/dist/cli/cli-entry.cjs.map +1 -0
- package/dist/index.d.ts +51 -56
- package/dist/index.js +517 -458
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.ts +0 -1
- package/docs/cli.md +108 -45
- package/docs/configuration.md +101 -116
- package/docs/getting-started.md +74 -44
- package/jest.config.ts +18 -8
- package/jest.setup.cjs +66 -146
- package/package.json +5 -5
- package/src/cli/cli-entry.ts +15 -15
- package/src/cli/cli.ts +130 -119
- package/src/core/bundler.ts +174 -63
- package/src/core/extractor.ts +364 -277
- package/src/core/web-fetcher.ts +205 -141
- package/src/index.ts +161 -224
- package/tests/unit/cli/cli-entry.test.ts +66 -77
- package/tests/unit/cli/cli.test.ts +243 -145
- package/tests/unit/core/bundler.test.ts +334 -258
- package/tests/unit/core/extractor.test.ts +608 -1064
- package/tests/unit/core/minifier.test.ts +130 -221
- package/tests/unit/core/packer.test.ts +255 -106
- package/tests/unit/core/parser.test.ts +89 -458
- package/tests/unit/core/web-fetcher.test.ts +310 -265
- package/tests/unit/index.test.ts +206 -300
- package/tests/unit/utils/logger.test.ts +32 -28
- package/tsconfig.jest.json +8 -7
- package/tsup.config.ts +34 -29
- package/dist/cli/cli-entry.js.map +0 -1
- package/docs/demo.md +0 -46
- package/output.html +0 -1
- package/site-packed.html +0 -1
- package/test-output.html +0 -0
package/.github/workflows/ci.yml
CHANGED
@@ -23,11 +23,12 @@ jobs:
|
|
23
23
|
cache: 'npm'
|
24
24
|
|
25
25
|
- run: npm ci
|
26
|
-
|
27
|
-
# - run: npm run lint
|
28
|
-
# - run: npm run format:check
|
29
|
-
- run: npm run build # for now we keep it simple to release
|
26
|
+
- run: npm run test:ci
|
30
27
|
|
28
|
+
- name: Upload coverage to Codecov
|
29
|
+
uses: codecov/codecov-action@v4
|
30
|
+
with:
|
31
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
31
32
|
# coverage:
|
32
33
|
# needs: build
|
33
34
|
# runs-on: ubuntu-latest
|
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## [0.3.1](https://github.com/manicinc/portapack/compare/v0.3.0...v0.3.1) (2025-04-14)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **ci:** update Codecov config [skip release] ([593b126](https://github.com/manicinc/portapack/commit/593b1262183d05a9a7099463b6da0f4deb916576))
|
7
|
+
* **extractor:** resolve test failures and coverage issues ([40ea42c](https://github.com/manicinc/portapack/commit/40ea42cbdbeec67657225c50eb97ef0965cd2769))
|
8
|
+
|
9
|
+
# [0.3.0](https://github.com/manicinc/portapack/compare/v0.2.1...v0.3.0) (2025-04-13)
|
10
|
+
|
11
|
+
|
12
|
+
### Bug Fixes
|
13
|
+
|
14
|
+
* **cli:** fix CLI execution via npx and global install ([88774e8](https://github.com/manicinc/portapack/commit/88774e80d28d0ac9292906ac7454d4528a5396ec))
|
15
|
+
|
16
|
+
|
17
|
+
### Features
|
18
|
+
|
19
|
+
* api upgrades / revamps; update types; more robust core features and test fixes; update docs ([34e7b4a](https://github.com/manicinc/portapack/commit/34e7b4af55c6c934af8be0f1c43d427fd00a9594))
|
20
|
+
|
1
21
|
## [0.2.1](https://github.com/manicinc/portapack/compare/v0.2.0...v0.2.1) (2025-04-11)
|
2
22
|
|
3
23
|
|
package/README.md
CHANGED
@@ -1,18 +1,13 @@
|
|
1
1
|
# ๐ฆ PortaPack
|
2
2
|
|
3
|
-
<div align="center">
|
4
|
-
<img src="./docs/portapack-transparent.png" alt="PortaPack Logo" style="max-width: 50%; height: auto; margin-bottom: 20px;">
|
5
|
-
|
6
3
|
[](https://www.npmjs.com/package/portapack)
|
7
4
|
[](https://github.com/manicinc/portapack/actions)
|
8
|
-
[](https://codecov.io/gh/manicinc/portapack)
|
6
|
+
[](./LICENSE)
|
10
7
|
|
11
|
-
|
8
|
+
**PortaPack** bundles your entire website โ HTML, CSS, JS, images, and fonts โ into one self-contained HTML file. Perfect for snapshots, demos, testing, and offline apps.
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
See our [roadmap]() (coming soon!)
|
10
|
+
*Minimal input. Maximal output.*
|
16
11
|
|
17
12
|
## ๐ Documentation
|
18
13
|
|
@@ -22,267 +17,134 @@ See our [roadmap]() (coming soon!)
|
|
22
17
|
- [๐ป API Reference](https://manicinc.github.io/portapack/api/)
|
23
18
|
- [๐ค Contributing Guidelines](https://manicinc.github.io/portapack/contributing)
|
24
19
|
|
25
|
-
## โจ Killer Features
|
26
|
-
|
27
|
-
| Feature | Description |
|
28
|
-
|---------|-------------|
|
29
|
-
| ๐งฉ **Recursive Packing** | Bundle entire websites into a single, portable file |
|
30
|
-
| ๐ฏ **Total Asset Embedding** | Inline CSS, JS, images, and fonts seamlessly |
|
31
|
-
| ๐งผ **Smart Minification** | Optimize HTML, CSS, and JS for minimal file size |
|
32
|
-
| ๐ **Universal Compatibility** | Works flawlessly with local and remote sites |
|
33
|
-
| ๐ **Blazing Fast** | Lightweight, efficient processing for quick results |
|
34
|
-
|
35
20
|
## ๐ Quick Start
|
36
21
|
|
37
|
-
###
|
22
|
+
### ๐ฆ Install
|
38
23
|
|
39
24
|
```bash
|
40
|
-
# Global
|
25
|
+
# Global CLI (recommended)
|
41
26
|
npm install -g portapack
|
42
27
|
|
43
|
-
#
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
### Basic Usage
|
48
|
-
|
49
|
-
```bash
|
50
|
-
# Bundle a local HTML file
|
51
|
-
portapack ./index.html -o portable.html
|
52
|
-
|
53
|
-
# Crawl a remote website
|
54
|
-
portapack https://example.com --recursive -o site.html
|
28
|
+
# OR use npx (no install needed)
|
29
|
+
npx portapack ./index.html -o bundle.html
|
55
30
|
```
|
56
31
|
|
57
|
-
|
58
|
-
|
59
|
-
### Command Syntax
|
32
|
+
### ๐งฐ CLI Options
|
60
33
|
|
61
34
|
```bash
|
62
|
-
portapack [
|
35
|
+
portapack [input] [options]
|
63
36
|
```
|
64
37
|
|
65
|
-
### Core Options
|
66
|
-
|
67
38
|
| Option | Description |
|
68
39
|
|--------|-------------|
|
69
40
|
| `-o, --output <file>` | Output file path |
|
70
|
-
| `-
|
71
|
-
| `--
|
72
|
-
| `-
|
73
|
-
| `--no-
|
74
|
-
| `-
|
75
|
-
|
|
76
|
-
| `-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
| `--no-minify-html` | Disable HTML minification |
|
83
|
-
| `--no-minify-css` | Disable CSS minification |
|
84
|
-
| `--no-minify-js` | Disable JavaScript minification |
|
85
|
-
|
86
|
-
### Recursive Crawling
|
87
|
-
|
88
|
-
| Option | Description |
|
89
|
-
|--------|-------------|
|
90
|
-
| `-r, --recursive [depth]` | Recursively crawl site (default depth: 1) |
|
91
|
-
| `--max-depth <n>` | Set maximum depth for recursive crawl |
|
92
|
-
|
93
|
-
### Logging
|
94
|
-
|
95
|
-
| Option | Description |
|
96
|
-
|--------|-------------|
|
97
|
-
| `--log-level <level>` | Set logging level: debug, info, warn, error, silent, none |
|
98
|
-
|
99
|
-
## ๐ CLI Examples
|
100
|
-
|
101
|
-
### Basic Examples
|
41
|
+
| `-r, --recursive [n]` | Crawl site up to n levels deep |
|
42
|
+
| `--max-depth <n>` | Explicit crawl depth |
|
43
|
+
| `-m, --minify` | Enable all minification |
|
44
|
+
| `--no-minify-*` | Disable html, css, or js minify |
|
45
|
+
| `-e, --embed-assets` | Inline all assets (default: true) |
|
46
|
+
| `--no-embed-assets` | Leave links as-is |
|
47
|
+
| `-b, --base-url <url>` | Override base URL resolution |
|
48
|
+
| `-v, --verbose` | Show debug output |
|
49
|
+
| `--log-level <lvl>` | Set log level: debug, info, warn, error |
|
50
|
+
| `-d, --dry-run` | Run without writing file |
|
51
|
+
|
52
|
+
### ๐ CLI Examples
|
102
53
|
|
103
54
|
```bash
|
104
|
-
#
|
55
|
+
# Basic
|
105
56
|
portapack ./index.html
|
57
|
+
portapack https://example.com
|
106
58
|
|
107
|
-
#
|
108
|
-
portapack
|
109
|
-
|
110
|
-
# Bundle with verbose logging
|
111
|
-
portapack ./index.html -v
|
112
|
-
```
|
113
|
-
|
114
|
-
### Advanced Options
|
115
|
-
|
116
|
-
```bash
|
117
|
-
# Disable all minification
|
118
|
-
portapack ./index.html --no-minify
|
119
|
-
|
120
|
-
# Disable only CSS minification
|
121
|
-
portapack ./index.html --no-minify-css
|
122
|
-
|
123
|
-
# Customize base URL for asset resolution
|
124
|
-
portapack ./index.html --base-url https://cdn.example.com
|
59
|
+
# With output path
|
60
|
+
portapack ./page.html -o dist/output.html
|
125
61
|
|
126
|
-
#
|
127
|
-
portapack
|
128
|
-
```
|
129
|
-
|
130
|
-
### Recursive Website Bundling
|
131
|
-
|
132
|
-
```bash
|
133
|
-
# Recursively bundle a website (default depth: 1)
|
134
|
-
portapack https://example.com --recursive
|
135
|
-
|
136
|
-
# Set custom crawl depth (3 levels)
|
137
|
-
portapack https://example.com --recursive 3
|
138
|
-
|
139
|
-
# Alternative depth syntax
|
140
|
-
portapack https://example.com --max-depth 3
|
141
|
-
|
142
|
-
# Recursive bundle with all options
|
143
|
-
portapack https://example.com \
|
144
|
-
--recursive 2 \
|
145
|
-
--base-url https://example.com \
|
146
|
-
--no-minify-js \
|
147
|
-
--log-level debug \
|
148
|
-
-o example-site.html
|
149
|
-
```
|
150
|
-
|
151
|
-
### Customized Workflow Examples
|
152
|
-
|
153
|
-
```bash
|
154
|
-
# Development workflow: no minification + verbose logs
|
155
|
-
portapack ./dev/index.html --no-minify -v -o ./dev/bundle.html
|
62
|
+
# Full recursive bundle
|
63
|
+
portapack https://example.com --recursive 2 -o full.html
|
156
64
|
|
157
|
-
#
|
158
|
-
portapack ./src/index.html -
|
65
|
+
# Dev mode (no minify, verbose)
|
66
|
+
portapack ./src/index.html --no-minify -v
|
159
67
|
|
160
|
-
#
|
161
|
-
portapack ./index.html
|
68
|
+
# Production mode (optimized)
|
69
|
+
portapack ./src/index.html -m -o dist/prod.html
|
162
70
|
|
163
|
-
#
|
164
|
-
portapack ./index.html --
|
71
|
+
# Dry run preview
|
72
|
+
portapack ./index.html --dry-run
|
165
73
|
```
|
166
74
|
|
167
|
-
##
|
75
|
+
## ๐ฆ Node.js API
|
168
76
|
|
169
|
-
PortaPack
|
77
|
+
PortaPack is fully usable via code.
|
170
78
|
|
171
|
-
###
|
172
|
-
|
173
|
-
The library exports these primary functions:
|
174
|
-
|
175
|
-
| Function | Description |
|
176
|
-
|----------|-------------|
|
177
|
-
| `generatePortableHTML()` | Bundle a single HTML file or URL with its assets |
|
178
|
-
| `generateRecursivePortableHTML()` | Recursively crawl and bundle a website |
|
179
|
-
| `fetchAndPackWebPage()` | Fetch and pack a single web page |
|
180
|
-
| `bundleMultiPageHTML()` | Bundle multiple HTML pages into a single file |
|
181
|
-
|
182
|
-
### Basic API Usage
|
79
|
+
### Simple Usage
|
183
80
|
|
184
81
|
```typescript
|
185
|
-
import {
|
186
|
-
|
187
|
-
// Simple usage with local file
|
188
|
-
const result = await generatePortableHTML('./index.html');
|
189
|
-
console.log(`Generated HTML: ${result.html.length} bytes`);
|
190
|
-
console.log(`Build time: ${result.metadata.buildTimeMs}ms`);
|
82
|
+
import { pack } from 'portapack';
|
191
83
|
|
192
|
-
|
193
|
-
|
84
|
+
const result = await pack('./index.html'); // local or URL
|
85
|
+
console.log(result.html); // bundled HTML
|
194
86
|
```
|
195
87
|
|
196
|
-
###
|
88
|
+
### With Options
|
197
89
|
|
198
90
|
```typescript
|
199
|
-
import {
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
embedAssets: true, // Embed assets as data URIs
|
208
|
-
minifyHtml: true, // Minify HTML
|
209
|
-
minifyCss: true, // Minify CSS
|
210
|
-
minifyJs: true, // Minify JavaScript
|
211
|
-
baseUrl: './src', // Base URL for resolving assets
|
212
|
-
logLevel: LogLevel.INFO // Set logging level
|
91
|
+
import { pack, LogLevel } from 'portapack';
|
92
|
+
|
93
|
+
const result = await pack('https://example.com', {
|
94
|
+
minifyCss: true,
|
95
|
+
minifyJs: false,
|
96
|
+
recursive: 2,
|
97
|
+
output: 'site.html',
|
98
|
+
logLevel: LogLevel.INFO
|
213
99
|
});
|
214
|
-
|
215
|
-
// Save the HTML to a file
|
216
|
-
import fs from 'fs';
|
217
|
-
fs.writeFileSync('output.html', result.html, 'utf-8');
|
218
|
-
|
219
|
-
// Access build metadata
|
220
|
-
console.log(`Build Stats:
|
221
|
-
- Input: ${result.metadata.input}
|
222
|
-
- Output Size: ${result.metadata.outputSize} bytes
|
223
|
-
- Assets: ${result.metadata.assetCount}
|
224
|
-
- Build Time: ${result.metadata.buildTimeMs}ms
|
225
|
-
`);
|
226
100
|
```
|
227
101
|
|
228
|
-
###
|
102
|
+
### Save to Disk
|
229
103
|
|
230
104
|
```typescript
|
231
|
-
import
|
232
|
-
|
233
|
-
// Crawl a website with depth 2
|
234
|
-
const result = await generateRecursivePortableHTML(
|
235
|
-
'https://example.com',
|
236
|
-
2,
|
237
|
-
{ logLevel: LogLevel.DEBUG }
|
238
|
-
);
|
239
|
-
|
240
|
-
console.log(`Bundled ${result.metadata.pagesBundled} pages`);
|
105
|
+
import fs from 'fs';
|
106
|
+
fs.writeFileSync('output.html', result.html);
|
241
107
|
```
|
242
108
|
|
243
|
-
###
|
244
|
-
|
245
|
-
```typescript
|
246
|
-
import { bundleMultiPageHTML } from 'portapack';
|
109
|
+
### Advanced API Usage
|
247
110
|
|
248
|
-
|
249
|
-
const pages = [
|
250
|
-
{ url: '/home', html: '<h1>Home</h1>' },
|
251
|
-
{ url: '/about', html: '<h1>About</h1>' },
|
252
|
-
{ url: '/contact', html: '<h1>Contact</h1>' }
|
253
|
-
];
|
111
|
+
You can access individual building blocks too:
|
254
112
|
|
255
|
-
|
256
|
-
|
113
|
+
```typescript
|
114
|
+
import {
|
115
|
+
generatePortableHTML,
|
116
|
+
generateRecursivePortableHTML,
|
117
|
+
bundleMultiPageHTML,
|
118
|
+
fetchAndPackWebPage,
|
119
|
+
} from 'portapack';
|
257
120
|
```
|
258
121
|
|
259
|
-
|
122
|
+
| Function | Purpose |
|
123
|
+
|----------|---------|
|
124
|
+
| `generatePortableHTML()` | Bundle a single file or URL |
|
125
|
+
| `generateRecursivePortableHTML()` | Crawl & bundle entire site |
|
126
|
+
| `fetchAndPackWebPage()` | Just fetch HTML (no asset processing) |
|
127
|
+
| `bundleMultiPageHTML()` | Combine multiple HTMLs with router |
|
260
128
|
|
261
|
-
|
262
|
-
[](https://discord.gg/DzNgXdYm)
|
129
|
+
## ๐ค Contribute
|
263
130
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
131
|
+
```bash
|
132
|
+
# Get started
|
133
|
+
git clone https://github.com/manicinc/portapack
|
134
|
+
cd portapack
|
135
|
+
npm install
|
136
|
+
npm run dev
|
137
|
+
```
|
268
138
|
|
269
139
|
## ๐ Project Health
|
270
140
|
|
271
|
-
|
272
|
-
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
277
|
-
## ๐ Connect
|
278
|
-
|
279
|
-
[](https://x.com/manicagency)
|
280
|
-
[](https://www.linkedin.com/company/manic-agency-llc/)
|
141
|
+
| Metric | Value |
|
142
|
+
|--------------|-------|
|
143
|
+
| ๐ฆ Version | [](https://www.npmjs.com/package/portapack) |
|
144
|
+
| โ
Build | [](https://github.com/manicinc/portapack/actions) |
|
145
|
+
| ๐งช Coverage | [](https://codecov.io/gh/manicinc/portapack) |
|
281
146
|
|
282
147
|
## ๐ License
|
283
148
|
|
284
|
-
|
149
|
+
MIT โ Built by Manic.agency
|
285
150
|
|
286
|
-
<div align="center">
|
287
|
-
<sub>Open Source Empowering Designers and Developers ๐ฅ๏ธ</sub>
|
288
|
-
</div>
|