Comparing version 1.0.14 to 1.0.15
# @gilamran/tsc-watch CHANGELOG | ||
## v1.0.15 - 18/01/2018 | ||
* Added `--onFailure` argument | ||
## v1.0.14 - 18/01/2018 | ||
@@ -4,0 +7,0 @@ * Fixed Windows newline issue |
@@ -15,3 +15,4 @@ #!/usr/bin/env node | ||
const onFirstSuccessCommandSyntax = ' --onFirstSuccess COMMAND Run the COMMAND on the first successful compilation (Will not run the onSuccess)'; | ||
const newAdditionToSyntax = ['Watch input files. [always on]', onSuccessCommandSyntax, onFirstSuccessCommandSyntax].join('\n'); | ||
const onFailureCommandSyntax = ' --onFailure COMMAND Run the COMMAND on each failed compilation'; | ||
const newAdditionToSyntax = ['Watch input files. [always on]', onSuccessCommandSyntax, onFirstSuccessCommandSyntax, onFailureCommandSyntax].join('\n'); | ||
@@ -24,2 +25,4 @@ let hadErrors = false; | ||
let successProcessExited = null; | ||
let failureProcess = null; | ||
let failureProcessExited = null; | ||
@@ -48,2 +51,3 @@ function color(line) { | ||
.filter(arg => arg.toLowerCase() !== '--onsuccess') | ||
.filter(arg => arg.toLowerCase() !== '--onfailure') | ||
.filter(arg => arg.toLowerCase() !== '--onfirstsuccess'); | ||
@@ -68,3 +72,3 @@ } | ||
function killAllProcesses() { | ||
function killAllSuccessProcesses() { | ||
const promises = []; | ||
@@ -84,2 +88,13 @@ if (firstSuccessProcess) { | ||
function killFailureProcess() { | ||
const promises = []; | ||
if (failureProcess) { | ||
promises.push(killer(failureProcess).then(() => failureProcess = null)); | ||
promises.push(failureProcessExited.then(() => failureProcessExited = null)); | ||
} | ||
return Promise.all(promises); | ||
} | ||
let allArgs = process.argv; | ||
@@ -102,2 +117,10 @@ // onSuccess | ||
// onFailure | ||
let onFailureCommandIdx = getCommandIdx(allArgs, '--onFailure'); | ||
let onFailureCommand = null; | ||
if (onFailureCommandIdx > -1) { | ||
onFailureCommand = allArgs[onFailureCommandIdx + 1]; | ||
allArgs.splice(onFailureCommandIdx, 2) | ||
} | ||
let args = cleanArgs(allArgs); | ||
@@ -131,6 +154,15 @@ args.push('--watch'); // force watch | ||
if (hadErrors) { | ||
console.log('Had errors, not spawning'); | ||
Signal.emitFail(); | ||
killFailureProcess().then(() => { | ||
Signal.emitFail(); | ||
if (onFailureCommand) { | ||
failureProcess = runCommand(onFailureCommand); | ||
failureProcessExited = new Promise(resolve => { | ||
failureProcess.on('exit', code => { | ||
resolve(code); | ||
}); | ||
}); | ||
} | ||
}); | ||
} else { | ||
killAllProcesses().then(() => { | ||
killAllSuccessProcesses().then(() => { | ||
Signal.emitSuccess(); | ||
@@ -169,2 +201,2 @@ if (firstTime && onFirstSuccessCommand) { | ||
tscProcess.on('exit', killAllProcesses); | ||
tscProcess.on('exit', () => Promise.all([killAllSuccessProcesses(), killFailureProcess()])); |
{ | ||
"name": "tsc-watch", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"description": "The TypeScript compiler with onSuccess command", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# The TypeScript compiler with `--watch` and a new onSuccess argument | ||
`tsc-watch` starts the `tsc` (TypeScript compiler) with `--watch` parameter, it also adds a new argument `--onSuccess COMMAND`. this `COMMAND` will be executed on every successful TypeScript compilation. | ||
`tsc-watch` starts the `tsc` (TypeScript compiler) with `--watch` parameter, there are 3 new arguments. | ||
- `--onSuccess COMMAND` - The `COMMAND` will be executed on every successful TypeScript compilation. | ||
- `--onFirstSuccess COMMAND` - The `COMMAND` will be executed only one time, on the first successful TypeScript compilation. | ||
- `--onFailure COMMAND` - The `COMMAND` will be executed on failed TypeScript compilation. | ||
## Install | ||
@@ -15,3 +19,3 @@ | ||
```sh | ||
tsc-watch server.ts --outDir ./dist --onSuccess "node ./dist/server.ts" | ||
tsc-watch server.ts --outDir ./dist --onSuccess "node ./dist/server.ts" --onFailure "echo Beep! Compilation Failed" | ||
``` | ||
@@ -58,6 +62,6 @@ | ||
Notes: | ||
* The `COMMAND` will not run if the compilation failed. | ||
* The child process (`COMMAND`) will be terminated before creating a new one. | ||
* 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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15668
343
66