portapack 0.3.0 → 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.
@@ -48,7 +48,6 @@ export default defineConfig({
48
48
  { text: 'Advanced Usage', link: '/advanced' }
49
49
  ]
50
50
  },
51
- { text: 'Demo', link: '/demo' },
52
51
  { text: 'Contributing', link: '/contributing' }
53
52
  ],
54
53
 
package/docs/cli.md CHANGED
@@ -16,43 +16,32 @@ npm install -g portapack
16
16
 
17
17
  ## Command Syntax
18
18
 
19
- PortaPack supports two command styles for specifying input:
19
+ The basic syntax for the PortaPack CLI is:
20
20
 
21
21
  ```bash
22
- # Positional argument style (recommended)
23
- portapack <path_or_url> [options]
24
-
25
- # Named argument style
26
- portapack --input <path_or_url> [options]
27
- # or using shorthand
28
- portapack -i <path_or_url> [options]
22
+ portapack [input] [options]
29
23
  ```
30
24
 
31
- Both methods work identically - choose whichever you prefer.
25
+ Where `[input]` is the path to a local HTML file or a remote URL.
32
26
 
33
27
  ## Options
34
28
 
35
29
  | Option | Shorthand | Description | Default |
36
30
  |--------|-----------|-------------|---------|
37
- | `<path_or_url>` or `--input <path_or_url>` | `-i` | Required. Input local file path or remote URL (http/https) to process. | - |
38
- | `--output <file>` | `-o` | Output file path for the bundled HTML. | `{input}.packed.html` |
31
+ | `[input]` | | Required. Input local file path or remote URL (http/https) to process. | - |
32
+ | `--output <file>` | `-o` | Output file path for the bundled HTML. | `{input-basename}.packed.html` |
33
+ | `--recursive [depth]` | `-r` | Recursively bundle links up to depth. If depth omitted, defaults to true (no limit). Only applies to remote URLs. | `false` (disabled) |
34
+ | `--max-depth <n>` | | Set maximum depth for recursive crawling (alternative to `-r <n>`). | - |
39
35
  | `--minify` | `-m` | Enable all minification (HTML, CSS, JS). | - |
40
36
  | `--no-minify` | | Disable all asset minification (HTML, CSS, JS). | `false` |
41
37
  | `--no-minify-html` | | Disable only HTML minification. | `false` |
42
38
  | `--no-minify-css` | | Disable only CSS minification. | `false` |
43
39
  | `--no-minify-js` | | Disable only JavaScript minification. | `false` |
44
- | `--recursive [depth]` | `-r` | Recursively bundle links up to depth. If depth omitted, defaults to 1. Only applies to remote URLs. | - (disabled) |
45
- | `--max-depth <n>` | | Set maximum depth for recursive crawling (alternative to `-r <n>`). | - |
46
- | `--base-url <url>` | `-b` | Base URL for resolving relative URLs found in the input HTML. | Input path/URL |
47
40
  | `--embed-assets` | `-e` | Embed external assets (CSS, JS, images, fonts) as data URIs or inline content. | `true` |
48
41
  | `--no-embed-assets` | | Keep external assets as links (requires network access when viewing). | `false` |
49
- | `--timeout <ms>` | `-t` | Network timeout in milliseconds for fetching remote resources. | `30000` (30 seconds) |
50
- | `--user-agent <string>` | `-U` | Custom User-Agent string for network requests. | Default Node.js agent |
51
- | `--include <glob>` | | Glob pattern for URLs to include during recursion (can be specified multiple times). | `**` (all) |
52
- | `--exclude <glob>` | | Glob pattern for URLs to exclude during recursion (can be specified multiple times). | - |
53
- | `--log-level <level>` | `-l` | Set logging level (debug, info, warn, error, silent). | `info` |
42
+ | `--base-url <url>` | `-b` | Base URL for resolving relative URLs found in the input HTML. | Input path/URL |
43
+ | `--log-level <level>` | | Set logging level (debug, info, warn, error, silent, none). | `info` |
54
44
  | `--verbose` | `-v` | Enable verbose logging (shortcut for `--log-level debug`). | `false` |
