/ts-node-tmpl

TypeScript and Node.js template

Primary LanguageTypeScript

ts-node-template

TypeScriptを利用してnode.jsの開発を行うためのテンプレートです。
主に次のものをサポートしています。

  • TypeScript
  • jest
  • eslint
  • prettier
  • typedoc

dependencies modules.

次のモジュールは package.json で管理しています。

dependencies

devDependencies

  • 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 を実行します。

設定

各モジュールの設定について説明します。

tsc

  • 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のバージョンによって targetlib は変更して下さい。

Node.js version target lib
v12.9 ES2019 ES2020
v14 ES2020 ES2020

設定ファイル

jest

  • ts-jest有効化
  • モッククリア有効化
  • モジュールのパスエリアス設定 /src/foo.ts -> @/foo.ts

設定ファイル

eslint

  • eslint:recommended有効化
  • typescript-eslint有効化
  • prettier有効化

設定ファイル

prettier

  • eslintのrulesを参照

設定ファイル

husky

  • git commit前にlintを実行する

設定ファイル

lint-staged

  • 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

参考