Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
843453f9d4 | |||
9b6e3e49f4 | |||
c24c272f6e | |||
4b8bb062c7 |
798
package-lock.json
generated
798
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@gitzone/tswatch",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.4",
|
||||
"private": false,
|
||||
"description": "watch typescript projects during development",
|
||||
"main": "dist/index.js",
|
||||
@@ -8,23 +8,24 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "node ./cli.ts.js test",
|
||||
"test": "node ./cli.ts.js test --timeout 10000",
|
||||
"test2": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tstest": "^1.0.20",
|
||||
"@pushrocks/tapbundle": "^3.0.9",
|
||||
"@types/node": "^12.0.0",
|
||||
"tslint": "^5.16.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gitzone/tsrun": "^1.1.13",
|
||||
"@pushrocks/smartcli": "^3.0.6",
|
||||
"@pushrocks/smartshell": "^2.0.6",
|
||||
"@gitzone/tsrun": "^1.2.6",
|
||||
"@pushrocks/smartcli": "^3.0.7",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartshell": "^2.0.13",
|
||||
"filewatcher": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
@@ -6,11 +6,13 @@ let testTsWatchInstance: tswatch.TsWatch;
|
||||
tap.test('should create a valid TsWatch instance', async () => {
|
||||
testTsWatchInstance = new tswatch.TsWatch({
|
||||
filePathToWatch: process.cwd(),
|
||||
commandToExecute: 'npm -v'
|
||||
commandToExecute: 'npm -v',
|
||||
timeout: 1000
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should start the tswatch instance', async () => {
|
||||
testTsWatchInstance.start();
|
||||
console.log('test executed');
|
||||
});
|
||||
|
||||
|
@@ -1,5 +1,11 @@
|
||||
import * as plugins from './tswatch.plugins';
|
||||
|
||||
export interface ITsWatchConstructorOptions {
|
||||
filePathToWatch: string;
|
||||
commandToExecute: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* handles the management of watching for foes
|
||||
*/
|
||||
@@ -9,15 +15,10 @@ export class TsWatch {
|
||||
});
|
||||
private currentExecution: plugins.smartshell.IExecResultStreaming;
|
||||
private watcher = plugins.fileWatcher();
|
||||
private filePathToWatch: string;
|
||||
private commandToExecute: string;
|
||||
private options: ITsWatchConstructorOptions;
|
||||
|
||||
constructor(optionsArg: {
|
||||
filePathToWatch: string,
|
||||
commandToExecute: string
|
||||
}) {
|
||||
this.filePathToWatch = optionsArg.filePathToWatch;
|
||||
this.commandToExecute = optionsArg.commandToExecute;
|
||||
constructor(optionsArg: ITsWatchConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,8 +26,8 @@ export class TsWatch {
|
||||
*/
|
||||
public async start() {
|
||||
this.setupCleanup();
|
||||
console.log(`Looking at ${this.filePathToWatch} for changes`);
|
||||
this.watcher.add(this.filePathToWatch); // __dirname refers to the directory of this very file
|
||||
console.log(`Looking at ${this.options.filePathToWatch} for changes`);
|
||||
this.watcher.add(this.options.filePathToWatch); // __dirname refers to the directory of this very file
|
||||
this.watcher.on('change', async (file, stat) => {
|
||||
console.log('Noticed change!');
|
||||
if (!stat) {
|
||||
@@ -41,14 +42,14 @@ export class TsWatch {
|
||||
if (this.currentExecution) {
|
||||
process.kill(-this.currentExecution.childProcess.pid);
|
||||
}
|
||||
this.currentExecution = await this.smartshellInstance.execStreaming(this.commandToExecute);
|
||||
this.currentExecution = await this.smartshellInstance.execStreaming(this.options.commandToExecute);
|
||||
this.currentExecution = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method sets up a clean exit strategy
|
||||
*/
|
||||
private setupCleanup() {
|
||||
private async setupCleanup() {
|
||||
const cleanup = () => {
|
||||
if (this.currentExecution) {
|
||||
process.kill(-this.currentExecution.childProcess.pid);
|
||||
@@ -66,5 +67,14 @@ export class TsWatch {
|
||||
cleanup();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// handle timeout
|
||||
if (this.options.timeout) {
|
||||
plugins.smartdelay.delayFor(this.options.timeout).then(() => {
|
||||
console.log(`timed out afer ${this.options.timeout} milliseconds! exiting!`);
|
||||
cleanup();
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,15 @@ const tswatchCli = new plugins.smartcli.Smartcli();
|
||||
tswatchCli.addCommand('test').subscribe(argvArg => {
|
||||
const tsWatch = new TsWatch({
|
||||
filePathToWatch: paths.cwd,
|
||||
commandToExecute: 'npm run test2'
|
||||
commandToExecute: 'npm run test2',
|
||||
timeout: (() => {
|
||||
if (argvArg.timeout) {
|
||||
console.log(`timeing out after ${argvArg.timeout}`);
|
||||
return argvArg.timeout;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})()
|
||||
});
|
||||
tsWatch.start();
|
||||
});
|
||||
|
@@ -3,9 +3,10 @@ export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartcli from '@pushrocks/smartcli';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartshell from '@pushrocks/smartshell';
|
||||
|
||||
export { smartshell, smartcli };
|
||||
export { smartdelay, smartshell, smartcli };
|
||||
|
||||
// Third Pary
|
||||
import * as fileWatcher from 'filewatcher';
|
||||
|
Reference in New Issue
Block a user