Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
5715c6fe67 | |||
9628e914b5 | |||
55746f5d92 | |||
90ae869686 | |||
771c454411 | |||
99395794d8 | |||
1763ede6df | |||
102b6ac9ae | |||
cd9ca458f6 | |||
2c4fc8b212 | |||
ce48b6f889 | |||
2e851cbabc | |||
4c001f5270 | |||
dfbbe8090f | |||
40dd48533d | |||
1e252d2cd7 | |||
34eb725d40 | |||
0298bfe3c6 | |||
ea26987ca6 | |||
8f6a4f4909 | |||
c7b0722155 | |||
6cbd74eb12 | |||
fe52811dcd | |||
9c1e306c99 | |||
19ab839853 | |||
cb6c8f3c8e | |||
9e06369139 | |||
7d4975cea8 | |||
af9eb0d99e | |||
46e7b52930 | |||
bf7ec659b7 | |||
ab3ad55c43 | |||
5e5f2ce6c2 | |||
89566ebc1d | |||
fda93fa553 | |||
583cf6f446 | |||
8d87616971 |
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,4 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
pages/
|
|
||||||
public/
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
133
.gitlab-ci.yml
133
.gitlab-ci.yml
@ -1,48 +1,141 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
# gitzone ci_default
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- security
|
||||||
- release
|
- test
|
||||||
- page
|
- release
|
||||||
|
- metadata
|
||||||
|
|
||||||
testLEGACY:
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
testLTS:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci npm prepare
|
||||||
tags:
|
- npmci node install stable
|
||||||
- docker
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
testSTABLE:
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
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:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
stage: metadata
|
||||||
stage: page
|
|
||||||
script:
|
script:
|
||||||
- npmci command npmpage --host gitlab
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
52
README.md
52
README.md
@ -1,52 +0,0 @@
|
|||||||
# smartchok
|
|
||||||
smart wrapper for chokidar
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
[](https://www.npmjs.com/package/smartchok)
|
|
||||||
[](https://GitLab.com/pushrocks/smartchok)
|
|
||||||
[](https://github.com/pushrocks/smartchok)
|
|
||||||
[](https://pushrocks.gitlab.io/smartchok/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/smartchok)
|
|
||||||
[](https://david-dm.org/pushrocks/smartchok)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartchok/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartchok)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { Smartchok } from 'smartchok'
|
|
||||||
|
|
||||||
let mySmartChok = new Smartchok(['some/path/**/*.any','/absolute/*.js'], chokidarOptions)
|
|
||||||
|
|
||||||
mySmartChok.add(['/some/**/*.any']) // add files
|
|
||||||
|
|
||||||
mySmartChok.remove('some/**/*.js')
|
|
||||||
|
|
||||||
mySmartChok.start() // starts the watch process
|
|
||||||
|
|
||||||
mySmartChok.getObservableFor('change').then((observableArg) => {
|
|
||||||
observableArg.subscribe(x => {
|
|
||||||
// do something here when a change is detected
|
|
||||||
// possible events are 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
|
|
||||||
// note that the observable is only created once you call .start() on the Smartchok instance
|
|
||||||
// hence the promise construction
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
mySmartChok.stop()
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
41
dist/index.d.ts
vendored
41
dist/index.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;
|
|
||||||
}
|
|
83
dist/index.js
vendored
83
dist/index.js
vendored
@ -1,83 +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);
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLCtDQUE4QztBQUM5Qyw2QkFBK0I7QUFLL0I7O0dBRUc7QUFDSDtJQVFFOztPQUVHO0lBQ0gsWUFBWSxhQUF1QixFQUFFLGFBQTRDLEVBQUU7UUFWbkYsbUJBQWMsR0FBRyxJQUFJLGVBQVMsRUFBRSxDQUFBO1FBRWhDLFdBQU0sR0FBcUIsTUFBTSxDQUFBO1FBRXpCLHFCQUFnQixHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUEsQ0FBQyxpREFBaUQ7UUFDNUYsdUJBQWtCLEdBQUcsSUFBSSxPQUFPLENBQUMsR0FBRyxDQUFDLGFBQWEsRUFBRSxDQUFBLENBQUMsb0NBQW9DO1FBTS9GLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxDQUFDLGFBQWEsQ0FBQyxDQUFBO1FBQ2pELElBQUksQ0FBQyxlQUFlLEdBQUcsVU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FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUFqRkQsOEJBaUZDIn0=
|
|
6
dist/smartchok.plugins.d.ts
vendored
6
dist/smartchok.plugins.d.ts
vendored
@ -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');
|
|
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.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBNEM7QUFDNUMsNkJBQWtDO0FBQ2xDLCtCQUFvQztBQUNwQyx5QkFBOEI7QUFDOUIsZ0NBQXFDIn0=
|
|
@ -1,10 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
|
||||||
"mode": "default"
|
|
||||||
},
|
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartchok",
|
||||||
|
"shortDescription": "smart wrapper for chokidar",
|
||||||
|
"npmPackagename": "@pushrocks/smartchokidar",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
27540
package-lock.json
generated
Normal file
27540
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
54
package.json
54
package.json
@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartchok",
|
"name": "@pushrocks/smartchok",
|
||||||
"version": "1.0.7",
|
"version": "1.0.24",
|
||||||
|
"private": false,
|
||||||
"description": "smart wrapper for chokidar",
|
"description": "smart wrapper for chokidar",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/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,17 +21,35 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/chokidar": "^1.6.0",
|
"@pushrocks/lik": "^5.0.0",
|
||||||
"@types/q": "x.x.x",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"chokidar": "^1.6.1",
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"lik": "^1.0.30",
|
"@types/chokidar": "^2.1.3",
|
||||||
"q": "^1.5.0",
|
"chokidar": "^3.5.2"
|
||||||
"rxjs": "^5.3.0",
|
|
||||||
"smartipc": "^1.0.9",
|
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"smartfile": "^4.1.9",
|
"@gitzone/tsbuild": "^2.1.28",
|
||||||
"tapbundle": "^1.0.5"
|
"@gitzone/tsrun": "^1.2.18",
|
||||||
}
|
"@gitzone/tstest": "^1.0.60",
|
||||||
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
|
"@types/node": "^16.11.10",
|
||||||
|
"tslint": "^6.1.3",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
38
test/test.js
38
test/test.js
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsdUNBQXNDO0FBRXRDLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyxFQUFDO0lBQ2pCLElBQUksYUFBa0MsQ0FBQTtJQUN0QyxJQUFJLGlCQUFxQyxDQUFBO0lBQ3pDLElBQUksZ0JBQWlDLENBQUE7SUFDckMsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1FBQzlCLGFBQWEsR0FBRyxJQUFJLFNBQVMsQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLENBQUE7UUFDM0MsTUFBTSxDQUFDLGFBQWEsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDL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NWLENBQUMsQ0FBQyxDQUFBO1FBQ0YsU0FBUyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFDLHNCQUFzQixDQUFDLENBQUE7SUFDdEQsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsK0JBQStCLEVBQUM7UUFDL0IsYUFBYSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
|
64
test/test.ts
64
test/test.ts
@ -1,43 +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'
|
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 () => {
|
await testSmartchok.start()
|
||||||
testSmartchok.add([ './test/assets/**/*.md' ])
|
testSmartchok.add(['./test/assets/**/*.md']);
|
||||||
})
|
});
|
||||||
return 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) => {
|
await testSmartchok.getObservableFor('add').then(async (observableArg) => {
|
||||||
testAddObservable = observableArg
|
testAddObservable = observableArg;
|
||||||
})
|
});
|
||||||
return 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 testDeferred.promise;
|
||||||
}).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();
|
||||||
|
92
ts/index.ts
92
ts/index.ts
@ -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() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
98
ts/smartchok.classes.smartchok.ts
Normal file
98
ts/smartchok.classes.smartchok.ts
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
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 {
|
||||||
|
public watchStringmap = new Stringmap();
|
||||||
|
public chokidarOptions: plugins.chokidar.WatchOptions;
|
||||||
|
public 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
|
||||||
|
*/
|
||||||
|
public add(pathArrayArg: string[]) {
|
||||||
|
this.watchStringmap.addStringArray(pathArrayArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes files from the list of watched files
|
||||||
|
*/
|
||||||
|
public remove(pathArg: string) {
|
||||||
|
this.watchStringmap.removeString(pathArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets an observable for a certain event
|
||||||
|
*/
|
||||||
|
public getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<any>> {
|
||||||
|
const done = plugins.smartpromise.defer<plugins.smartrx.rxjs.Observable<any>>();
|
||||||
|
this.watchingDeferred.promise.then(() => {
|
||||||
|
const eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
|
||||||
|
this.watcher,
|
||||||
|
fsEvent
|
||||||
|
);
|
||||||
|
done.resolve(eventObservable);
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the watcher
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
public start(): Promise<void> {
|
||||||
|
const 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
|
||||||
|
*/
|
||||||
|
public async stop() {
|
||||||
|
const closeWatcher = async () => {
|
||||||
|
await this.watcher.close();
|
||||||
|
};
|
||||||
|
if (this.status === 'watching') {
|
||||||
|
console.log('closing while watching');
|
||||||
|
await closeWatcher();
|
||||||
|
} else if (this.status === 'starting') {
|
||||||
|
await this.watchingDeferred.promise;
|
||||||
|
await closeWatcher();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,24 @@
|
|||||||
import 'typings-global'
|
// node native
|
||||||
export import chokidar = require('chokidar')
|
import * as path from 'path';
|
||||||
export import lik = require('lik')
|
|
||||||
export import path = require('path')
|
export {
|
||||||
export import q = require('q')
|
path
|
||||||
export import rx = require('rxjs/Rx')
|
}
|
||||||
|
|
||||||
|
// @pushrocks scope
|
||||||
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
|
export {
|
||||||
|
lik,
|
||||||
|
smartpromise,
|
||||||
|
smartrx
|
||||||
|
}
|
||||||
|
|
||||||
|
// thirdparty scope
|
||||||
|
import * as chokidar from 'chokidar';
|
||||||
|
|
||||||
|
export {
|
||||||
|
chokidar
|
||||||
|
}
|
16
tslint.json
16
tslint.json
@ -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"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user