README
generator-typescript-package
A yeoman generator for TypeScript packages with best practices
Features
- supports scoped npm packages
- supports github
- supports gitlab
- supports lerna mono-repos
- continuous integration (travis-ci/gitlab-ci)
- runs tests in parallel with ava
- property-testing with fast-check
- code coverage (codecov)
- linting with typescript-eslint
- publishes only compiled JavaScript to npm (no typescript sources)
- automatic deploys to NPM if configured
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 thenpm login
command
A workflow leveraging this auto-publication could then resemble:
- develop changes on a feature-branch
- commit changes
- use
npm version
to bump version - push feature-branch
- open a pull-request to master
- approve the pull-request after ci passes
Note: if
NPM_TOKEN
is not defined ci will skip the deploy stage without breaking