22 Commits

Author SHA1 Message Date
771c454411 1.0.22 2019-08-22 10:54:26 +02:00
99395794d8 fix(core): update 2019-08-22 10:54:26 +02:00
1763ede6df 1.0.21 2019-08-22 10:53:29 +02:00
102b6ac9ae fix(core): update 2019-08-22 10:53:29 +02:00
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
25 changed files with 2196 additions and 1846 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,71 +1,121 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
variables:
GIT_STRATEGY: clone
cache: cache:
paths: paths:
- .yarn/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: "$CI_BUILD_STAGE"
stages: stages:
- security
- test - test
- release - release
- trigger - metadata
- pages
testLEGACY: # ====================
stage: test # security stage
# ====================
mirror:
stage: security
script: script:
- npmci test legacy - npmci git mirror
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
allow_failure: true - 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/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testSTABLE:
testBuild:
stage: test stage: test
script: script:
- npmci test stable - npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci publish - npmci node install lts
- 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: trigger:
stage: trigger stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-dbase:npmci
stage: pages services:
- docker:18-dind
stage: metadata
script: script:
- npmci command yarn global add npmpage - npmci command npm install -g @gitzone/tsdoc
- npmci command npmpage --publish gitlab - npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags: tags:
- docker - 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,52 +1,51 @@
# smartchok # @pushrocks/smartchok
smart wrapper for chokidar smart wrapper for chokidar
## Availabililty ## Availabililty and Links
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartchok) * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartchok) * [gitlab.com (source)](https://gitlab.com/pushrocks/smartchok)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartchok) * [github.com (source mirror)](https://github.com/pushrocks/smartchok)
[![docs](https://pushrocks.gitlab.io/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)
[![npm downloads per month](https://img.shields.io/npm/dm/smartchok.svg)](https://www.npmjs.com/package/smartchok) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartchokidar.svg)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
[![Dependency Status](https://david-dm.org/pushrocks/smartchok.svg)](https://david-dm.org/pushrocks/smartchok) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartchokidar/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartchokidar)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartchok/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartchok/master/dependencies/npm) [![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartchok/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartchok) [![node](https://img.shields.io/badge/node->=%2010.x.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/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
[![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/)
## Usage ## Usage
Use TypeScript for best in class instellisense. 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) const 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();
``` ```
For further information read the linked docs at the top of this README. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

1
dist/index.d.ts vendored
View File

@ -1 +0,0 @@
export * from './smartchok.classes.smartchok';

7
dist/index.js vendored
View File

@ -1,7 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartchok.classes.smartchok"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9

View File

View File

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNoaWxkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNoaWxkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==

View File

@ -1,40 +0,0 @@
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): Promise<plugins.rx.Observable<any>>;
/**
* starts the watcher
* @returns Promise<void>
*/
start(): Promise<void>;
/**
* stop the watcher process if watching
*/
stop(): void;
}

View File

@ -1,75 +0,0 @@
"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.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.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjs7R0FFRztBQUNIO0lBUUU7O09BRUc7SUFDSCxZQUFhLGFBQXVCLEVBQUUsYUFBNEMsRUFBRTtRQVZwRixtQkFBYyxHQUFHLElBQUksZUFBUyxFQUFFLENBQUE7UUFFaEMsV0FBTSxHQUFxQixNQUFNLENBQUE7UUFFekIscUJBQWdCLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLEVBQVEsQ0FBQSxDQUFDLGlEQUFpRDtRQUNqRyx1QkFBa0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLENBQUEsQ0FBQyxvQ0FBb0M7UUFNL0YsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDakQsSUFBSSxDQUFDLGVBQWUsR0FBRyxVQUFVLENBQUE7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFlBQXNCO1FBQ3hCLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxDQUFDLFlBQVksQ0FBQyxDQUFBO0lBQ2xELENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sQ0FBRSxPQUFlO1FBQ3JCLElBQUksQ0FBQyxjQUFjLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQzNDLENBQUM7SUFFRDs7T0FFRztJQUNILGdCQUFnQixDQUFFLE9BQWlCO1FBQ2pDLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUE4QixDQUFBO1FBQzdELElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDO1lBQ2pDLElBQUksZUFBZSxHQUFHLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyw0QkFBNEIsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFBO1lBQ2pHLElBQUksQ0FBQyxPQUFPLENBQUMsZUFBZSxDQUFDLENBQUE7UUFDL0IsQ0FBQyxDQUFDLENBQUE7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsS0FBSztRQUNILElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDdkMsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUE7UUFDeEIsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsY0FBYyxDQUFDLGNBQWMsRUFBRSxFQUFFLElBQUksQ0FBQyxlQUFlLENBQUMsQ0FBQTtRQUNqRyxJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUU7WUFDdkIsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUE7WUFDeEIsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxDQUFBO1lBQy9CLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNoQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDRixJQUFJLFlBQVksR0FBRztZQUNqQixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ3RCLENBQUMsQ0FBQTtRQUNELEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUMvQixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUF4RUQsOEJBd0VDIn0=

View File

View File

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMud2F0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2hvay5jbGFzc2VzLndhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9

View File

@ -1,13 +0,0 @@
import 'typings-global';
export import lik = require('lik');
export import chokidar = require('chokidar');
export import path = require('path');
export import smartq = require('smartq');
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>;
}
}

View File

@ -1,9 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
exports.lik = require("lik");
exports.chokidar = require("chokidar");
exports.path = require("path");
exports.smartq = require("smartq");
exports.rx = require("rxjs/Rx");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw2QkFBa0M7QUFDbEMsdUNBQTRDO0FBQzVDLCtCQUFvQztBQUNwQyxtQ0FBd0M7QUFDeEMsZ0NBQXFDIn0=

View File

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

1907
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.11", "version": "1.0.22",
"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": "(yarn 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,16 +21,31 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartchok#README", "homepage": "https://gitlab.com/pushrocks/smartchok#README",
"dependencies": { "dependencies": {
"@types/chokidar": "^1.7.0", "@pushrocks/lik": "^3.0.5",
"chokidar": "^1.7.0", "@pushrocks/smartpromise": "^3.0.2",
"lik": "^1.0.32", "@pushrocks/smartrx": "^2.0.3",
"rxjs": "^5.4.1", "@types/chokidar": "^2.1.3",
"smartipc": "^1.0.9", "chokidar": "^3.0.1"
"smartq": "^1.1.1",
"typings-global": "^1.0.19"
}, },
"devDependencies": { "devDependencies": {
"smartfile": "^4.2.17", "@gitzone/tsbuild": "^2.1.11",
"tapbundle": "^1.0.14" "@gitzone/tsrun": "^1.2.6",
} "@gitzone/tstest": "^1.0.24",
"@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/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

View File

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

View File

@ -1 +1 @@
export * from './smartchok.classes.smartchok' export * from './smartchok.classes.smartchok';

View File

@ -1 +0,0 @@
import chokidar = require('chokidar')

View File

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

View File

@ -1,2 +0,0 @@
import * as plugins from './smartchok.plugins'

View File

@ -1,15 +1,5 @@
import 'typings-global' export import lik = require('@pushrocks/lik');
export import lik = require('lik') export import chokidar = require('chokidar');
export import chokidar = require('chokidar') export import path = require('path');
export import path = require('path') export import smartpromise = require('@pushrocks/smartpromise');
export import smartq = require('smartq') export import smartrx = require('@pushrocks/smartrx');
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>
}
}

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"
} }

1526
yarn.lock

File diff suppressed because it is too large Load Diff