fix(core): update

This commit is contained in:
2018-10-28 02:48:43 +02:00
commit fb382bba21
15 changed files with 1766 additions and 0 deletions

3
ts/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './tswatch.classes.tswatch';
import './tswatch.cli';

View File

@ -0,0 +1,70 @@
import * as plugins from './tswatch.plugins';
/**
* handles the management of watching for foes
*/
export class TsWatch {
private smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
private currentExecution: plugins.smartshell.IExecResultStreaming;
private watcher = plugins.fileWatcher();
private filePathToWatch: string;
private commandToExecute: string;
constructor(optionsArg: {
filePathToWatch: string,
commandToExecute: string
}) {
this.filePathToWatch = optionsArg.filePathToWatch;
this.commandToExecute = optionsArg.commandToExecute;
}
/**
* start the file
*/
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
this.watcher.on('change', async (file, stat) => {
console.log('Noticed change!');
if (!stat) {
console.log('deleted');
}
this.updateCurrentExecution();
});
this.updateCurrentExecution();
}
private async updateCurrentExecution() {
if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid);
}
this.currentExecution = await this.smartshellInstance.execStreaming(this.commandToExecute);
this.currentExecution = null;
}
/**
* this method sets up a clean exit strategy
*/
private setupCleanup() {
const cleanup = () => {
if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid);
}
};
process.on('exit', () => {
console.log('');
console.log('now exiting!');
cleanup();
process.exit(0);
});
process.on('SIGINT', () => {
console.log('');
console.log('ok! got SIGINT We are exiting! Just cleaning up to exit neatly :)');
cleanup();
process.exit(0);
});
}
}

16
ts/tswatch.cli.ts Normal file
View File

@ -0,0 +1,16 @@
import * as plugins from './tswatch.plugins';
import * as paths from './tswatch.paths';
import { TsWatch } from './tswatch.classes.tswatch';
const tswatchCli = new plugins.smartcli.Smartcli();
tswatchCli.addCommand('test').subscribe(argvArg => {
const tsWatch = new TsWatch({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2'
});
tsWatch.start();
});
tswatchCli.startParse();

3
ts/tswatch.paths.ts Normal file
View File

@ -0,0 +1,3 @@
import * as plugins from './tswatch.plugins';
export const cwd = process.cwd();

13
ts/tswatch.plugins.ts Normal file
View File

@ -0,0 +1,13 @@
import * as path from 'path';
export { path };
// @pushrocks scope
import * as smartcli from '@pushrocks/smartcli';
import * as smartshell from '@pushrocks/smartshell';
export { smartshell, smartcli };
// Third Pary
import * as fileWatcher from 'filewatcher';
export { fileWatcher };