portapack 0.2.1 โ 0.3.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/CHANGELOG.md +12 -0
- package/README.md +83 -216
- package/dist/cli/{cli-entry.js โ cli-entry.cjs} +626 -498
- package/dist/cli/cli-entry.cjs.map +1 -0
- package/dist/index.d.ts +51 -56
- package/dist/index.js +523 -443
- package/dist/index.js.map +1 -1
- package/docs/cli.md +158 -42
- 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 +243 -203
- 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 +391 -1051
- 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 +330 -285
- package/tests/unit/index.test.ts +206 -300
- package/tests/unit/utils/logger.test.ts +32 -28
- package/tsconfig.jest.json +7 -7
- package/tsup.config.ts +34 -29
- package/dist/cli/cli-entry.js.map +0 -1
- package/output.html +0 -1
- package/site-packed.html +0 -1
- package/test-output.html +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# [0.3.0](https://github.com/manicinc/portapack/compare/v0.2.1...v0.3.0) (2025-04-13)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **cli:** fix CLI execution via npx and global install ([88774e8](https://github.com/manicinc/portapack/commit/88774e80d28d0ac9292906ac7454d4528a5396ec))
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* api upgrades / revamps; update types; more robust core features and test fixes; update docs ([34e7b4a](https://github.com/manicinc/portapack/commit/34e7b4af55c6c934af8be0f1c43d427fd00a9594))
|
12
|
+
|
1
13
|
## [0.2.1](https://github.com/manicinc/portapack/compare/v0.2.0...v0.2.1) (2025-04-11)
|
2
14
|
|
3
15
|
|
package/README.md
CHANGED
@@ -1,18 +1,12 @@
|
|
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
5
|
[](https://coveralls.io/github/manicinc/portapack)
|
9
|
-
</div>
|
10
6
|
|
11
|
-
|
7
|
+
**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
8
|
|
13
|
-
|
14
|
-
|
15
|
-
See our [roadmap]() (coming soon!)
|
9
|
+
*Minimal input. Maximal output.*
|
16
10
|
|
17
11
|
## ๐ Documentation
|
18
12
|
|
@@ -22,267 +16,140 @@ See our [roadmap]() (coming soon!)
|
|
22
16
|
- [๐ป API Reference](https://manicinc.github.io/portapack/api/)
|
23
17
|
- [๐ค Contributing Guidelines](https://manicinc.github.io/portapack/contributing)
|
24
18
|
|
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
19
|
## ๐ Quick Start
|
36
20
|
|
37
|
-
###
|
21
|
+
### ๐ฆ Install
|
38
22
|
|
39
23
|
```bash
|
40
|
-
# Global
|
24
|
+
# Global CLI (recommended)
|
41
25
|
npm install -g portapack
|
42
26
|
|
43
|
-
#
|
44
|
-
|
27
|
+
# OR use npx (no install needed)
|
28
|
+
npx portapack ./index.html -o bundle.html
|
45
29
|
```
|
46
30
|
|
47
|
-
###
|
31
|
+
### ๐งฐ CLI Options
|
48
32
|
|
49
33
|
```bash
|
50
|
-
|
51
|
-
portapack ./index.html -o portable.html
|
52
|
-
|
53
|
-
# Crawl a remote website
|
54
|
-
portapack https://example.com --recursive -o site.html
|
34
|
+
portapack [input] [options]
|
55
35
|
```
|
56
36
|
|
57
|
-
## ๐ป CLI Reference
|
58
|
-
|
59
|
-
### Command Syntax
|
60
|
-
|
61
|
-
```bash
|
62
|
-
portapack [options] [input]
|
63
|
-
```
|
64
|
-
|
65
|
-
### Core Options
|
66
|
-
|
67
37
|
| Option | Description |
|
68
38
|
|--------|-------------|
|
69
39
|
| `-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
|
40
|
+
| `-r, --recursive [n]` | Crawl site up to n levels deep |
|
41
|
+
| `--max-depth <n>` | Explicit crawl depth |
|
42
|
+
| `-m, --minify` | Enable all minification |
|
43
|
+
| `--no-minify-*` | Disable html, css, or js minify |
|
44
|
+
| `-e, --embed-assets` | Inline all assets (default: true) |
|
45
|
+
| `--no-embed-assets` | Leave links as-is |
|
46
|
+
| `-b, --base-url <url>` | Override base URL resolution |
|
47
|
+
| `-v, --verbose` | Show debug output |
|
48
|
+
| `--log-level <lvl>` | Set log level: debug, info, warn, error |
|
49
|
+
| `-d, --dry-run` | Run without writing file |
|
50
|
+
|
51
|
+
### ๐ CLI Examples
|
102
52
|
|
103
53
|
```bash
|
104
|
-
#
|
54
|
+
# Basic
|
105
55
|
portapack ./index.html
|
56
|
+
portapack https://example.com
|
106
57
|
|
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
|
58
|
+
# With output path
|
59
|
+
portapack ./page.html -o dist/output.html
|
122
60
|
|
123
|
-
#
|
124
|
-
portapack
|
61
|
+
# Full recursive bundle
|
62
|
+
portapack https://example.com --recursive 2 -o full.html
|
125
63
|
|
126
|
-
#
|
127
|
-
portapack ./index.html --no-
|
128
|
-
```
|
64
|
+
# Dev mode (no minify, verbose)
|
65
|
+
portapack ./src/index.html --no-minify -v
|
129
66
|
|
130
|
-
|
67
|
+
# Production mode (optimized)
|
68
|
+
portapack ./src/index.html -m -o dist/prod.html
|
131
69
|
|
132
|
-
|
133
|
-
|
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
|
70
|
+
# Dry run preview
|
71
|
+
portapack ./index.html --dry-run
|
149
72
|
```
|
150
73
|
|
151
|
-
|
74
|
+
## ๐ฆ Node.js API
|
152
75
|
|
153
|
-
|
154
|
-
# Development workflow: no minification + verbose logs
|
155
|
-
portapack ./dev/index.html --no-minify -v -o ./dev/bundle.html
|
76
|
+
PortaPack is fully usable via code.
|
156
77
|
|
157
|
-
|
158
|
-
portapack ./src/index.html -o ./dist/index.html
|
78
|
+
### Simple Usage
|
159
79
|
|
160
|
-
|
161
|
-
|
80
|
+
```typescript
|
81
|
+
import { pack } from 'portapack';
|
162
82
|
|
163
|
-
|
164
|
-
|
83
|
+
const result = await pack('./index.html'); // local or URL
|
84
|
+
console.log(result.html); // bundled HTML
|
165
85
|
```
|
166
86
|
|
167
|
-
|
168
|
-
|
169
|
-
PortaPack provides a flexible JavaScript/TypeScript API that can be used in your own projects.
|
170
|
-
|
171
|
-
### Main Functions
|
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
|
87
|
+
### With Options
|
183
88
|
|
184
89
|
```typescript
|
185
|
-
import {
|
90
|
+
import { pack, LogLevel } from 'portapack';
|
91
|
+
|
92
|
+
const result = await pack('https://example.com', {
|
93
|
+
minifyCss: true,
|
94
|
+
minifyJs: false,
|
95
|
+
recursive: 2,
|
96
|
+
output: 'site.html',
|
97
|
+
logLevel: LogLevel.INFO
|
98
|
+
});
|
99
|
+
```
|
186
100
|
|
187
|
-
|
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`);
|
101
|
+
### Save to Disk
|
191
102
|
|
192
|
-
|
193
|
-
|
103
|
+
```typescript
|
104
|
+
import fs from 'fs';
|
105
|
+
fs.writeFileSync('output.html', result.html);
|
194
106
|
```
|
195
107
|
|
196
108
|
### Advanced API Usage
|
197
109
|
|
110
|
+
You can access individual building blocks too:
|
111
|
+
|
198
112
|
```typescript
|
199
|
-
import {
|
200
|
-
generatePortableHTML,
|
113
|
+
import {
|
114
|
+
generatePortableHTML,
|
201
115
|
generateRecursivePortableHTML,
|
202
|
-
|
116
|
+
bundleMultiPageHTML,
|
117
|
+
fetchAndPackWebPage,
|
203
118
|
} from 'portapack';
|
204
|
-
|
205
|
-
// With full options
|
206
|
-
const result = await generatePortableHTML('./index.html', {
|
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
|
213
|
-
});
|
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
119
|
```
|
227
120
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
const result = await generateRecursivePortableHTML(
|
235
|
-
'https://example.com',
|
236
|
-
2,
|
237
|
-
{ logLevel: LogLevel.DEBUG }
|
238
|
-
);
|
121
|
+
| Function | Purpose |
|
122
|
+
|----------|---------|
|
123
|
+
| `generatePortableHTML()` | Bundle a single file or URL |
|
124
|
+
| `generateRecursivePortableHTML()` | Crawl & bundle entire site |
|
125
|
+
| `fetchAndPackWebPage()` | Just fetch HTML (no asset processing) |
|
126
|
+
| `bundleMultiPageHTML()` | Combine multiple HTMLs with router |
|
239
127
|
|
240
|
-
|
241
|
-
```
|
128
|
+
## ๐งช Use Cases
|
242
129
|
|
243
|
-
|
130
|
+
- Archive pages for offline use
|
131
|
+
- Create demo bundles without a web server
|
132
|
+
- Simplify distribution of small apps
|
133
|
+
- QA test static assets
|
134
|
+
- Embed pages in PDFs or ebooks
|
135
|
+
- Analyze asset weight impact
|
244
136
|
|
245
|
-
|
246
|
-
import { bundleMultiPageHTML } from 'portapack';
|
137
|
+
## ๐ค Contribute
|
247
138
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
// Bundle into a single HTML with client-side router
|
256
|
-
const html = bundleMultiPageHTML(pages);
|
139
|
+
```bash
|
140
|
+
# Get started
|
141
|
+
git clone https://github.com/manicinc/portapack
|
142
|
+
cd portapack
|
143
|
+
npm install
|
144
|
+
npm run dev
|
257
145
|
```
|
258
146
|
|
259
|
-
## ๐ค Contribute & Support
|
260
|
-
|
261
|
-
[](https://github.com/sponsors/manicinc)
|
262
|
-
[](https://discord.gg/DzNgXdYm)
|
263
|
-
|
264
|
-
1. Fork the repo
|
265
|
-
2. Create a feature branch
|
266
|
-
3. Commit with `npm run commit`
|
267
|
-
4. Push & open a PR
|
268
|
-
|
269
147
|
## ๐ Project Health
|
270
148
|
|
271
|
-
|
272
|
-
|--------|--------|
|
273
|
-
| **Tests** | [](https://codecov.io/gh/manicinc/portapack) |
|
274
|
-
| **Code Quality** | [](https://codeclimate.com/github/manicinc/portapack) |
|
275
|
-
| **Dependencies** | [](https://libraries.io/github/manicinc/portapack) | -->
|
276
|
-
|
277
|
-
## ๐ Connect
|
278
|
-
|
279
|
-
[](https://x.com/manicagency)
|
280
|
-
[](https://www.linkedin.com/company/manic-agency-llc/)
|
149
|
+
(Metrics auto-generated coming soon)
|
281
150
|
|
282
151
|
## ๐ License
|
283
152
|
|
284
|
-
|
153
|
+
MIT โ Built with โจ by Manic Agency
|
285
154
|
|
286
|
-
|
287
|
-
<sub>Open Source Empowering Designers and Developers ๐ฅ๏ธ</sub>
|
288
|
-
</div>
|
155
|
+
*Open Source Empowering Designers and Developers ๐ฅ๏ธ*
|