Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
40dd48533d | |||
1e252d2cd7 | |||
34eb725d40 | |||
0298bfe3c6 | |||
ea26987ca6 | |||
8f6a4f4909 | |||
c7b0722155 | |||
6cbd74eb12 | |||
fe52811dcd | |||
9c1e306c99 | |||
19ab839853 | |||
cb6c8f3c8e | |||
9e06369139 | |||
7d4975cea8 | |||
af9eb0d99e | |||
46e7b52930 | |||
bf7ec659b7 | |||
ab3ad55c43 | |||
5e5f2ce6c2 |
@ -3,69 +3,145 @@ image: hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
tags:
|
||||||
|
- 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
|
||||||
|
# ====================
|
||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci npm prepare
|
||||||
|
- npmci node install legacy
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
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
|
||||||
|
- 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/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
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
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
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-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage --publish gitlab
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
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
|
||||||
|
|
||||||
|
windowsCompatibility:
|
||||||
|
image: stefanscherer/node-windows:10-build-tools
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npm install & npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- windows
|
||||||
|
allow_failure: true
|
||||||
|
9
.snyk
Normal file
9
.snyk
Normal 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: {}
|
24
README.md
24
README.md
@ -1,13 +1,16 @@
|
|||||||
# smartchok
|
# smartchok
|
||||||
|
|
||||||
smart wrapper for chokidar
|
smart wrapper for chokidar
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartchok)
|
[](https://www.npmjs.com/package/smartchok)
|
||||||
[](https://GitLab.com/pushrocks/smartchok)
|
[](https://GitLab.com/pushrocks/smartchok)
|
||||||
[](https://github.com/pushrocks/smartchok)
|
[](https://github.com/pushrocks/smartchok)
|
||||||
[](https://pushrocks.gitlab.io/smartchok/)
|
[](https://pushrocks.gitlab.io/smartchok/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
||||||
[](https://www.npmjs.com/package/smartchok)
|
[](https://www.npmjs.com/package/smartchok)
|
||||||
@ -19,34 +22,35 @@ smart wrapper for chokidar
|
|||||||
[](http://standardjs.com/)
|
[](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)
|
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();
|
||||||
```
|
```
|
||||||
|
|
||||||
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.html)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://push.rocks)
|
||||||
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './smartchok.classes.smartchok';
|
|
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -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
|
|
0
dist/smartchok.child.d.ts
vendored
0
dist/smartchok.child.d.ts
vendored
3
dist/smartchok.child.js
vendored
3
dist/smartchok.child.js
vendored
@ -1,3 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNoaWxkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNoaWxkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
|
41
dist/smartchok.classes.smartchok.d.ts
vendored
41
dist/smartchok.classes.smartchok.d.ts
vendored
@ -1,41 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as plugins from './smartchok.plugins';
|
|
||||||
import { Stringmap } from 'lik';
|
|
||||||
export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
|
||||||
export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
|
|
||||||
/**
|
|
||||||
* Smartchok allows easy wathcing of files
|
|
||||||
*/
|
|
||||||
export declare class Smartchok {
|
|
||||||
watchStringmap: Stringmap;
|
|
||||||
chokidarOptions: plugins.chokidar.WatchOptions;
|
|
||||||
status: TSmartchokStatus;
|
|
||||||
private watcher;
|
|
||||||
private watchingDeferred;
|
|
||||||
private eventObservablemap;
|
|
||||||
/**
|
|
||||||
* constructor of class smartchok
|
|
||||||
*/
|
|
||||||
constructor(watchArrayArg: string[], optionsArg?: plugins.chokidar.WatchOptions);
|
|
||||||
/**
|
|
||||||
* adds files to the list of watched files
|
|
||||||
*/
|
|
||||||
add(pathArrayArg: string[]): void;
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg: string): void;
|
|
||||||
/**
|
|
||||||
* gets an observable for a certain event
|
|
||||||
*/
|
|
||||||
getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>>;
|
|
||||||
/**
|
|
||||||
* starts the watcher
|
|
||||||
* @returns Promise<void>
|
|
||||||
*/
|
|
||||||
start(): plugins.q.Promise<void>;
|
|
||||||
/**
|
|
||||||
* stop the watcher process if watching
|
|
||||||
*/
|
|
||||||
stop(): void;
|
|
||||||
}
|
|
75
dist/smartchok.classes.smartchok.js
vendored
75
dist/smartchok.classes.smartchok.js
vendored
@ -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.q.defer(); // used to run things when watcher is initialized
|
|
||||||
this.eventObservablemap = new plugins.lik.Observablemap(); // register one observable per event
|
|
||||||
this.watchStringmap.addStringArray(watchArrayArg);
|
|
||||||
this.chokidarOptions = optionsArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* adds files to the list of watched files
|
|
||||||
*/
|
|
||||||
add(pathArrayArg) {
|
|
||||||
this.watchStringmap.addStringArray(pathArrayArg);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg) {
|
|
||||||
this.watchStringmap.removeString(pathArg);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* gets an observable for a certain event
|
|
||||||
*/
|
|
||||||
getObservableFor(fsEvent) {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent);
|
|
||||||
done.resolve(eventObservable);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* starts the watcher
|
|
||||||
* @returns Promise<void>
|
|
||||||
*/
|
|
||||||
start() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
this.status = 'starting';
|
|
||||||
this.watcher = plugins.chokidar.watch(this.watchStringmap.getStringArray(), this.chokidarOptions);
|
|
||||||
this.watcher.on('ready', () => {
|
|
||||||
this.status = 'watching';
|
|
||||||
this.watchingDeferred.resolve();
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* stop the watcher process if watching
|
|
||||||
*/
|
|
||||||
stop() {
|
|
||||||
let closeWatcher = () => {
|
|
||||||
this.watcher.close();
|
|
||||||
};
|
|
||||||
if (this.status === 'watching') {
|
|
||||||
console.log('closing while watching');
|
|
||||||
closeWatcher();
|
|
||||||
}
|
|
||||||
else if (this.status === 'starting') {
|
|
||||||
this.watchingDeferred.promise.then(() => { closeWatcher(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Smartchok = Smartchok;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMv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ZQUMvQixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUF4RUQsOEJBd0VDIn0=
|
|
0
dist/smartchok.classes.watcher.d.ts
vendored
0
dist/smartchok.classes.watcher.d.ts
vendored
3
dist/smartchok.classes.watcher.js
vendored
3
dist/smartchok.classes.watcher.js
vendored
@ -1,3 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMud2F0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2hvay5jbGFzc2VzLndhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
13
dist/smartchok.plugins.d.ts
vendored
13
dist/smartchok.plugins.d.ts
vendored
@ -1,13 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
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');
|
|
||||||
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>;
|
|
||||||
}
|
|
||||||
}
|
|
9
dist/smartchok.plugins.js
vendored
9
dist/smartchok.plugins.js
vendored
@ -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.q = require("q");
|
|
||||||
exports.rx = require("rxjs/Rx");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw2QkFBa0M7QUFDbEMsdUNBQTRDO0FBQzVDLCtCQUFvQztBQUNwQyx5QkFBOEI7QUFDOUIsZ0NBQXFDIn0=
|
|
@ -1,10 +1,7 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
|
||||||
"mode": "default"
|
|
||||||
},
|
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [
|
||||||
"npmts"
|
],
|
||||||
]
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
1694
package-lock.json
generated
Normal file
1694
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartchok",
|
"name": "@pushrocks/smartchok",
|
||||||
"version": "1.0.9",
|
"version": "1.0.17",
|
||||||
|
"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,19 @@
|
|||||||
},
|
},
|
||||||
"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",
|
||||||
"@types/q": "x.x.x",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"chokidar": "^1.7.0",
|
"@pushrocks/smartrx": "^2.0.3",
|
||||||
"lik": "^1.0.32",
|
"@pushrocks/smartspawn": "^2.0.4",
|
||||||
"q": "^1.5.0",
|
"@types/chokidar": "^2.1.3",
|
||||||
"rxjs": "^5.4.1",
|
"chokidar": "^3.0.0"
|
||||||
"smartipc": "^1.0.9",
|
|
||||||
"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.20",
|
||||||
|
"@pushrocks/smartfile": "^7.0.2",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.9",
|
||||||
|
"@types/node": "^12.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
60
test/test.ts
60
test/test.ts
@ -1,45 +1,45 @@
|
|||||||
import { tap, expect } from 'tapbundle'
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartfile from 'smartfile'
|
import * as smartchok from '../ts/index';
|
||||||
import * as smartq from 'smartq'
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as rx from 'rxjs/Rx'
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
// the module to test
|
// the module to test
|
||||||
import * as smartchok from '../dist/index'
|
|
||||||
|
|
||||||
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();
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from './smartchok.classes.smartchok'
|
export * from './smartchok.classes.smartchok';
|
||||||
|
@ -1 +0,0 @@
|
|||||||
import chokidar = require('chokidar')
|
|
@ -1,68 +1,83 @@
|
|||||||
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;
|
||||||
private watchingDeferred = plugins.q.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): plugins.q.Promise<plugins.rx.Observable<any>> {
|
getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<any>> {
|
||||||
let done = plugins.q.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts the watcher
|
* starts the watcher
|
||||||
* @returns Promise<void>
|
* @returns Promise<void>
|
||||||
*/
|
*/
|
||||||
start(): plugins.q.Promise<void> {
|
start(): Promise<void> {
|
||||||
let done = plugins.q.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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
import * as plugins from './smartchok.plugins'
|
|
||||||
|
|
@ -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 q = require('q')
|
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>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user