|
| 1 | +# Contributing to `create-polyglot` |
| 2 | + |
| 3 | +Thanks for your interest in contributing! This document explains how to set up a local development environment, propose changes, add new service templates or generators, and submit pull requests. |
| 4 | + |
| 5 | +--- |
| 6 | +## Table of Contents |
| 7 | +1. Prerequisites |
| 8 | +2. Project Overview |
| 9 | +3. Getting Started (Local Dev) |
| 10 | +4. Running / Debugging the CLI |
| 11 | +5. Adding or Updating Service Templates |
| 12 | +6. Adding External Generators (e.g. create-next-app) |
| 13 | +7. Docker & Compose Generation |
| 14 | +8. Presets (Turborepo / Nx) |
| 15 | +9. Shared Packages (Workspaces) |
| 16 | +10. Code Style & Tooling |
| 17 | +11. Commit Message Conventions |
| 18 | +12. Testing Strategy (Current & Future) |
| 19 | +13. Releasing / Publishing |
| 20 | +14. Issue Reporting & Pull Request Workflow |
| 21 | +15. Security / Responsible Disclosure |
| 22 | +16. Roadmap / Ideas |
| 23 | + |
| 24 | +--- |
| 25 | +## 1. Prerequisites |
| 26 | +- **Node.js**: >= 20 (commander@14 & other deps require current LTS / Active version). |
| 27 | +- **npm** (or pnpm / yarn / bun if you want to test multi-PM flows). |
| 28 | +- **Git** for version control. |
| 29 | +- Internet access if you test the `--frontend-generator` flag (uses `npx create-next-app`). |
| 30 | + |
| 31 | +Optional tooling: |
| 32 | +- Docker (to validate generated Dockerfiles / `compose.yaml`). |
| 33 | +- Java 21 & Maven if testing the Spring Boot template build. |
| 34 | +- Go toolchain (>=1.22) for the Go service. |
| 35 | +- Python 3.12 for the FastAPI service. |
| 36 | + |
| 37 | +--- |
| 38 | +## 2. Project Overview |
| 39 | +`create-polyglot` scaffolds a polyglot microservice monorepo supporting multiple languages & frameworks: |
| 40 | +- Node.js (Express) |
| 41 | +- Python (FastAPI) |
| 42 | +- Go (net/http minimal) |
| 43 | +- Java (Spring Boot) |
| 44 | +- Frontend (Next.js) via internal template or `create-next-app` generator |
| 45 | + |
| 46 | +Features: |
| 47 | +- Interactive wizard (like `create-next-app`) if no arguments passed. |
| 48 | +- Non‑interactive flags for automation. |
| 49 | +- Optional presets: Turborepo or Nx. |
| 50 | +- Shared workspace package example (`packages/shared`). |
| 51 | +- Dockerfile generation + `compose.yaml` (multi-service) with a shared network. |
| 52 | +- Linting / formatting (ESLint + Prettier) + root scripts. |
| 53 | + |
| 54 | +--- |
| 55 | +## 3. Getting Started (Local Dev) |
| 56 | +```bash |
| 57 | +# Clone your fork |
| 58 | +git clone https://github.com/<your-username>/create-polyglot.git |
| 59 | +cd create-polyglot |
| 60 | + |
| 61 | +# Install dependencies |
| 62 | +npm install |
| 63 | + |
| 64 | +# Link globally to test the CLI |
| 65 | +npm link |
| 66 | + |
| 67 | +# Run interactively |
| 68 | +create-polyglot |
| 69 | + |
| 70 | +# Or scripted |
| 71 | +create-polyglot demo -s node,python,go,java,frontend --preset turborepo --git |
| 72 | +``` |
| 73 | +To unlink later: |
| 74 | +```bash |
| 75 | +npm unlink -g create-polyglot |
| 76 | +``` |
| 77 | + |
| 78 | +--- |
| 79 | +## 4. Running / Debugging the CLI |
| 80 | +Without linking you can run directly: |
| 81 | +```bash |
| 82 | +node bin/index.js my-app -s node,python |
| 83 | +``` |
| 84 | +Use environment variable `DEBUG=1` (you can instrument logs) if you add debug branches. |
| 85 | + |
| 86 | +You can also insert `console.log` statements or use an inspector: |
| 87 | +```bash |
| 88 | +node --inspect-brk bin/index.js demo -s node |
| 89 | +``` |
| 90 | +Then attach a debugger (e.g., VS Code). |
| 91 | + |
| 92 | +--- |
| 93 | +## 5. Adding or Updating Service Templates |
| 94 | +1. Add a folder under `templates/<service-name>`. |
| 95 | +2. Include minimal runnable code (avoid giant dependency graphs). |
| 96 | +3. Add necessary dependency manifests (e.g., `package.json`, `requirements.txt`, `pom.xml`, `go.mod`). |
| 97 | +4. If the template has files that some dev tools may auto-ignore (like `application.properties` earlier), you can store as `.txt` then rename during copy (see Spring Boot handling in `bin/index.js`). |
| 98 | +5. Update `allServiceChoices` array AND if you need alias matching add to `templateMap`. |
| 99 | +6. Document new service in README + (optionally) `--help` details. |
| 100 | + |
| 101 | +Design guidelines: |
| 102 | +- Keep templates minimal & fast to scaffold. |
| 103 | +- Provide a `/health` endpoint for consistency. |
| 104 | +- Avoid binding privileged ports or random ephemeral ports. |
| 105 | + |
| 106 | +--- |
| 107 | +## 6. Adding External Generators (e.g. `create-next-app`) |
| 108 | +Current support: `--frontend-generator` triggers `npx create-next-app`. To add more: |
| 109 | +1. Introduce a general flag (e.g., `--use-generator <service[:generator]>`). |
| 110 | +2. Parse mapping: service -> command. |
| 111 | +3. Use `execa` to run the tool in the target directory. |
| 112 | +4. Wrap in try/catch, fallback to internal template on failure. |
| 113 | +5. Sanitize directory (remove pre-existing files) before invoking generation. |
| 114 | + |
| 115 | +Keep external executions opt-in to avoid slow default scaffolds. |
| 116 | + |
| 117 | +--- |
| 118 | +## 7. Docker & Compose Generation |
| 119 | +The generator creates per-service `Dockerfile`s and a `compose.yaml`: |
| 120 | +- Shared network: `app-net`. |
| 121 | +- Ports mapped 1:1 (e.g., Node 3001:3001). |
| 122 | +- Environment variable `PORT` injected. |
| 123 | + |
| 124 | +To modify behavior: |
| 125 | +- Edit section in `bin/index.js` after `// Generate Dockerfiles + compose.yaml`. |
| 126 | +- Consider adding `healthcheck` blocks or dependencies (e.g., databases) behind a new flag `--with-db`. |
| 127 | + |
| 128 | +Testing: |
| 129 | +```bash |
| 130 | +cd <generated-project> |
| 131 | +docker compose up --build |
| 132 | +``` |
| 133 | + |
| 134 | +--- |
| 135 | +## 8. Presets (Turborepo / Nx) |
| 136 | +- Preset selected via `--preset turborepo` or `--preset nx` (or interactive). |
| 137 | +- Alters `dev` script and adds `turbo.json` or `nx.json` plus relevant dev dependency. |
| 138 | +- Add a new preset: extend conditional block where `rootPkg` is built, then emit configuration file. |
| 139 | + |
| 140 | +--- |
| 141 | +## 9. Shared Packages (Workspaces) |
| 142 | +The example `packages/shared` demonstrates a simple util export. To add new shared libs: |
| 143 | +```bash |
| 144 | +mkdir -p packages/logger/src |
| 145 | +cat > packages/logger/package.json <<'EOF' |
| 146 | +{ |
| 147 | + "name": "@shared/logger", |
| 148 | + "version": "0.0.1", |
| 149 | + "type": "module", |
| 150 | + "main": "src/index.js" |
| 151 | +} |
| 152 | +EOF |
| 153 | +``` |
| 154 | +Then import from services that use Node.js / Frontend. (Other languages each maintain their own dependency system.) |
| 155 | + |
| 156 | +--- |
| 157 | +## 10. Code Style & Tooling |
| 158 | +- **Formatting**: Prettier (`npm run format`). |
| 159 | +- **Linting**: ESLint (`npm run lint`). |
| 160 | +- Keep `bin/index.js` logically segmented—prefer small helper functions if it grows. |
| 161 | +- Avoid introducing TypeScript in the CLI unless you add a build step. |
| 162 | + |
| 163 | +Suggested style: keep functions small, prefer async/await, graceful error handling with actionable messages. |
| 164 | + |
| 165 | +--- |
| 166 | +## 11. Commit Message Conventions |
| 167 | +Use Conventional Commits where possible: |
| 168 | +``` |
| 169 | +feat: add Rust service template |
| 170 | +fix: correct compose environment mapping |
| 171 | +chore: bump dependencies |
| 172 | +refactor: extract docker writer helper |
| 173 | +docs: update contributing guidelines |
| 174 | +``` |
| 175 | +This assists in automated changelog generation later. |
| 176 | + |
| 177 | +--- |
| 178 | +## 12. Testing Strategy (Current & Future) |
| 179 | +Currently there are no automated tests. Suggested roadmap: |
| 180 | +- Unit tests for helper functions (after refactoring CLI logic into modules). |
| 181 | +- Snapshot tests for generated directory structures. |
| 182 | +- E2E tests using a temporary tmpdir: run CLI, assert expected files, run `node apps/node/src/index.js` health check. |
| 183 | +- Integration test to ensure docker compose builds (can be optional in CI). |
| 184 | + |
| 185 | +Potential frameworks: `vitest` or `jest`. |
| 186 | + |
| 187 | +--- |
| 188 | +## 13. Releasing / Publishing |
| 189 | +1. Ensure `main` is green & docs updated. |
| 190 | +2. Bump version in `package.json` (follow semver). |
| 191 | +3. Update / create `CHANGELOG.md`. |
| 192 | +4. Commit & tag: |
| 193 | + ```bash |
| 194 | + git add . |
| 195 | + git commit -m "chore: release vX.Y.Z" |
| 196 | + git tag vX.Y.Z |
| 197 | + git push origin main --tags |
| 198 | + ``` |
| 199 | +5. Publish: |
| 200 | + ```bash |
| 201 | + npm publish --access public |
| 202 | + ``` |
| 203 | +6. Verify install: |
| 204 | + ```bash |
| 205 | + npx create-polyglot --help |
| 206 | + ``` |
| 207 | + |
| 208 | +--- |
| 209 | +## 14. Issue Reporting & Pull Request Workflow |
| 210 | +**Issues:** |
| 211 | +- Use the issue template (if/when added). |
| 212 | +- Provide: environment (OS, Node version), command run, reproduction steps, expected vs actual. |
| 213 | + |
| 214 | +**Pull Requests Checklist:** |
| 215 | +- One focused change per PR. |
| 216 | +- Updated docs / README / CONTRIBUTING sections if behavior changes. |
| 217 | +- Ran a local scaffold test (`node bin/index.js test -s node --no-install --force`). |
| 218 | +- No large unrelated formatting diffs. |
| 219 | + |
| 220 | +**Review Tips:** Split big refactors into multiple smaller PRs whenever possible. |
| 221 | + |
| 222 | +--- |
| 223 | +## 15. Security / Responsible Disclosure |
| 224 | +If you discover a security issue (e.g., command injection risk in generator inputs), **do not** open a public issue immediately. Instead contact the maintainer (add contact method in README or via GitHub security advisories once configured). Provide clear reproduction details. |
| 225 | + |
| 226 | +--- |
| 227 | +## 16. Roadmap / Ideas |
| 228 | +- Add additional language templates: Rust (Axum), .NET (Minimal API), PHP (Laravel Octane lightweight variant), Deno/Fresh. |
| 229 | +- Configurable port allocation & detection of conflicts. |
| 230 | +- Pluggable recipe system (YAML describing services & generators). |
| 231 | +- Telemetry (opt-in) for anonymized feature usage. |
| 232 | +- `--with-ci github-actions` to generate workflow. |
| 233 | +- Test harness & code coverage. |
| 234 | +- Multi-stage infra: generate k8s manifests or helm charts. |
| 235 | +- Monorepo plugin system for custom user templates in `~/.config/create-polyglot/templates`. |
| 236 | + |
| 237 | +--- |
| 238 | +## Questions / Help |
| 239 | +Open an issue or start a discussion. PRs welcome! |
| 240 | + |
| 241 | +Happy building 🌟 |
0 commit comments