35 Commits

Author SHA1 Message Date
cd9ca458f6 1.0.20 2019-06-04 14:04:07 +02:00
2c4fc8b212 fix(core): update 2019-06-04 14:04:06 +02:00
ce48b6f889 1.0.19 2019-06-04 13:59:54 +02:00
2e851cbabc fix(core): update 2019-06-04 13:59:54 +02:00
4c001f5270 1.0.18 2019-05-05 20:54:02 +02:00
dfbbe8090f fix(core): update 2019-05-05 20:54:02 +02:00
40dd48533d 1.0.17 2019-05-05 20:46:25 +02:00
1e252d2cd7 fix(core): update 2019-05-05 20:46:25 +02:00
34eb725d40 1.0.16 2019-05-05 20:41:29 +02:00
0298bfe3c6 fix(core): update 2019-05-05 20:41:29 +02:00
ea26987ca6 1.0.15 2018-10-10 17:06:40 +02:00
8f6a4f4909 fix(core): update 2018-10-10 17:06:40 +02:00
c7b0722155 1.0.14 2018-03-01 00:19:22 +01:00
6cbd74eb12 update ci 2018-03-01 00:19:18 +01:00
fe52811dcd 1.0.13 2018-03-01 00:17:37 +01:00
9c1e306c99 update ci 2018-03-01 00:17:33 +01:00
19ab839853 1.0.12 2018-03-01 00:08:11 +01:00
cb6c8f3c8e update ci 2018-03-01 00:08:08 +01:00
9e06369139 1.0.11 2017-06-30 20:32:59 +02:00
7d4975cea8 fix Promise issues 2017-06-30 20:32:35 +02:00
af9eb0d99e update test 2017-06-30 18:20:48 +02:00
46e7b52930 update 2017-06-30 18:16:59 +02:00
bf7ec659b7 1.0.10 2017-06-30 18:12:02 +02:00
ab3ad55c43 fix loading of rxjs 2017-06-30 18:12:00 +02:00
5e5f2ce6c2 clean up code 2017-06-30 18:06:37 +02:00
89566ebc1d 1.0.9 2017-06-30 18:05:57 +02:00
fda93fa553 update to wirj like expected 2017-06-30 18:05:55 +02:00
583cf6f446 1.0.8 2017-04-09 16:59:14 +02:00
8d87616971 update ci 2017-04-09 16:59:10 +02:00
e3e70a680e 1.0.7 2017-04-09 16:57:53 +02:00
49e7146320 update npmextra.json 2017-04-09 16:57:49 +02:00
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
18 changed files with 2347 additions and 366 deletions

24
.gitignore vendored
View File

@ -1,4 +1,22 @@
node_modules/ .nogit/
pages/
public/ # artifacts
coverage/ coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,48 +1,117 @@
image: hosttoday/ht-docker-node:npmts # gitzone ci_default
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages: stages:
- security
- test - test
- release - release
- page - metadata
testLEGACY: # ====================
stage: test # security stage
# ====================
mirror:
stage: security
script: script:
- npmci test legacy - npmci git mirror
tags: tags:
- docker - docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS: testLTS:
stage: test stage: test
script: script:
- npmci test lts - npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci test stable - npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
environment: npmjs-com_registry
script: script:
- npmci publish - npmci node install stable
- npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmpage image: hosttoday/ht-docker-node:npmci
stage: page stage: metadata
script: script:
- npmci command npmpage --host gitlab - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
- notpriv
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true

9
.snyk Normal file
View File

@ -0,0 +1,9 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.12.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
'npm:chownr:20180731':
- chokidar > fsevents > node-pre-gyp > tar > chownr:
reason: None given
expires: '2018-11-09T15:06:03.003Z'
patch: {}

View File

@ -1,46 +1,51 @@
# smartchok # @pushrocks/smartchok
smart wrapper for chokidar smart wrapper for chokidar
## Availabililty ## Availabililty and Links
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartchok) * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartchok) * [gitlab.com (source)](https://gitlab.com/pushrocks/smartchok)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartchok) * [github.com (source mirror)](https://github.com/pushrocks/smartchok)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartchok/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartchok/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartchok/badges/master/build.svg)](https://gitlab.com/pushrocks/smartchok/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/smartchok/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartchok/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/smartchok.svg)](https://david-dm.org/pushrocks/smartchok) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartchokidar.svg)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartchok/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartchok/master/dependencies/npm) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartchokidar/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartchokidar)
[![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->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.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->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.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-prettier-ff69b4.svg)](https://prettier.io/)
[![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';
let mySmartChok = new Smartchok(['some/path/**/*.any','/absolute/*.js'], chokidarOptions) let mySmartChok = new Smartchok(['some/path/**/*.any', '/absolute/*.js'], chokidarOptions);
mySmartChok.add(['/some/**/*.any']) // add files mySmartChok.add(['/some/**/*.any']); // add files
mySmartChok.remove('some/**/*.js') mySmartChok.remove('some/**/*.js');
mySmartChok.start() // starts the watch process 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 is detected // do something here when a change is detected
// possible events are 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw' // 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
}) });
}) });
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://maintainedby.lossless.com)

