Compare commits
42 Commits
Author | SHA1 | Date | |
---|---|---|---|
50b0fd357a | |||
42976a32d7 | |||
b214de9370 | |||
3d98c2ba6f | |||
e4a349c85e | |||
2abfa7c47a | |||
50aa0a136a | |||
b98a9be2b7 | |||
3314928c5f | |||
0b7c29eae7 | |||
779e495941 | |||
8402deeccb | |||
7c4324b3ad | |||
268201727c | |||
12ae27b2ff | |||
3bb9b2229d | |||
e17e4c376e | |||
d5f2427aad | |||
5715c6fe67 | |||
9628e914b5 | |||
55746f5d92 | |||
90ae869686 | |||
771c454411 | |||
99395794d8 | |||
1763ede6df | |||
102b6ac9ae | |||
cd9ca458f6 | |||
2c4fc8b212 | |||
ce48b6f889 | |||
2e851cbabc | |||
4c001f5270 | |||
dfbbe8090f | |||
40dd48533d | |||
1e252d2cd7 | |||
34eb725d40 | |||
0298bfe3c6 | |||
ea26987ca6 | |||
8f6a4f4909 | |||
c7b0722155 | |||
6cbd74eb12 | |||
fe52811dcd | |||
9c1e306c99 |
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
|
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
|
@ -1,97 +0,0 @@
|
|||||||
# gitzone standard
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .yarn/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- mirror
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- trigger
|
|
||||||
- pages
|
|
||||||
|
|
||||||
mirror:
|
|
||||||
stage: mirror
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
security:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command yarn global add snyk
|
|
||||||
- npmci command yarn install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: trigger
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: pages
|
|
||||||
script:
|
|
||||||
- npmci command yarn global add npmpage
|
|
||||||
- npmci command npmpage
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
56
README.md
56
README.md
@ -1,56 +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)
|
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './smartchok.classes.smartchok';
|
|
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -1,7 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
function __export(m) {
|
|
||||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
||||||
}
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
__export(require("./smartchok.classes.smartchok"));
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE4QyJ9
|
|
39
dist/smartchok.classes.smartchok.d.ts
vendored
39
dist/smartchok.classes.smartchok.d.ts
vendored
@ -1,39 +0,0 @@
|
|||||||
import * as plugins from './smartchok.plugins';
|
|
||||||
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: plugins.lik.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): Promise<plugins.smartrx.rxjs.Observable<any>>;
|
|
||||||
/**
|
|
||||||
* starts the watcher
|
|
||||||
* @returns Promise<void>
|
|
||||||
*/
|
|
||||||
start(): Promise<void>;
|
|
||||||
/**
|
|
||||||
* stop the watcher process if watching
|
|
||||||
*/
|
|
||||||
stop(): void;
|
|
||||||
}
|
|
77
dist/smartchok.classes.smartchok.js
vendored
77
dist/smartchok.classes.smartchok.js
vendored
@ -1,77 +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.smartq.defer(); // used to run things when watcher is initialized
|
|
||||||
this.eventObservablemap = new plugins.smartrx.Observablemap(); // register one observable per event
|
|
||||||
this.watchStringmap.addStringArray(watchArrayArg);
|
|
||||||
this.chokidarOptions = optionsArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* adds files to the list of watched files
|
|
||||||
*/
|
|
||||||
add(pathArrayArg) {
|
|
||||||
this.watchStringmap.addStringArray(pathArrayArg);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg) {
|
|
||||||
this.watchStringmap.removeString(pathArg);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* gets an observable for a certain event
|
|
||||||
*/
|
|
||||||
getObservableFor(fsEvent) {
|
|
||||||
let done = plugins.smartq.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.smartq.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQStDO0FBQy9DLDZCQUFnQztBQWNoQzs7R0FFRztBQUNIO0lBUUU7O09BRUc7SUFDSCxZQUFZLGFBQXVCLEVBQUUsYUFBNEMsRUFBRTtRQVZuRixtQkFBYyxHQUFHLElBQUksZUFBUyxFQUFFLENBQUM7UUFFakMsV0FBTSxHQUFxQixNQUFNLENBQUM7UUFFMUIscUJBQWdCLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLEVBQVEsQ0FBQyxDQUFDLGlEQUFpRDtRQUNsRyx1QkFBa0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsYUFBYSxFQUFFLENBQUMsQ0FBQyxvQ0FBb0M7UUFNcEcsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsYUFBYSxDQUFDLENBQUM7UUFDbEQsSUFBSSxDQUFDLGVBQWUsR0FBRyxVQUFVLENBQUM7SUFDcEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFlBQXNCO1FBQ3hCLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxDQUFDLFlBQVksQ0FBQyxDQUFDO0lBQ25ELENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sQ0FBQyxPQUFlO1FBQ3BCLElBQUksQ0FBQyxjQUFjLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVDLENBQUM7SUFFRDs7T0FFRztJQUNILGdCQUFnQixDQUFDLE9BQWlCO1FBQ2hDLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUF3QyxDQUFDO1FBQ3hFLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEdBQUcsRUFBRTtZQUN0QyxJQUFJLGVBQWUsR0FBRyxJQUFJLENBQUMsa0JBQWtCLENBQUMsNEJBQTRCLENBQ3hFLElBQUksQ0FBQyxPQUFPLEVBQ1osT0FBTyxDQUNSLENBQUM7WUFDRixJQUFJLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQ2hDLENBQUMsQ0FBQyxDQUFDO1FBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDdEIsQ0FBQztJQUVEOzs7T0FHRztJQUNILEtBQUs7UUFDSCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBUSxDQUFDO1FBQ3hDLElBQUksQ0FBQyxNQUFNLEdBQUcsVUFBVSxDQUFDO1FBQ3pCLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxLQUFLLENBQ25DLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxFQUFFLEVBQ3BDLElBQUksQ0FBQyxlQUFlLENBQ3JCLENBQUM7UUFDRixJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUUsR0FBRyxFQUFFO1lBQzVCLElBQUksQ0FBQyxNQUFNLEdBQUcsVUFBVSxDQUFDO1lBQ3pCLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLEVBQUUsQ0FBQztZQUNoQyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDakIsQ0FBQyxDQUFDLENBQUM7UUFDSCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN0QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0YsSUFBSSxZQUFZLEdBQUcsR0FBRyxFQUFFO1lBQ3RCLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDdkIsQ0FBQyxDQUFDO1FBQ0YsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLE1BQU0sS0FBSyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQy9CLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQztZQUN0QyxZQUFZLEVBQUUsQ0FBQztRQUNqQixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUN0QyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUU7Z0JBQ3RDLFlBQVksRUFBRSxDQUFDO1lBQ2pCLENBQUMsQ0FBQyxDQUFDO1FBQ0wsQ0FBQztJQUNILENBQUM7Q0FDRjtBQWhGRCw4QkFnRkMifQ==
|
|
5
dist/smartchok.plugins.d.ts
vendored
5
dist/smartchok.plugins.d.ts
vendored
@ -1,5 +0,0 @@
|
|||||||
export import lik = require('lik');
|
|
||||||
export import chokidar = require('chokidar');
|
|
||||||
export import path = require('path');
|
|
||||||
export import smartq = require('smartq');
|
|
||||||
export import smartrx = require('smartrx');
|
|
8
dist/smartchok.plugins.js
vendored
8
dist/smartchok.plugins.js
vendored
@ -1,8 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.lik = require("lik");
|
|
||||||
exports.chokidar = require("chokidar");
|
|
||||||
exports.path = require("path");
|
|
||||||
exports.smartq = require("smartq");
|
|
||||||
exports.smartrx = require("smartrx");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDZCQUFtQztBQUNuQyx1Q0FBNkM7QUFDN0MsK0JBQXFDO0FBQ3JDLG1DQUF5QztBQUN6QyxxQ0FBMkMifQ==
|
|
@ -1,10 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
"npmci": {
|
||||||
"mode": "default"
|
"npmGlobalTools": [],
|
||||||
},
|
"npmAccessLevel": "public"
|
||||||
"npmci": {
|
},
|
||||||
"globalNpmTools": [
|
"gitzone": {
|
||||||
"npmts"
|
"projectType": "npm",
|
||||||
]
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartchok",
|
||||||
|
"description": "smart wrapper for chokidar",
|
||||||
|
"npmPackagename": "@push.rocks/smartchokidar",
|
||||||
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
58
package.json
58
package.json
@ -1,34 +1,54 @@
|
|||||||
{
|
{
|
||||||
"name": "smartchok",
|
"name": "@push.rocks/smartchok",
|
||||||
"version": "1.0.12",
|
"version": "1.0.32",
|
||||||
|
"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": "(yarn 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",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartchok.git"
|
"url": "git+https://gitlab.com/push.rocks/smartchok.git"
|
||||||
},
|
},
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"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": {
|
"dependencies": {
|
||||||
"@types/chokidar": "^1.7.5",
|
"@push.rocks/lik": "^6.0.2",
|
||||||
"chokidar": "^2.0.2",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"lik": "^2.0.5",
|
"@push.rocks/smartrx": "^3.0.2",
|
||||||
"smartipc": "^1.0.11",
|
"@tempfix/watcher": "^2.3.0"
|
||||||
"smartq": "^1.1.6",
|
|
||||||
"smartrx": "^1.0.5"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^9.4.6",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"smartfile": "^4.2.28",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"tapbundle": "^2.0.0"
|
"@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_*/**/*",
|
||||||
|
"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
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)
|
68
test/test.ts
68
test/test.ts
@ -1,45 +1,49 @@
|
|||||||
import { tap, expect } from 'tapbundle'
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
import * as smartchok from '../ts/index'
|
import * as smartchok from '../ts/index.js';
|
||||||
import * as smartfile from 'smartfile'
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as smartq from 'smartq'
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as rx from 'rxjs/Rx'
|
import * as smartrx from '@push.rocks/smartrx';
|
||||||
|
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
// the module to test
|
// the module to test
|
||||||
|
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<[string, fs.Stats]>;
|
||||||
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([]);
|
||||||
expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
|
expect(testSmartchok).toBeInstanceOf(smartchok.Smartchok);
|
||||||
})
|
});
|
||||||
|
|
||||||
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 = smartq.defer()
|
let testDeferred = smartpromise.defer();
|
||||||
testSubscription = testAddObservable.subscribe(x => {
|
testSubscription = testAddObservable.subscribe(pathArg => {
|
||||||
testDeferred.resolve()
|
const pathResult = pathArg[0];
|
||||||
})
|
console.log(pathResult);
|
||||||
smartfile.memory.toFs('HI', './test/assets/hi.txt')
|
testDeferred.resolve();
|
||||||
await expect(testDeferred.promise).to.eventually.be.fulfilled
|
});
|
||||||
})
|
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 () => {
|
||||||
testSmartchok.stop()
|
testSmartchok.stop();
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.start();
|
||||||
|
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.32',
|
||||||
|
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 * as plugins from './smartchok.plugins.js';
|
||||||
import { Stringmap } from 'lik';
|
import { Stringmap } from '@push.rocks/lik';
|
||||||
import { Observablemap } from 'smartrx';
|
|
||||||
|
|
||||||
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
||||||
export type TFsEvent =
|
export type TFsEvent =
|
||||||
@ -17,42 +16,69 @@ 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 status: TSmartchokStatus = 'idle';
|
||||||
status: TSmartchokStatus = 'idle';
|
private watcher: plugins.watcher;
|
||||||
private watcher;
|
private watchingDeferred = plugins.smartpromise.defer<void>(); // used to run things when watcher is initialized
|
||||||
private watchingDeferred = plugins.smartq.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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor of class smartchok
|
* constructor of class smartchok
|
||||||
*/
|
*/
|
||||||
constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
|
constructor(watchArrayArg: string[]) {
|
||||||
this.watchStringmap.addStringArray(watchArrayArg);
|
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
|
* 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(
|
||||||
let done = plugins.smartq.defer<plugins.smartrx.rxjs.Observable<any>>();
|
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(() => {
|
this.watchingDeferred.promise.then(() => {
|
||||||
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
|
const eventObservable = this.eventObservablemap.getSubjectForEmitterEvent(
|
||||||
this.watcher,
|
this.watcher,
|
||||||
fsEvent
|
fsEvent
|
||||||
);
|
);
|
||||||
@ -65,12 +91,15 @@ 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.smartq.defer<void>();
|
const done = plugins.smartpromise.defer<void>();
|
||||||
this.status = 'starting';
|
this.status = 'starting';
|
||||||
this.watcher = plugins.chokidar.watch(
|
this.watcher = new plugins.watcher(
|
||||||
this.watchStringmap.getStringArray(),
|
this.watchStringmap.getStringArray().map((string) => this.getGlobBase(string)),
|
||||||
this.chokidarOptions
|
{
|
||||||
|
depth: 20,
|
||||||
|
recursive: true,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
this.watcher.on('ready', () => {
|
this.watcher.on('ready', () => {
|
||||||
this.status = 'watching';
|
this.status = 'watching';
|
||||||
@ -83,17 +112,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,27 @@
|
|||||||
export import lik = require('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 smartq = require('smartq');
|
|
||||||
export import smartrx = require('smartrx');
|
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
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"
|
||||||
|
]
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint-config-standard"
|
|
||||||
}
|
|
Reference in New Issue
Block a user