tsc-watch
The TypeScript compiler with onSuccess command
Last updated 16 days ago by gilamran .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install tsc-watch 
SYNC missed versions from official npm registry.

Build Status

The nodemon for TypeScript

tsc-watch starts a TypeScript compiler with --watch parameter, with the ability to react to compilation status. tsc-watch was created to allow an easy dev process with TypeScript. Commonly used to restart a node server, similar to nodemon but for TypeScript.

Argument Description
--onSuccess COMMAND Executes COMMAND on every successful compilation.
--onFirstSuccess COMMAND Executes COMMAND on the first successful compilation.
--onFailure COMMAND Executes COMMAND on every failed compilation.
--onCompilationComplete COMMAND Executes COMMAND on every successful or failed compilation.
--noColors By default tsc-watch adds colors the output with green
on success, and in red on failiure.
Add this argument to prevent that.
--noClear In watch mode the tsc compiler clears the screen before reporting
Add this argument to prevent that.
--compiler PATH The PATH will be used instead of typescript compiler.
Default is typescript/bin/tsc

Notes:

  • That all the above COMMANDs will be killed on process exit. (Using SIGTERM)

  • A COMMAND is a single command and not multi command like script1.sh && script2.sh

  • Any child process (COMMAND) will be terminated before creating a new one.

Install

npm install tsc-watch --save-dev

Usage

From Command-Line

## Watching a project (with tsconfig.json)
tsc-watch --onSuccess "node ./dist/server.js"

## Beep on failure
tsc-watch --onFailure "echo Beep! Compilation Failed"

## Wathcing a single file
tsc-watch server.ts --outDir ./dist --onSuccess "node ./dist/server.js"

## Custom compiler
tsc-watch --onSuccess "node ./dist/server.js" --compiler my-typescript/bin/tsc

From Code

The client is implemented as an instance of Node.JS's EventEmitter, with the following events:

  • first_success - Emitted upon first successful compilation.
  • subsequent_success - Emitted upon every subsequent successful compilation.
  • compile_errors - Emitted upon every failing compilation.

Once subscribed to the relevant events, start the client by running watch.start()

To kill the client, run watch.kill()

Example usage:

const TscWatchClient = require('tsc-watch/client');
const watch = new TscWatchClient();

watch.on('first_success', () => {
  console.log('First success!');
});

watch.on('success', () => {
  // Your code goes here...
});

watch.on('compile_errors', () => {
  // Your code goes here...
});

watch.start('--project', '.');

try {
  // do something...
} catch (e) {
  watch.kill(); // Fatal error, kill the compiler instance.
}

Notes:

  • The (onSuccess) COMMAND will not run if the compilation failed.
  • tsc-watch is using the currently installed TypeScript compiler.
  • tsc-watch is not changing the compiler, just adds the new arguments, compilation is the same, and all other arguments are the same.

Current Tags

  • 4.2.9                                ...           latest (16 days ago)
  • 4.2.0-rc1                                ...           next (4 months ago)

65 Versions

  • 4.2.9                                ...           16 days ago
  • 4.2.8                                ...           2 months ago
  • 4.2.7                                ...           2 months ago
  • 4.2.6                                ...           2 months ago
  • 4.2.5                                ...           2 months ago
  • 4.2.4                                ...           2 months ago
  • 4.2.3                                ...           4 months ago
  • 4.2.2                                ...           4 months ago
  • 4.2.1                                ...           4 months ago
  • 4.2.0                                ...           4 months ago
  • 4.2.0-rc1                                ...           4 months ago
  • 4.1.0                                ...           6 months ago
  • 4.0.0                                ...           10 months ago
  • 3.0.2                                ...           10 months ago
  • 3.0.1                                ...           10 months ago
  • 3.0.0                                ...           10 months ago
  • 2.4.0                                ...           a year ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 1.1.39                                ...           a year ago
  • 1.1.38                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.1.37                                ...           a year ago
  • 1.1.36                                ...           a year ago
  • 1.1.35                                ...           a year ago
  • 1.1.34                                ...           a year ago
  • 1.1.33                                ...           a year ago
  • 1.1.32                                ...           a year ago
  • 1.0.32                                ...           a year ago
  • 1.0.31                                ...           2 years ago
  • 1.0.30                                ...           2 years ago
  • 1.0.29                                ...           2 years ago
  • 1.0.28                                ...           2 years ago
  • 1.0.27                                ...           2 years ago
  • 1.0.26                                ...           2 years ago
  • 1.0.25                                ...           2 years ago
  • 1.0.24                                ...           2 years ago
  • 1.0.23                                ...           2 years ago
  • 1.0.22                                ...           2 years ago
  • 1.0.21                                ...           2 years ago
  • 1.0.20                                ...           2 years ago
  • 1.0.19                                ...           2 years ago
  • 1.0.18                                ...           2 years ago
  • 1.0.17                                ...           2 years ago
  • 1.0.16                                ...           2 years ago
  • 1.0.15                                ...           2 years ago
  • 1.0.14                                ...           2 years ago
  • 1.0.13                                ...           3 years ago
  • 1.0.12                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago

Copyright 2014 - 2016 © taobao.org |