36
dist/index.d.ts vendored
View File

@ -1,36 +0,0 @@
/// <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;
}

76
dist/index.js vendored
View File

@ -1,76 +0,0 @@
"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;
}
/**
* 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQThDO0FBQzlDLDZ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FQUFFLENBQUE7UUFDbEIsQ0FBQyxDQUFDLENBQUE7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0EsSUFBSSxZQUFZLEdBQUc7WUFDZixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ3hCLENBQUMsQ0FBQTtRQUNELEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUM3QixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDbEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDcEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ2hFLENBQUM7SUFDTCxDQUFDO0NBQ0o7QUE5RUQsOEJBOEVDIn0=

View File

@ -1,6 +0,0 @@
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');

View File

@ -1,8 +0,0 @@
"use strict";
require("typings-global");
exports.chokidar = require("chokidar");
exports.lik = require("lik");
exports.path = require("path");
exports.q = require("q");
exports.rx = require("rxjs/Rx");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVDQUE0QztBQUM1Qyw2QkFBa0M7QUFDbEMsK0JBQW9DO0FBQ3BDLHlCQUE4QjtBQUM5QixnQ0FBcUMifQ==

View File

@ -1,5 +1,16 @@
{ {
"npmts": { "npmci": {
"mode": "default" "npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartchok",
"shortDescription": "smart wrapper for chokidar",
"npmPackagename": "@pushrocks/smartchokidar",
"license": "MIT"
}
} }
} }

1987
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
{ {
"name": "smartchok", "name": "@pushrocks/smartchok",
"version": "1.0.4", "version": "1.0.20",
"private": false,
"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",
"scripts": { "scripts": {
"test": "(npm run prepareTest && npmts)", "test": "(npm run prepareTest && tstest test/)",
"prepareTest": "(rm -f ./test/assets/hi.txt)" "prepareTest": "(rm -f ./test/assets/hi.txt)",
"build": "tsbuild"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -19,18 +21,31 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartchok#README", "homepage": "https://gitlab.com/pushrocks/smartchok#README",
"dependencies": { "dependencies": {
"@types/chokidar": "^1.4.29", "@pushrocks/lik": "^3.0.5",
"@types/q": "x.x.x", "@pushrocks/smartpromise": "^3.0.2",
"chokidar": "^1.6.1", "@pushrocks/smartrx": "^2.0.3",
"lik": "^1.0.24", "@pushrocks/smartspawn": "^2.0.4",
"q": "^1.4.1", "@types/chokidar": "^2.1.3",
"rxjs": "^5.0.0-rc.3", "chokidar": "^3.0.1"
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "@gitzone/tsbuild": "^2.1.11",
"should": "^11.1.1", "@gitzone/tsrun": "^1.2.6",
"smartfile": "^4.1.0", "@gitzone/tstest": "^1.0.24",
"typings-test": "^1.0.3" "@pushrocks/smartfile": "^7.0.2",
} "@pushrocks/tapbundle": "^3.0.9",
"@types/node": "^12.0.4",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

1
test/test.d.ts vendored
View File

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

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsdUNBQXNDO0FBRXRDLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyxFQUFDO0lBQ2pCLElBQUksYUFBa0MsQ0FBQTtJQUN0QyxJQUFJLGlC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Q0FBQTtJQUN6QyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxrQ0FBa0MsRUFBQyxVQUFTLElBQUk7UUFDL0MsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUNsQixnQkFBZ0IsR0FBRyxpQkFBaUIsQ0FBQyxTQUFTLENBQUMsQ0FBQztZQUM1QyxJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO1FBQ0YsU0FBUyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFDLHNCQUFzQixDQUFDLENBQUE7SUFDdEQsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsK0JBQStCLEVBQUM7UUFDL0IsYUFBYSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

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

View File

@ -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() })
}
}
}

View File

@ -0,0 +1,99 @@
import * as plugins from './smartchok.plugins';
import { Stringmap } from '@pushrocks/lik';
import { Observablemap } from '@pushrocks/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: plugins.chokidar.FSWatcher;
private watchingDeferred = plugins.smartpromise.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.smartpromise.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.smartpromise.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();
});
}
}
}

View File

@ -1,6 +1,5 @@
import 'typings-global' export import lik = require('@pushrocks/lik');
export import chokidar = require('chokidar') export import chokidar = require('chokidar');
export import lik = require('lik') export import path = require('path');
export import path = require('path') export import smartpromise = require('@pushrocks/smartpromise');
export import q = require('q') export import smartrx = require('@pushrocks/smartrx');
export import rx = require('rxjs/Rx')

View File

@ -1,3 +1,17 @@
{ {
"extends": "tslint-config-standard" "extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
} }