|
| 1 | +# DEVELOPER.md |
| 2 | + |
| 3 | +This document provides a guide for developers who want to contribute to or work with the `@interactive-video-labs/react` project. It covers setting up the development environment, understanding the project structure, running tests, building the project, and working with examples. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +1. [Getting Started](#getting-started) |
| 8 | +2. [Project Structure](#project-structure) |
| 9 | +3. [Available Scripts](#available-scripts) |
| 10 | +4. [Testing](#testing) |
| 11 | +5. [Building the Project](#building-the-project) |
| 12 | +6. [Working with Examples](#working-with-examples) |
| 13 | +7. [Contributing](#contributing) |
| 14 | +8. [Troubleshooting](#troubleshooting) |
| 15 | + |
| 16 | +## 1. Getting Started |
| 17 | + |
| 18 | +To get started with development, follow these steps: |
| 19 | + |
| 20 | +1. **Clone the repository:** |
| 21 | + ```bash |
| 22 | + git clone https://github.com/interactive-video-labs/interactive-video-react-wrapper.git |
| 23 | + cd interactive-video-react-wrapper |
| 24 | + ``` |
| 25 | + |
| 26 | +2. **Install dependencies:** |
| 27 | + This project uses `pnpm` as its package manager. If you don't have `pnpm` installed, you can install it via npm: |
| 28 | + ```bash |
| 29 | + npm install -g pnpm |
| 30 | + ``` |
| 31 | + Then, install the project dependencies: |
| 32 | + ```bash |
| 33 | + pnpm install |
| 34 | + ``` |
| 35 | +
|
| 36 | +## 2. Project Structure |
| 37 | +
|
| 38 | +Here's an overview of the key directories and files in this project: |
| 39 | + |
| 40 | +* `src/`: Contains the main source code for the React wrapper (`index.tsx`). |
| 41 | +* `test/`: Contains unit tests for the components (`InteractiveVideo.test.tsx`) and test setup (`setupTests.ts`). |
| 42 | +* `examples/`: Contains a simple example React application demonstrating how to use the wrapper. |
| 43 | + * `index.html`: The HTML entry point for the example. |
| 44 | + * `index.tsx`: The React application code for the example. |
| 45 | +* `dist/`: The output directory for the compiled library files. |
| 46 | +* `tsup.config.ts`: Configuration for `tsup`, the bundler used to build the library. |
| 47 | +* `vitest.config.ts`: Configuration for `Vitest`, the testing framework. |
| 48 | +* `package.json`: Project metadata, dependencies, and scripts. |
| 49 | + |
| 50 | +## 3. Available Scripts |
| 51 | + |
| 52 | +This project includes several scripts defined in `package.json` to help with development: |
| 53 | + |
| 54 | +* `pnpm build`: Compiles the TypeScript source code into JavaScript for distribution (`dist` folder). |
| 55 | +* `pnpm dev`: Starts `tsup` in watch mode, recompiling the library whenever source files change. |
| 56 | +* `pnpm test`: Runs all unit tests using Vitest. |
| 57 | +* `pnpm clean`: Removes the `dist` directory. |
| 58 | +* `pnpm prepare`: Runs `pnpm build`. This script is typically run before publishing the package. |
| 59 | +* `pnpm serve-examples`: Builds the example application and serves it using `http-server`. |
| 60 | +* `pnpm build-examples`: Compiles the example application using `esbuild`. |
| 61 | + |
| 62 | +## 4. Testing |
| 63 | + |
| 64 | +Tests are written using `Vitest` and `React Testing Library`. You can run all tests with: |
| 65 | + |
| 66 | +```bash |
| 67 | +pnpm test |
| 68 | +``` |
| 69 | + |
| 70 | +When adding new features or fixing bugs, please ensure you add or update relevant tests to maintain code quality and prevent regressions. |
| 71 | + |
| 72 | +## 5. Building the Project |
| 73 | + |
| 74 | +The project is built using `tsup`. To compile the library for production, run: |
| 75 | + |
| 76 | +```bash |
| 77 | +pnpm build |
| 78 | +``` |
| 79 | + |
| 80 | +This will generate the compiled JavaScript files and TypeScript declaration files in the `dist` directory. |
| 81 | + |
| 82 | +## 6. Working with Examples |
| 83 | + |
| 84 | +The `examples/` directory contains a basic usage example. To run it: |
| 85 | + |
| 86 | +```bash |
| 87 | +pnpm serve-examples |
| 88 | +``` |
| 89 | + |
| 90 | +This will build the example and start a local web server, usually accessible at `http://localhost:8080` (or another port if 8080 is in use). You can modify the `examples/index.tsx` file to test your changes in a live environment. |
| 91 | + |
| 92 | +## 7. Contributing |
| 93 | + |
| 94 | +We welcome contributions to this project! Please refer to our [CONTRIBUTING.md](CONTRIBUTING.md) file for detailed guidelines on how to contribute, including information on: |
| 95 | + |
| 96 | +* Reporting bugs |
| 97 | +* Suggesting enhancements |
| 98 | +* Submitting pull requests |
| 99 | +* Coding style and conventions |
| 100 | + |
| 101 | +## 8. Troubleshooting |
| 102 | + |
| 103 | +* **`pnpm` command not found**: Ensure `pnpm` is installed globally (`npm install -g pnpm`). |
| 104 | +* **Build errors**: Check the output of `pnpm build` for specific error messages. Ensure all dependencies are installed (`pnpm install`). |
| 105 | +* **Test failures**: Review the test output for details on failing tests. You can often debug tests by adding `console.log` statements or using your IDE's debugger. |
| 106 | +* **Example server not starting**: Check if port 8080 (or the default `http-server` port) is already in use. You might need to stop other processes using that port or configure `http-server` to use a different port (though this is not directly supported by the `serve-examples` script). |
0 commit comments