6 Commits

Author SHA1 Message Date
1f1fef1610 1.0.6 2017-04-09 16:51:36 +02:00
1365676a12 update to new gitzone standard 2017-04-09 16:51:33 +02:00
44dd315c6f 1.0.5 2017-02-15 22:00:59 +01:00
722bd0ea61 update dependencies 2017-02-15 21:58:34 +01:00
c6104ed00e 1.0.4 2016-11-19 00:41:08 +01:00
69149a717b improve README 2016-11-19 00:41:05 +01:00
9 changed files with 2427 additions and 130 deletions

View File

@ -2,23 +2,24 @@
smart wrapper for chokidar smart wrapper for chokidar
## Availabililty ## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/npmts) [![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartchok)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/npmts) [![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartchok)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/npmts) [![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartchok)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/npmts/) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartchok/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/npmts/badges/master/build.svg)](https://gitlab.com/pushrocks/npmts/commits/master) [![build status](https://GitLab.com/pushrocks/smartchok/badges/master/build.svg)](https://GitLab.com/pushrocks/smartchok/commits/master)
[![coverage report](https://gitlab.com/pushrocks/npmts/badges/master/coverage.svg)](https://gitlab.com/pushrocks/npmts/commits/master) [![coverage report](https://GitLab.com/pushrocks/smartchok/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartchok/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/npmts.svg)](https://david-dm.org/pushrocks/npmts) [![npm downloads per month](https://img.shields.io/npm/dm/smartchok.svg)](https://www.npmjs.com/package/smartchok)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/npmts/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/npmts/master/dependencies/npm) [![Dependency Status](https://david-dm.org/pushrocks/smartchok.svg)](https://david-dm.org/pushrocks/smartchok)
[![bitHound Code](https://www.bithound.io/github/pushrocks/npmts/badges/code.svg)](https://www.bithound.io/github/pushrocks/npmts) [![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartchok/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartchok/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartchok/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartchok)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
We recommend the use of TypeScript for best in class Intellisense Use TypeScript for best in class instellisense.
```javascript ```javascript
import { Smartchok } from 'smartchok' import { Smartchok } from 'smartchok'
@ -33,7 +34,8 @@ mySmartChok.start() // starts the watch process
mySmartChok.getObservableFor('change').then((observableArg) => { mySmartChok.getObservableFor('change').then((observableArg) => {
observableArg.subscribe(x => { observableArg.subscribe(x => {
// do something here when a change detected // 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 // note that the observable is only created once you call .start() on the Smartchok instance
// hence the promise construction // hence the promise construction
}) })
@ -42,4 +44,9 @@ mySmartChok.getObservableFor('change').then((observableArg) => {
mySmartChok.stop() mySmartChok.stop()
``` ```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks) 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

7
dist/index.d.ts vendored
View File

@ -1,9 +1,11 @@
/// <reference types="chokidar" />
/// <reference types="q" /> /// <reference types="q" />
import * as plugins from './smartchok.plugins'; import * as plugins from './smartchok.plugins';
import { Stringmap } from 'lik'; import { Stringmap } from 'lik';
export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching'; export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching';
export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'; export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
/**
* Smartchok allows easy wathcing of files
*/
export declare class Smartchok { export declare class Smartchok {
watchStringmap: Stringmap; watchStringmap: Stringmap;
chokidarOptions: plugins.chokidar.WatchOptions; chokidarOptions: plugins.chokidar.WatchOptions;
@ -11,6 +13,9 @@ export declare class Smartchok {
private watcher; private watcher;
private watchingDeferred; private watchingDeferred;
private eventObservablemap; private eventObservablemap;
/**
* constructor of class smartchok
*/
constructor(watchArrayArg: string[], optionsArg?: plugins.chokidar.WatchOptions); constructor(watchArrayArg: string[], optionsArg?: plugins.chokidar.WatchOptions);
/** /**
* adds files to the list of watched files * adds files to the list of watched files

9
dist/index.js vendored
View File

@ -1,7 +1,14 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartchok.plugins"); const plugins = require("./smartchok.plugins");
const lik_1 = require("lik"); const lik_1 = require("lik");
/**
* Smartchok allows easy wathcing of files
*/
class Smartchok { class Smartchok {
/**
* constructor of class smartchok
*/
constructor(watchArrayArg, optionsArg = {}) { constructor(watchArrayArg, optionsArg = {}) {
this.watchStringmap = new lik_1.Stringmap(); this.watchStringmap = new lik_1.Stringmap();
this.status = 'idle'; this.status = 'idle';
@ -73,4 +80,4 @@ class Smartchok {
} }
} }
exports.Smartchok = Smartchok; exports.Smartchok = Smartchok;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjtJQVFJLFlBQVksYUFBdUIsRUFBRSxhQUE0QyxFQUFFO1FBUG5GLG1CQUFjLEdBQUcsSUFBSSxlQUFTLEVBQUUsQ0FBQTtRQUVoQyxXQUFNLEdBQXFCLE1BQU0sQ0FBQTtRQUV6QixxQkFBZ0IsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBUSxDQUFBLENBQUMsaURBQWlEO1FBQzVGLHVCQUFrQixHQUFHLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxhQUFhLEVBQUUsQ0FBQSxDQUFDLG9DQUFvQztRQUc3RixJQUFJLENBQUMsY0FBYyxDQUFDLGNBQWMsQ0FBQyxhQUFhLENBQUMsQ0FBQTtRQUNqRCxJQUFJLENBQUMsZUFBZSxHQUFHLFVBQVUsQ0FBQTtJQUNyQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxHQUFHLENBQUMsWUFBc0I7UUFDdEIsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsWUFBWSxDQUFDLENBQUE7UUFDaEQsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLE1BQU0sS0FBSyxNQUFN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RUFBRSxFQUFFLElBQUksQ0FBQyxlQUFlLENBQUMsQ0FBQTtRQUNqRyxJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUU7WUFDdkIsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUE7WUFDeEIsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxDQUFBO1lBQy9CLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNoQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDRixJQUFJLFlBQVksR0FBRztZQUNqQixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ3RCLENBQUMsQ0FBQTtRQUNELEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUMvQixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUFqRkQsOEJBaUZDIn0=

View File

@ -1,8 +1,9 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
exports.chokidar = require("chokidar"); exports.chokidar = require("chokidar");
exports.lik = require("lik"); exports.lik = require("lik");
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVDQUE0QztBQUM1Qyw2QkFBa0M7QUFDbEMsK0JBQW9DO0FBQ3BDLHlCQUE4QjtBQUM5QixnQ0FBcUMifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBNEM7QUFDNUMsNkJBQWtDO0FBQ2xDLCtCQUFvQztBQUNwQyx5QkFBOEI7QUFDOUIsZ0NBQXFDIn0=

View File

@ -1,6 +1,6 @@
{ {
"name": "smartchok", "name": "smartchok",
"version": "1.0.3", "version": "1.0.6",
"description": "smart wrapper for chokidar", "description": "smart wrapper for chokidar",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
@ -19,18 +19,17 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartchok#README", "homepage": "https://gitlab.com/pushrocks/smartchok#README",
"dependencies": { "dependencies": {
"@types/chokidar": "^1.4.29", "@types/chokidar": "^1.6.0",
"@types/q": "x.x.x", "@types/q": "x.x.x",
"chokidar": "^1.6.1", "chokidar": "^1.6.1",
"lik": "^1.0.24", "lik": "^1.0.30",
"q": "^1.4.1", "q": "^1.5.0",
"rxjs": "^5.0.0-rc.3", "rxjs": "^5.3.0",
"smartipc": "^1.0.9",
"typings-global": "^1.0.14" "typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "smartfile": "^4.1.9",
"should": "^11.1.1", "tapbundle": "^1.0.5"
"smartfile": "^4.1.0",
"typings-test": "^1.0.3"
} }
} }

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,38 +1,43 @@
import 'typings-test' import { tap, expect } from 'tapbundle'
import * as should from 'should'
import * as smartfile from 'smartfile' import * as smartfile from 'smartfile'
import * as smartq from 'smartq'
import * as rx from 'rxjs/Rx' import * as rx from 'rxjs/Rx'
// the module to test
import * as smartchok from '../dist/index' import * as smartchok from '../dist/index'
describe('smartchok',function(){ let testSmartchok: smartchok.Smartchok
let testSmartchok: smartchok.Smartchok let testAddObservable: rx.Observable<any>
let testAddObservable: rx.Observable<any> let testSubscription: rx.Subscription
let testSubscription: rx.Subscription tap.test('should create a new instance', async () => {
it('should create a new instance',function(){ testSmartchok = new smartchok.Smartchok([])
testSmartchok = new smartchok.Smartchok([]) return expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
should(testSmartchok).be.instanceof(smartchok.Smartchok) }).catch(tap.threw)
})
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.add([ './test/assets/**/*.txt' ])
testSmartchok.start().then(() => { let localPromise = testSmartchok.start().then(async () => {
testSmartchok.add(['./test/assets/**/*.md']) testSmartchok.add([ './test/assets/**/*.md' ])
done() })
}).catch(err => { console.log(err) }) return await expect(localPromise).to.eventually.be.fulfilled
}) }).catch(tap.threw)
it('should get an observable for a certain event',function(done){
testSmartchok.getObservableFor('add').then((observableArg) => { tap.test('should get an observable for a certain event', async () => {
testAddObservable = observableArg let localPromise = testSmartchok.getObservableFor('add').then(async (observableArg) => {
done() testAddObservable = observableArg
}).catch(err => { console.log(err) }) })
}) return await expect(localPromise).to.eventually.be.fulfilled
it('should register an add operation',function(done){ }).catch(tap.threw)
this.timeout(5000)
testSubscription = testAddObservable.subscribe(x => { tap.test('should register an add operation', async () => {
done() let testDeferred = smartq.defer()
}) testSubscription = testAddObservable.subscribe(x => {
smartfile.memory.toFs('HI','./test/assets/hi.txt') testDeferred.resolve()
}) })
it('should stop the watch process',function() { smartfile.memory.toFs('HI', './test/assets/hi.txt')
testSmartchok.stop() return await expect(testDeferred.promise).to.eventually.be.fulfilled
}) }).catch(tap.threw)
})
tap.test('should stop the watch process', async () => {
testSmartchok.stop()
}).catch(tap.threw)

View File

@ -8,84 +8,84 @@ export type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlin
* Smartchok allows easy wathcing of files * Smartchok allows easy wathcing of files
*/ */
export class Smartchok { export class Smartchok {
watchStringmap = new Stringmap() watchStringmap = new Stringmap()
chokidarOptions: plugins.chokidar.WatchOptions chokidarOptions: plugins.chokidar.WatchOptions
status: TSmartchokStatus = 'idle' status: TSmartchokStatus = 'idle'
private watcher private watcher
private watchingDeferred = plugins.q.defer<void>() // used to run things when watcher is initialized 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 private eventObservablemap = new plugins.lik.Observablemap() // register one observable per event
/** /**
* constructor of class smartchok * constructor of class smartchok
*/ */
constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) { constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
this.watchStringmap.addStringArray(watchArrayArg) this.watchStringmap.addStringArray(watchArrayArg)
this.chokidarOptions = optionsArg 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)
})
} }
/** }
* 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)
})
}
/** /**
* removes files from the list of watched files * gets an observable for a certain event
*/ */
remove(pathArg: string) { getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>> {
this.watchStringmap.removeString('') // TODO let done = plugins.q.defer<plugins.rx.Observable<any>>()
this.watchingDeferred.promise.then(() => { this.watchingDeferred.promise.then(() => {
this.watcher.unwatch(pathArg) let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent)
}) done.resolve(eventObservable)
} })
return done.promise
}
/** /**
* gets an observable for a certain event * starts the watcher
*/ * @returns Promise<void>
getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>> { */
let done = plugins.q.defer<plugins.rx.Observable<any>>() start(): plugins.q.Promise<void> {
this.watchingDeferred.promise.then(() => { let done = plugins.q.defer<void>()
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent) this.status = 'starting'
done.resolve(eventObservable) this.watcher = plugins.chokidar.watch(this.watchStringmap.getStringArray(), this.chokidarOptions)
}) this.watcher.on('ready', () => {
return done.promise this.status = 'watching'
} this.watchingDeferred.resolve()
done.resolve()
})
return done.promise
}
/** /**
* starts the watcher * stop the watcher process if watching
* @returns Promise<void> */
*/ stop() {
start(): plugins.q.Promise<void> { let closeWatcher = () => {
let done = plugins.q.defer<void>() this.watcher.close()
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
} }
if (this.status === 'watching') {
/** console.log('closing while watching')
* stop the watcher process if watching closeWatcher()
*/ } else if (this.status === 'starting') {
stop() { this.watchingDeferred.promise.then(() => { closeWatcher() })
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() })
}
} }
}
} }

2274
yarn.lock Normal file

File diff suppressed because it is too large Load Diff