Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
7c4324b3ad | |||
268201727c | |||
12ae27b2ff | |||
3bb9b2229d | |||
e17e4c376e | |||
d5f2427aad | |||
5715c6fe67 | |||
9628e914b5 | |||
55746f5d92 | |||
90ae869686 | |||
771c454411 | |||
99395794d8 | |||
1763ede6df | |||
102b6ac9ae |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -1,10 +1,10 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -19,38 +22,42 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
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
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@ -60,7 +67,17 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -70,6 +87,7 @@ release:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -79,11 +97,15 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -94,18 +116,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
|
9
.snyk
9
.snyk
@ -1,9 +0,0 @@
|
|||||||
# 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: {}
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
51
README.md
51
README.md
@ -1,51 +0,0 @@
|
|||||||
# @pushrocks/smartchok
|
|
||||||
smart wrapper for chokidar
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartchok)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartchok)
|
|
||||||
* [docs (typedoc)](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/@pushrocks/smartchokidar)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartchokidar)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## 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://maintainedby.lossless.com)
|
|
@ -4,6 +4,7 @@
|
|||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
27239
package-lock.json
generated
27239
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartchok",
|
"name": "@pushrocks/smartchok",
|
||||||
"version": "1.0.20",
|
"version": "1.0.27",
|
||||||
"private": false,
|
"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 && tstest test/)",
|
"test": "(npm run prepareTest && tstest test/)",
|
||||||
"prepareTest": "(rm -f ./test/assets/hi.txt)",
|
"prepareTest": "(rm -f ./test/assets/hi.txt)",
|
||||||
@ -21,31 +21,34 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.5",
|
"@pushrocks/lik": "^5.0.0",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartrx": "^2.0.3",
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"@pushrocks/smartspawn": "^2.0.4",
|
"chokidar": "^3.5.2"
|
||||||
"@types/chokidar": "^2.1.3",
|
|
||||||
"chokidar": "^3.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.28",
|
||||||
"@gitzone/tsrun": "^1.2.6",
|
"@gitzone/tsrun": "^1.2.18",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.60",
|
||||||
"@pushrocks/smartfile": "^7.0.2",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^12.0.4",
|
"@types/node": "^16.11.10",
|
||||||
"tslint": "^5.17.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"assets/*",
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
63
readme.md
Normal file
63
readme.md
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# @pushrocks/smartchok
|
||||||
|
smart wrapper for chokidar
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartchok)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartchok)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartchok/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { Smartchok } from 'smartchok';
|
||||||
|
|
||||||
|
const 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();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
17
test/test.ts
17
test/test.ts
@ -4,13 +4,15 @@ import * as smartfile from '@pushrocks/smartfile';
|
|||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrx from '@pushrocks/smartrx';
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
// the module to test
|
// the module to test
|
||||||
if (process.env.CI) {
|
if (process.env.CI) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let testSmartchok: smartchok.Smartchok;
|
let testSmartchok: smartchok.Smartchok;
|
||||||
let testAddObservable: smartrx.rxjs.Observable<any>;
|
let testAddObservable: smartrx.rxjs.Observable<[string, fs.Stats]>;
|
||||||
let testSubscription: smartrx.rxjs.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([]);
|
||||||
@ -19,26 +21,25 @@ tap.test('should create a new instance', async () => {
|
|||||||
|
|
||||||
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']);
|
||||||
});
|
});
|
||||||
await expect(localPromise).to.eventually.be.fulfilled;
|
|
||||||
});
|
|
||||||
|
|
||||||
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;
|
||||||
});
|
});
|
||||||
await expect(localPromise).to.eventually.be.fulfilled;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should register an add operation', async () => {
|
tap.test('should register an add operation', async () => {
|
||||||
let testDeferred = smartpromise.defer();
|
let testDeferred = smartpromise.defer();
|
||||||
testSubscription = testAddObservable.subscribe(x => {
|
testSubscription = testAddObservable.subscribe(pathArg => {
|
||||||
|
const pathResult = pathArg[0];
|
||||||
|
console.log(pathResult);
|
||||||
testDeferred.resolve();
|
testDeferred.resolve();
|
||||||
});
|
});
|
||||||
smartfile.memory.toFs('HI', './test/assets/hi.txt');
|
smartfile.memory.toFs('HI', './test/assets/hi.txt');
|
||||||
await expect(testDeferred.promise).to.eventually.be.fulfilled;
|
await testDeferred.promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop the watch process', async () => {
|
tap.test('should stop the watch process', async () => {
|
||||||
|
@ -17,9 +17,9 @@ export type TFsEvent =
|
|||||||
* Smartchok allows easy wathcing of files
|
* Smartchok allows easy wathcing of files
|
||||||
*/
|
*/
|
||||||
export class Smartchok {
|
export class Smartchok {
|
||||||
watchStringmap = new Stringmap();
|
public watchStringmap = new Stringmap();
|
||||||
chokidarOptions: plugins.chokidar.WatchOptions;
|
public chokidarOptions: plugins.chokidar.WatchOptions;
|
||||||
status: TSmartchokStatus = 'idle';
|
public status: TSmartchokStatus = 'idle';
|
||||||
private watcher: plugins.chokidar.FSWatcher;
|
private watcher: plugins.chokidar.FSWatcher;
|
||||||
private watchingDeferred = plugins.smartpromise.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.smartrx.Observablemap(); // register one observable per event
|
private eventObservablemap = new plugins.smartrx.Observablemap(); // register one observable per event
|
||||||
@ -35,24 +35,24 @@ export class Smartchok {
|
|||||||
/**
|
/**
|
||||||
* adds files to the list of watched files
|
* adds files to the list of watched files
|
||||||
*/
|
*/
|
||||||
add(pathArrayArg: string[]) {
|
public 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) {
|
public 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.smartrx.rxjs.Observable<any>> {
|
public getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<[string, plugins.fs.Stats]>> {
|
||||||
let done = plugins.smartpromise.defer<plugins.smartrx.rxjs.Observable<any>>();
|
const done = plugins.smartpromise.defer<plugins.smartrx.rxjs.Observable<any>>();
|
||||||
this.watchingDeferred.promise.then(() => {
|
this.watchingDeferred.promise.then(() => {
|
||||||
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
|
const eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
|
||||||
this.watcher,
|
this.watcher,
|
||||||
fsEvent
|
fsEvent
|
||||||
);
|
);
|
||||||
@ -65,8 +65,8 @@ export class Smartchok {
|
|||||||
* starts the watcher
|
* starts the watcher
|
||||||
* @returns Promise<void>
|
* @returns Promise<void>
|
||||||
*/
|
*/
|
||||||
start(): Promise<void> {
|
public start(): Promise<void> {
|
||||||
let done = plugins.smartpromise.defer<void>();
|
const done = plugins.smartpromise.defer<void>();
|
||||||
this.status = 'starting';
|
this.status = 'starting';
|
||||||
this.watcher = plugins.chokidar.watch(
|
this.watcher = plugins.chokidar.watch(
|
||||||
this.watchStringmap.getStringArray(),
|
this.watchStringmap.getStringArray(),
|
||||||
@ -83,17 +83,16 @@ export class Smartchok {
|
|||||||
/**
|
/**
|
||||||
* stop the watcher process if watching
|
* stop the watcher process if watching
|
||||||
*/
|
*/
|
||||||
stop() {
|
public async stop() {
|
||||||
let closeWatcher = () => {
|
const closeWatcher = async () => {
|
||||||
this.watcher.close();
|
await this.watcher.close();
|
||||||
};
|
};
|
||||||
if (this.status === 'watching') {
|
if (this.status === 'watching') {
|
||||||
console.log('closing while watching');
|
console.log('closing while watching');
|
||||||
closeWatcher();
|
await closeWatcher();
|
||||||
} else if (this.status === 'starting') {
|
} else if (this.status === 'starting') {
|
||||||
this.watchingDeferred.promise.then(() => {
|
await this.watchingDeferred.promise;
|
||||||
closeWatcher();
|
await closeWatcher();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
export import lik = require('@pushrocks/lik');
|
// node native
|
||||||
export import chokidar = require('chokidar');
|
import * as fs from 'fs';
|
||||||
export import path = require('path');
|
import * as path from 'path';
|
||||||
export import smartpromise = require('@pushrocks/smartpromise');
|
|
||||||
export import smartrx = require('@pushrocks/smartrx');
|
export {
|
||||||
|
fs,
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
// @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
|
||||||
|
}
|
Reference in New Issue
Block a user