Compare commits
60 Commits
Author | SHA1 | Date | |
---|---|---|---|
3444b7c74d | |||
bf76b225c6 | |||
3bad722c25 | |||
28ba176b62 | |||
da500d7fd4 | |||
6aaf66ac5c | |||
34ba87a1fb | |||
8cd846e8bf | |||
d98c54fba9 | |||
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 | |||
19ab839853 | |||
cb6c8f3c8e | |||
9e06369139 | |||
7d4975cea8 | |||
af9eb0d99e | |||
46e7b52930 | |||
bf7ec659b7 | |||
ab3ad55c43 | |||
5e5f2ce6c2 |
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/
|
||||
pages/
|
||||
public/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
@ -1,71 +0,0 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci 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 --publish gitlab
|
||||
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
52
README.md
52
README.md
@ -1,52 +0,0 @@
|
||||
# smartchok
|
||||
smart wrapper for chokidar
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartchok)
|
||||
[](https://GitLab.com/pushrocks/smartchok)
|
||||
[](https://github.com/pushrocks/smartchok)
|
||||
[](https://pushrocks.gitlab.io/smartchok/)
|
||||
|
||||
## Status for master
|
||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartchok/commits/master)
|
||||
[](https://www.npmjs.com/package/smartchok)
|
||||
[](https://david-dm.org/pushrocks/smartchok)
|
||||
[](https://www.bithound.io/github/pushrocks/smartchok/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartchok)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import { Smartchok } from 'smartchok'
|
||||
|
||||
let mySmartChok = new Smartchok(['some/path/**/*.any','/absolute/*.js'], chokidarOptions)
|
||||
|
||||
mySmartChok.add(['/some/**/*.any']) // add files
|
||||
|
||||
mySmartChok.remove('some/**/*.js')
|
||||
|
||||
mySmartChok.start() // starts the watch process
|
||||
|
||||
mySmartChok.getObservableFor('change').then((observableArg) => {
|
||||
observableArg.subscribe(x => {
|
||||
// do something here when a change is detected
|
||||
// possible events are 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
|
||||
// note that the observable is only created once you call .start() on the Smartchok instance
|
||||
// hence the promise construction
|
||||
})
|
||||
})
|
||||
|
||||
mySmartChok.stop()
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9
|
0
dist/smartchok.child.d.ts
vendored
0
dist/smartchok.child.d.ts
vendored
3
dist/smartchok.child.js
vendored
3
dist/smartchok.child.js
vendored
@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNoaWxkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNoaWxkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
41
dist/smartchok.classes.smartchok.d.ts
vendored
41
dist/smartchok.classes.smartchok.d.ts
vendored
@ -1,41 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from './smartchok.plugins';
|
||||
import { Stringmap } from 'lik';
|
||||
export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
||||
export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
|
||||
/**
|
||||
* Smartchok allows easy wathcing of files
|
||||
*/
|
||||
export declare class Smartchok {
|
||||
watchStringmap: Stringmap;
|
||||
chokidarOptions: plugins.chokidar.WatchOptions;
|
||||
status: TSmartchokStatus;
|
||||
private watcher;
|
||||
private watchingDeferred;
|
||||
private eventObservablemap;
|
||||
/**
|
||||
* constructor of class smartchok
|
||||
*/
|
||||
constructor(watchArrayArg: string[], optionsArg?: plugins.chokidar.WatchOptions);
|
||||
/**
|
||||
* adds files to the list of watched files
|
||||
*/
|
||||
add(pathArrayArg: string[]): void;
|
||||
/**
|
||||
* removes files from the list of watched files
|
||||
*/
|
||||
remove(pathArg: string): void;
|
||||
/**
|
||||
* gets an observable for a certain event
|
||||
*/
|
||||
getObservableFor(fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>>;
|
||||
/**
|
||||
* starts the watcher
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
start(): plugins.q.Promise<void>;
|
||||
/**
|
||||
* stop the watcher process if watching
|
||||
*/
|
||||
stop(): void;
|
||||
}
|
75
dist/smartchok.classes.smartchok.js
vendored
75
dist/smartchok.classes.smartchok.js
vendored
@ -1,75 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugins = require("./smartchok.plugins");
|
||||
const lik_1 = require("lik");
|
||||
/**
|
||||
* Smartchok allows easy wathcing of files
|
||||
*/
|
||||
class Smartchok {
|
||||
/**
|
||||
* constructor of class smartchok
|
||||
*/
|
||||
constructor(watchArrayArg, optionsArg = {}) {
|
||||
this.watchStringmap = new lik_1.Stringmap();
|
||||
this.status = 'idle';
|
||||
this.watchingDeferred = plugins.q.defer(); // used to run things when watcher is initialized
|
||||
this.eventObservablemap = new plugins.lik.Observablemap(); // register one observable per event
|
||||
this.watchStringmap.addStringArray(watchArrayArg);
|
||||
this.chokidarOptions = optionsArg;
|
||||
}
|
||||
/**
|
||||
* adds files to the list of watched files
|
||||
*/
|
||||
add(pathArrayArg) {
|
||||
this.watchStringmap.addStringArray(pathArrayArg);
|
||||
}
|
||||
/**
|
||||
* 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.q.defer();
|
||||
this.watchingDeferred.promise.then(() => {
|
||||
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent);
|
||||
done.resolve(eventObservable);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* starts the watcher
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
start() {
|
||||
let done = plugins.q.defer();
|
||||
this.status = 'starting';
|
||||
this.watcher = plugins.chokidar.watch(this.watchStringmap.getStringArray(), this.chokidarOptions);
|
||||
this.watcher.on('ready', () => {
|
||||
this.status = 'watching';
|
||||
this.watchingDeferred.resolve();
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* stop the watcher process if watching
|
||||
*/
|
||||
stop() {
|
||||
let closeWatcher = () => {
|
||||
this.watcher.close();
|
||||
};
|
||||
if (this.status === 'watching') {
|
||||
console.log('closing while watching');
|
||||
closeWatcher();
|
||||
}
|
||||
else if (this.status === 'starting') {
|
||||
this.watchingDeferred.promise.then(() => { closeWatcher(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Smartchok = Smartchok;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjs7R0FFRztBQUNIO0lBUUU7O09BRUc7SUFDSCxZQUFhLGFBQXVCLEVBQUUsYUFBNEMsRUFBRTtRQVZwRixtQkFBYyxHQUFHLElBQUksZUFBUyxFQUFFLENBQUE7UUFFaEMsV0FBTSxHQUFxQixNQUFNLENBQUE7UUFFekIscUJBQWdCLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQVEsQ0FBQSxDQUFDLGlEQUFpRDtRQUM1Rix1QkFBa0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLENBQUEsQ0FBQyxvQ0FBb0M7UUFNL0YsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDakQsSUFBSSxDQUFDLGVBQWUsR0FBRyxVQUFVLENBQUE7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFlBQXNCO1FBQ3hCLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxDQUFDLFlBQVksQ0FBQyxDQUFBO0lBQ2xELENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sQ0FBRSxPQUFlO1FBQ3JCLElBQUksQ0FBQyxjQUFjLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQzNDLENBQUM7SUFFRDs7T0FFRztJQUNILGdCQUFnQixDQUFFLE9BQWlCO1FBQ2pDLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUE4QixDQUFBO1FBQ3hELElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDO1lBQ2pDLElBQUksZUFBZSxHQUFHLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyw0QkFBNEIsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFBO1lBQ2pHLElBQUksQ0FBQyxPQUFPLENBQUMsZUFBZSxDQUFDLENBQUE7UUFDL0IsQ0FBQyxDQUFDLENBQUE7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsS0FBSztRQUNILElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDbEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUE7UUFDeEIsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsY0FBYyxDQUFDLGNBQWMsRUFBRSxFQUFFLElBQUksQ0FBQyxlQUFlLENBQUMsQ0FBQTtRQUNqRyxJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUU7WUFDdkIsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUE7WUFDeEIsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxDQUFBO1lBQy9CLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNoQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDRixJQUFJLFlBQVksR0FBRztZQUNqQixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ3RCLENBQUMsQ0FBQTtRQUNELEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUMvQixPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsWUFBWSxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxZQUFZLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzlELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUF4RUQsOEJBd0VDIn0=
|
0
dist/smartchok.classes.watcher.d.ts
vendored
0
dist/smartchok.classes.watcher.d.ts
vendored
3
dist/smartchok.classes.watcher.js
vendored
3
dist/smartchok.classes.watcher.js
vendored
@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMud2F0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2hvay5jbGFzc2VzLndhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
13
dist/smartchok.plugins.d.ts
vendored
13
dist/smartchok.plugins.d.ts
vendored
@ -1,13 +0,0 @@
|
||||
import 'typings-global';
|
||||
export import lik = require('lik');
|
||||
export import chokidar = require('chokidar');
|
||||
export import path = require('path');
|
||||
export import q = require('q');
|
||||
export import rx = require('rxjs/Rx');
|
||||
import { Operator } from 'rxjs/Operator';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
declare module 'rxjs/Subject' {
|
||||
interface Subject<T> {
|
||||
lift<R>(operator: Operator<T, R>): Observable<R>;
|
||||
}
|
||||
}
|
9
dist/smartchok.plugins.js
vendored
9
dist/smartchok.plugins.js
vendored
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
exports.lik = require("lik");
|
||||
exports.chokidar = require("chokidar");
|
||||
exports.path = require("path");
|
||||
exports.q = require("q");
|
||||
exports.rx = require("rxjs/Rx");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw2QkFBa0M7QUFDbEMsdUNBQTRDO0FBQzVDLCtCQUFvQztBQUNwQyx5QkFBOEI7QUFDOUIsZ0NBQXFDIn0=
|
@ -1,10 +1,32 @@
|
||||
{
|
||||
"npmts": {
|
||||
"mode": "default"
|
||||
},
|
||||
"npmci": {
|
||||
"globalNpmTools": [
|
||||
"npmts"
|
||||
]
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartchok",
|
||||
"description": "A smart wrapper for chokidar to facilitate file watching with enhanced features.",
|
||||
"npmPackagename": "@push.rocks/smartchokidar",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"file watching",
|
||||
"chokidar",
|
||||
"filesystem",
|
||||
"observable",
|
||||
"typescript",
|
||||
"node.js",
|
||||
"development tool",
|
||||
"file system events",
|
||||
"real-time",
|
||||
"watch files"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
76
package.json
76
package.json
@ -1,36 +1,66 @@
|
||||
{
|
||||
"name": "smartchok",
|
||||
"version": "1.0.9",
|
||||
"description": "smart wrapper for chokidar",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartchok",
|
||||
"version": "1.0.34",
|
||||
"private": false,
|
||||
"description": "A smart wrapper for chokidar to facilitate file watching with enhanced features.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npm run prepareTest && npmts)",
|
||||
"prepareTest": "(rm -f ./test/assets/hi.txt)"
|
||||
"test": "(npm run prepareTest && tstest test/)",
|
||||
"prepareTest": "(rm -f ./test/assets/hi.txt)",
|
||||
"build": "tsbuild",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartchok.git"
|
||||
"url": "https://code.foss.global/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://code.foss.global/push.rocks/smartchok",
|
||||
"dependencies": {
|
||||
"@types/chokidar": "^1.7.0",
|
||||
"@types/q": "x.x.x",
|
||||
"chokidar": "^1.7.0",
|
||||
"lik": "^1.0.32",
|
||||
"q": "^1.5.0",
|
||||
"rxjs": "^5.4.1",
|
||||
"smartipc": "^1.0.9",
|
||||
"smartq": "^1.1.1",
|
||||
"typings-global": "^1.0.19"
|
||||
"@push.rocks/lik": "^6.0.2",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartrx": "^3.0.2",
|
||||
"@tempfix/watcher": "^2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"smartfile": "^4.2.17",
|
||||
"tapbundle": "^1.0.14"
|
||||
}
|
||||
}
|
||||
"@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_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"file watching",
|
||||
"chokidar",
|
||||
"filesystem",
|
||||
"observable",
|
||||
"typescript",
|
||||
"node.js",
|
||||
"development tool",
|
||||
"file system events",
|
||||
"real-time",
|
||||
"watch files"
|
||||
]
|
||||
}
|
5697
pnpm-lock.yaml
generated
Normal file
5697
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
133
readme.md
Normal file
133
readme.md
Normal file
@ -0,0 +1,133 @@
|
||||
# @push.rocks/smartchok
|
||||
smart wrapper for chokidar
|
||||
|
||||
## Install
|
||||
|
||||
Install the package by running the following command in your terminal:
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartchok --save
|
||||
```
|
||||
|
||||
This command adds `@push.rocks/smartchok` to your project's dependencies, ensuring that your project can use its functionality and that it will be installed when running `npm install` in your project root.
|
||||
|
||||
## Usage
|
||||
|
||||
The `@push.rocks/smartchok` package provides a convenient and smart wrapper around the popular `chokidar` library for file watching with enhanced features such as observable support for filesystem events. This guide will introduce you to the usage of `@push.rocks/smartchok`, leveraging TypeScript for type safety and better developer experience.
|
||||
|
||||
### Setting Up Your Project
|
||||
|
||||
To use `@push.rocks/smartchok`, ensure your project is set up to use TypeScript and ECMAScript modules (ESM). You need to have a `tsconfig.json` file at the root of your project with the following minimum settings:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"strict": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
```
|
||||
|
||||
This configuration enables TypeScript compilation targeting the latest ECMAScript standards and includes all TypeScript files (`*.ts`) in your `src` directory.
|
||||
|
||||
### Basic Setup
|
||||
|
||||
To start using `smartchok`, first import it into your TypeScript file:
|
||||
|
||||
```typescript
|
||||
import { Smartchok } from '@push.rocks/smartchok';
|
||||
```
|
||||
|
||||
#### Initializing Smartchok
|
||||
|
||||
Create an instance of `Smartchok` by specifying an array of glob patterns to watch:
|
||||
|
||||
```typescript
|
||||
const smartchokInstance = new Smartchok([
|
||||
'./src/**/*.ts', // Watch all TypeScript files in the src directory
|
||||
'./public/assets/**/*' // Watch all files in the public/assets directory
|
||||
]);
|
||||
```
|
||||
|
||||
#### Adding and Removing Files Dynamically
|
||||
|
||||
You can dynamically add and remove paths from being watched by using the `add` and `remove` methods:
|
||||
|
||||
```typescript
|
||||
// Add additional files or patterns
|
||||
smartchokInstance.add(['./tests/**/*.spec.ts']);
|
||||
|
||||
// Remove specific patterns from watch
|
||||
smartchokInstance.remove('./src/**/*.test.ts');
|
||||
```
|
||||
|
||||
#### Handling Filesystem Events
|
||||
|
||||
`smartchok` leverages RxJS observables to notify about filesystem events. This allows you to respond to various events such as file additions, changes, and deletions with ease.
|
||||
|
||||
First, start the watcher:
|
||||
|
||||
```typescript
|
||||
await smartchokInstance.start();
|
||||
```
|
||||
|
||||
Then, subscribe to an event:
|
||||
|
||||
```typescript
|
||||
const changeObservable = await smartchokInstance.getObservableFor('change');
|
||||
|
||||
changeObservable.subscribe({
|
||||
next: ([path, stats]) => {
|
||||
console.log(`File changed: ${path}`);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error(`An error occurred: ${err}`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Supported events include 'add', 'change', 'unlink' (for deletions), and others. Refer to the chokidar documentation for a full list of events.
|
||||
|
||||
#### Stopping the Watcher
|
||||
|
||||
To stop watching for file changes, simply call:
|
||||
|
||||
```typescript
|
||||
await smartchokInstance.stop();
|
||||
```
|
||||
|
||||
### Advanced Usage
|
||||
|
||||
Beyond the basics, `smartchok` allows for more complex monitoring scenarios, such as debounced notifications for rapid changes, filtering events, and integrating with other observables for complex asynchronous workflows.
|
||||
|
||||
### Conclusion
|
||||
|
||||
`@push.rocks/smartchok` provides a robust, observable-based wrapper around `chokidar`, making it an excellent choice for projects requiring efficient and flexible file monitoring. Its integration with RxJS opens up a wide array of possibilities for handling file system events in a reactive manner, making your code more concise, readable, and maintainable.
|
||||
|
||||
By following the guidelines provided in this document, you should now be equipped to integrate `@push.rocks/smartchok` into your TypeScript project, enhancing its capabilities with efficient file system monitoring.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
71
test/test.ts
71
test/test.ts
@ -1,45 +1,50 @@
|
||||
import { tap, expect } from 'tapbundle'
|
||||
import * as smartfile from 'smartfile'
|
||||
import * as smartq from 'smartq'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
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
|
||||
import * as smartchok from '../dist/index'
|
||||
if (process.env.CI) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
let testSmartchok: smartchok.Smartchok
|
||||
let testAddObservable: rx.Observable<any>
|
||||
let testSubscription: rx.Subscription
|
||||
let testSmartchok: smartchok.Smartchok;
|
||||
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([])
|
||||
return expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
|
||||
}).catch(tap.threw)
|
||||
testSmartchok = new 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 () => {
|
||||
testSmartchok.add([ './test/assets/**/*.md' ])
|
||||
})
|
||||
return await expect(localPromise).to.eventually.be.fulfilled
|
||||
}).catch(tap.threw)
|
||||
testSmartchok.add(['./test/**/*.txt']);
|
||||
await testSmartchok.start()
|
||||
testSmartchok.add(['./test/**/*.md']);
|
||||
});
|
||||
|
||||
tap.test('should get an observable for a certain event', async () => {
|
||||
let localPromise = testSmartchok.getObservableFor('add').then(async (observableArg) => {
|
||||
testAddObservable = observableArg
|
||||
})
|
||||
return await expect(localPromise).to.eventually.be.fulfilled
|
||||
}).catch(tap.threw)
|
||||
await testSmartchok.getObservableFor('add').then(async (observableArg) => {
|
||||
testAddObservable = observableArg;
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should register an add operation', async () => {
|
||||
let testDeferred = smartq.defer()
|
||||
testSubscription = testAddObservable.subscribe(x => {
|
||||
testDeferred.resolve()
|
||||
})
|
||||
smartfile.memory.toFs('HI', './test/assets/hi.txt')
|
||||
return await expect(testDeferred.promise).to.eventually.be.fulfilled
|
||||
}).catch(tap.threw)
|
||||
let testDeferred = smartpromise.defer();
|
||||
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 () => {
|
||||
testSmartchok.stop()
|
||||
}).catch(tap.threw)
|
||||
tap.test('should stop the watch process', async (tools) => {
|
||||
await tools.delayFor(10000);
|
||||
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.34',
|
||||
description: 'A smart wrapper for chokidar to facilitate file watching with enhanced features.'
|
||||
}
|
@ -1 +1 @@
|
||||
export * from './smartchok.classes.smartchok'
|
||||
export * from './smartchok.classes.smartchok.js';
|
||||
|
@ -1 +0,0 @@
|
||||
import chokidar = require('chokidar')
|
@ -1,82 +1,131 @@
|
||||
import * as plugins from './smartchok.plugins'
|
||||
import { Stringmap } from 'lik'
|
||||
import * as plugins from './smartchok.plugins.js';
|
||||
import { Stringmap } from '@push.rocks/lik';
|
||||
|
||||
export type TSmartchokStatus = 'idle' | 'starting' | 'watching'
|
||||
export type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
|
||||
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
||||
export type TFsEvent =
|
||||
| 'add'
|
||||
| 'addDir'
|
||||
| 'change'
|
||||
| 'error'
|
||||
| 'unlink'
|
||||
| 'unlinkDir'
|
||||
| 'ready'
|
||||
| 'raw';
|
||||
|
||||
/**
|
||||
* Smartchok allows easy wathcing of files
|
||||
*/
|
||||
export class Smartchok {
|
||||
watchStringmap = new Stringmap()
|
||||
chokidarOptions: plugins.chokidar.WatchOptions
|
||||
status: TSmartchokStatus = 'idle'
|
||||
private watcher
|
||||
private watchingDeferred = plugins.q.defer<void>() // used to run things when watcher is initialized
|
||||
private eventObservablemap = new plugins.lik.Observablemap() // register one observable per event
|
||||
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 = {}) {
|
||||
this.watchStringmap.addStringArray(watchArrayArg)
|
||||
this.chokidarOptions = optionsArg
|
||||
constructor(watchArrayArg: string[]) {
|
||||
this.watchStringmap.addStringArray(watchArrayArg);
|
||||
}
|
||||
|
||||
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[]) {
|
||||
this.watchStringmap.addStringArray(pathArrayArg)
|
||||
public add(pathArrayArg: string[]) {
|
||||
this.watchStringmap.addStringArray(pathArrayArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes files from the list of watched files
|
||||
*/
|
||||
remove (pathArg: string) {
|
||||
this.watchStringmap.removeString(pathArg)
|
||||
public remove(pathArg: string) {
|
||||
this.watchStringmap.removeString(pathArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets an observable for a certain event
|
||||
*/
|
||||
getObservableFor (fsEvent: TFsEvent): plugins.q.Promise<plugins.rx.Observable<any>> {
|
||||
let done = plugins.q.defer<plugins.rx.Observable<any>>()
|
||||
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(this.watcher, fsEvent)
|
||||
done.resolve(eventObservable)
|
||||
})
|
||||
return done.promise
|
||||
const eventObservable = this.eventObservablemap.getSubjectForEmitterEvent(
|
||||
this.watcher,
|
||||
fsEvent
|
||||
);
|
||||
done.resolve(eventObservable);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the watcher
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
start(): plugins.q.Promise<void> {
|
||||
let done = plugins.q.defer<void>()
|
||||
this.status = 'starting'
|
||||
this.watcher = plugins.chokidar.watch(this.watchStringmap.getStringArray(), this.chokidarOptions)
|
||||
public start(): Promise<void> {
|
||||
const done = plugins.smartpromise.defer<void>();
|
||||
this.status = 'starting';
|
||||
this.watcher = new plugins.watcher(
|
||||
this.watchStringmap.getStringArray().map((string) => {
|
||||
const result = this.getGlobBase(string);
|
||||
console.log(`Watching ${result} for changes`);
|
||||
return result;
|
||||
}),
|
||||
{
|
||||
depth: 4,
|
||||
recursive: true,
|
||||
}
|
||||
);
|
||||
this.watcher.on('ready', () => {
|
||||
this.status = 'watching'
|
||||
this.watchingDeferred.resolve()
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
this.status = 'watching';
|
||||
this.watchingDeferred.resolve();
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
console.log('closing while watching');
|
||||
await closeWatcher();
|
||||
} else if (this.status === 'starting') {
|
||||
this.watchingDeferred.promise.then(() => { closeWatcher() })
|
||||
await this.watchingDeferred.promise;
|
||||
await closeWatcher();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
import * as plugins from './smartchok.plugins'
|
||||
|
@ -1,15 +1,27 @@
|
||||
import 'typings-global'
|
||||
export import lik = require('lik')
|
||||
export import chokidar = require('chokidar')
|
||||
export import path = require('path')
|
||||
export import q = require('q')
|
||||
export import rx = require('rxjs/Rx')
|
||||
// node native
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
// workaround
|
||||
import {Operator} from 'rxjs/Operator';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
declare module 'rxjs/Subject' {
|
||||
interface Subject<T> {
|
||||
lift<R>(operator: Operator<T, R>): Observable<R>;
|
||||
}
|
||||
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"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user