Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
8cd846e8bf | |||
d98c54fba9 | |||
50b0fd357a | |||
42976a32d7 | |||
b214de9370 | |||
3d98c2ba6f | |||
e4a349c85e | |||
2abfa7c47a | |||
50aa0a136a | |||
b98a9be2b7 | |||
3314928c5f | |||
0b7c29eae7 | |||
779e495941 | |||
8402deeccb | |||
7c4324b3ad | |||
268201727c | |||
12ae27b2ff | |||
3bb9b2229d | |||
e17e4c376e | |||
d5f2427aad |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal 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
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal 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
|
141
.gitlab-ci.yml
141
.gitlab-ci.yml
@ -1,141 +0,0 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
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
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
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:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- 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:
|
||||
stage: metadata
|
||||
script:
|
||||
- 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:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
@ -7,10 +7,10 @@
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
27540
package-lock.json
generated
27540
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartchok",
|
||||
"version": "1.0.24",
|
||||
"name": "@push.rocks/smartchok",
|
||||
"version": "1.0.33",
|
||||
"private": false,
|
||||
"description": "smart wrapper for chokidar",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -8,34 +8,32 @@
|
||||
"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": "^5.0.0",
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smartrx": "^2.0.19",
|
||||
"@types/chokidar": "^2.1.3",
|
||||
"chokidar": "^3.5.2"
|
||||
"@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.28",
|
||||
"@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"
|
||||
"@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/**/*",
|
||||
@ -51,5 +49,6 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
],
|
||||
"type": "module"
|
||||
}
|
||||
|
5697
pnpm-lock.yaml
generated
Normal file
5697
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
63
readme.md
Normal file
63
readme.md
Normal 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 | [](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)
|
27
test/test.ts
27
test/test.ts
@ -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,17 +12,17 @@ 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']);
|
||||
testSmartchok.add(['./test/**/*.txt']);
|
||||
await testSmartchok.start()
|
||||
testSmartchok.add(['./test/assets/**/*.md']);
|
||||
testSmartchok.add(['./test/**/*.md']);
|
||||
});
|
||||
|
||||
tap.test('should get an observable for a certain event', async () => {
|
||||
@ -31,14 +33,17 @@ tap.test('should get an observable for a certain event', async () => {
|
||||
|
||||
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 testDeferred.promise;
|
||||
});
|
||||
|
||||
tap.test('should stop the watch process', async () => {
|
||||
tap.test('should stop the watch process', async (tools) => {
|
||||
await tools.delayFor(10000);
|
||||
testSmartchok.stop();
|
||||
});
|
||||
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartchok',
|
||||
version: '1.0.33',
|
||||
description: 'smart wrapper for chokidar'
|
||||
}
|
@ -1 +1 @@
|
||||
export * from './smartchok.classes.smartchok';
|
||||
export * from './smartchok.classes.smartchok.js';
|
||||
|
@ -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 =
|
||||
@ -18,18 +17,43 @@ export type TFsEvent =
|
||||
*/
|
||||
export class Smartchok {
|
||||
public watchStringmap = new Stringmap();
|
||||
public chokidarOptions: plugins.chokidar.WatchOptions;
|
||||
public status: TSmartchokStatus = 'idle';
|
||||
private watcher: plugins.chokidar.FSWatcher;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,10 +73,12 @@ export class Smartchok {
|
||||
/**
|
||||
* gets an observable for a certain event
|
||||
*/
|
||||
public getObservableFor(fsEvent: TFsEvent): Promise<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(() => {
|
||||
const eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
|
||||
const eventObservable = this.eventObservablemap.getSubjectForEmitterEvent(
|
||||
this.watcher,
|
||||
fsEvent
|
||||
);
|
||||
@ -68,9 +94,16 @@ export class Smartchok {
|
||||
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) => {
|
||||
const result = this.getGlobBase(string);
|
||||
console.log(`Watching ${result} for changes`);
|
||||
return result;
|
||||
}),
|
||||
{
|
||||
depth: 20,
|
||||
recursive: false,
|
||||
}
|
||||
);
|
||||
this.watcher.on('ready', () => {
|
||||
this.status = 'watching';
|
||||
|
@ -1,14 +1,16 @@
|
||||
// node native
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
fs,
|
||||
path
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrx from '@pushrocks/smartrx';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrx from '@push.rocks/smartrx';
|
||||
|
||||
export {
|
||||
lik,
|
||||
@ -17,8 +19,9 @@ export {
|
||||
}
|
||||
|
||||
// thirdparty scope
|
||||
import * as chokidar from 'chokidar';
|
||||
// @ts-nocheck
|
||||
import watcher from '@tempfix/watcher';
|
||||
|
||||
export {
|
||||
chokidar
|
||||
}
|
||||
watcher,
|
||||
}
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -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"
|
||||
}
|
Reference in New Issue
Block a user