55
- | `--config <path>` | `-c` | Path to a configuration file (e.g., `.portapackrc.json`) to load options from. | - |
56
45
  | `--dry-run` | `-d` | Perform all steps except writing the output file. Logs intended actions. | `false` |
57
46
  | `--help` | `-h` | Show help information and exit. | - |
58
47
  | `--version` | | Show PortaPack CLI version number and exit. | - |
@@ -64,21 +53,13 @@ Both methods work identically - choose whichever you prefer.
64
53
  Bundle `index.html` into `bundle.html`:
65
54
 
66
55
  ```bash
67
- # Using positional argument style
68
56
  portapack ./index.html -o bundle.html
69
-
70
- # Using named argument style
71
- portapack -i ./index.html -o bundle.html
72
57
  ```
73
58
 
74
- Use default output name (`index.html.packed.html`):
59
+ Use default output name (`index.packed.html`):
75
60
 
76
61
  ```bash
77
- # Using positional argument style
78
62
  portapack ./index.html
79
-
80
- # Using named argument style
81
- portapack -i ./index.html
82
63
  ```
83
64
 
84
65
  ### Web Page Bundling
@@ -86,11 +67,7 @@ portapack -i ./index.html
86
67
  Bundle a single remote webpage:
87
68
 
88
69
  ```bash
89
- # Using positional argument style
90
70
  portapack https://example.com -o example-bundle.html
91
-
92
- # Using named argument style
93
- portapack -i https://example.com -o example-bundle.html
94
71
  ```
95
72
 
96
73
  ### Recursive Bundling
@@ -113,15 +90,6 @@ Alternative using `--max-depth` option:
113
90
  portapack https://example.com --max-depth 2 -o site-bundle-depth2.html
114
91
  ```
115
92
 
116
- Recursively bundle only blog posts, excluding images:
117
-
118
- ```bash
119
- portapack https://example.com -r \
120
- --include "/blog/**" \
121
- --exclude "**/*.{jpg,png,gif}" \
122
- -o blog-bundle.html
123
- ```
124
-
125
93
  ### Asset Handling
126
94
 
127
95
  Bundle without embedding assets (keep external links):
@@ -160,14 +128,6 @@ portapack ./index.html --no-minify-html -o selective-min.html
160
128
  portapack ./index.html --no-minify-js -o no-js-min.html
161
129
  ```
162
130
 
163
- ### Advanced Network Options
164
-
165
- Bundle a remote page with a longer timeout and custom user agent:
166
-
167
- ```bash
168
- portapack https://example.com -t 60000 -U "MyCustomBot/1.0" -o example-custom.html
169
- ```
170
-
171
131
  ### Base URL for Relative Links
172
132
 
173
133
  Process a local file as if it were hosted at https://example.com:
@@ -198,14 +158,6 @@ See what files and assets would be processed without saving:
198
158
  portapack ./index.html --dry-run
