|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +This document describes how to use the package manager (npm) for development tasks. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js 14.0.0 or higher |
| 8 | +- npm (comes with Node.js) |
| 9 | + |
| 10 | +## Getting Started |
| 11 | + |
| 12 | +Install development dependencies: |
| 13 | + |
| 14 | +```bash |
| 15 | +npm install |
| 16 | +``` |
| 17 | + |
| 18 | +## Available Scripts |
| 19 | + |
| 20 | +### Linting |
| 21 | + |
| 22 | +Check code for potential issues: |
| 23 | + |
| 24 | +```bash |
| 25 | +npm run lint |
| 26 | +``` |
| 27 | + |
| 28 | +Automatically fix linting issues where possible: |
| 29 | + |
| 30 | +```bash |
| 31 | +npm run lint:fix |
| 32 | +``` |
| 33 | + |
| 34 | +### Code Formatting |
| 35 | + |
| 36 | +Check code formatting (JavaScript files only): |
| 37 | + |
| 38 | +```bash |
| 39 | +npm run format:check |
| 40 | +``` |
| 41 | + |
| 42 | +Format JavaScript files: |
| 43 | + |
| 44 | +```bash |
| 45 | +npm run format |
| 46 | +``` |
| 47 | + |
| 48 | +> **Note**: The existing codebase uses its original formatting style. Prettier and ESLint are provided as optional tools for new code or improvements. |
| 49 | +
|
| 50 | +### Validation |
| 51 | + |
| 52 | +Run all checks (formatting and linting): |
| 53 | + |
| 54 | +```bash |
| 55 | +npm run validate |
| 56 | +``` |
| 57 | + |
| 58 | +### Testing |
| 59 | + |
| 60 | +Currently, there are no automated tests configured: |
| 61 | + |
| 62 | +```bash |
| 63 | +npm run test |
| 64 | +``` |
| 65 | + |
| 66 | +### Docker |
| 67 | + |
| 68 | +Build Docker images: |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run docker:build # Standard Debian-based image |
| 72 | +npm run docker:build-alpine # Alpine-based image |
| 73 | +``` |
| 74 | + |
| 75 | +## Development Tools |
| 76 | + |
| 77 | +The package manager setup includes: |
| 78 | + |
| 79 | +- **ESLint**: JavaScript linting tool to catch common errors |
| 80 | +- **Prettier**: Code formatting tool to maintain consistent style |
| 81 | + |
| 82 | +These tools are configured but non-intrusive to the existing codebase. |
| 83 | + |
| 84 | +## Project Structure |
| 85 | + |
| 86 | +``` |
| 87 | +. |
| 88 | +├── speedtest.js # Main speedtest library |
| 89 | +├── speedtest_worker.js # Web Worker for speed testing |
| 90 | +├── index.html # Default UI |
| 91 | +├── backend/ # PHP backend files |
| 92 | +├── examples/ # Example implementations |
| 93 | +├── results/ # Results/telemetry handling |
| 94 | +├── docker/ # Docker-related files |
| 95 | +└── package.json # npm package configuration |
| 96 | +``` |
| 97 | + |
| 98 | +## Why Use a Package Manager? |
| 99 | + |
| 100 | +The package manager provides several benefits: |
| 101 | + |
| 102 | +1. **Standardized tooling**: Common commands across different environments |
| 103 | +2. **Development dependencies**: Easy installation of linting and formatting tools |
| 104 | +3. **Project metadata**: Version, description, and licensing information |
| 105 | +4. **Future extensibility**: Foundation for adding build tools, tests, or bundlers if needed |
| 106 | +5. **npm distribution**: Makes the library easy to use in other Node.js projects |
| 107 | + |
| 108 | +## Contributing |
| 109 | + |
| 110 | +When making changes: |
| 111 | + |
| 112 | +1. Run `npm run lint` to check for potential issues |
| 113 | +2. Consider running `npm run format` on new files for consistency |
| 114 | +3. Test your changes manually in a browser |
| 115 | +4. For PHP backend changes, test with the appropriate server setup |
| 116 | + |
| 117 | +## Notes |
| 118 | + |
| 119 | +- The core library has **no runtime dependencies** - it's pure vanilla JavaScript |
| 120 | +- Development dependencies (ESLint, Prettier) are only needed for development |
| 121 | +- The library can still be used standalone without npm (just include the JS files) |
| 122 | +- npm setup is completely optional and doesn't change how the library is deployed |
0 commit comments