tswatch/ts/tswatch.classes.tswatch.ts

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-10-28 00:48:43 +00:00
import * as plugins from './tswatch.plugins';
2019-05-08 22:08:40 +00:00
import * as paths from './tswatch.paths';
import * as interfaces from './interfaces';
2018-10-28 00:48:43 +00:00
2019-05-08 22:08:40 +00:00
import { Watcher } from './tswatch.classes.watcher';
2018-10-28 18:28:08 +00:00
2018-10-28 00:48:43 +00:00
export class TsWatch {
2019-05-08 22:08:40 +00:00
public watchmode: interfaces.TWatchModes;
public watcherMap = new plugins.lik.Objectmap<Watcher>();
2018-10-28 00:48:43 +00:00
2019-05-08 22:08:40 +00:00
constructor(watchmodeArg: interfaces.TWatchModes) {
this.watchmode = watchmodeArg;
2018-10-28 00:48:43 +00:00
}
/**
2019-05-08 22:08:40 +00:00
* starts the TsWatch instance
2018-10-28 00:48:43 +00:00
*/
2019-05-08 22:08:40 +00:00
public async start () {
switch (this.watchmode) {
case 'test':
const tsWatchInstanceTest = new Watcher({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2',
timeout: null
});
this.watcherMap.add(tsWatchInstanceTest);
break;
case 'gitzone_npm':
const tsWatchInstanceGitzoneNpm = new Watcher({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test',
timeout: null
});
this.watcherMap.add(tsWatchInstanceGitzoneNpm);
break;
case 'gitzone_website':
const tsWatchInstanceGitzoneWebsite = new Watcher({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test',
timeout: null
});
this.watcherMap.add(tsWatchInstanceGitzoneWebsite);
break;
case 'echoSomething':
const tsWatchInstanceEchoSomething = new Watcher({
filePathToWatch: paths.cwd,
commandToExecute: 'npm -v',
timeout: null
});
this.watcherMap.add(tsWatchInstanceEchoSomething);
break;
default:
break;
2018-10-28 00:48:43 +00:00
}
2019-05-08 22:08:40 +00:00
this.watcherMap.forEach(async watcher => {
await watcher.start();
});
2018-10-28 00:48:43 +00:00
}
/**
2019-05-08 22:08:40 +00:00
* stops the execution of any active Watchers
2018-10-28 00:48:43 +00:00
*/
2019-05-08 22:08:40 +00:00
public async stop () {
this.watcherMap.forEach(async watcher => {
await watcher.stop();
})
2018-10-28 00:48:43 +00:00
}
}