Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion typescript-node/.nvmrc

This file was deleted.

2 changes: 2 additions & 0 deletions typescript-node/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node 22
yarn 3
Binary file removed typescript-node/.yarn/install-state.gz
Binary file not shown.
28 changes: 21 additions & 7 deletions typescript-node/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
# TypeScript

Skeleton project for TypeScript (via NodeJS) with Jest for testing.
Skeleton project for TypeScript (via NodeJS).

## Usage
- `./script/setup` to install dependencies
- `./script/test` to run the tests
## Prerequisites

The toolchain this project needs is declared in [`.tool-versions`](./.tool-versions):

```
node 22
yarn 3
```

### Other commands
- `yarn watch` will constantly compile `index.ts` then execute the compiled version on every file change (for quick development feedback loop) using [tsc-watch](https://www.npmjs.com/package/tsc-watch) under the hood.
Install those however you prefer, as long as they end up on your `PATH`. The quickest route is
[mise](https://mise.jdx.dev/), which reads the file for you:

```sh
mise install
```

## Usage
- `./script/setup` to fetch dependencies
- `./script/test` to run the tests, or `./script/test --watch` to re-run them on every change
- `./script/start` to run the app (watches for changes and recompiles automatically)

## Structure
- Code located in [`index.ts`](./src/index.ts)
- Tests located in [`index.test.ts`](./src/index.test.ts)

However, you're free to organise your code as you like.
However, you're free to organise your code as you like.
3 changes: 2 additions & 1 deletion typescript-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"scripts": {
"test": "jest",
"tsc": "tsc",
"watch": "tsc-watch --onSuccess 'node ./dist/index.js' --onFailure 'echo Beep! Compilation Failed' --compiler typescript/bin/tsc"
"watch": "tsc-watch --onSuccess 'node ./dist/index.js' --onFailure 'echo Beep! Compilation Failed' --compiler typescript/bin/tsc",
"start": "tsc && node ./dist/index.js"
},
"devDependencies": {
"@guardian/tsconfig": "0.2.0",
Expand Down
4 changes: 3 additions & 1 deletion typescript-node/script/setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."

yarn
11 changes: 11 additions & 0 deletions typescript-node/script/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."

if [[ "${1:-}" == "--watch" ]]; then
yarn watch
else
yarn start
fi
Loading