Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7b0722155 | |||
6cbd74eb12 | |||
fe52811dcd | |||
9c1e306c99 | |||
19ab839853 | |||
cb6c8f3c8e | |||
9e06369139 | |||
7d4975cea8 | |||
af9eb0d99e | |||
46e7b52930 | |||
bf7ec659b7 | |||
ab3ad55c43 | |||
5e5f2ce6c2 | |||
89566ebc1d | |||
fda93fa553 | |||
583cf6f446 | |||
8d87616971 | |||
e3e70a680e | |||
49e7146320 | |||
1f1fef1610 | |||
1365676a12 | |||
44dd315c6f | |||
722bd0ea61 | |||
c6104ed00e | |||
69149a717b | |||
aed6e12270 | |||
396853f7c4 | |||
40f1e2c938 |
@ -1,41 +1,93 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- mirror
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- page
|
||||
- trigger
|
||||
- pages
|
||||
|
||||
mirror:
|
||||
stage: mirror
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
|
||||
security:
|
||||
stage: security
|
||||
script:
|
||||
- npmci command yarn global add snyk
|
||||
- npmci command yarn install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci node install legacy
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci npm prepare
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: page
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
tags:
|
||||
- docker
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
|
56
README.md
Normal file
56
README.md
Normal file
@ -0,0 +1,56 @@
|
||||
# smartchok
|
||||
|
||||
smart wrapper for chokidar
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/smartchok)
|
||||
[](https://GitLab.com/pushrocks/smartchok)
|
||||
[](https://github.com/pushrocks/smartchok)
|
||||
[](https://pushrocks.gitlab.io/smartchok/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
||||
[](https://www.npmjs.com/package/smartchok)
|
||||
[](https://david-dm.org/pushrocks/smartchok)
|
||||
[](https://www.bithound.io/github/pushrocks/smartchok/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartchok)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import { Smartchok } from 'smartchok';
|
||||
|
||||
let mySmartChok = new Smartchok(['some/path/**/*.any', '/absolute/*.js'], chokidarOptions);
|
||||
|
||||
mySmartChok.add(['/some/**/*.any']); // add files
|
||||
|
||||
mySmartChok.remove('some/**/*.js');
|
||||
|
||||
mySmartChok.start(); // starts the watch process
|
||||
|
||||
mySmartChok.getObservableFor('change').then(observableArg => {
|
||||
observableArg.subscribe(x => {
|
||||
// do something here when a change is detected
|
||||
// possible events are 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
|
||||
// note that the observable is only created once you call .start() on the Smartchok instance
|
||||
// hence the promise construction
|
||||
});
|
||||
});
|
||||
|
||||
mySmartChok.stop();
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
37
dist/index.d.ts
vendored
37
dist/index.d.ts
vendored
@ -1,36 +1 @@
|
||||
/// <reference types="chokidar" />
|
||||
/// <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';
|
||||
export declare class Smartchok {
|
||||
watchStringmap: Stringmap;
|
||||
chokidarOptions: plugins.chokidar.WatchOptions;
|
||||
status: TSmartchokStatus;
|
||||
private watcher;
|
||||
private watchingDeferred;
|
||||
private eventObservablemap;
|
||||
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;
|
||||
}
|
||||
export * from './smartchok.classes.smartchok';
|
||||
|
79
dist/index.js
vendored
79
dist/index.js
vendored
@ -1,76 +1,7 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartchok.plugins");
|
||||
const lik_1 = require("lik");
|
||||
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;
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjtJQVFJLFlBQVksYUFBdUIsRUFBRSxVQUFVLEdBQWtDLEVBQUU7UUFQbkYsbUJBQWMsR0FBRyxJQUFJLGVBQVMsRUFBRSxDQUFBO1FBRWhDLFdBQU0sR0FBcUIsTUFBTSxDQUFBO1FBRXpCLHFCQUFnQixHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUEsQ0FBQyxpREFBaUQ7UUFDNUYsdUJBQW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FBSSxDQUFDLE1BQU0sS0FBSyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQzdCLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQTtZQUNyQyxZQUFZLEVBQUUsQ0FBQTtRQUNsQixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUNwQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLFlBQVksRUFBRSxDQUFBLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDaEUsQ0FBQztJQUNMLENBQUM7Q0FDSjtBQTlFRCw4QkE4RUMifQ==
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./smartchok.classes.smartchok"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE4QyJ9
|
39
dist/smartchok.classes.smartchok.d.ts
vendored
Normal file
39
dist/smartchok.classes.smartchok.d.ts
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
import * as plugins from './smartchok.plugins';
|
||||
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: plugins.lik.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): Promise<plugins.smartrx.rxjs.Observable<any>>;
|
||||
/**
|
||||
* starts the watcher
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
start(): Promise<void>;
|
||||
/**
|
||||
* stop the watcher process if watching
|
||||
*/
|
||||
stop(): void;
|
||||
}
|
77
dist/smartchok.classes.smartchok.js
vendored
Normal file
77
dist/smartchok.classes.smartchok.js
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
"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.smartq.defer(); // used to run things when watcher is initialized
|
||||
this.eventObservablemap = new plugins.smartrx.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.smartq.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.smartq.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQStDO0FBQy9DLDZCQUFnQztBQWNoQzs7R0FFRztBQUNIO0lBUUU7O09BRUc7SUFDSCxZQUFZLGFBQXVCLEVBQUUsYUFBNEMsRUFBRTtRQVZuRixtQkFBYyxHQUFHLElBQUksZUFBUyxFQUFFLENBQUM7UUFFakMsV0FBTSxHQUFxQixNQUFNLENBQUM7UUFFM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BQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUU7Z0JBQ3RDLFlBQVksRUFBRSxDQUFDO1lBQ2pCLENBQUMsQ0FBQyxDQUFDO1FBQ0wsQ0FBQztJQUNILENBQUM7Q0FDRjtBQWhGRCw4QkFnRkMifQ==
|
7
dist/smartchok.plugins.d.ts
vendored
7
dist/smartchok.plugins.d.ts
vendored
@ -1,6 +1,5 @@
|
||||
import 'typings-global';
|
||||
export import chokidar = require('chokidar');
|
||||
export import lik = require('lik');
|
||||
export import chokidar = require('chokidar');
|
||||
export import path = require('path');
|
||||
export import q = require('q');
|
||||
export import rx = require('rxjs/Rx');
|
||||
export import smartq = require('smartq');
|
||||
export import smartrx = require('smartrx');
|
||||
|
10
dist/smartchok.plugins.js
vendored
10
dist/smartchok.plugins.js
vendored
@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.chokidar = require("chokidar");
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.lik = require("lik");
|
||||
exports.chokidar = require("chokidar");
|
||||
exports.path = require("path");
|
||||
exports.q = require("q");
|
||||
exports.rx = require("rxjs/Rx");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVDQUE0QztBQUM1Qyw2QkFBa0M7QUFDbEMsK0JBQW9DO0FBQ3BDLHlCQUE4QjtBQUM5QixnQ0FBcUMifQ==
|
||||
exports.smartq = require("smartq");
|
||||
exports.smartrx = require("smartrx");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDZCQUFtQztBQUNuQyx1Q0FBNkM7QUFDN0MsK0JBQXFDO0FBQ3JDLG1DQUF5QztBQUN6QyxxQ0FBMkMifQ==
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"npmts": {
|
||||
"mode": "default"
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"npmts"
|
||||
]
|
||||
}
|
||||
}
|
24
package.json
24
package.json
@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "smartchok",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.14",
|
||||
"description": "smart wrapper for chokidar",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npm run prepareTest && npmts)",
|
||||
"test": "(yarn run prepareTest && npmts)",
|
||||
"prepareTest": "(rm -f ./test/assets/hi.txt)"
|
||||
},
|
||||
"repository": {
|
||||
@ -19,18 +19,16 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
||||
"dependencies": {
|
||||
"@types/chokidar": "^1.4.29",
|
||||
"@types/q": "0.0.31",
|
||||
"chokidar": "^1.6.0",
|
||||
"lik": "^1.0.20",
|
||||
"q": "^1.4.1",
|
||||
"rxjs": "^5.0.0-beta.12",
|
||||
"typings-global": "^1.0.14"
|
||||
"@types/chokidar": "^1.7.5",
|
||||
"chokidar": "^2.0.2",
|
||||
"lik": "^2.0.5",
|
||||
"smartipc": "^1.0.11",
|
||||
"smartq": "^1.1.6",
|
||||
"smartrx": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.0",
|
||||
"smartfile": "^4.0.20",
|
||||
"typings-test": "^1.0.3"
|
||||
"@types/node": "^9.4.6",
|
||||
"smartfile": "^4.2.28",
|
||||
"tapbundle": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
35
test/test.js
35
test/test.js
@ -1,35 +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(() => { 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsdUNBQXNDO0FBRXRDLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyxFQUFDO0lBQ2pCLElBQUksYUFBa0MsQ0FBQTtJQUN0QyxJQUFJLGlCQ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VQUFTLElBQUk7UUFDL0MsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUNsQixnQkFBZ0IsR0FBRyxpQkFBaUIsQ0FBQyxTQUFTLENBQUMsQ0FBQztZQUM1QyxJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO1FBQ0YsU0FBUyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFDLHNCQUFzQixDQUFDLENBQUE7SUFDdEQsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsK0JBQStCLEVBQUM7UUFDL0IsYUFBYSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
44
test/test.ts
44
test/test.ts
@ -1,35 +1,45 @@
|
||||
import 'typings-test'
|
||||
import * as should from 'should'
|
||||
import { tap, expect } from 'tapbundle'
|
||||
import * as smartchok from '../ts/index'
|
||||
import * as smartfile from 'smartfile'
|
||||
import * as smartq from 'smartq'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as smartchok from '../dist/index'
|
||||
|
||||
describe('smartchok',function(){
|
||||
// the module to test
|
||||
|
||||
let testSmartchok: smartchok.Smartchok
|
||||
let testAddObservable: rx.Observable<any>
|
||||
let testSubscription: rx.Subscription
|
||||
it('should create a new instance',function(){
|
||||
tap.test('should create a new instance', async () => {
|
||||
testSmartchok = new smartchok.Smartchok([])
|
||||
should(testSmartchok).be.instanceof(smartchok.Smartchok)
|
||||
expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
|
||||
})
|
||||
it('should add some files to watch and start',function(done){
|
||||
|
||||
tap.test('should add some files to watch and start', async () => {
|
||||
testSmartchok.add([ './test/assets/**/*.txt' ])
|
||||
testSmartchok.start().then(() => { done() }).catch(err => { console.log(err) })
|
||||
let localPromise = testSmartchok.start().then(async () => {
|
||||
testSmartchok.add([ './test/assets/**/*.md' ])
|
||||
})
|
||||
it('should get an observable for a certain event',function(done){
|
||||
testSmartchok.getObservableFor('add').then((observableArg) => {
|
||||
await expect(localPromise).to.eventually.be.fulfilled
|
||||
})
|
||||
|
||||
tap.test('should get an observable for a certain event', async () => {
|
||||
let localPromise = testSmartchok.getObservableFor('add').then(async (observableArg) => {
|
||||
testAddObservable = observableArg
|
||||
done()
|
||||
}).catch(err => { console.log(err) })
|
||||
})
|
||||
it('should register an add operation',function(done){
|
||||
this.timeout(5000)
|
||||
await expect(localPromise).to.eventually.be.fulfilled
|
||||
})
|
||||
|
||||
tap.test('should register an add operation', async () => {
|
||||
let testDeferred = smartq.defer()
|
||||
testSubscription = testAddObservable.subscribe(x => {
|
||||
done()
|
||||
testDeferred.resolve()
|
||||
})
|
||||
smartfile.memory.toFs('HI', './test/assets/hi.txt')
|
||||
await expect(testDeferred.promise).to.eventually.be.fulfilled
|
||||
})
|
||||
it('should stop the watch process',function() {
|
||||
|
||||
tap.test('should stop the watch process', async () => {
|
||||
testSmartchok.stop()
|
||||
})
|
||||
})
|
||||
|
||||
tap.start()
|
||||
|
86
ts/index.ts
86
ts/index.ts
@ -1,85 +1 @@
|
||||
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'
|
||||
|
||||
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(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() })
|
||||
}
|
||||
}
|
||||
}
|
||||
export * from './smartchok.classes.smartchok';
|
||||
|
99
ts/smartchok.classes.smartchok.ts
Normal file
99
ts/smartchok.classes.smartchok.ts
Normal file
@ -0,0 +1,99 @@
|
||||
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';
|
||||
|
||||
/**
|
||||
* 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.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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): 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the watcher
|
||||
* @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
|
||||
);
|
||||
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,6 +1,5 @@
|
||||
import 'typings-global'
|
||||
export import chokidar = require('chokidar')
|
||||
export import lik = require('lik')
|
||||
export import path = require('path')
|
||||
export import q = require('q')
|
||||
export import rx = require('rxjs/Rx')
|
||||
export import lik = require('lik');
|
||||
export import chokidar = require('chokidar');
|
||||
export import path = require('path');
|
||||
export import smartq = require('smartq');
|
||||
export import smartrx = require('smartrx');
|
||||
|
Reference in New Issue
Block a user