Skip to content

Commit 1a2aac9

Browse files
committed
docs: Add comprehensive CONTRIBUTING.md guide
- How to use Phantom.js in projects (installation, examples) - Development setup and testing instructions - Code style guidelines (ES5 compatibility) - Pull request workflow and checklist - License requirements (GPL v3 copyleft) - Issue reporting and getting help - Complete guide for contributors
1 parent 6ac4597 commit 1a2aac9

1 file changed

Lines changed: 361 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
1+
# Contributing to Phantom.js
2+
3+
Thank you for your interest in contributing to Phantom.js! This guide will help you understand how to use Phantom.js in your projects and how to contribute to the project.
4+
5+
---
6+
7+
## 📖 Table of Contents
8+
9+
1. [Using Phantom.js in Your Projects](#using-phantomjs-in-your-projects)
10+
2. [Development Setup](#development-setup)
11+
3. [Running Tests](#running-tests)
12+
4. [Making Contributions](#making-contributions)
13+
5. [Code Style Guidelines](#code-style-guidelines)
14+
6. [License Requirements](#license-requirements)
15+
16+
---
17+
18+
## 🚀 Using Phantom.js in Your Projects
19+
20+
### Installation
21+
22+
Phantom.js is designed for use in **Mirth Connect**, **Open Integration Engine (OIE)**, and **BridgeLink** environments.
23+
24+
#### Step-by-Step Installation:
25+
26+
1. **Get the Library:**
27+
- Download `phantom.js` or `phantom.min.js` from the [releases page](https://github.com/OS366/phantom/releases)
28+
- Or copy the code directly from the repository
29+
30+
2. **Install in Mirth Connect / OIE / BridgeLink:**
31+
- Go to **Channels****Edit Code Template**
32+
- Click **New Library**
33+
- Select **New Code Templates**
34+
- Paste the Phantom.js code
35+
- Set **Context** to **Select All Context** (or specific contexts as needed)
36+
- Name it (e.g., "Phantom.js Library")
37+
- Click **Save**
38+
39+
3. **Use in Your Scripts:**
40+
```javascript
41+
// No initialization needed - immediately available!
42+
var result = phantom.strings.operation.trim(" hello ");
43+
// Output: "hello"
44+
45+
// Check version
46+
logger.info("Using Phantom.js " + phantom.version);
47+
```
48+
49+
### Quick Examples
50+
51+
```javascript
52+
// String Operations
53+
var cleaned = phantom.strings.operation.trim(" hello world ");
54+
var padded = phantom.strings.operation.leftPad("5", 3, "0"); // "005"
55+
56+
// Number Operations
57+
var sum = phantom.numbers.operation.add(10, 20); // 30
58+
var rounded = phantom.numbers.operation.round(3.14159, 2); // 3.14
59+
60+
// JSON Operations
61+
var json = phantom.json.operation.parse('{"name": "John"}');
62+
var value = phantom.json.operation.get(json, "name"); // "John"
63+
64+
// Map Operations (Mirth Connect)
65+
phantom.maps.channel.save("key", "value");
66+
var value = phantom.maps.channel.get("key"); // "value"
67+
68+
// Chaining API (v0.1.6+)
69+
var result = phantom.numbers.chain(10)
70+
.add(5)
71+
.multiply(2)
72+
.round(0)
73+
.value(); // 30
74+
```
75+
76+
### Documentation
77+
78+
- **[Wiki Home](https://github.com/OS366/phantom/wiki)** - Complete documentation
79+
- **[API Reference](https://github.com/OS366/phantom/wiki/API-Reference)** - All available functions
80+
- **[Examples](https://github.com/OS366/phantom/wiki/Examples)** - Real-world usage examples
81+
- **[Best Practices](https://github.com/OS366/phantom/wiki/Best-Practices)** - Tips and patterns
82+
83+
---
84+
85+
## 🛠️ Development Setup
86+
87+
If you want to contribute code to Phantom.js, follow these steps:
88+
89+
### Prerequisites
90+
91+
- **Node.js** (v14 or higher recommended)
92+
- **npm** (comes with Node.js)
93+
- **Git**
94+
95+
### Setup Steps
96+
97+
1. **Fork the Repository:**
98+
- Click "Fork" on [GitHub](https://github.com/OS366/phantom)
99+
- This creates your own copy of the repository
100+
101+
2. **Clone Your Fork:**
102+
```bash
103+
git clone https://github.com/YOUR_USERNAME/phantom.git
104+
cd phantom
105+
```
106+
107+
3. **Add Upstream Remote:**
108+
```bash
109+
git remote add upstream https://github.com/OS366/phantom.git
110+
```
111+
112+
4. **Install Dependencies:**
113+
```bash
114+
cd scripts
115+
npm install
116+
```
117+
118+
5. **Verify Setup:**
119+
```bash
120+
# Run tests to make sure everything works
121+
npm test
122+
```
123+
124+
---
125+
126+
## ✅ Running Tests
127+
128+
Phantom.js has comprehensive test coverage. Always run tests before submitting changes.
129+
130+
### Test Commands
131+
132+
```bash
133+
# Run all tests
134+
npm test
135+
136+
# Run tests in watch mode (auto-rerun on changes)
137+
npm run test:watch
138+
139+
# Run tests with coverage report
140+
npm run test:coverage
141+
142+
# Check test coverage (strict mode)
143+
npm run test:check
144+
145+
# Check test coverage with diff (for CI)
146+
npm run test:check-diff
147+
```
148+
149+
### Test Structure
150+
151+
- **Test File:** `phantom.test.js` (in root directory)
152+
- **Test Framework:** Jest
153+
- **Coverage Target:** 100% (all functions must be tested)
154+
155+
### Writing Tests
156+
157+
When adding new features, you **must** add corresponding tests:
158+
159+
```javascript
160+
describe('phantom.numbers.operation.newFeature', function() {
161+
it('should handle normal case', function() {
162+
var result = phantom.numbers.operation.newFeature(10);
163+
expect(result).toBe(20);
164+
});
165+
166+
it('should handle edge cases', function() {
167+
var result = phantom.numbers.operation.newFeature(null);
168+
expect(result).toBeNull();
169+
});
170+
171+
it('should handle errors', function() {
172+
expect(function() {
173+
phantom.numbers.operation.newFeature("invalid");
174+
}).toThrow();
175+
});
176+
});
177+
```
178+
179+
---
180+
181+
## 📝 Making Contributions
182+
183+
### Workflow
184+
185+
1. **Create a Branch:**
186+
```bash
187+
git checkout -b feature/your-feature-name
188+
# or
189+
git checkout -b fix/your-bug-fix
190+
```
191+
192+
2. **Make Your Changes:**
193+
- Write code following the [Code Style Guidelines](#code-style-guidelines)
194+
- Add tests for new features
195+
- Update documentation if needed
196+
197+
3. **Test Your Changes:**
198+
```bash
199+
npm test
200+
npm run test:coverage
201+
```
202+
203+
4. **Commit Your Changes:**
204+
```bash
205+
git add .
206+
git commit -m "feat: Add new feature description"
207+
```
208+
209+
**Commit Message Format:**
210+
- `feat:` - New feature
211+
- `fix:` - Bug fix
212+
- `docs:` - Documentation changes
213+
- `test:` - Test additions/changes
214+
- `refactor:` - Code refactoring
215+
- `chore:` - Maintenance tasks
216+
217+
5. **Push to Your Fork:**
218+
```bash
219+
git push origin feature/your-feature-name
220+
```
221+
222+
6. **Create Pull Request:**
223+
- Go to [GitHub](https://github.com/OS366/phantom)
224+
- Click "New Pull Request"
225+
- Select your branch
226+
- Fill out the PR template
227+
- Submit for review
228+
229+
### Pull Request Checklist
230+
231+
Before submitting a PR, ensure:
232+
233+
- [ ] All tests pass (`npm test`)
234+
- [ ] Test coverage is 100% (`npm run test:check`)
235+
- [ ] Code follows style guidelines
236+
- [ ] Documentation is updated (if needed)
237+
- [ ] Commit messages are clear and descriptive
238+
- [ ] No merge conflicts with `main` branch
239+
240+
---
241+
242+
## 📋 Code Style Guidelines
243+
244+
### JavaScript Style
245+
246+
Phantom.js uses **ES5 (ECMAScript 5)** for maximum compatibility:
247+
248+
- ✅ Use `var` (not `let` or `const`)
249+
- ✅ Use `function` declarations
250+
- ✅ Use `"use strict"` mode
251+
- ✅ Use traditional `for` loops (not `for...of`)
252+
- ✅ Use `typeof` for type checking
253+
254+
### Code Structure
255+
256+
```javascript
257+
// ✅ Good: Clear structure, error handling
258+
phantom.category.operation.method = function(param1, param2) {
259+
"use strict";
260+
261+
try {
262+
// Validation
263+
if (param1 === null || param1 === undefined) {
264+
throw new Error("[phantom] category.operation.method: param1 is required");
265+
}
266+
267+
// Implementation
268+
var result = /* your logic */;
269+
270+
return result;
271+
} catch (e) {
272+
// Error logging
273+
if (typeof logger !== 'undefined' && logger !== null) {
274+
logger.error("[phantom] category.operation.method: " + e.message);
275+
}
276+
throw e;
277+
}
278+
};
279+
```
280+
281+
### Naming Conventions
282+
283+
- **Functions:** `camelCase` (e.g., `trim`, `leftPad`, `parseJson`)
284+
- **Objects:** `camelCase` (e.g., `phantom.maps.channel`)
285+
- **Constants:** `UPPER_SNAKE_CASE` (e.g., `FORMAT.ISO_DATE`)
286+
287+
### Error Handling
288+
289+
- Always use try-catch blocks
290+
- Log errors with `[phantom]` prefix
291+
- Provide specific error messages
292+
- Throw errors (don't return null silently)
293+
294+
### Documentation
295+
296+
- Add JSDoc comments for new functions:
297+
```javascript
298+
/**
299+
* Trims whitespace from both ends of a string
300+
* @param {string} str - The string to trim
301+
* @returns {string} The trimmed string
302+
*/
303+
```
304+
305+
---
306+
307+
## ⚖️ License Requirements
308+
309+
**Important:** Phantom.js is licensed under **GPL v3 (GNU General Public License v3.0)**.
310+
311+
### For Contributors
312+
313+
By contributing to Phantom.js, you agree that:
314+
315+
1. Your contributions will be licensed under GPL v3
316+
2. You have the right to contribute the code
317+
3. Your code follows the project's coding standards
318+
319+
### For Users
320+
321+
**Copyleft License:** If you use Phantom.js in your project, your project must also be:
322+
323+
- Licensed under GPL v3
324+
- Open source (source code must be available)
325+
- Distributed with the same license
326+
327+
**This means:** If you use Phantom.js, you cannot keep your project proprietary/closed-source.
328+
329+
### License Text
330+
331+
See [LICENSE](LICENSE) file for the complete GPL v3 license text.
332+
333+
---
334+
335+
## 🐛 Reporting Issues
336+
337+
Found a bug or have a suggestion? Please [open an issue](https://github.com/OS366/phantom/issues) with:
338+
339+
- Clear description of the problem
340+
- Steps to reproduce
341+
- Expected vs. actual behavior
342+
- Environment details (Mirth Connect version, Java version, etc.)
343+
344+
---
345+
346+
## 💬 Getting Help
347+
348+
- **Documentation:** [Wiki](https://github.com/OS366/phantom/wiki)
349+
- **Issues:** [GitHub Issues](https://github.com/OS366/phantom/issues)
350+
- **Discussions:** [GitHub Discussions](https://github.com/OS366/phantom/discussions) (if enabled)
351+
352+
---
353+
354+
## 🙏 Thank You!
355+
356+
Your contributions help make Phantom.js better for everyone. Thank you for taking the time to contribute!
357+
358+
---
359+
360+
**Questions?** Feel free to open an issue or start a discussion on GitHub.
361+

0 commit comments

Comments
 (0)