199
159
  ```
200
160
 
201
- ### Using a Configuration File
202
-
203
- Load options from a config file:
204
-
205
- ```bash
206
- portapack -c ./.portapackrc.json
207
- ```
208
-
209
161
  ### NPX Usage
210
162
 
211
163
  Use PortaPack without installing globally:
@@ -219,15 +171,10 @@ npx portapack ./index.html -o bundle.html
219
171
  | Code | Description |
220
172
  |------|-------------|
221
173
  | 0 | Success |
222
- | 1 | General Error (e.g., invalid options, file IO) |
223
- | 2 | Input Error (e.g., missing input, invalid URL) |
224
- | 3 | Network Error (e.g., fetch failed, timeout) |
225
- | 4 | Processing Error (e.g., parsing failed) |
226
-
227
- (Note: Specific error codes might vary)
174
+ | 1 | Error |
228
175
 
229
176
  ## Related Resources
230
177
 
231
- - Getting Started (Link needs validation)
232
- - API Reference (Link needs validation)
233
- - Configuration Guide (Link needs validation)
178
+ - [Getting Started](https://manicinc.github.io/portapack/getting-started)
179
+ - [API Reference](https://manicinc.github.io/portapack/api/)
180
+ - [Configuration Guide](https://manicinc.github.io/portapack/configuration)
@@ -1,151 +1,136 @@
1
- # 🛠 PortaPack Configuration Guide
1
+ # 🚀 Getting Started with PortaPack
2
2
 
3
- ## 📝 Configuration Options
3
+ ## Prerequisites
4
4
 
5
- PortaPack provides multiple ways to configure its behavior:
5
+ - Node.js (v16.0.0+)
6
+ - npm (v8.0.0+)
6
7
 
7
- ### CLI Configuration
8
+ ## Quick Installation
8
9
 
9
- | Option | Type | Default | Description |
10
- |--------|------|---------|-------------|
11
- | `-i, --input` | String | Required | Input HTML file or URL |
12
- | `-o, --output` | String | `{input}.packed.html` | Output file path |
13
- | `-m, --minify` | Number | `2` | Minification level (0-3) |
14
- | `--no-minify` | Flag | - | Disable minification |
15
- | `-r, --recursive` | Boolean/Number | `false` | Crawl site recursively, optionally with depth |
16
- | `-b, --base-url` | String | Detected | Base URL for resolving paths |
17
- | `-d, --dry-run` | Flag | `false` | Preview without generating output |
18
- | `-v, --verbose` | Flag | `false` | Enable verbose logging |
19
-
20
- ### Programmatic Configuration
21
-
22
- ```typescript
23
- // Simple string input
24
- await generatePortableHTML('./index.html');
25
-
26
- // With options as second parameter
27
- await generatePortableHTML('./index.html', {
28
- minify: true,
29
- minifyLevel: 2,
30
- baseUrl: 'https://example.com'
31
- });
10
+ ```bash
11
+ # Global installation
12
+ npm install -g portapack
32
13
 
33
- // Or with options object
34
- await generatePortableHTML({
35
- input: './index.html',
36
- minify: true,
37
- minifyLevel: 2,
38
- baseUrl: 'https://example.com',
39
-
40
- // Asset handling
41
- embedAssets: true,
42
- embedLimit: 1000000,
43
-
44
- // Minification controls
45
- minifyHtml: true,
46
- minifyCss: true,
47
- minifyJs: true,
48
-
49
- // Advanced options
50
- removeComments: true,
51
- collapseWhitespace: true
52
- });
14
+ # Or as a project dependency
15
+ npm install --save-dev portapack
53
16
  ```
54
17
 
55
- ## 🔧 Configuration Examples
18
+ ## Basic Usage
56
19
 
57
- ### CLI Configuration
20
+ ### CLI Quickstart
58
21
 
59
22
  ```bash
60
- # Basic usage
61
- portapack -i ./index.html -o bundled.html
62
-
63
- # Maximum minification
64
- portapack -i ./site -m 3 -o min.html
23
+ # Bundle a local HTML file
24
+ portapack ./index.html -o portable.html
65
25
 
66
- # Disable minification
67
- portapack -i ./site --no-minify
26
+ # Bundle a remote website
27
+ portapack https://example.com --recursive -o site.html
28
+ ```
68
29
 
69
- # Set custom base URL
70
- portapack -i ./local/site -b https://example.com
30
+ ### Node.js API Basic Example
71
31
 
72
- # Recursive crawling with depth
73
- portapack -i https://site.com -r 2
32
+ ```typescript
33
+ import { pack } from 'portapack';
74
34
 
75
- # Dry run to preview
76
- portapack -i https://example.com --dry-run -v
35
+ // Simple usage with a string path
36
+ async function bundleLocalSite() {
37
+ const result = await pack('./index.html');
38
+ console.log(result.html);
39
+
40
+ // Access metadata about the build
41
+ console.log(`Output size: ${result.metadata.outputSize} bytes`);
42
+ console.log(`Build time: ${result.metadata.buildTimeMs} ms`);
43
+ }
44
+
45
+ // Advanced options using configuration object
46
+ async function bundleWithOptions() {
47
+ const result = await pack('./index.html', {
48
+ minifyHtml: true,
49
+ minifyCss: true,
50
+ minifyJs: true,
51
+ baseUrl: 'https://example.com',
52
+ embedAssets: true
53
+ });
54
+
55
+ // Use or save the bundled HTML
56
+ console.log(result.html);
57
+ }
58
+
59
+ // Recursive bundling of a website
60
+ async function bundleWebsite() {
61
+ const result = await pack('https://example.com', {
62
+ recursive: 2, // Crawl up to 2 levels deep
63
+ minifyHtml: true,
64
+ minifyCss: true,
65
+ minifyJs: true
66
+ });
67
+
68
+ console.log(`Bundled ${result.metadata.pagesBundled} pages`);
69
+ }
77
70
  ```
