portapack 0.2.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.
Files changed (76) hide show
  1. package/.eslintrc.json +9 -0
  2. package/.github/workflows/ci.yml +73 -0
  3. package/.github/workflows/deploy-pages.yml +56 -0
  4. package/.prettierrc +9 -0
  5. package/.releaserc.js +29 -0
  6. package/CHANGELOG.md +21 -0
  7. package/README.md +288 -0
  8. package/commitlint.config.js +36 -0
  9. package/dist/cli/cli-entry.js +1694 -0
  10. package/dist/cli/cli-entry.js.map +1 -0
  11. package/dist/index.d.ts +275 -0
  12. package/dist/index.js +1405 -0
  13. package/dist/index.js.map +1 -0
  14. package/docs/.vitepress/config.ts +89 -0
  15. package/docs/.vitepress/sidebar-generator.ts +73 -0
  16. package/docs/cli.md +117 -0
  17. package/docs/code-of-conduct.md +65 -0
  18. package/docs/configuration.md +151 -0
  19. package/docs/contributing.md +107 -0
  20. package/docs/demo.md +46 -0
  21. package/docs/deployment.md +132 -0
  22. package/docs/development.md +168 -0
  23. package/docs/getting-started.md +106 -0
  24. package/docs/index.md +40 -0
  25. package/docs/portapack-transparent.png +0 -0
  26. package/docs/portapack.jpg +0 -0
  27. package/docs/troubleshooting.md +107 -0
  28. package/examples/main.ts +118 -0
  29. package/examples/sample-project/index.html +12 -0
  30. package/examples/sample-project/logo.png +1 -0
  31. package/examples/sample-project/script.js +1 -0
  32. package/examples/sample-project/styles.css +1 -0
  33. package/jest.config.ts +124 -0
  34. package/jest.setup.cjs +211 -0
  35. package/nodemon.json +11 -0
  36. package/output.html +1 -0
  37. package/package.json +161 -0
  38. package/site-packed.html +1 -0
  39. package/src/cli/cli-entry.ts +28 -0
  40. package/src/cli/cli.ts +139 -0
  41. package/src/cli/options.ts +151 -0
  42. package/src/core/bundler.ts +201 -0
  43. package/src/core/extractor.ts +618 -0
  44. package/src/core/minifier.ts +233 -0
  45. package/src/core/packer.ts +191 -0
  46. package/src/core/parser.ts +115 -0
  47. package/src/core/web-fetcher.ts +292 -0
  48. package/src/index.ts +262 -0
  49. package/src/types.ts +163 -0
  50. package/src/utils/font.ts +41 -0
  51. package/src/utils/logger.ts +139 -0
  52. package/src/utils/meta.ts +100 -0
  53. package/src/utils/mime.ts +90 -0
  54. package/src/utils/slugify.ts +70 -0
  55. package/test-output.html +0 -0
  56. package/tests/__fixtures__/sample-project/index.html +5 -0
  57. package/tests/unit/cli/cli-entry.test.ts +104 -0
  58. package/tests/unit/cli/cli.test.ts +230 -0
  59. package/tests/unit/cli/options.test.ts +316 -0
  60. package/tests/unit/core/bundler.test.ts +287 -0
  61. package/tests/unit/core/extractor.test.ts +1129 -0
  62. package/tests/unit/core/minifier.test.ts +414 -0
  63. package/tests/unit/core/packer.test.ts +193 -0
  64. package/tests/unit/core/parser.test.ts +540 -0
  65. package/tests/unit/core/web-fetcher.test.ts +374 -0
  66. package/tests/unit/index.test.ts +339 -0
  67. package/tests/unit/utils/font.test.ts +81 -0
  68. package/tests/unit/utils/logger.test.ts +275 -0
  69. package/tests/unit/utils/meta.test.ts +70 -0
  70. package/tests/unit/utils/mime.test.ts +96 -0
  71. package/tests/unit/utils/slugify.test.ts +71 -0
  72. package/tsconfig.build.json +11 -0
  73. package/tsconfig.jest.json +17 -0
  74. package/tsconfig.json +20 -0
  75. package/tsup.config.ts +71 -0
  76. package/typedoc.json +28 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "singleQuote": true,
