24 Commits

Author SHA1 Message Date
50b0fd357a 1.0.32 2024-01-28 17:25:48 +01:00
42976a32d7 fix(core): update 2024-01-28 17:25:47 +01:00
b214de9370 1.0.31 2024-01-28 02:11:50 +01:00
3d98c2ba6f fix(core): update 2024-01-28 02:11:49 +01:00
e4a349c85e 1.0.30 2024-01-28 01:24:00 +01:00
2abfa7c47a fix(core): update 2024-01-28 01:23:59 +01:00
50aa0a136a 1.0.29 2024-01-28 01:19:58 +01:00
b98a9be2b7 fix(core): update 2024-01-28 01:19:57 +01:00
3314928c5f 1.0.28 2024-01-28 01:18:39 +01:00
0b7c29eae7 fix(core): update 2024-01-28 01:18:39 +01:00
779e495941 switch to new org scheme 2023-07-11 00:23:30 +02:00
8402deeccb switch to new org scheme 2023-07-10 02:42:35 +02:00
7c4324b3ad 1.0.27 2021-12-01 02:04:21 +01:00
268201727c fix(core): update 2021-12-01 02:04:21 +01:00
12ae27b2ff 1.0.26 2021-12-01 01:53:29 +01:00
3bb9b2229d fix(core): update 2021-12-01 01:53:28 +01:00
e17e4c376e 1.0.25 2021-11-30 02:35:49 +01:00
d5f2427aad fix(core): update 2021-11-30 02:35:49 +01:00
5715c6fe67 1.0.24 2021-11-29 20:27:00 +01:00
9628e914b5 fix(core): update 2021-11-29 20:26:59 +01:00
55746f5d92 1.0.23 2019-09-29 16:35:12 +02:00
90ae869686 fix(core): update 2019-09-29 16:35:12 +02:00
771c454411 1.0.22 2019-08-22 10:54:26 +02:00
99395794d8 fix(core): update 2019-08-22 10:54:26 +02:00
20 changed files with 6143 additions and 2186 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -1,121 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
variables:
GIT_STRATEGY: clone
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
# ====================
# 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
# ====================
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install lts
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

9
.snyk
View File

@ -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
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -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
[![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)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartchokidar.svg)](https://www.npmjs.com/package/@pushrocks/smartchokidar)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartchokidar/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartchokidar)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -4,12 +4,13 @@
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitscope": "push.rocks",
"gitrepo": "smartchok",
"shortDescription": "smart wrapper for chokidar",
"npmPackagename": "@pushrocks/smartchokidar",
"description": "smart wrapper for chokidar",
"npmPackagename": "@push.rocks/smartchokidar",
"license": "MIT"
}
}

1907
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,51 +1,54 @@
{
"name": "@pushrocks/smartchok",
"version": "1.0.21",
"name": "@push.rocks/smartchok",
"version": "1.0.32",
"private": false,
"description": "smart wrapper for chokidar",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(npm run prepareTest && tstest test/)",
"prepareTest": "(rm -f ./test/assets/hi.txt)",
"build": "tsbuild"
"build": "tsbuild",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartchok.git"
"url": "git+https://gitlab.com/push.rocks/smartchok.git"
},
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartchok/issues"
"url": "https://gitlab.com/push.rocks/smartchok/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
"homepage": "https://gitlab.com/push.rocks/smartchok#readme",
"dependencies": {
"@pushrocks/lik": "^3.0.5",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrx": "^2.0.3",
"@types/chokidar": "^2.1.3",
"chokidar": "^3.0.1"
"@push.rocks/lik": "^6.0.2",
"@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smartrx": "^3.0.2",
"@tempfix/watcher": "^2.3.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.11",
"@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"
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/smartfile": "^11.0.4",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.11.8"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
}

5697
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

63
readme.md Normal file
View File