78
71
 
79
- ### Programmatic Configuration
72
+ ### Advanced API Usage
73
+
74
+ For more specific use cases, you can access individual components:
80
75
 
81
76
  ```typescript
82
- // Basic local file
83
- const html = await generatePortableHTML('index.html');
84
-
85
- // Remote URL with minification options
86
- const html = await generatePortableHTML({
87
- input: 'https://example.com',
88
- minify: true,
89
- minifyLevel: 3,
90
- removeComments: true
77
+ import {
78
+ generatePortableHTML,
79
+ generateRecursivePortableHTML,
80
+ bundleMultiPageHTML,
81
+ fetchAndPackWebPage,
82
+ } from 'portapack';
83
+
84
+ // Bundle a single HTML file or URL
85
+ const singleResult = await generatePortableHTML('./index.html', {
86
+ minifyHtml: true
91
87
  });
92
88
 
93
- // With custom base URL
94
- const html = await generatePortableHTML({
95
- input: './index.html',
96
- baseUrl: 'https://example.com',
97
- embedAssets: true
89
+ // Recursively bundle a site
90
+ const recursiveResult = await generateRecursivePortableHTML('https://example.com', 2, {
91
+ minifyCss: true
98
92
  });
99
93
 
100
- // Recursive site bundling
101
- await bundleSiteRecursively(
102
- 'https://example.com',
103
- 'output.html',
104
- 2 // Depth
105
- );
94
+ // Create multi-page bundle
95
+ const multiPageBundle = await bundleMultiPageHTML([
96
+ { path: '/', html: '<html>...</html>' },
97
+ { path: '/about', html: '<html>...</html>' }
98
+ ]);
106
99
  ```
107
100
 
108
- ## 💡 Best Practices
101
+ ## Configuration
109
102
 