3
+ "semi": true,
4
+ "tabWidth": 2,
5
+ "printWidth": 100,
6
+ "trailingComma": "es5",
7
+ "arrowParens": "avoid",
8
+ "endOfLine": "lf"
9
+ }
@@ -0,0 +1,73 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version: [18.x, 20.x]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v4
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ cache: 'npm'
24
+
25
+ - run: npm ci
26
+ # - run: npm run test:ci
27
+ # - run: npm run lint
28
+ # - run: npm run format:check
29
+ - run: npm run build # for now we keep it simple to release
30
+
31
+ # coverage:
32
+ # needs: build
33
+ # runs-on: ubuntu-latest
34
+ #
35
+ # steps:
36
+ # - uses: actions/checkout@v4
37
+ # - uses: actions/setup-node@v4
38
+ # with:
39
+ # node-version: 20.x
40
+ # cache: 'npm'
41
+ #
42
+ # - run: npm ci
43
+ # - run: npm run coveralls
44
+ #
45
+ # - name: Coveralls
46
+ # uses: coverallsapp/github-action@v2
47
+
48
+ release:
49
+ # needs: [build, coverage]
50
+ needs: [build]
51
+ if: github.event_name == 'push' && github.ref == 'refs/heads/master'
52
+ runs-on: ubuntu-latest
53
+ permissions:
54
+ contents: write
55
+ issues: write
56
+ pull-requests: write
57
+
58
+ steps:
59
+ - uses: actions/checkout@v4
60
+ with:
61
+ fetch-depth: 0
62
+
63
+ - uses: actions/setup-node@v4
64
+ with:
65
+ node-version: 20.x
66
+ cache: 'npm'
67
+
68
+ - run: npm ci
69
+ - run: npm run build
70
+ - run: npx semantic-release
71
+ env:
72
+ GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
73
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,56 @@
1
+ name: Deploy to GitHub Pages
2
+
3
+ on:
4
+ # Runs on pushes targeting the default branch
5
+ push:
6
+ branches: [master]
7
+
8
+ # Allows you to run this workflow manually from the Actions tab
9
+ workflow_dispatch:
10
+
11
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12
+ permissions:
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ # Allow only one concurrent deployment
18
+ concurrency:
19
+ group: "pages"
20
+ cancel-in-progress: true
21
+
22
+ jobs:
23
+ deploy:
24
+ environment:
25
+ name: github-pages
26
+ url: ${{ steps.deployment.outputs.page_url }}
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - name: Checkout
30
+ uses: actions/checkout@v4
31
+
32
+ - name: Setup Node
33
+ uses: actions/setup-node@v4
34
+ with:
35
+ node-version: "20"
36
+ cache: 'npm'
37
+
38
+ - name: Install dependencies
39
+ run: npm ci
40
+
41
+ - name: Build documentation
42
+ run: |
43
+ npm run docs:api
44
+ npm run docs:build
45
+
46
+ - name: Setup Pages
47
+ uses: actions/configure-pages@v4
48
+
49
+ - name: Upload artifact
50
+ uses: actions/upload-pages-artifact@v3
51
+ with:
52
+ path: 'docs/.vitepress/dist'
53
+
54
+ - name: Deploy to GitHub Pages
55
+ id: deployment
56
+ uses: actions/deploy-pages@v4
package/.prettierrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "singleQuote": true,
3
+ "semi": true,
4
+ "tabWidth": 2,
5
+ "printWidth": 100,
6
+ "trailingComma": "es5",
7
+ "arrowParens": "avoid",
8
+ "endOfLine": "lf"
9
+ }
package/.releaserc.js ADDED
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+ branches: ['main'],
3
+ plugins: [
4
+ '@semantic-release/commit-analyzer',
5
+ '@semantic-release/release-notes-generator',
6
+ '@semantic-release/npm',
7
+ [
8
+ '@semantic-release/github',
9
+ {
10
+ assets: [
11
+ { path: 'dist/**', label: 'Distribution' },
12
+ ],
13
+ },
14
+ ],
15
+ [
16
+ '@semantic-release/changelog',
17
+ {
18
+ changelogFile: 'CHANGELOG.md',
19
+ },
20
+ ],
21
+ [
22
+ '@semantic-release/git',
23
+ {
24
+ assets: ['package.json', 'CHANGELOG.md'],
25
+ message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
26
+ },
27
+ ],
28
+ ],
29
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## [0.2.1](https://github.com/manicinc/portapack/compare/v0.2.0...v0.2.1) (2025-04-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * rmv prepublishOnly for debug release ([6469768](https://github.com/manicinc/portapack/commit/6469768d6c14bd2ab243acfd5358115b7771f612))
7
+
8
+ # [0.2.0](https://github.com/manicinc/portapack/compare/v0.1.0...v0.2.0) (2025-04-11)
9
+
10
+
11
+ ### Features
12
+
13
+ * cleanup rerelease ([f8e599b](https://github.com/manicinc/portapack/commit/f8e599b596b18c62941e5bd46740283b013262b1))
14
+
15
+ # [1.2.0](https://github.com/manicinc/portapack/compare/v1.1.0...v1.2.0) (2025-04-11)
16
+
17
+
18
+ ### Features
19
+
20
+ * cleanup rerelease ([f8e599b](https://github.com/manicinc/portapack/commit/f8e599b596b18c62941e5bd46740283b013262b1))
21
+ * fix right version; trigger first release ([96147fc](https://github.com/manicinc/portapack/commit/96147fc61f5dc8e8f39e9d4343e22c79b25f0139))
package/README.md ADDED
@@ -0,0 +1,288 @@
1
+ # 📦 PortaPack
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
+ [![npm version](https://img.shields.io/npm/v/portapack.svg?style=for-the-badge&logo=npm&color=CB3837)](https://www.npmjs.com/package/portapack)
7
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/manicinc/portapack/ci.yml?branch=master&style=for-the-badge&logo=github)](https://github.com/manicinc/portapack/actions)
8
+ [![Coverage Status](https://img.shields.io/coveralls/github/manicinc/portapack?style=for-the-badge&logo=codecov)](https://coveralls.io/github/manicinc/portapack)
9
+ </div>
10
+
11
+ ## 🌟 Introduction
12
+
13
+ **PortaPack** is a powerful, lightning-fast HTML bundling tool that transforms websites into compact, portable files. Pack entire web experiences into a single, self-contained HTML document with minimal effort.
14
+
15
+ See our [roadmap]() (coming soon!)
16
+
17
+ ## 📚 Documentation
18
+
19
+ - [📖 Getting Started](https://manicinc.github.io/portapack/getting-started)
20
+ - [⚙️ CLI Reference](https://manicinc.github.io/portapack/cli)
21
+ - [🛠 Configuration Guide](https://manicinc.github.io/portapack/configuration)
22
+ - [💻 API Reference](https://manicinc.github.io/portapack/api/)
23
+ - [🤝 Contributing Guidelines](https://manicinc.github.io/portapack/contributing)
24
+
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
+ ## 🚀 Quick Start
36
+
37
+ ### Installation
38
+
39
+ ```bash
40
+ # Global install
41
+ npm install -g portapack
42
+
43
+ # Project dependency
44
+ npm install --save-dev portapack
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
55
+ ```
56
+
57
+ ## 💻 CLI Reference
58
+
59
+ ### Command Syntax
60
+
61
+ ```bash
62
+ portapack [options] [input]
63
+ ```
64
+
65
+ ### Core Options
66
+
67
+ | Option | Description |
68
+ |--------|-------------|
69
+ | `-o, --output <file>` | Output file path |
70
+ | `-m, --minify` | Enable all minification (HTML, CSS, JS) |
71
+ | `--no-minify` | Disable all minification |
72
+ | `-e, --embed-assets` | Embed assets as data URIs (default) |
73
+ | `--no-embed-assets` | Keep asset links relative/absolute |
74
+ | `-b, --base-url <url>` | Base URL for resolving relative links |
75
+ | `-d, --dry-run` | Run without writing output file |
76
+ | `-v, --verbose` | Enable verbose (debug) logging |
77
+
78
+ ### Minification Options
79
+
80
+ | Option | Description |
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
102
+
103
+ ```bash
104
+ # Bundle a local HTML file with default settings
105
+ portapack ./index.html
106
+
107
+ # Bundle a remote page
108
+ portapack https://example.com -o example.html
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
125
+
126
+ # Keep external links instead of embedding assets
127
+ portapack ./index.html --no-embed-assets
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
156
+
157
+ # Production workflow: full optimization
158
+ portapack ./src/index.html -o ./dist/index.html
159
+
160
+ # Test run without writing output
161
+ portapack ./index.html --dry-run -v
162
+
163
+ # Custom logging level
164
+ portapack ./index.html --log-level warn
165
+ ```
166
+
167
+ ## 🛠 Node.js API
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
183
+
184
+ ```typescript
185
+ import { generatePortableHTML } from 'portapack';
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`);
191
+
192
+ // Simple usage with remote URL
193
+ const remoteResult = await generatePortableHTML('https://example.com');
194
+ ```
195
+
196
+ ### Advanced API Usage
197
+
198
+ ```typescript
199
+ import {
200
+ generatePortableHTML,
201
+ generateRecursivePortableHTML,
202
+ LogLevel
203
+ } 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
+ ```
227
+
228
+ ### Recursive Website Crawling
229
+
230
+ ```typescript
231
+ import { generateRecursivePortableHTML } from 'portapack';
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`);
241
+ ```
242
+
243
+ ### Multi-page Bundling
244
+
245
+ ```typescript
246
+ import { bundleMultiPageHTML } from 'portapack';
247
+
248
+ // Define multiple pages to bundle
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
+ ];
254
+
255
+ // Bundle into a single HTML with client-side router
256
+ const html = bundleMultiPageHTML(pages);
257
+ ```
258
+
259
+ ## 🤝 Contribute & Support
260
+
261
+ [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-Manic_Agency-red?style=for-the-badge&logo=github&logoColor=white)](https://github.com/sponsors/manicinc)
262
+ [![Discord](https://img.shields.io/discord/your-discord-invite?style=for-the-badge&logo=discord&logoColor=white&label=Join%20Community&color=5865F2)](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
+ ## 📊 Project Health
270
+
271
+ <!-- | Aspect | Status |
272
+ |--------|--------|
273
+ | **Tests** | [![Coverage](https://img.shields.io/codecov/c/github/manicinc/portapack?style=flat-square)](https://codecov.io/gh/manicinc/portapack) |
274
+ | **Code Quality** | [![Maintainability](https://img.shields.io/codeclimate/maintainability/manicinc/portapack?style=flat-square)](https://codeclimate.com/github/manicinc/portapack) |
275
+ | **Dependencies** | [![Dependencies](https://img.shields.io/librariesio/github/manicinc/portapack?style=flat-square)](https://libraries.io/github/manicinc/portapack) | -->
276
+
277
+ ## 🌍 Connect
278
+
279
+ [![Twitter](https://img.shields.io/twitter/follow/manicagency?style=social)](https://x.com/manicagency)
280
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-Manic_Agency-0A66C2?style=flat-square&logo=linkedin)](https://www.linkedin.com/company/manic-agency-llc/)
281
+
282
+ ## 📄 License
283
+
284
+ **MIT** — Built by [Manic Agency](https://manicagency.com)
285
+
286
+ <div align="center">
287
+ <sub>Open Source Empowering Designers and Developers 🖥️</sub>
288
+ </div>
@@ -0,0 +1,36 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'body-leading-blank': [1, 'always'],
5
+ 'body-max-line-length': [2, 'always', 100],
6
+ 'footer-leading-blank': [1, 'always'],
7
+ 'footer-max-line-length': [2, 'always', 100],
8
+ 'header-max-length': [2, 'always', 100],
9
+ 'subject-case': [
10
+ 2,
11
+ 'never',
12
+ ['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
13
+ ],
14
+ 'subject-empty': [2, 'never'],
15
+ 'subject-full-stop': [2, 'never', '.'],
16
+ 'type-case': [2, 'always', 'lower-case'],
17
+ 'type-empty': [2, 'never'],
18
+ 'type-enum': [
19
+ 2,
20
+ 'always',
21
+ [
22
+ 'build',
23
+ 'chore',
24
+ 'ci',
25
+ 'docs',
26
+ 'feat',
27
+ 'fix',
28
+ 'perf',
29
+ 'refactor',
30
+ 'revert',
31
+ 'style',
32
+ 'test',
33
+ ],
34
+ ],
35
+ },
36
+ };