fix(core): update
This commit is contained in:
parent
1960b1d125
commit
390200ad2a
7
.Trash-1000/files/8ba64226-9d16-4f28-a568-49c1ea3aa1e7
Normal file
7
.Trash-1000/files/8ba64226-9d16-4f28-a568-49c1ea3aa1e7
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"lib": ["es2015"],
|
||||
"target": "ES2017"
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
[Trash Info]
|
||||
Path=/home/coder/project/tsconfig.json
|
||||
DeletionDate=2019-05-08T21:54:46.502Z
|
12
package-lock.json
generated
12
package-lock.json
generated
@ -503,12 +503,12 @@
|
||||
},
|
||||
"@types/minimatch": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fminimatch/-/minimatch-3.0.3.tgz",
|
||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.0.tgz",
|
||||
"integrity": "sha512-Jrb/x3HT4PTJp6a4avhmJCDEVrPdqLfl3e8GGMbpkGGdwAV5UGlIs4vVEfsHHfylZVOKZWpOqmqFH8CbfOZ6kg=="
|
||||
},
|
||||
"@types/vinyl": {
|
||||
@ -1205,9 +1205,9 @@
|
||||
}
|
||||
},
|
||||
"luxon": {
|
||||
"version": "1.13.0",
|
||||
"resolved": "https://verdaccio.lossless.one/luxon/-/luxon-1.13.0.tgz",
|
||||
"integrity": "sha512-j/t5wLTDCUbJgJ6MDp1VFNmeE/j7jmOhk3yKnZ972laS1ofpXVbOOVr9+7abyclAcG8FrPv8T2mg4A39V26vEQ=="
|
||||
"version": "1.13.1",
|
||||
"resolved": "https://verdaccio.lossless.one/luxon/-/luxon-1.13.1.tgz",
|
||||
"integrity": "sha512-IQKRIiz9ldUrgcozN13SAeNZVYfD3bEI9X6TcrGu+dkgE4GR/Iik03ozbTM5cTr0lz8ucYPL2jtYT7Va2Flbsg=="
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.5",
|
||||
@ -1725,7 +1725,7 @@
|
||||
},
|
||||
"symbol-tree": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz",
|
||||
"resolved": "https://verdaccio.lossless.one/symbol-tree/-/symbol-tree-3.2.2.tgz",
|
||||
"integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY="
|
||||
},
|
||||
"threads": {
|
||||
|
@ -8,8 +8,7 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "node ./cli.ts.js test --timeout 10000",
|
||||
"test2": "(tstest test/)",
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
@ -24,6 +23,7 @@
|
||||
"dependencies": {
|
||||
"@gitzone/tsrun": "^1.2.6",
|
||||
"@pushrocks/early": "^3.0.3",
|
||||
"@pushrocks/lik": "^3.0.5",
|
||||
"@pushrocks/smartchok": "^1.0.18",
|
||||
"@pushrocks/smartcli": "^3.0.7",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
|
15
test/test.ts
15
test/test.ts
@ -1,21 +1,20 @@
|
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as tswatch from '../ts/index';
|
||||
|
||||
let testTsWatchInstance: tswatch.TsWatch;
|
||||
|
||||
tap.test('should create a valid TsWatch instance', async () => {
|
||||
testTsWatchInstance = new tswatch.TsWatch({
|
||||
filePathToWatch: process.cwd(),
|
||||
commandToExecute: 'npm -v',
|
||||
timeout: 1000
|
||||
});
|
||||
testTsWatchInstance = new tswatch.TsWatch('echoSomething');
|
||||
});
|
||||
|
||||
tap.test('should start the tswatch instance', async () => {
|
||||
testTsWatchInstance.start();
|
||||
console.log('test executed');
|
||||
await testTsWatchInstance.start();
|
||||
});
|
||||
|
||||
tap.test('should run abitrary commands', async () => {});
|
||||
tap.test('should stop the instance', async (tools) => {
|
||||
tools.delayFor(2000);
|
||||
testTsWatchInstance.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './interfaces.watchmodes';
|
1
ts/interfaces/interfaces.watchmodes.ts
Normal file
1
ts/interfaces/interfaces.watchmodes.ts
Normal file
@ -0,0 +1 @@
|
||||
export type TWatchModes = 'test' | 'gitzone_npm' | 'gitzone_service' | 'gitzone_website' | 'echoSomething';
|
@ -1,79 +1,68 @@
|
||||
import * as plugins from './tswatch.plugins';
|
||||
import * as paths from './tswatch.paths';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
export interface ITsWatchConstructorOptions {
|
||||
filePathToWatch: string;
|
||||
commandToExecute: string;
|
||||
timeout?: number;
|
||||
}
|
||||
import { Watcher } from './tswatch.classes.watcher';
|
||||
|
||||
/**
|
||||
* 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 = new plugins.smartchok.Smartchok([], {});
|
||||
private options: ITsWatchConstructorOptions;
|
||||
public watchmode: interfaces.TWatchModes;
|
||||
public watcherMap = new plugins.lik.Objectmap<Watcher>();
|
||||
|
||||
constructor(optionsArg: ITsWatchConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
constructor(watchmodeArg: interfaces.TWatchModes) {
|
||||
this.watchmode = watchmodeArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the file
|
||||
* starts the TsWatch instance
|
||||
*/
|
||||
public async start() {
|
||||
this.setupCleanup();
|
||||
console.log(`Looking at ${this.options.filePathToWatch} for changes`);
|
||||
this.watcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file
|
||||
const changeObservable = await this.watcher.getObservableFor('change');
|
||||
changeObservable.subscribe(() => {
|
||||
this.updateCurrentExecution();
|
||||
});
|
||||
this.updateCurrentExecution();
|
||||
}
|
||||
|
||||
private async updateCurrentExecution() {
|
||||
if (this.currentExecution) {
|
||||
process.kill(-this.currentExecution.childProcess.pid);
|
||||
}
|
||||
this.currentExecution = await this.smartshellInstance.execStreaming(
|
||||
this.options.commandToExecute
|
||||
);
|
||||
this.currentExecution = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method sets up a clean exit strategy
|
||||
*/
|
||||
private async 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);
|
||||
});
|
||||
|
||||
// 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);
|
||||
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;
|
||||
}
|
||||
this.watcherMap.forEach(async watcher => {
|
||||
await watcher.start();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the execution of any active Watchers
|
||||
*/
|
||||
public async stop () {
|
||||
this.watcherMap.forEach(async watcher => {
|
||||
await watcher.stop();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
97
ts/tswatch.classes.watcher.ts
Normal file
97
ts/tswatch.classes.watcher.ts
Normal file
@ -0,0 +1,97 @@
|
||||
import * as plugins from './tswatch.plugins';
|
||||
import { logger } from './tswatch.logging';
|
||||
|
||||
export interface IWatcherConstructorOptions {
|
||||
filePathToWatch: string;
|
||||
commandToExecute: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A watcher keeps track of one child execution
|
||||
*/
|
||||
export class Watcher {
|
||||
private smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
});
|
||||
private currentExecution: plugins.smartshell.IExecResultStreaming;
|
||||
private smartchokWatcher = new plugins.smartchok.Smartchok([], {});
|
||||
private options: IWatcherConstructorOptions;
|
||||
|
||||
constructor(optionsArg: IWatcherConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the file
|
||||
*/
|
||||
public async start() {
|
||||
this.setupCleanup();
|
||||
console.log(`Looking at ${this.options.filePathToWatch} for changes`);
|
||||
this.smartchokWatcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file
|
||||
await this.smartchokWatcher.start();
|
||||
const changeObservable = await this.smartchokWatcher.getObservableFor('change');
|
||||
changeObservable.subscribe(() => {
|
||||
this.updateCurrentExecution();
|
||||
});
|
||||
this.updateCurrentExecution();
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the current execution
|
||||
*/
|
||||
private async updateCurrentExecution() {
|
||||
if (this.currentExecution) {
|
||||
logger.log('ok', `reexecuting ${this.options.commandToExecute}`);
|
||||
process.kill(-this.currentExecution.childProcess.pid);
|
||||
} else {
|
||||
logger.log('ok', `executing ${this.options.commandToExecute} for the first time`);
|
||||
}
|
||||
this.currentExecution = await this.smartshellInstance.execStreaming(
|
||||
this.options.commandToExecute
|
||||
);
|
||||
this.currentExecution = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method sets up a clean exit strategy
|
||||
*/
|
||||
private async 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);
|
||||
});
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the watcher
|
||||
*/
|
||||
public async stop() {
|
||||
await this.smartchokWatcher.stop();
|
||||
if (this.currentExecution) {
|
||||
process.kill(-this.currentExecution.childProcess.pid);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,21 +8,10 @@ const tswatchCli = new plugins.smartcli.Smartcli();
|
||||
|
||||
// standard behaviour will assume gitzone setup
|
||||
|
||||
tswatchCli.addCommand('test').subscribe(argvArg => {
|
||||
tswatchCli.addCommand('test').subscribe(async argvArg => {
|
||||
logger.log('info', `running test task`);
|
||||
const tsWatch = new TsWatch({
|
||||
filePathToWatch: paths.cwd,
|
||||
commandToExecute: 'npm run test2',
|
||||
timeout: (() => {
|
||||
if (argvArg.timeout) {
|
||||
console.log(`timeing out after ${argvArg.timeout}`);
|
||||
return argvArg.timeout;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})()
|
||||
});
|
||||
tsWatch.start();
|
||||
const tsWatch = new TsWatch('test');
|
||||
await tsWatch.start();
|
||||
});
|
||||
|
||||
tswatchCli.startParse();
|
||||
|
@ -2,6 +2,7 @@ import * as path from 'path';
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartchok from '@pushrocks/smartchok';
|
||||
import * as smartcli from '@pushrocks/smartcli';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
@ -9,4 +10,4 @@ import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
|
||||
import * as smartshell from '@pushrocks/smartshell';
|
||||
|
||||
export { smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell };
|
||||
export { lik, smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell };
|
||||
|
Loading…
Reference in New Issue
Block a user