110
- - **Base URL Handling**: Always specify a `baseUrl` when working with relative paths
111
- - **Asset Size**: Be mindful of embedding large assets; use `embedLimit` to set thresholds
112
- - **Minification Levels**: Start with level 2 and adjust based on needs:
113
- - Level 0: No minification
114
- - Level 1: Basic whitespace removal
115
- - Level 2: Standard minification (recommended)
116
- - Level 3: Aggressive minification (may affect readability)
117
- - **Testing**: Use `--dry-run -v` to preview configuration without generating files
118
- - **Performance**: For large sites, increase Node's memory limit with `NODE_OPTIONS=--max-old-space-size=4096`
103
+ See our full [Configuration Guide](https://manicinc.github.io/portapack/configuration) for detailed options.
104
+
105
+ ## CLI Options
106
+
107
+ PortaPack offers many command-line options for customizing the bundling process:
108
+
109
+ ```bash
110
+ # Get full help
111
+ portapack --help
112
+ ```
119
113
 
120
- ## 🚨 Configuration Warnings
114
+ For details, see the [CLI Reference](https://manicinc.github.io/portapack/cli).
121
115
 
122
- - Deep recursive crawling can be resource-intensive
123
- - Large sites may require increased memory allocation
124
- - Some asset embedding might fail with complex dynamic sites
125
- - External scripts with CORS restrictions may not embed properly
116
+ ## Next Steps
126
117
 
127
- ## 📂 File Types Supported
118
+ - 📖 [Explore CLI Options](https://manicinc.github.io/portapack/cli)
119
+ - 🛠 [Advanced Configuration](https://manicinc.github.io/portapack/configuration)
120
+ - 💻 [API Reference](https://manicinc.github.io/portapack/api/)
128
121
 
129
- PortaPack automatically detects and processes:
122
+ ## Troubleshooting
130
123
 
131
- - **HTML files**: Main content files
132
- - **CSS stylesheets**: Both inline and external
133
- - **JavaScript**: Script files and inline scripts
134
- - **Images**: PNG, JPEG, GIF, SVG, WebP (converted to data URLs)
135
- - **Fonts**: WOFF, WOFF2, TTF, EOT (embedded)
136
- - **Other assets**: PDFs, JSON, text files, etc.
124
+ Encountering issues? Check our [Troubleshooting Guide](https://manicinc.github.io/portapack/troubleshooting)
137
125
 
138
- ## 🔄 Environment Variables
126
+ ## Contributing
139
127
 
140
- PortaPack also supports configuration via environment variables:
128
+ Interested in improving PortaPack?
129
+ - [View Contributing Guidelines](https://manicinc.github.io/portapack/contributing)
141
130
 
142
- - `PORTAPACK_BASE_URL`: Sets the base URL
143
- - `PORTAPACK_MINIFY_LEVEL`: Sets minification level
144
- - `PORTAPACK_NO_EMBED`: Disables asset embedding when set to "true"
131
+ ## Support
145
132
 
146
- ## 📚 Related Documentation
133
+ - 🐛 [Report an Issue](https://github.com/manicinc/portapack/issues)
134
+ - 💬 [Community Support](https://discord.gg/DzNgXdYm)
147
135
 
148
- - [CLI Reference](/cli)
149
- - [API Reference](/api/README)
150
- - [Getting Started Guide](/getting-started)
151
- - [Troubleshooting](/troubleshooting)
136
+ Built by [Manic.agency](https://manic.agency)
@@ -15,88 +15,118 @@ npm install -g portapack
15
15
  npm install --save-dev portapack
16
16
  ```
17
17
 
18
- ## Documentation
19
-
20
- Our documentation is automatically generated and hosted locally:
21
-
22
- - 🌐 **Local Docs**: at `http://localhost:5173`
23
- - 📦 **Auto-Generated API Docs**: Dynamically created from TypeDoc comments
24
- - 🧩 **Sidebar Generation**: Intelligent, automated sidebar creation
25
-
26
- ### Running Documentation Locally
27
-
28
- ```bash
29
- # Start documentation development server
30
- npm run docs:dev
31
- ```
32
-
33
18
  ## Basic Usage
34
19
 
35
20
  ### CLI Quickstart
36
21
 
37
22
  ```bash
38
23
  # Bundle a local HTML file
39
- portapack -i ./index.html -o portable.html
24
+ portapack ./index.html -o portable.html
40
25
 
41
26
  # Bundle a remote website
42
- portapack -i https://example.com --recursive -o site.html
27
+ portapack https://example.com --recursive -o site.html
43
28
  ```
44
29
 
45
30
  ### Node.js API Basic Example
46
31
 
47
32
  ```typescript
48
- import { generatePortableHTML } from 'portapack';
33
+ import { pack } from 'portapack';
49
34
 
50
35
  // Simple usage with a string path
51
36
  async function bundleLocalSite() {
52
- const portableHtml = await generatePortableHTML('./index.html');
53
- console.log(portableHtml);
37
+ const result = await pack('./index.html');
38
+ console.log(result.html);
39
+
40
+ // Access metadata about the build
41
+ console.log(`Output size: ${result.metadata.outputSize} bytes`);
42
+ console.log(`Build time: ${result.metadata.buildTimeMs} ms`);
54
43
  }
55
44
 
56
45
  // Advanced options using configuration object
57
46
  async function bundleWithOptions() {
58
- const portableHtml = await generatePortableHTML({
59
- input: './index.html',
60
- minify: true,
61
- minifyLevel: 2,
62
- baseUrl: 'https://example.com'
47
+ const result = await pack('./index.html', {
48
+ minifyHtml: true,
49
+ minifyCss: true,
50
+ minifyJs: true,
51
+ baseUrl: 'https://example.com',
52
+ embedAssets: true
63
53
  });
64
-
54
+
65
55
  // Use or save the bundled HTML
66
- console.log(portableHtml);
56
+ console.log(result.html);
67
57
  }
58
+
59
+ // Recursive bundling of a website
60
+ async function bundleWebsite() {
61
+ const result = await pack('https://example.com', {
62
+ recursive: 2, // Crawl up to 2 levels deep
63
+ minifyHtml: true,
64
+ minifyCss: true,
65
+ minifyJs: true
66
+ });
67
+
68
+ console.log(`Bundled ${result.metadata.pagesBundled} pages`);
69
+ }
70
+ ```
71
+
72
+ ### Advanced API Usage
73
+
74
+ For more specific use cases, you can access individual components:
75
+
76
+ ```typescript
77
+ import {
78
+ generatePortableHTML,
79
+ generateRecursivePortableHTML,
80
+ bundleMultiPageHTML,
81
+ fetchAndPackWebPage,
82
+ } from 'portapack';
83
+
84
+ // Bundle a single HTML file or URL
85
+ const singleResult = await generatePortableHTML('./index.html', {
86
+ minifyHtml: true
87
+ });
88
+
89
+ // Recursively bundle a site
90
+ const recursiveResult = await generateRecursivePortableHTML('https://example.com', 2, {
91
+ minifyCss: true
92
+ });
93
+
94
+ // Create multi-page bundle
95
+ const multiPageBundle = await bundleMultiPageHTML([
96
+ { path: '/', html: '<html>...</html>' },
97
+ { path: '/about', html: '<html>...</html>' }
98
+ ]);
68
99
  ```
69
100
 
70
- ## Documentation Architecture
101
+ ## Configuration
102
+
103
+ See our full [Configuration Guide](https://manicinc.github.io/portapack/configuration) for detailed options.
71
104
 
72
- ### Automatic Documentation Generation
105
+ ## CLI Options
73
106
 
74
- PortaPack uses a custom sidebar generator (`buildDocsSidebar()`) to:
75
- - Automatically scan TypeDoc-generated markdown files
76
- - Create dynamic, organized documentation sidebars
77
- - Support multiple documentation types (modules, classes, interfaces, etc.)
107
+ PortaPack offers many command-line options for customizing the bundling process:
78
108
 
79
- #### How It Works
109
+ ```bash
110
+ # Get full help
111
+ portapack --help
112
+ ```
80
113
 
81
- 1. TypeDoc generates markdown from source code comments
82
- 2. Custom sidebar generator reads generated files
83
- 3. VitePress renders dynamically generated sidebar
114
+ For details, see the [CLI Reference](https://manicinc.github.io/portapack/cli).
84
115
 
85
116
  ## Next Steps
86
117
 
87
- - 📖 [Explore CLI Options](/cli)
88
- - 🛠 [Advanced Configuration](/configuration)
89
- - 💻 [API Reference](/api/README)
118
+ - 📖 [Explore CLI Options](https://manicinc.github.io/portapack/cli)
119
+ - 🛠 [Advanced Configuration](https://manicinc.github.io/portapack/configuration)
120
+ - 💻 [API Reference](https://manicinc.github.io/portapack/api/)
90
121
 
91
122
  ## Troubleshooting
92
123
 
93
- Encountering issues? Check our [Troubleshooting Guide](/troubleshooting)
124
+ Encountering issues? Check our [Troubleshooting Guide](https://manicinc.github.io/portapack/troubleshooting)
94
125
 
95
126
  ## Contributing
96
127
 
97
- Interested in improving PortaPack?
98
- - [View Contributing Guidelines](/contributing)
99
- - [Development Guide](/development)
128
+ Interested in improving PortaPack?
129
+ - [View Contributing Guidelines](https://manicinc.github.io/portapack/contributing)
100
130
 
101
131
  ## Support
102
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "portapack",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "📦 A tool to bundle and minify HTML and all its dependencies into a single portable file.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",