generator-typescript-package

Yet another Yeoman generator for TypeScript packages

Usage no npm install needed!

<script type="module">
  import generatorTypescriptPackage from 'https://cdn.skypack.dev/generator-typescript-package';
</script>

README

generator-typescript-package

License Build status Code Coverage NPM Package NPM Downloads

A yeoman generator for TypeScript packages with best practices

Features

Note: there has been no explicit compatibility testing for Windows development-environments

Install

npm install -g generator-typescript-package

Use

Create a directory for the new package, cd inside and generate the package skeleton with

yo typescript-package [--lerna] [--bin]
git commit -m 'Initial commit'

Finally, address each TODO: statement in the generated project.

Options

lerna

default: false

Generate a package in a lerna mono-repo. This package is expected to be built with TypeScript 3.0's build mode.

bin

default: false

Define an executable file under the bin section in the package.json.

Test

Test the generated package

npm test

Or use watch-mode and run tests when files are modified

npm run watch:ava
npm run watch:ava:fail-fast  # stops printing on first test-failure

Configuring Integrations

Travis CI

Supports: GitHub repositories

Just enable Travis CI for your new github repository and on each push ci will run automatically.

Travis CI Deploys to NPM

Supports: GitHub repositories

The generated travis.yml file will automatically deploy your package to NPM, if configured with an NPM auth-token, on builds meeting the following criteria:

  • travis-ci is building a commit to the master branch
  • the commit includes a git tag (which is added automatically by npm version)
  • travis-ci is not building a pull-request commit
  • travis-ci environment variable NPM_TOKEN has been defined

All you have to do to enable this feature is define the variable NPM_TOKEN in Travis CI's repository settings. You can determine your NPM auth-token with the following shell command

cat ~/.npmrc | grep _authToken | cut -d'=' -f2

Note: ~/.npmrc is created by the npm login command

A workflow leveraging this auto-publication could then resemble:

  1. develop changes on a feature-branch
  2. commit changes
  3. use npm version to bump version
  4. push feature-branch
  5. open a pull-request to master
  6. approve the pull-request after ci passes

Note: if NPM_TOKEN is not defined ci will skip the deploy stage without breaking