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.
- package/.eslintrc.json +9 -0
- package/.github/workflows/ci.yml +73 -0
- package/.github/workflows/deploy-pages.yml +56 -0
- package/.prettierrc +9 -0
- package/.releaserc.js +29 -0
- package/CHANGELOG.md +21 -0
- package/README.md +288 -0
- package/commitlint.config.js +36 -0
- package/dist/cli/cli-entry.js +1694 -0
- package/dist/cli/cli-entry.js.map +1 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +1405 -0
- package/dist/index.js.map +1 -0
- package/docs/.vitepress/config.ts +89 -0
- package/docs/.vitepress/sidebar-generator.ts +73 -0
- package/docs/cli.md +117 -0
- package/docs/code-of-conduct.md +65 -0
- package/docs/configuration.md +151 -0
- package/docs/contributing.md +107 -0
- package/docs/demo.md +46 -0
- package/docs/deployment.md +132 -0
- package/docs/development.md +168 -0
- package/docs/getting-started.md +106 -0
- package/docs/index.md +40 -0
- package/docs/portapack-transparent.png +0 -0
- package/docs/portapack.jpg +0 -0
- package/docs/troubleshooting.md +107 -0
- package/examples/main.ts +118 -0
- package/examples/sample-project/index.html +12 -0
- package/examples/sample-project/logo.png +1 -0
- package/examples/sample-project/script.js +1 -0
- package/examples/sample-project/styles.css +1 -0
- package/jest.config.ts +124 -0
- package/jest.setup.cjs +211 -0
- package/nodemon.json +11 -0
- package/output.html +1 -0
- package/package.json +161 -0
- package/site-packed.html +1 -0
- package/src/cli/cli-entry.ts +28 -0
- package/src/cli/cli.ts +139 -0
- package/src/cli/options.ts +151 -0
- package/src/core/bundler.ts +201 -0
- package/src/core/extractor.ts +618 -0
- package/src/core/minifier.ts +233 -0
- package/src/core/packer.ts +191 -0
- package/src/core/parser.ts +115 -0
- package/src/core/web-fetcher.ts +292 -0
- package/src/index.ts +262 -0
- package/src/types.ts +163 -0
- package/src/utils/font.ts +41 -0
- package/src/utils/logger.ts +139 -0
- package/src/utils/meta.ts +100 -0
- package/src/utils/mime.ts +90 -0
- package/src/utils/slugify.ts +70 -0
- package/test-output.html +0 -0
- package/tests/__fixtures__/sample-project/index.html +5 -0
- package/tests/unit/cli/cli-entry.test.ts +104 -0
- package/tests/unit/cli/cli.test.ts +230 -0
- package/tests/unit/cli/options.test.ts +316 -0
- package/tests/unit/core/bundler.test.ts +287 -0
- package/tests/unit/core/extractor.test.ts +1129 -0
- package/tests/unit/core/minifier.test.ts +414 -0
- package/tests/unit/core/packer.test.ts +193 -0
- package/tests/unit/core/parser.test.ts +540 -0
- package/tests/unit/core/web-fetcher.test.ts +374 -0
- package/tests/unit/index.test.ts +339 -0
- package/tests/unit/utils/font.test.ts +81 -0
- package/tests/unit/utils/logger.test.ts +275 -0
- package/tests/unit/utils/meta.test.ts +70 -0
- package/tests/unit/utils/mime.test.ts +96 -0
- package/tests/unit/utils/slugify.test.ts +71 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.jest.json +17 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +71 -0
- package/typedoc.json +28 -0
package/docs/cli.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# โ๏ธ CLI Reference
|
2
|
+
|
3
|
+
PortaPack provides a powerful command-line interface for bundling HTML files and websites.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To use the CLI, install PortaPack globally:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
npm install -g portapack
|
11
|
+
```
|
12
|
+
|
13
|
+
## Command Syntax
|
14
|
+
|
15
|
+
The basic command structure is:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
portapack [options]
|
19
|
+
```
|
20
|
+
|
21
|
+
## Options
|
22
|
+
|
23
|
+
| Option | Shorthand | Description | Default |
|
24
|
+
|--------|----------|------------|---------|
|
25
|
+
| `--input <path>` | `-i` | Input file or URL to process | - |
|
26
|
+
| `--output <file>` | `-o` | Output file path | `{input}.packed.html` |
|
27
|
+
| `--minify [level]` | `-m` | Minification level (0-3) | `2` |
|
28
|
+
| `--no-minify` | - | Disable minification | - |
|
29
|
+
| `--recursive [depth]` | `-r` | Recursively bundle links up to specified depth | - |
|
30
|
+
| `--base-url <url>` | `-b` | Base URL for resolving relative URLs | - |
|
31
|
+
| `--dry-run` | `-d` | Show what would be done without writing files | - |
|
32
|
+
| `--verbose` | `-v` | Enable verbose logging | - |
|
33
|
+
| `--help` | `-h` | Show help information | - |
|
34
|
+
| `--version` | - | Show version information | - |
|
35
|
+
|
36
|
+
## Examples
|
37
|
+
|
38
|
+
### Basic Usage
|
39
|
+
|
40
|
+
Bundle a local HTML file:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
portapack -i ./index.html -o bundle.html
|
44
|
+
```
|
45
|
+
|
46
|
+
### Web Page Bundling
|
47
|
+
|
48
|
+
Bundle a remote website:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
portapack -i https://example.com -o example-bundle.html
|
52
|
+
```
|
53
|
+
|
54
|
+
### Recursive Bundling
|
55
|
+
|
56
|
+
Bundle a website and follow its links to a depth of 2:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
portapack -i https://example.com -r 2 -o site-bundle.html
|
60
|
+
```
|
61
|
+
|
62
|
+
### Minification Control
|
63
|
+
|
64
|
+
Apply maximum minification:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
portapack -i ./index.html -m 3 -o min-bundle.html
|
68
|
+
```
|
69
|
+
|
70
|
+
Disable minification:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
portapack -i ./index.html --no-minify -o unmin-bundle.html
|
74
|
+
```
|
75
|
+
|
76
|
+
### Base URL for Relative Links
|
77
|
+
|
78
|
+
Specify a base URL for resolving relative paths:
|
79
|
+
|
80
|
+
```bash
|
81
|
+
portapack -i ./index.html -b https://example.com -o bundle.html
|
82
|
+
```
|
83
|
+
|
84
|
+
### Dry Run
|
85
|
+
|
86
|
+
Preview what would be bundled without creating an output file:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
portapack -i ./index.html --dry-run
|
90
|
+
```
|
91
|
+
|
92
|
+
### Verbose Logging
|
93
|
+
|
94
|
+
Enable detailed logs during bundling:
|
95
|
+
|
96
|
+
```bash
|
97
|
+
portapack -i ./index.html -v -o bundle.html
|
98
|
+
```
|
99
|
+
|
100
|
+
## Exit Codes
|
101
|
+
|
102
|
+
| Code | Description |
|
103
|
+
|------|-------------|
|
104
|
+
| `0` | Success |
|
105
|
+
| `1` | Error (missing input, invalid URL, processing error, etc.) |
|
106
|
+
|
107
|
+
## Environment Variables
|
108
|
+
|
109
|
+
| Variable | Description |
|
110
|
+
|----------|-------------|
|
111
|
+
| `NODE_ENV` | Set to `test` during testing to suppress console output |
|
112
|
+
|
113
|
+
## Related Resources
|
114
|
+
|
115
|
+
- [Getting Started](/getting-started)
|
116
|
+
- [API Reference](/api/README)
|
117
|
+
- [Configuration Guide](/configuration)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# ๐ค Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We are committed to providing a friendly, safe, and welcoming environment for all contributors, regardless of:
|
6
|
+
- Age
|
7
|
+
- Body size
|
8
|
+
- Disability
|
9
|
+
- Ethnicity
|
10
|
+
- Gender identity and expression
|
11
|
+
- Level of experience
|
12
|
+
- Nationality
|
13
|
+
- Personal appearance
|
14
|
+
- Race
|
15
|
+
- Religion
|
16
|
+
- Sexual identity and orientation
|
17
|
+
|
18
|
+
## Our Standards
|
19
|
+
|
20
|
+
### Positive Behavior
|
21
|
+
- Using welcoming and inclusive language
|
22
|
+
- Being respectful of differing viewpoints
|
23
|
+
- Gracefully accepting constructive criticism
|
24
|
+
- Focusing on what is best for the community
|
25
|
+
- Showing empathy towards other community members
|
26
|
+
|
27
|
+
### Unacceptable Behavior
|
28
|
+
- Trolling, insulting/derogatory comments
|
29
|
+
- Public or private harassment
|
30
|
+
- Publishing others' private information
|
31
|
+
- Other conduct reasonably considered inappropriate in a professional setting
|
32
|
+
|
33
|
+
## Enforcement Responsibilities
|
34
|
+
|
35
|
+
Community leaders are responsible for:
|
36
|
+
- Clarifying acceptable behavior standards
|
37
|
+
- Providing fair and consistent feedback
|
38
|
+
- Removing, editing, or rejecting contributions that violate this Code of Conduct
|
39
|
+
|
40
|
+
## Reporting Issues
|
41
|
+
|
42
|
+
If you experience or witness unacceptable behavior:
|
43
|
+
1. Email [conduct@manicinc.com](mailto:conduct@manicinc.com)
|
44
|
+
2. Provide:
|
45
|
+
- Your contact information
|
46
|
+
- Names of involved parties
|
47
|
+
- Description of the incident
|
48
|
+
- Any additional context
|
49
|
+
|
50
|
+
## Consequences
|
51
|
+
|
52
|
+
Violations may result in:
|
53
|
+
- Temporary or permanent ban from community spaces
|
54
|
+
- Removal of contributions
|
55
|
+
- Public or private warnings
|
56
|
+
|
57
|
+
## Attribution
|
58
|
+
|
59
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1.
|
60
|
+
|
61
|
+
[homepage]: https://www.contributor-covenant.org
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
This Code of Conduct is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# ๐ PortaPack Configuration Guide
|
2
|
+
|
3
|
+
## ๐ Configuration Options
|
4
|
+
|
5
|
+
PortaPack provides multiple ways to configure its behavior:
|
6
|
+
|
7
|
+
### CLI Configuration
|
8
|
+
|
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
|
+
});
|
32
|
+
|
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
|
+
});
|
53
|
+
```
|
54
|
+
|
55
|
+
## ๐ง Configuration Examples
|
56
|
+
|
57
|
+
### CLI Configuration
|
58
|
+
|
59
|
+
```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
|
65
|
+
|
66
|
+
# Disable minification
|
67
|
+
portapack -i ./site --no-minify
|
68
|
+
|
69
|
+
# Set custom base URL
|
70
|
+
portapack -i ./local/site -b https://example.com
|
71
|
+
|
72
|
+
# Recursive crawling with depth
|
73
|
+
portapack -i https://site.com -r 2
|
74
|
+
|
75
|
+
# Dry run to preview
|
76
|
+
portapack -i https://example.com --dry-run -v
|
77
|
+
```
|
78
|
+
|
79
|
+
### Programmatic Configuration
|
80
|
+
|
81
|
+
```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
|
91
|
+
});
|
92
|
+
|
93
|
+
// With custom base URL
|
94
|
+
const html = await generatePortableHTML({
|
95
|
+
input: './index.html',
|
96
|
+
baseUrl: 'https://example.com',
|
97
|
+
embedAssets: true
|
98
|
+
});
|
99
|
+
|
100
|
+
// Recursive site bundling
|
101
|
+
await bundleSiteRecursively(
|
102
|
+
'https://example.com',
|
103
|
+
'output.html',
|
104
|
+
2 // Depth
|
105
|
+
);
|
106
|
+
```
|
107
|
+
|
108
|
+
## ๐ก Best Practices
|
109
|
+
|
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`
|
119
|
+
|
120
|
+
## ๐จ Configuration Warnings
|
121
|
+
|
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
|
126
|
+
|
127
|
+
## ๐ File Types Supported
|
128
|
+
|
129
|
+
PortaPack automatically detects and processes:
|
130
|
+
|
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.
|
137
|
+
|
138
|
+
## ๐ Environment Variables
|
139
|
+
|
140
|
+
PortaPack also supports configuration via environment variables:
|
141
|
+
|
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"
|
145
|
+
|
146
|
+
## ๐ Related Documentation
|
147
|
+
|
148
|
+
- [CLI Reference](/cli)
|
149
|
+
- [API Reference](/api/README)
|
150
|
+
- [Getting Started Guide](/getting-started)
|
151
|
+
- [Troubleshooting](/troubleshooting)
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# ๐ค Contributing to PortaPack
|
2
|
+
|
3
|
+
## ๐ Ways to Contribute
|
4
|
+
|
5
|
+
1. **Code Improvements**
|
6
|
+
2. **Bug Fixes**
|
7
|
+
3. **Documentation Enhancements**
|
8
|
+
4. **Feature Development**
|
9
|
+
5. **Testing and Quality Assurance**
|
10
|
+
|
11
|
+
## ๐ Contribution Guidelines
|
12
|
+
|
13
|
+
### ๐ Setup
|
14
|
+
|
15
|
+
Refer to our detailed [Development Guide](./development.md) for comprehensive setup instructions.
|
16
|
+
|
17
|
+
### ๐งช Development Workflow
|
18
|
+
|
19
|
+
1. **Fork the Repository**
|
20
|
+
- Navigate to [PortaPack GitHub Repository](https://github.com/manicinc/portapack)
|
21
|
+
- Click "Fork"
|
22
|
+
|
23
|
+
2. **Clone Your Fork**
|
24
|
+
```bash
|
25
|
+
git clone https://github.com/YOUR_USERNAME/portapack.git
|
26
|
+
cd portapack
|
27
|
+
```
|
28
|
+
|
29
|
+
3. **Create a Branch**
|
30
|
+
```bash
|
31
|
+
git checkout -b feature/your-feature-name
|
32
|
+
# or
|
33
|
+
git checkout -b bugfix/issue-description
|
34
|
+
```
|
35
|
+
|
36
|
+
### ๐ Commit Guidelines
|
37
|
+
|
38
|
+
We use [Conventional Commits](https://www.conventionalcommits.org/) for structured commit messages.
|
39
|
+
|
40
|
+
#### Commit Types
|
41
|
+
- `feat`: New features
|
42
|
+
- `fix`: Bug fixes
|
43
|
+
- `docs`: Documentation changes
|
44
|
+
- `style`: Code formatting
|
45
|
+
- `refactor`: Code restructuring
|
46
|
+
- `test`: Test-related changes
|
47
|
+
- `chore`: Maintenance tasks
|
48
|
+
|
49
|
+
#### Commit Command
|
50
|
+
```bash
|
51
|
+
npm run commit
|
52
|
+
```
|
53
|
+
|
54
|
+
### ๐งช Before Submitting a Pull Request
|
55
|
+
|
56
|
+
```bash
|
57
|
+
# Run tests
|
58
|
+
npm test
|
59
|
+
|
60
|
+
# Lint code
|
61
|
+
npm run lint
|
62
|
+
|
63
|
+
# Format code
|
64
|
+
npm run format
|
65
|
+
```
|
66
|
+
|
67
|
+
### ๐ค Pull Request Process
|
68
|
+
|
69
|
+
1. Ensure all tests pass
|
70
|
+
2. Update documentation if needed
|
71
|
+
3. Add description of changes
|
72
|
+
4. Link any related issues
|
73
|
+
|
74
|
+
## ๐ Contributor Recognition
|
75
|
+
|
76
|
+
- Contributors are listed in `CONTRIBUTORS.md`
|
77
|
+
- Significant contributions may be highlighted in release notes
|
78
|
+
|
79
|
+
## ๐ Code of Conduct
|
80
|
+
|
81
|
+
Please review our [Code of Conduct](./code-of-conduct.md) before contributing.
|
82
|
+
|
83
|
+
## ๐จ Reporting Issues
|
84
|
+
|
85
|
+
- Use GitHub Issues
|
86
|
+
- Provide detailed description
|
87
|
+
- Include reproduction steps
|
88
|
+
- Share relevant code snippets or error logs
|
89
|
+
|
90
|
+
## ๐ก๏ธ Security Vulnerabilities
|
91
|
+
|
92
|
+
- Do NOT open public issues for security vulnerabilities
|
93
|
+
- Email security details to security@portapack.dev
|
94
|
+
- Include reproduction steps
|
95
|
+
- Allow time for responsible disclosure
|
96
|
+
|
97
|
+
## ๐ฌ Community
|
98
|
+
|
99
|
+
- Join our [Discord Community](#)
|
100
|
+
- Follow us on [Twitter](#)
|
101
|
+
- Use GitHub Discussions for ideas and questions
|
102
|
+
|
103
|
+
## ๐ Thank You!
|
104
|
+
|
105
|
+
Open source thrives on community contributions. Your effort helps improve PortaPack for everyone! ๐
|
106
|
+
|
107
|
+
**Happy Coding!** ๐ปโจ
|
package/docs/demo.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
# ๐ Live Demo
|
3
|
+
|
4
|
+
## What Youโll See
|
5
|
+
|
6
|
+
- A fully portable HTML site
|
7
|
+
- Every internal page inlined
|
8
|
+
- No external requests
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
## Example Output
|
13
|
+
|
14
|
+
> Download this page and open it offline. It works!
|
15
|
+
|
16
|
+
<!-- [Download Demo Portable HTML](./bootstrap-packed.html) -->
|
17
|
+
|
18
|
+
---
|
19
|
+
|
20
|
+
## How It Was Generated
|
21
|
+
|
22
|
+
```bash
|
23
|
+
portapack -i https://getbootstrap.com --recursive --max-depth 1 -o bootstrap-packed.html
|
24
|
+
```
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Client-Side Navigation
|
29
|
+
|
30
|
+
Recursively packed pages are wrapped in `<template>` blocks with an embedded router.
|
31
|
+
|
32
|
+
```html
|
33
|
+
<template id="page-home">
|
34
|
+
<h1>Homepage</h1>
|
35
|
+
</template>
|
36
|
+
<template id="page-about">
|
37
|
+
<h1>About</h1>
|
38
|
+
</template>
|
39
|
+
```
|
40
|
+
|
41
|
+
```js
|
42
|
+
window.addEventListener('hashchange', () => {
|
43
|
+
const id = location.hash.replace('#', '') || 'home';
|
44
|
+
showPage(id);
|
45
|
+
});
|
46
|
+
```
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# ๐ Deployment Guide
|
2
|
+
|
3
|
+
## ๐ Release Process
|
4
|
+
|
5
|
+
This project uses [`semantic-release`](https://github.com/semantic-release/semantic-release) to automate versioning and publishing to npm.
|
6
|
+
|
7
|
+
### Automatic Publishing
|
8
|
+
|
9
|
+
When changes are pushed to master, semantic-release will:
|
10
|
+
|
11
|
+
1. Analyze your commit messages (using [Conventional Commits](https://www.conventionalcommits.org/))
|
12
|
+
2. Automatically bump the version (`patch`, `minor`, `major`)
|
13
|
+
3. Generate or update `CHANGELOG.md`
|
14
|
+
4. Create a GitHub release
|
15
|
+
5. Publish the package to npm
|
16
|
+
|
17
|
+
### Release Types
|
18
|
+
|
19
|
+
| Commit Format | Result |
|
20
|
+
|--------------|--------|
|
21
|
+
| `fix:` | ๐ง PATCH release |
|
22
|
+
| `feat:` | โจ MINOR release |
|
23
|
+
| `feat:` + `BREAKING CHANGE:` | ๐จ MAJOR release |
|
24
|
+
|
25
|
+
## ๐ฆ Manual Release (Optional Fallback)
|
26
|
+
|
27
|
+
```bash
|
28
|
+
# Build the project
|
29
|
+
npm run build
|
30
|
+
|
31
|
+
# Run tests and check coverage
|
32
|
+
npm test
|
33
|
+
|
34
|
+
# Publish to npm manually
|
35
|
+
npm run publish:npm
|
36
|
+
```
|
37
|
+
|
38
|
+
## ๐ GitHub Actions + NPM Setup
|
39
|
+
|
40
|
+
### Required Secrets
|
41
|
+
|
42
|
+
In your GitHub repository:
|
43
|
+
|
44
|
+
1. Go to **Settings > Secrets and variables > Actions**
|
45
|
+
2. Add the following secrets:
|
46
|
+
|
47
|
+
- `NPM_TOKEN`
|
48
|
+
- Create at npmjs.com > Access Tokens
|
49
|
+
- Choose type: `Automation` (read + publish)
|
50
|
+
- Paste into GitHub as `NPM_TOKEN`
|
51
|
+
|
52
|
+
- `GITHUB_TOKEN`
|
53
|
+
- This is automatically available in GitHub Actions
|
54
|
+
|
55
|
+
### GitHub Repo Settings
|
56
|
+
|
57
|
+
1. Go to **Settings > Actions > General**
|
58
|
+
2. Under **Workflow Permissions**:
|
59
|
+
- โ
Enable: **Read and write permissions**
|
60
|
+
|
61
|
+
## ๐งช Test Coverage
|
62
|
+
|
63
|
+
### Tools Used
|
64
|
+
- Jest
|
65
|
+
- Coveralls
|
66
|
+
|
67
|
+
### CLI Usage
|
68
|
+
|
69
|
+
```bash
|
70
|
+
# Run all tests with coverage
|
71
|
+
npm test
|
72
|
+
|
73
|
+
# View interactive HTML coverage report
|
74
|
+
npm run coverage
|
75
|
+
# (opens coverage/lcov-report/index.html)
|
76
|
+
|
77
|
+
# Generate and copy coverage report to docs
|
78
|
+
npm run docs:coverage
|
79
|
+
```
|
80
|
+
|
81
|
+
### Coverage Badge Setup (Optional)
|
82
|
+
|
83
|
+
1. Go to https://coveralls.io/
|
84
|
+
2. Log in with GitHub
|
85
|
+
3. Enable your repo
|
86
|
+
4. Your GitHub Actions workflow (CI) will push coverage data automatically
|
87
|
+
|
88
|
+
Add badge to README:
|
89
|
+
|
90
|
+
```markdown
|
91
|
+
[](https://coveralls.io/github/YOUR_USERNAME/portapack?branch=master)
|
92
|
+
```
|
93
|
+
|
94
|
+
## ๐ VitePress Coverage Page
|
95
|
+
|
96
|
+
The project automatically generates a test coverage report and makes it accessible via VitePress:
|
97
|
+
|
98
|
+
- Coverage report is generated to `docs/test-coverage/`
|
99
|
+
- Accessible at `/test-coverage/` in your documentation site
|
100
|
+
- Automatically updated with each test run
|
101
|
+
|
102
|
+
## ๐งผ Pre-commit Hooks
|
103
|
+
|
104
|
+
We use Husky + `lint-staged`:
|
105
|
+
- โ
Auto-lint + format on commit
|
106
|
+
- โ
Validate commit messages via Commitizen
|
107
|
+
|
108
|
+
## ๐งฏ Troubleshooting
|
109
|
+
|
110
|
+
### Commit Fails?
|
111
|
+
- Use `npm run commit` (or `git cz`) to follow the correct format
|
112
|
+
- Check Husky is installed (`.husky/` exists)
|
113
|
+
- Run `npm install` again to restore hooks
|
114
|
+
|
115
|
+
### Release Fails?
|
116
|
+
- Check GitHub Actions logs
|
117
|
+
- Ensure `NPM_TOKEN` secret is added
|
118
|
+
- Ensure commit messages follow Conventional Commits
|
119
|
+
|
120
|
+
## โ๏ธ Recommended Commit Format
|
121
|
+
|
122
|
+
```bash
|
123
|
+
npm run commit
|
124
|
+
```
|
125
|
+
|
126
|
+
### Examples
|
127
|
+
|
128
|
+
```
|
129
|
+
feat(fonts): add base64 embedding with MIME detection
|
130
|
+
fix(extractor): fallback on missing asset
|
131
|
+
chore(ci): enable docs deploy with GitHub Pages
|
132
|
+
```
|