update ci

This commit is contained in:
2018-03-01 00:08:08 +01:00
parent 9e06369139
commit cb6c8f3c8e
19 changed files with 1017 additions and 670 deletions

View File

@ -1,52 +1,64 @@
import * as plugins from './smartchok.plugins'
import { Stringmap } from 'lik'
import * as plugins from './smartchok.plugins';
import { Stringmap } from 'lik';
import { Observablemap } from 'smartrx';
export type TSmartchokStatus = 'idle' | 'starting' | 'watching'
export type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
export type TFsEvent =
| 'add'
| 'addDir'
| 'change'
| 'error'
| 'unlink'
| 'unlinkDir'
| 'ready'
| 'raw';
/**
* Smartchok allows easy wathcing of files
*/
export class Smartchok {
watchStringmap = new Stringmap()
chokidarOptions: plugins.chokidar.WatchOptions
status: TSmartchokStatus = 'idle'
private watcher
private watchingDeferred = plugins.smartq.defer<void>() // used to run things when watcher is initialized
private eventObservablemap = new plugins.lik.Observablemap() // register one observable per event
watchStringmap = new Stringmap();
chokidarOptions: plugins.chokidar.WatchOptions;
status: TSmartchokStatus = 'idle';
private watcher;
private watchingDeferred = plugins.smartq.defer<void>(); // used to run things when watcher is initialized
private eventObservablemap = new plugins.smartrx.Observablemap(); // register one observable per event
/**
* constructor of class smartchok
*/
constructor (watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
this.watchStringmap.addStringArray(watchArrayArg)
this.chokidarOptions = optionsArg
constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
this.watchStringmap.addStringArray(watchArrayArg);
this.chokidarOptions = optionsArg;
}
/**
* adds files to the list of watched files
*/
add(pathArrayArg: string[]) {
this.watchStringmap.addStringArray(pathArrayArg)
this.watchStringmap.addStringArray(pathArrayArg);
}
/**
* removes files from the list of watched files
*/
remove (pathArg: string) {
this.watchStringmap.removeString(pathArg)
remove(pathArg: string) {
this.watchStringmap.removeString(pathArg);
}
/**
* gets an observable for a certain event
*/
getObservableFor (fsEvent: TFsEvent): Promise<plugins.rx.Observable<any>> {
let done = plugins.smartq.defer<plugins.rx.Observable<any>>()
getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<any>> {
let done = plugins.smartq.defer<plugins.smartrx.rxjs.Observable<any>>();
this.watchingDeferred.promise.then(() => {
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent)
done.resolve(eventObservable)
})
return done.promise
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
this.watcher,
fsEvent
);
done.resolve(eventObservable);
});
return done.promise;
}
/**
@ -54,15 +66,18 @@ export class Smartchok {
* @returns Promise<void>
*/
start(): Promise<void> {
let done = plugins.smartq.defer<void>()
this.status = 'starting'
this.watcher = plugins.chokidar.watch(this.watchStringmap.getStringArray(), this.chokidarOptions)
let done = plugins.smartq.defer<void>();
this.status = 'starting';
this.watcher = plugins.chokidar.watch(
this.watchStringmap.getStringArray(),
this.chokidarOptions
);
this.watcher.on('ready', () => {
this.status = 'watching'
this.watchingDeferred.resolve()
done.resolve()
})
return done.promise
this.status = 'watching';
this.watchingDeferred.resolve();
done.resolve();
});
return done.promise;
}
/**
@ -70,13 +85,15 @@ export class Smartchok {
*/
stop() {
let closeWatcher = () => {
this.watcher.close()
}
this.watcher.close();
};
if (this.status === 'watching') {
console.log('closing while watching')
closeWatcher()
console.log('closing while watching');
closeWatcher();
} else if (this.status === 'starting') {
this.watchingDeferred.promise.then(() => { closeWatcher() })
this.watchingDeferred.promise.then(() => {
closeWatcher();
});
}
}
}