Giter Club home page Giter Club logo

tsc-watch's Introduction

Build Status

The TypeScript compiler with --onSuccess argument

tsc-watch starts a TypeScript compiler with --watch parameter, there are 5 new arguments.

  • --onSuccess COMMAND - The COMMAND will be executed on every successful TypeScript compilation. The process will be killed and restarted on every successful compilation.
  • --onFirstSuccess COMMAND - The COMMAND will be executed only one time, on the first successful TypeScript compilation, it will not get killed on every success.
  • --onFailure COMMAND - The COMMAND will be executed on failed TypeScript compilation.
  • --noColors - tsc-watch 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, using this option will prevent that.
  • --compiler PATH - The PATH will be used instead of typescript compiler. Defaults typescript/bin/tsc.

Notes:

  • That all the above COMMANDs will be killed on process exit.
  • A COMMAND is a single command and not multi command like script1.sh && script2.sh

Install

npm install tsc-watch --save-dev

Usage

From Command-Line

## Compiles the server.ts into the dist folder and run it
tsc-watch server.ts --outDir ./dist --onSuccess "node ./dist/server.js" --onFailure "echo Beep! Compilation Failed" --compiler typescript/bin/tsc

## With tsconfig.json
tsc-watch --onSuccess "node ./dist/server.js" --onFailure "echo Beep! Compilation Failed" --compiler 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.
  • Any child process (COMMAND) will be terminated before creating a new one.
  • 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.
  • tsc-watch was created to allow an easy dev process with TypeScript. Commonly used to restart a node server.

tsc-watch's People

Contributors

asapien avatar barkayal avatar boyanio avatar ddunkin avatar frank-orellana avatar galkin avatar gilamran avatar hwwi avatar igrayson avatar jonaskello avatar roblav96 avatar sosoba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.