diff --git a/typescript-node/.nvmrc b/typescript-node/.nvmrc deleted file mode 100644 index b009dfb..0000000 --- a/typescript-node/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -lts/* diff --git a/typescript-node/.tool-versions b/typescript-node/.tool-versions new file mode 100644 index 0000000..e2d8fff --- /dev/null +++ b/typescript-node/.tool-versions @@ -0,0 +1,2 @@ +node 22 +yarn 3 diff --git a/typescript-node/.yarn/install-state.gz b/typescript-node/.yarn/install-state.gz deleted file mode 100644 index 599ea7c..0000000 Binary files a/typescript-node/.yarn/install-state.gz and /dev/null differ diff --git a/typescript-node/README.md b/typescript-node/README.md index 3d2ea8d..c52f962 100644 --- a/typescript-node/README.md +++ b/typescript-node/README.md @@ -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. diff --git a/typescript-node/package.json b/typescript-node/package.json index e2b1801..4f925b2 100644 --- a/typescript-node/package.json +++ b/typescript-node/package.json @@ -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", diff --git a/typescript-node/script/setup b/typescript-node/script/setup index d302646..e2cee61 100755 --- a/typescript-node/script/setup +++ b/typescript-node/script/setup @@ -1,5 +1,7 @@ #!/usr/bin/env bash -set -e +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." yarn diff --git a/typescript-node/script/start b/typescript-node/script/start new file mode 100755 index 0000000..4e750b0 --- /dev/null +++ b/typescript-node/script/start @@ -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