1.0.37 • Published 7 years ago
watch-tsc v1.0.37
The TypeScript compiler with --watch and a new onSuccess argument
tsc-watch starts the tsc (TypeScript compiler) with --watch parameter, there are 3 new arguments.
--onSuccess COMMAND- TheCOMMANDwill be executed on every successful TypeScript compilation.--onFirstSuccess COMMAND- TheCOMMANDwill be executed only one time, on the first successful TypeScript compilation.--onFailure COMMAND- TheCOMMANDwill be executed on failed TypeScript compilation.--noColors-tsc-watchcolors the output with green on success, and in red on failiure. Add this argument to prevent that.
Install
npm install tsc-watch --save-devUsage
From Command-Line
tsc-watch server.ts --outDir ./dist --onSuccess "node ./dist/server.js" --onFailure "echo Beep! Compilation Failed"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 watch = require('tsc-watch/client');
watch.on('first_success', () => {
console.log('First success!');
});
watch.on('subsequent_success', () => {
// Your code goes here...
});
watch.on('compile_errors', () => {
// Your code goes here...
});
watch.start();
try {
// do something...
} catch (e) {
watch.kill(); // Fatal error, kill the compiler instance.
}Notes:
- The (
onSuccess)COMMANDwill not run if the compilation failed. - Any child process (
COMMAND) will be terminated before creating a new one. tsc-watchis using the currently installed TypeScript compiler.tsc-watchis not changing the compiler, just adds the new arguments, compilation is the same, and all other arguments are the same.tsc-watchwas created to allow an easy dev process with TypeScript. Commonly used to restart a node server.