1.0.0 • Published 5 years ago

typescript-library-starter v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Typescript Library Starter

greenkeeper badge Build Status codecov: percent commitizen: friendly code style: prettier semantic-release linter: eslint docs: gh-pages

This project provides the boilerplate for starting a typescript library to be hosted on npm.

Recommended Editor

You should be using Visual Studio Code because its simple, fast, extensible and beloved by many developers.

Make sure to install all the recommended extensions that come with the repository for the best possible coding experience.

NPM Scripts

Note that these examples use yarn but you can use the equivalent npm run <command> instead.

Most of these commands will automatically run when you perform certain actions on the repository.

Code style

Ensures code consistency in your code base. They automatically get run before commits.

  • yarn style - Runs all the style commands.
  • yarn style:lint - Lints your code using eslint.
  • yarn style:format - Formats your code using prettier.

Build Tasks

Creates builds from your Typescript files.

  • yarn build - Runs all build commands to create builds for different node environments.
  • yarn build:main - Creates a build using CommonJS (cjs) modules.
  • yarn build:module - Creates a build using ES6 modules (esm).

Testing

Tasks to run jest tests to ensure your code is reliable.

Tests will automatically run before commits.

  • yarn test - Runs all tests and generates a code coverage report.
  • yarn test:watch - Watches file changes and reruns tests for those changed files.

Code Coverage

Tasks for generating and publishing code coverage reports.

If you sign up to travis and codecov these reports automatically get published after successful builds.

  • yarn cov - Generate a code coverage report.
  • yarn cov:open - Open generated code coverage report.
  • yarn cov:publish - Publish generated code coverage reports to codecov.

Documentation

Tasks for generating and publishing documentation based on your typedoc comments.

If you sign up to travis, docs automatically get published to github pages after successful builds.

  • yarn doc - Generates documentation from code.
  • yarn doc:open - Opens generated documentation in your default browser.
  • yarn doc:publish - Publishes generated documentation.

Helpers

These commands perform misc tasks.

  • yarn commit - Create a new commit using the commitizen cli.
  • yarn clean - Cleans up all build artifacts such as the distribution folder.

Conventional Commits

Commit messages to this repository that don't follow the conventional commit guidelines will be rejected by a commit-msg git hook.

No one likes rejection so please use the yarn commit script which provides a CLI interface for creating formated commits.

Git Hooks

If you would like to run custom tasks during important actions on a repository you can use git hooks.

To make this as simple as possible we use husky which is also used in the conventional commits toolchain.

Debugging

The following launch configurations will assist with debugging your library.

  • Current TS File - debug current typescript file.
  • Current Jest Test - debug current jest test.
  • All Jest Tests - debug all jest tests.

Continuous Integration

You can vet and automate a project build pipeline using a continuous integration service.

As it so happens, developers love automation so we set up Travis CI for this repository.

To get started register your repository on travis and push to the master branch.

The default CI pipeline starts off with validating your code by running tests.

If Travis is pleased it will then publish your artifacts and finally your build to npm using semantic release.

You will need to add some environment variables to travis to enable semantic releases, see their docs for more on getting started.

You can change the CI pipeline by configuring the .travis.yml file and the release options by configuring .releaserc.json.

Greenkeeper

Greenkeeper is a service that will keep your dependencies up to date to avoid dependency related issues.

Make sure to enable this service on your repository for peace of mind.

Special Sauce

Collect many badges to give your readme that that special something something 😎.

Once you have travis and codecov set up make sure to add their badges on your readme.

You can also create your own badges to link to any important resources such as your documentation.

Refer to the badges in this readme for examples.