TypeScriptを利用してnode.jsの開発を行うためのテンプレートです。
主に次のものをサポートしています。
- TypeScript
- jest
- eslint
- prettier
- typedoc
次のモジュールは package.json で管理しています。
- typescript
- tsc-alias
- ts-node
- ts-node-dev
- tsconfig-paths
- jest
- ts-jest
- babel-jest
- eslint
- eslint-config-prettier
- eslint-plugin-prettier
- eslint-plugin-jest
- prettier
- typedoc
- @types/jest
- @babel/core
- @babel/preset-env
- @babel/preset-typescript
- @typescript-eslint/parser
- @typescript-eslint/eslint-plugin
- rimraf
- husky
- lint-staged
- Linux / MacOS
- Node.js v12.9 or latter
- yarn
git clone
したディレクトリ内で yarn
を実行します。
各モジュールの設定について説明します。
- ES2019
- CommonJS
- Java Scriptのコードを許可
- 型チェックなどのオプションの無効化
- noImplicitAny
- strictNullChecks
- strictFunctionTypes
- strictBindCallApply
- strictPropertyInitialization
- noImplicitThis
- noUnusedParameters
- nodeモジュール
- モジュールのパスエリアス設定
/src/foo.ts
->@/foo.ts
ts-node
でパスエリアスを有効にするには、tsconfig-paths
が必要.tsc
でパスエリアスを有効にするには、tsc-alias
が必要.
なお利用するNode.jsのバージョンによって target
と lib
は変更して下さい。
Node.js version | target | lib |
---|---|---|
v12.9 | ES2019 | ES2020 |
v14 | ES2020 | ES2020 |
- ts-jest有効化
- モッククリア有効化
- モジュールのパスエリアス設定
/src/foo.ts
->@/foo.ts
- eslint:recommended有効化
- typescript-eslint有効化
- prettier有効化
- eslintのrulesを参照
- git commit前にlintを実行する
- gitのステージに上がっているファイルに対し、eslintを実行する
出力ディレクトリは ./dist
です。
yarn clean
yarn build
トランスパイルしたコードでアプリケーションを実行します。
yarn start
yarn dev
コードの修正を検知して再実行したい場合はこちらです。
yarn dev:watch
yarn test
カバレッジを確認する場合はこちらです。
yarn test:cov
yarn lint
チェックと同時に問題を修正します。
yarn lint:fix
yarn typedoc