A minimal Yeoman Generator for creating NodeJS modules using TypeScript
JavaScript TypeScript
Latest commit ffdfaab Jul 19, 2017 @ospatil 3.1.0

README.md

TypeScript NodeJS Generator

Build Status npm version

For my 1.x release documentation for TypeScript 1.8, refer to readme file for 1.x release.

I'm a minimal Yeoman generator for creating NodeJS packages using TypeScript. I let you quickly setup a project with latest available tools and best practices.

I use:

  • npm - as task runner. You can choose to use gulp instead.
  • tslint - as linter for TypeScript source files.
  • ava - as testing framework to write specs in TypeScript itself. You can choose to use mocha instead.
  • nyc - a JavaScript code coverage tool working on TypeScript files.

You want to know if you can change any of these? Of course, why not? It is your package after all. I simply get down to business of generating, no questions asked. Once done, I get out of the way and you can do as you please!

Usage

Install generator-node-typescript globally. If you are planning to use gulp, install gulp-cli globally.

$npm install -g generator-node-typescript

Create a new directory and cd into it.

$mkdir my-new-project && cd $_

Run the generator.

$yo node-typescript

You can choose to use gulp as your build system using command - $yo node-typescript --gulp

You can choose to use mocha as your test framework using command - $yo node-typescript --mocha

Run npm run for information on available tasks.

 $npm run
Lifecycle scripts included in ts-node-ava:
  prepublish
    npm run build
  test
    npm run clean && tsc -p tsconfig.test.json --pretty && nyc --exclude "**/*-spec.js" ava "**/*-spec.js" --verbose

available via `npm run-script`:
  clean
    rimraf lib && rimraf coverage && rimraf .nyc_output && rimraf lib_test
  format
    prettier --write "{src,test}/**/*.ts"
  lint
    tslint --force --format verbose "src/**/*.ts"
  prebuild
    npm run clean && npm run format && npm run lint && echo Using TypeScript && tsc --version
  build
    tsc --pretty
  coverage
    nyc report --reporter=lcov --reporter=text --reporter=html
  watch
    npm run build -- --watch
  watch:test
    npm run test -- --watch

If you choose to use gulp, you can find the available tasks using command gulp help.

$gulp help

Usage
  gulp [TASK] [OPTIONS...]

Available tasks
  build  Compiles all TypeScript source files [lint]
  clean  Cleans the generated js files from lib directory
  help   Display this help text.
  lint   Lints all TypeScript source files
  test   Runs the mocha test specs [build]
  watch  Watches ts source files and runs build on change

Highlights of the latest release

  • I use latest version of TypeScript.
  • I use yarn in place of npm if it is already installed on your machine.
  • I use ava which is a Futuristic JavaScript test runner as testing framework (optionally mocha). Also, one of the most important things regarding testing is you can write tests in TypeScript itself.
  • I use prettier integrated with tslint to provide no-fuss code formatting and linting.
  • I need no global dependencies. Every dependency such as TypeScript and tslint is installed as local dev dependency allowing you to freely use different versions of these for different modules.
  • I provide test coverage support using nyc.
  • I provide nice integration with VS Code editor. I configure build, clean, lint, coverage, 'format' and test tasks that you can run using Run Task option.
  • You can directly run the currently open TypeScript file in VS Code using task ts-node: Run current file. I use ts-node to provide this functionality.

License

MIT