update to wirj like expected
This commit is contained in:
parent
583cf6f446
commit
fda93fa553
42
dist/index.d.ts
vendored
42
dist/index.d.ts
vendored
@ -1,41 +1 @@
|
|||||||
/// <reference types="q" />
|
export * from './smartchok.classes.smartchok';
|
||||||
import * as plugins from './smartchok.plugins';
|
|
||||||
import { Stringmap } from 'lik';
|
|
||||||
export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
|
||||||
export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
|
|
||||||
/**
|
|
||||||
* Smartchok allows easy wathcing of files
|
|
||||||
*/
|
|
||||||
export declare class Smartchok {
|
|
||||||
watchStringmap: Stringmap;
|
|
||||||
chokidarOptions: plugins.chokidar.WatchOptions;
|
|
||||||
status: TSmartchokStatus;
|
|
||||||
private watcher;
|
|
||||||
private watchingDeferred;
|
|
||||||
private eventObservablemap;
|
|
||||||
/**
|
|
||||||
* constructor of class smartchok
|
|
||||||
*/
|
|
||||||
constructor(watchArrayArg: string[], optionsArg?: plugins.chokidar.WatchOptions);
|
|
||||||
/**
|
|
||||||
* adds files to the list of watched files
|
|
||||||
*/
|
|
||||||
add(pathArrayArg: string[]): void;
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg: string): void;
|
|
||||||
/**
|
|
||||||
* gets an observable for a certain event
|
|
||||||
*/
|
|
||||||
getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>>;
|
|
||||||
/**
|
|
||||||
* starts the watcher
|
|
||||||
* @returns Promise<void>
|
|
||||||
*/
|
|
||||||
start(): plugins.q.Promise<void>;
|
|
||||||
/**
|
|
||||||
* stop the watcher process if watching
|
|
||||||
*/
|
|
||||||
stop(): void;
|
|
||||||
}
|
|
||||||
|
86
dist/index.js
vendored
86
dist/index.js
vendored
@ -1,83 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
function __export(m) {
|
||||||
const plugins = require("./smartchok.plugins");
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||||
const lik_1 = require("lik");
|
|
||||||
/**
|
|
||||||
* Smartchok allows easy wathcing of files
|
|
||||||
*/
|
|
||||||
class Smartchok {
|
|
||||||
/**
|
|
||||||
* constructor of class smartchok
|
|
||||||
*/
|
|
||||||
constructor(watchArrayArg, optionsArg = {}) {
|
|
||||||
this.watchStringmap = new lik_1.Stringmap();
|
|
||||||
this.status = 'idle';
|
|
||||||
this.watchingDeferred = plugins.q.defer(); // used to run things when watcher is initialized
|
|
||||||
this.eventObservablemap = new plugins.lik.Observablemap(); // register one observable per event
|
|
||||||
this.watchStringmap.addStringArray(watchArrayArg);
|
|
||||||
this.chokidarOptions = optionsArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* adds files to the list of watched files
|
|
||||||
*/
|
|
||||||
add(pathArrayArg) {
|
|
||||||
this.watchStringmap.addStringArray(pathArrayArg);
|
|
||||||
if (this.status !== 'idle') {
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.add(pathArrayArg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg) {
|
|
||||||
this.watchStringmap.removeString(''); // TODO
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.unwatch(pathArg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* gets an observable for a certain event
|
|
||||||
*/
|
|
||||||
getObservableFor(fsEvent) {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent);
|
|
||||||
done.resolve(eventObservable);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* starts the watcher
|
|
||||||
* @returns Promise<void>
|
|
||||||
*/
|
|
||||||
start() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* stop the watcher process if watching
|
|
||||||
*/
|
|
||||||
stop() {
|
|
||||||
let closeWatcher = () => {
|
|
||||||
this.watcher.close();
|
|
||||||
};
|
|
||||||
if (this.status === 'watching') {
|
|
||||||
console.log('closing while watching');
|
|
||||||
closeWatcher();
|
|
||||||
}
|
|
||||||
else if (this.status === 'starting') {
|
|
||||||
this.watchingDeferred.promise.then(() => { closeWatcher(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.Smartchok = Smartchok;
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLCtDQUE4QztBQUM5Qyw2QkFBK0I7QUFLL0I7O0dBRUc7QUFDSDtJQVFFOztPQUVHO0lBQ0gsWUFBWSxhQUF1QixFQUFFLGFBQTRDLEVBQUU7UUFWbkYsbUJBQWMsR0FBRyxJQUFJLGVBQVMsRUFBRSxDQUFBO1FBRWhDLFdBQU0sR0FBcUIsTUFBTSxDQUFBO1FBRXpCLHFCQUFnQixHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUEsQ0FBQyxpREFBaUQ7UUFDNUYsdUJBQWtCLEd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ksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUMvQixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUFqRkQsOEJBaUZDIn0=
|
__export(require("./smartchok.classes.smartchok"));
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9
|
0
dist/smartchok.child.d.ts
vendored
Normal file
0
dist/smartchok.child.d.ts
vendored
Normal file
3
dist/smartchok.child.js
vendored
Normal file
3
dist/smartchok.child.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNoaWxkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNoaWxkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
41
dist/smartchok.classes.smartchok.d.ts
vendored
Normal file
41
dist/smartchok.classes.smartchok.d.ts
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/// <reference types="q" />
|
||||||
|
import * as plugins from './smartchok.plugins';
|
||||||
|
import { Stringmap } from 'lik';
|
||||||
|
export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
||||||
|
export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
|
||||||
|
/**
|
||||||
|
* Smartchok allows easy wathcing of files
|
||||||
|
*/
|
||||||
|
export declare class Smartchok {
|
||||||
|
watchStringmap: Stringmap;
|
||||||
|
chokidarOptions: plugins.chokidar.WatchOptions;
|
||||||
|
status: TSmartchokStatus;
|
||||||
|
private watcher;
|
||||||
|
private watchingDeferred;
|
||||||
|
private eventObservablemap;
|
||||||
|
/**
|
||||||
|
* constructor of class smartchok
|
||||||
|
*/
|
||||||
|
constructor(watchArrayArg: string[], optionsArg?: plugins.chokidar.WatchOptions);
|
||||||
|
/**
|
||||||
|
* adds files to the list of watched files
|
||||||
|
*/
|
||||||
|
add(pathArrayArg: string[]): void;
|
||||||
|
/**
|
||||||
|
* removes files from the list of watched files
|
||||||
|
*/
|
||||||
|
remove(pathArg: string): void;
|
||||||
|
/**
|
||||||
|
* gets an observable for a certain event
|
||||||
|
*/
|
||||||
|
getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>>;
|
||||||
|
/**
|
||||||
|
* starts the watcher
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
start(): plugins.q.Promise<void>;
|
||||||
|
/**
|
||||||
|
* stop the watcher process if watching
|
||||||
|
*/
|
||||||
|
stop(): void;
|
||||||
|
}
|
75
dist/smartchok.classes.smartchok.js
vendored
Normal file
75
dist/smartchok.classes.smartchok.js
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const plugins = require("./smartchok.plugins");
|
||||||
|
const lik_1 = require("lik");
|
||||||
|
/**
|
||||||
|
* Smartchok allows easy wathcing of files
|
||||||
|
*/
|
||||||
|
class Smartchok {
|
||||||
|
/**
|
||||||
|
* constructor of class smartchok
|
||||||
|
*/
|
||||||
|
constructor(watchArrayArg, optionsArg = {}) {
|
||||||
|
this.watchStringmap = new lik_1.Stringmap();
|
||||||
|
this.status = 'idle';
|
||||||
|
this.watchingDeferred = plugins.q.defer(); // used to run things when watcher is initialized
|
||||||
|
this.eventObservablemap = new plugins.lik.Observablemap(); // register one observable per event
|
||||||
|
this.watchStringmap.addStringArray(watchArrayArg);
|
||||||
|
this.chokidarOptions = optionsArg;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* adds files to the list of watched files
|
||||||
|
*/
|
||||||
|
add(pathArrayArg) {
|
||||||
|
this.watchStringmap.addStringArray(pathArrayArg);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* removes files from the list of watched files
|
||||||
|
*/
|
||||||
|
remove(pathArg) {
|
||||||
|
this.watchStringmap.removeString(pathArg);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* gets an observable for a certain event
|
||||||
|
*/
|
||||||
|
getObservableFor(fsEvent) {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
this.watchingDeferred.promise.then(() => {
|
||||||
|
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent);
|
||||||
|
done.resolve(eventObservable);
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* starts the watcher
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
start() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* stop the watcher process if watching
|
||||||
|
*/
|
||||||
|
stop() {
|
||||||
|
let closeWatcher = () => {
|
||||||
|
this.watcher.close();
|
||||||
|
};
|
||||||
|
if (this.status === 'watching') {
|
||||||
|
console.log('closing while watching');
|
||||||
|
closeWatcher();
|
||||||
|
}
|
||||||
|
else if (this.status === 'starting') {
|
||||||
|
this.watchingDeferred.promise.then(() => { closeWatcher(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Smartchok = Smartchok;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjs7R0FFRztBQUNIO0lBUUU7O09BRUc7SUFDSCxZQUFhLGFBQXVCLEVBQUUsYUFBNEMsRUFBRTtRQVZwRixtQkFBYyxHQUFHLElBQUksZUFBUyxFQUFFLENBQUE7UUFFaEMsV0FBTSxHQUFxQixNQUFNLENBQUE7UUFFekIscUJBQWdCLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQVEsQ0FBQSxDQUFDLGlEQUFpRDtRQUM1Rix1QkFBa0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLENBQUEsQ0FBQyxvQ0FBb0M7UUFNL0YsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDakQsSUFBSSxDQUFDLGVBQWUsR0FBRyxVQUFVLENBQUE7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFlBQXNCO1F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QU0sR0FBRyxVQUFVLENBQUE7WUFDeEIsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxDQUFBO1lBQy9CLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNoQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDRixJQUFJLFlBQVksR0FBRztZQUNqQixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ3RCLENBQUMsQ0FBQTtRQUNELEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUMvQixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUF4RUQsOEJBd0VDIn0=
|
0
dist/smartchok.classes.watcher.d.ts
vendored
Normal file
0
dist/smartchok.classes.watcher.d.ts
vendored
Normal file
3
dist/smartchok.classes.watcher.js
vendored
Normal file
3
dist/smartchok.classes.watcher.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMud2F0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2hvay5jbGFzc2VzLndhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
9
dist/smartchok.plugins.d.ts
vendored
9
dist/smartchok.plugins.d.ts
vendored
@ -1,6 +1,13 @@
|
|||||||
import 'typings-global';
|
import 'typings-global';
|
||||||
export import chokidar = require('chokidar');
|
|
||||||
export import lik = require('lik');
|
export import lik = require('lik');
|
||||||
|
export import chokidar = require('chokidar');
|
||||||
export import path = require('path');
|
export import path = require('path');
|
||||||
export import q = require('q');
|
export import q = require('q');
|
||||||
export import rx = require('rxjs/Rx');
|
export import rx = require('rxjs/Rx');
|
||||||
|
import { Operator } from 'rxjs/Operator';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
declare module 'rxjs/Subject' {
|
||||||
|
interface Subject<T> {
|
||||||
|
lift<R>(operator: Operator<T, R>): Observable<R>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4
dist/smartchok.plugins.js
vendored
4
dist/smartchok.plugins.js
vendored
@ -1,9 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.chokidar = require("chokidar");
|
|
||||||
exports.lik = require("lik");
|
exports.lik = require("lik");
|
||||||
|
exports.chokidar = require("chokidar");
|
||||||
exports.path = require("path");
|
exports.path = require("path");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
exports.rx = require("rxjs/Rx");
|
exports.rx = require("rxjs/Rx");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBNEM7QUFDNUMsNkJBQWtDO0FBQ2xDLCtCQUFvQztBQUNwQyx5QkFBOEI7QUFDOUIsZ0NBQXFDIn0=
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw2QkFBa0M7QUFDbEMsdUNBQTRDO0FBQzVDLCtCQUFvQztBQUNwQyx5QkFBOEI7QUFDOUIsZ0NBQXFDIn0=
|
15
package.json
15
package.json
@ -19,17 +19,18 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/chokidar": "^1.6.0",
|
"@types/chokidar": "^1.7.0",
|
||||||
"@types/q": "x.x.x",
|
"@types/q": "x.x.x",
|
||||||
"chokidar": "^1.6.1",
|
"chokidar": "^1.7.0",
|
||||||
"lik": "^1.0.30",
|
"lik": "^1.0.32",
|
||||||
"q": "^1.5.0",
|
"q": "^1.5.0",
|
||||||
"rxjs": "^5.3.0",
|
"rxjs": "^5.4.1",
|
||||||
"smartipc": "^1.0.9",
|
"smartipc": "^1.0.9",
|
||||||
"typings-global": "^1.0.14"
|
"smartq": "^1.1.1",
|
||||||
|
"typings-global": "^1.0.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"smartfile": "^4.1.9",
|
"smartfile": "^4.2.17",
|
||||||
"tapbundle": "^1.0.5"
|
"tapbundle": "^1.0.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
test/test.js
38
test/test.js
@ -1,38 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const should = require("should");
|
|
||||||
const smartfile = require("smartfile");
|
|
||||||
const smartchok = require("../dist/index");
|
|
||||||
describe('smartchok', function () {
|
|
||||||
let testSmartchok;
|
|
||||||
let testAddObservable;
|
|
||||||
let testSubscription;
|
|
||||||
it('should create a new instance', function () {
|
|
||||||
testSmartchok = new smartchok.Smartchok([]);
|
|
||||||
should(testSmartchok).be.instanceof(smartchok.Smartchok);
|
|
||||||
});
|
|
||||||
it('should add some files to watch and start', function (done) {
|
|
||||||
testSmartchok.add(['./test/assets/**/*.txt']);
|
|
||||||
testSmartchok.start().then(() => {
|
|
||||||
testSmartchok.add(['./test/assets/**/*.md']);
|
|
||||||
done();
|
|
||||||
}).catch(err => { console.log(err); });
|
|
||||||
});
|
|
||||||
it('should get an observable for a certain event', function (done) {
|
|
||||||
testSmartchok.getObservableFor('add').then((observableArg) => {
|
|
||||||
testAddObservable = observableArg;
|
|
||||||
done();
|
|
||||||
}).catch(err => { console.log(err); });
|
|
||||||
});
|
|
||||||
it('should register an add operation', function (done) {
|
|
||||||
this.timeout(5000);
|
|
||||||
testSubscription = testAddObservable.subscribe(x => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
smartfile.memory.toFs('HI', './test/assets/hi.txt');
|
|
||||||
});
|
|
||||||
it('should stop the watch process', function () {
|
|
||||||
testSmartchok.stop();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsdUNBQXNDO0FBRXRDLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBV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BQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUN6QyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxrQ0FBa0MsRUFBQyxVQUFTLElBQUk7UUFDL0MsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUNsQixnQkFBZ0IsR0FBRyxpQkFBaUIsQ0FBQyxTQUFTLENBQUMsQ0FBQztZQUM1QyxJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO1FBQ0YsU0FBUyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFDLHNCQUFzQixDQUFDLENBQUE7SUFDdEQsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsK0JBQStCLEVBQUM7UUFDL0IsYUFBYSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
|
@ -41,3 +41,5 @@ tap.test('should register an add operation', async () => {
|
|||||||
tap.test('should stop the watch process', async () => {
|
tap.test('should stop the watch process', async () => {
|
||||||
testSmartchok.stop()
|
testSmartchok.stop()
|
||||||
}).catch(tap.threw)
|
}).catch(tap.threw)
|
||||||
|
|
||||||
|
tap.start()
|
||||||
|
92
ts/index.ts
92
ts/index.ts
@ -1,91 +1 @@
|
|||||||
import * as plugins from './smartchok.plugins'
|
export * from './smartchok.classes.smartchok'
|
||||||
import { Stringmap } from 'lik'
|
|
||||||
|
|
||||||
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.q.defer<void>() // used to run things when watcher is initialized
|
|
||||||
private eventObservablemap = new plugins.lik.Observablemap() // register one observable per event
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor of class smartchok
|
|
||||||
*/
|
|
||||||
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)
|
|
||||||
if (this.status !== 'idle') {
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.add(pathArrayArg)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg: string) {
|
|
||||||
this.watchStringmap.removeString('') // TODO
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.unwatch(pathArg)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets an observable for a certain event
|
|
||||||
*/
|
|
||||||
getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>> {
|
|
||||||
let done = plugins.q.defer<plugins.rx.Observable<any>>()
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent)
|
|
||||||
done.resolve(eventObservable)
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* starts the watcher
|
|
||||||
* @returns Promise<void>
|
|
||||||
*/
|
|
||||||
start(): plugins.q.Promise<void> {
|
|
||||||
let done = plugins.q.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
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stop the watcher process if watching
|
|
||||||
*/
|
|
||||||
stop() {
|
|
||||||
let closeWatcher = () => {
|
|
||||||
this.watcher.close()
|
|
||||||
}
|
|
||||||
if (this.status === 'watching') {
|
|
||||||
console.log('closing while watching')
|
|
||||||
closeWatcher()
|
|
||||||
} else if (this.status === 'starting') {
|
|
||||||
this.watchingDeferred.promise.then(() => { closeWatcher() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
1
ts/smartchok.child.ts
Normal file
1
ts/smartchok.child.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import chokidar = require('chokidar')
|
82
ts/smartchok.classes.smartchok.ts
Normal file
82
ts/smartchok.classes.smartchok.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import * as plugins from './smartchok.plugins'
|
||||||
|
import { Stringmap } from 'lik'
|
||||||
|
|
||||||
|
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.q.defer<void>() // used to run things when watcher is initialized
|
||||||
|
private eventObservablemap = new plugins.lik.Observablemap() // register one observable per event
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor of class smartchok
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes files from the list of watched files
|
||||||
|
*/
|
||||||
|
remove (pathArg: string) {
|
||||||
|
this.watchStringmap.removeString(pathArg)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets an observable for a certain event
|
||||||
|
*/
|
||||||
|
getObservableFor (fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>> {
|
||||||
|
let done = plugins.q.defer<plugins.rx.Observable<any>>()
|
||||||
|
this.watchingDeferred.promise.then(() => {
|
||||||
|
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent)
|
||||||
|
done.resolve(eventObservable)
|
||||||
|
})
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the watcher
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
start(): plugins.q.Promise<void> {
|
||||||
|
let done = plugins.q.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
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop the watcher process if watching
|
||||||
|
*/
|
||||||
|
stop() {
|
||||||
|
let closeWatcher = () => {
|
||||||
|
this.watcher.close()
|
||||||
|
}
|
||||||
|
if (this.status === 'watching') {
|
||||||
|
console.log('closing while watching')
|
||||||
|
closeWatcher()
|
||||||
|
} else if (this.status === 'starting') {
|
||||||
|
this.watchingDeferred.promise.then(() => { closeWatcher() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
ts/smartchok.classes.watcher.ts
Normal file
2
ts/smartchok.classes.watcher.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import * as plugins from './smartchok.plugins'
|
||||||
|
|
@ -1,6 +1,15 @@
|
|||||||
import 'typings-global'
|
import 'typings-global'
|
||||||
export import chokidar = require('chokidar')
|
|
||||||
export import lik = require('lik')
|
export import lik = require('lik')
|
||||||
|
export import chokidar = require('chokidar')
|
||||||
export import path = require('path')
|
export import path = require('path')
|
||||||
export import q = require('q')
|
export import q = require('q')
|
||||||
export import rx = require('rxjs/Rx')
|
export import rx = require('rxjs/Rx')
|
||||||
|
|
||||||
|
// workaround
|
||||||
|
import {Operator} from 'rxjs/Operator';
|
||||||
|
import {Observable} from 'rxjs/Observable';
|
||||||
|
declare module 'rxjs/Subject' {
|
||||||
|
interface Subject<T> {
|
||||||
|
lift<R>(operator: Operator<T, R>): Observable<R>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user