@ -0,0 +1,63 @@
# @push.rocks/smartchok
smart wrapper for chokidar
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/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 | [![pipeline status](https://gitlab.com/pushrocks/smartchok/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartchok/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartchokidar)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartchok)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartchokidar)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartchokidar)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartchokidar)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,8 +1,10 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartchok from '../ts/index';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
import { tap, expect } from '@push.rocks/tapbundle';
import * as smartchok from '../ts/index.js';
import * as smartfile from '@push.rocks/smartfile';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';
import * as fs from 'fs';
// the module to test
if (process.env.CI) {
@ -10,35 +12,34 @@ if (process.env.CI) {
}
let testSmartchok: smartchok.Smartchok;
let testAddObservable: smartrx.rxjs.Observable<any>;
let testAddObservable: smartrx.rxjs.Observable<[string, fs.Stats]>;
let testSubscription: smartrx.rxjs.Subscription;
tap.test('should create a new instance', async () => {
testSmartchok = new smartchok.Smartchok([]);
expect(testSmartchok).to.be.instanceof(smartchok.Smartchok);
expect(testSmartchok).toBeInstanceOf(smartchok.Smartchok);
});
tap.test('should add some files to watch and start', async () => {
testSmartchok.add(['./test/assets/**/*.txt']);
let localPromise = testSmartchok.start().then(async () => {
await testSmartchok.start()
testSmartchok.add(['./test/assets/**/*.md']);
});
await expect(localPromise).to.eventually.be.fulfilled;
});
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;
});
await expect(localPromise).to.eventually.be.fulfilled;
});
tap.test('should register an add operation', async () => {
let testDeferred = smartpromise.defer();
testSubscription = testAddObservable.subscribe(x => {
testSubscription = testAddObservable.subscribe(pathArg => {
const pathResult = pathArg[0];
console.log(pathResult);
testDeferred.resolve();
});
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 () => {

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartchok',
version: '1.0.32',
description: 'smart wrapper for chokidar'
}

View File

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

View File

@ -1,6 +1,5 @@
import * as plugins from './smartchok.plugins';
import { Stringmap } from '@pushrocks/lik';
import { Observablemap } from '@pushrocks/smartrx';
import * as plugins from './smartchok.plugins.js';
import { Stringmap } from '@push.rocks/lik';
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
export type TFsEvent =
@ -17,42 +16,69 @@ export type TFsEvent =
* Smartchok allows easy wathcing of files
*/
export class Smartchok {
watchStringmap = new Stringmap();
chokidarOptions: plugins.chokidar.WatchOptions;
status: TSmartchokStatus = 'idle';
private watcher: plugins.chokidar.FSWatcher;
public watchStringmap = new Stringmap();
public status: TSmartchokStatus = 'idle';
private watcher: plugins.watcher;
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 = {}) {
constructor(watchArrayArg: string[]) {
this.watchStringmap.addStringArray(watchArrayArg);
this.chokidarOptions = optionsArg;
}
private getGlobBase(globPattern: string) {
// Characters that mark the beginning of a glob pattern
const globChars = ['*', '?', '[', ']', '{', '}'];
// Find the index of the first glob character
const firstGlobCharIndex = globPattern.split('').findIndex((char) => globChars.includes(char));
// If no glob characters are found, return the entire string
if (firstGlobCharIndex === -1) {
return globPattern;
}
// Extract the substring up to the first glob character
const basePathPortion = globPattern.substring(0, firstGlobCharIndex);
// Find the last slash before the glob pattern starts
const lastSlashIndex = basePathPortion.lastIndexOf('/');
// If there is no slash, return the basePathPortion as is
if (lastSlashIndex === -1) {
return basePathPortion;
}
// Return the base path up to and including the last slash
return basePathPortion.substring(0, lastSlashIndex + 1);
}
/**
* adds files to the list of watched files
*/
add(pathArrayArg: string[]) {
public add(pathArrayArg: string[]) {
this.watchStringmap.addStringArray(pathArrayArg);
}
/**
* removes files from the list of watched files
*/
remove(pathArg: string) {
public remove(pathArg: string) {
this.watchStringmap.removeString(pathArg);
}
/**
* gets an observable for a certain event
*/
getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<any>> {
let done = plugins.smartpromise.defer<plugins.smartrx.rxjs.Observable<any>>();
public getObservableFor(
fsEvent: TFsEvent
): Promise<plugins.smartrx.rxjs.Observable<[string, plugins.fs.Stats]>> {
const done = plugins.smartpromise.defer<plugins.smartrx.rxjs.Observable<any>>();
this.watchingDeferred.promise.then(() => {
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
const eventObservable = this.eventObservablemap.getSubjectForEmitterEvent(
this.watcher,
fsEvent
);
@ -65,12 +91,15 @@ export class Smartchok {
* starts the watcher
* @returns Promise<void>
*/
start(): Promise<void> {
let done = plugins.smartpromise.defer<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 = new plugins.watcher(
this.watchStringmap.getStringArray().map((string) => this.getGlobBase(string)),
{
depth: 20,
recursive: true,
}
);
this.watcher.on('ready', () => {
this.status = 'watching';
@ -83,17 +112,16 @@ export class Smartchok {
/**
* stop the watcher process if watching
*/
stop() {
let closeWatcher = () => {
this.watcher.close();
public async stop() {
const closeWatcher = async () => {
await this.watcher.close();
};
if (this.status === 'watching') {
console.log('closing while watching');
closeWatcher();
await closeWatcher();
} else if (this.status === 'starting') {
this.watchingDeferred.promise.then(() => {
closeWatcher();
});
await this.watchingDeferred.promise;
await closeWatcher();
}
}
}

View File

@ -1,5 +1,27 @@
export import lik = require('@pushrocks/lik');
export import chokidar = require('chokidar');
export import path = require('path');
export import smartpromise = require('@pushrocks/smartpromise');
export import smartrx = require('@pushrocks/smartrx');
// node native
import * as fs from 'fs';
import * as path from 'path';
export {
fs,
path
}
// @pushrocks scope
import * as lik from '@push.rocks/lik';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';
export {
lik,
smartpromise,
smartrx
}
// thirdparty scope
// @ts-nocheck
import watcher from '@tempfix/watcher';
export {
watcher,
}

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,17 +0,0 @@
{
"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"
}