DEV Community

Cover image for Typescript Node Module Starter Template
Ivan V.
Ivan V.

Posted on • Edited on

Typescript Node Module Starter Template

Archived

This post and accompanying repository have been archived. However, there is a new repository (starter template) which includes Typescript, Babel, Jest and Rollup configuration.

Github template repository for quickly starting new node modules with typescript.

Are you tired of setting up TypeScript and other dependencies before even writing a single line of code? I am, so I have decided to create a small template repository with some of the tools that I use for everyday development.

You can go check out the repository on github or continue reading to learn about included tasks, continuous integration, git hooks etc.

What's Inside

  • Typescript is set to strict configuration with source map generation.
  • ESLint is set up to use standardJS configuration for typescript, with a few overrides which I think make good common sense. You can see the overrides inside the .eslintrc.js file.
  • Unit testing is done via Jest in combination with ts-jest
  • Prettier configuration with a few custom rules.
  • Code coverage.

Tasks

  • prepublishOnly: run before publishing the module to npm.
  • build: build typescript.
  • build:watch: build and watch typescript for changes.
  • test: run all tests and generate code coverage.
  • test:watch: run and watch tests for changes (with typeahead feature)
  • ci:test task that is executed by the continuous integration provider (CircleCI) runs tests and uploads code coverage.
  • format: format all files with prettier (tests and src directories).

  • fix:src: run ESLint on src directory with --fix flag.

  • fix:tests: run ESLint on tests directory with --fix flag.

  • fix: run fix:src and fix:tests task in parallel.

  • docs: generate typescript documentation via typedoc

Continous Integration

CircleCI is used for continuous integration.
Tests are run for node versions 8, 10 and 12.

CircleCI is also set up to upload code coverage to codecov.io however you can also use coveralls for code coverage ( it's currently commented out).

Git Hooks

There is one git hook setup via husky package in combination with lint-staged. Before committing the files all staged files will be run through ESLint and Prettier.

Debugging

If you are using VS Code as your editor,
there is one debug configuration which is set up to debug currently focused test file inside the editor.

Typescript Documentation Generator

Typescript documentation is generated via typedoc.
Currently, it is set up to go into docs/api directory and it is generated in markdown so it can be displayed on Github.

  • Private members are excluded.
  • Only exported properties are documented.

Conclusion

This repository template has provided me a quick way to start working on a node module with typescript. Feel free to fork the repository and create your version of the template. For example, you can replace StandardJS with Airbnb style guide.

I hope you find it useful.

Top comments (0)