|
1 | | -# Contributing to Formo Node SDK |
| 1 | +# How to contribute |
2 | 2 |
|
3 | | -Thank you for your interest in contributing to the Formo Node SDK! This guide will help you get started. |
| 3 | +If you want to contribute or run a local version of the Formo Node SDK, follow these steps: |
4 | 4 |
|
5 | | -## Table of Contents |
| 5 | +## Build the SDK Locally |
6 | 6 |
|
7 | | -- [Project Structure](#project-structure) |
8 | | -- [Setting Up the Development Environment](#setting-up-the-development-environment) |
9 | | -- [Making Changes](#making-changes) |
10 | | -- [Running Tests](#running-tests) |
11 | | -- [Code Style](#code-style) |
| 7 | +Run the following command to build both CommonJS and ESM versions of the SDK: |
12 | 8 |
|
13 | | -## Project Structure |
14 | | - |
15 | | -``` |
16 | | -sdk-node/ |
17 | | -├── src/ # Main SDK source code |
18 | | -│ ├── FormoAnalytics.ts # Main SDK class |
19 | | -│ ├── queue/ # Event batching and retry logic |
20 | | -│ ├── types/ # TypeScript type definitions |
21 | | -│ ├── utils/ # Utilities (address checksumming, etc.) |
22 | | -│ └── validators/ # Input validation |
23 | | -├── test/ # Tests |
24 | | -│ ├── __tests__/ # Integration tests |
25 | | -│ └── queue/ # Unit tests for queue/events |
26 | | -├── scripts/ # Utility and test scripts |
27 | | -└── package.json |
| 9 | +```bash |
| 10 | +pnpm install |
| 11 | +pnpm build |
| 12 | +pnpm test |
28 | 13 | ``` |
29 | 14 |
|
30 | | -## Setting Up the Development Environment |
| 15 | +## Testing Locally |
31 | 16 |
|
32 | | -1. **Clone the repository:** |
| 17 | +### Link the Local Package |
33 | 18 |
|
34 | | - ```bash |
35 | | - git clone <repo-url> |
36 | | - cd sdk-node |
37 | | - ``` |
| 19 | +To test your SDK changes in a test app, you can link the package locally using `npm link` or `pnpm link`. |
38 | 20 |
|
39 | | -2. **Install dependencies:** |
| 21 | +For example, if your projects are in the same directory: |
40 | 22 |
|
41 | | - This project uses [pnpm](https://pnpm.io/). Other package managers may work but are not officially supported. |
| 23 | +``` |
| 24 | +~/ |
| 25 | +├── your-app/ |
| 26 | +└── sdk-node/ |
| 27 | +``` |
42 | 28 |
|
43 | | - ```bash |
44 | | - pnpm install |
45 | | - ``` |
| 29 | +Run the following commands: |
46 | 30 |
|
47 | | -3. **Build the project:** |
| 31 | +```bash |
| 32 | +# In ~/your-app |
| 33 | +pnpm link ../sdk-node |
| 34 | +``` |
48 | 35 |
|
49 | | - ```bash |
50 | | - pnpm build |
51 | | - ``` |
| 36 | +Or with npm: |
52 | 37 |
|
53 | | -## Making Changes |
| 38 | +```bash |
| 39 | +# In ~/your-app |
| 40 | +npm link ../sdk-node |
| 41 | +``` |
54 | 42 |
|
55 | | -The core SDK logic in `src/` is manually maintained. |
| 43 | +### Apply Changes |
56 | 44 |
|
57 | | -Key components: |
| 45 | +Any changes you make to your local package require rebuilding to be reflected: |
58 | 46 |
|
59 | | -- `FormoAnalytics.ts`: Main entry point and public API. |
60 | | -- `queue/`: Handles event buffering, batching, and retrying. |
61 | | -- `types/`: Use this for all shared interfaces and types. |
| 47 | +```bash |
| 48 | +# In ~/sdk-node |
| 49 | +pnpm build |
| 50 | +``` |
62 | 51 |
|
63 | | -When making changes: |
| 52 | +The changes will automatically be available in the linked project. |
64 | 53 |
|
65 | | -1. Create a feature branch from `main`. |
66 | | -2. Make your changes with appropriate tests. |
67 | | -3. Ensure all unit tests pass: `npm test`. |
68 | | -4. If modifying API interactions, verify with integration tests (see below). |
69 | | -5. Submit a pull request. |
| 54 | +### Unlink the Package |
70 | 55 |
|
71 | | -## Running Tests |
| 56 | +To remove the link: |
72 | 57 |
|
73 | | -### Unit Tests |
| 58 | +```bash |
| 59 | +# In ~/your-app |
| 60 | +pnpm unlink ../sdk-node |
| 61 | +``` |
74 | 62 |
|
75 | | -Run the full unit test suite: |
| 63 | +Or with npm: |
76 | 64 |
|
77 | 65 | ```bash |
78 | | -npm test |
| 66 | +# In ~/your-app |
| 67 | +npm unlink ../sdk-node |
79 | 68 | ``` |
80 | 69 |
|
81 | | -Or just the queue/logic tests: |
| 70 | +## Running Tests |
| 71 | + |
| 72 | +Run the test suite: |
82 | 73 |
|
83 | 74 | ```bash |
84 | | -npm run test:queue |
| 75 | +pnpm test |
85 | 76 | ``` |
86 | 77 |
|
87 | 78 | ### Integration Tests |
88 | 79 |
|
89 | | -These tests make real network requests to the Formo API. You need a valid Write Key. |
| 80 | +These tests make real network requests to the Formo API. You need a valid Write Key: |
90 | 81 |
|
91 | 82 | ```bash |
92 | | -FORMO_WRITE_KEY=your-key npm run test:integration |
| 83 | +FORMO_WRITE_KEY=your-key pnpm run test:integration |
93 | 84 | ``` |
94 | 85 |
|
95 | | -### Manual Testing Script |
96 | | - |
97 | | -To verify functionality with a real script in a separate environment: |
| 86 | +## Linting |
98 | 87 |
|
99 | | -1. Create a `.env` file with `FORMO_WRITE_KEY=your-key` |
100 | | -2. Run the manual test script: |
101 | | - ```bash |
102 | | - pnpm run script:test-analytics |
103 | | - ``` |
| 88 | +Check code style and types: |
104 | 89 |
|
105 | | -### Testing Packaging |
| 90 | +```bash |
| 91 | +pnpm lint |
| 92 | +``` |
106 | 93 |
|
107 | | -To simulate consuming the package as a real user: |
| 94 | +## Publishing |
108 | 95 |
|
109 | | -1. Create a tarball: |
| 96 | +1. **Update the version** using npm: |
110 | 97 |
|
111 | 98 | ```bash |
112 | | - npm pack |
| 99 | + npm version patch # For bug fixes |
| 100 | + npm version minor # For new features |
| 101 | + npm version major # For breaking changes |
113 | 102 | ``` |
114 | 103 |
|
115 | | - This creates a file like `formo-analytics-node-1.0.0.tgz`. |
| 104 | + This automatically: |
116 | 105 |
|
117 | | -2. Install it in another project: |
| 106 | + - Updates `package.json` with the new version |
| 107 | + - Creates a git commit with the change |
| 108 | + - Creates a version tag (e.g., `v1.0.1`) |
| 109 | + |
| 110 | +2. **Push the commit and tag**: |
118 | 111 |
|
119 | 112 | ```bash |
120 | | - npm install /path/to/sdk-node/formo-analytics-node-1.0.0.tgz |
| 113 | + git push --follow-tags |
121 | 114 | ``` |
122 | 115 |
|
123 | | -3. Verify usage works as expected. |
124 | | - |
125 | | -## Code Style |
126 | | - |
127 | | -This project uses: |
128 | | - |
129 | | -- [Prettier](https://prettier.io/) for code formatting |
130 | | -- [ESLint](https://eslint.org/) for linting |
131 | | - |
132 | | -```bash |
133 | | -# Check linting |
134 | | -pnpm lint |
135 | | - |
136 | | -# Fix linting and formatting issues |
137 | | -pnpm fix |
138 | | -``` |
139 | | - |
140 | | -## Questions? |
141 | | - |
142 | | -If you have questions or need help, please open an issue on GitHub. |
| 116 | +3. **Automatic workflow execution**: |
| 117 | + - GitHub Actions workflow triggers on the `v*` tag |
| 118 | + - Builds and tests the package |
| 119 | + - Publishes to npm |
0 commit comments