3.2 KiB
Pegasus typescript template
Template for typescript, node.js projects in Pegasus. The template defines typescript settings, folder structure and testing setup.
TBD: to use on new project we could just copy the whole repo and "search and replace" typescript-template with the new projects name.
- But maybe there is a cleaner method?
Setup
Set up your machine as described in dev-environment - setup.
Coding standards
Cases
For repositories, files and routes we use kebab-case.
For variables and functions we use camelCase.
For classes, types and interfaces we use PascalCase.
For global constants we use SCREAMING_SNAKE_CASE.
Biome.js
Uses rules defined in biome.json for linting & formatting.
Husky
Uses git hooks to automatically lint & format on every commit. If you want to skip hooks to commit anything that's WIP, use the "-n" flag (--no-verify).
Run locally
Bare metal
We expect node.js v22. Run npm install before.
Scripts that can be used bare metal:
npm run typechecknpm run typecheck:devnpm run test:unit
Docker
Option 1: run the app with dev-environment
Option 2: run the included test docker-compose:
- Have docker and compose installed.
- Create
.envfile in root of repo with content
replaceALICORN_NPM_TOKEN=<YOUR_TOKEN><YOUR_TOKEN>with an access token as described in dev-environment - Choose one of the Scripts to start docker compose:
npm run test:docker(startstest:dev)npm run test:docker:sh(starts into interactive shell)
Inside the docker container you can also use following scripts:
npm run test(unit and integration tests)npm run test:dev(watch and inspect/debug)npm run test:integrationnpm run coverage
Discussion points
src/globalholds global plugins like redis currently- was named
src/pluginspreviously, but everything is a plugin in fastify, so too ambiguous in my opinion src/sharedcould be an alternative name like in vastproxy-ts- other names?
- was named
- Folderstructure is currently "by feature" and not "by type"
- I prefer "by feature"
- I know Philipp prefers "by type"
- see also: https://softwareengineering.stackexchange.com/questions/338597/folder-by-type-or-folder-by-feature
- test naming scheme
*.(unit|integration).test.ts- could switch to
*.test.(unit|integration).ts: test will stick together sorted alphabetically, but vscode default config would not detect them as test file. - other naming other structure?
- could switch to
- test location currently with source files
- alternative: rebuild
srcfolder structure undertesthave tests there. Less clutter insrc, but tests are more far away -> more cumbersome when doing changes where you have to adjust/add tests
- alternative: rebuild
- integration tests use real redis, mongodb etc.
- that means integration tests can only be executed in docker-compose or other environments where real databases, etc. are configured
- we could instead always mock, so we could execute integration locally
- more work
- not testing the real thing