Compare commits
66 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
89566ebc1d | |||
fda93fa553 | |||
583cf6f446 | |||
8d87616971 | |||
e3e70a680e | |||
49e7146320 | |||
1f1fef1610 | |||
1365676a12 | |||
44dd315c6f | |||
722bd0ea61 | |||
c6104ed00e | |||
69149a717b | |||
aed6e12270 | |||
396853f7c4 | |||
40f1e2c938 | |||
7c9d25560c | |||
0fe26b4b44 |
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,44 +0,0 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- page
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
environment: npmjs-com_registry
|
|
||||||
script:
|
|
||||||
- npmci publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
|
||||||
stage: page
|
|
||||||
script:
|
|
||||||
- npmci command npmpage --host gitlab
|
|
||||||
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
36
dist/index.d.ts
vendored
36
dist/index.d.ts
vendored
@ -1,36 +0,0 @@
|
|||||||
/// <reference types="chokidar" />
|
|
||||||
/// <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';
|
|
||||||
export declare class Smartchok {
|
|
||||||
watchStringmap: Stringmap;
|
|
||||||
chokidarOptions: plugins.chokidar.WatchOptions;
|
|
||||||
status: TSmartchokStatus;
|
|
||||||
private watcher;
|
|
||||||
private watchingDeferred;
|
|
||||||
private eventObservablemap;
|
|
||||||
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;
|
|
||||||
}
|
|
81
dist/index.js
vendored
81
dist/index.js
vendored
@ -1,81 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const plugins = require("./smartchok.plugins");
|
|
||||||
const lik_1 = require("lik");
|
|
||||||
class Smartchok {
|
|
||||||
constructor(watchArrayArg, optionsArg = {}) {
|
|
||||||
this.watchStringmap = new lik_1.Stringmap();
|
|
||||||
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);
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.add(pathArrayArg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg) {
|
|
||||||
this.watchStringmap.removeString(''); // TODO
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.unwatch(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 = () => {
|
|
||||||
let watchedFiles = this.watcher.getWatched();
|
|
||||||
for (let key in watchedFiles) {
|
|
||||||
let files = watchedFiles[key];
|
|
||||||
for (let file in files) {
|
|
||||||
let filePath = plugins.path.join(key, file);
|
|
||||||
this.watcher.unwatch(filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjtJQVFJLFlBQVksYUFBdUIsRUFBRSxVQUFVLEdBQWtDLEVBQUU7UUFQbkYsbUJBQWMsR0FBRyxJQUFJLGVBQVMsRUFBRSxDQUFBO1FBSXhCLHFCQUFnQixHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUEsQ0FBQyxpREFBaUQ7UUFDNUYsdUJBQWtCLEdBQUcsSUFBSSxPQUFPLENBQUMsR0FBRyxDQUFDLGFBQWEsRUFBRSxDQUFBLENBQUMsb0NBQW9DO1FBRzdGLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxDQUFDLGFBQWEsQ0FBQyxDQUFBO1FBQ2pELElBQUksQ0FBQyxlQUFlLEdBQUcsVUFBVSxDQUFBO0lBQ3JDLENBQUM7SUFFRDs7T0FFRztJQUNILEdBQUcsQ0FBQyxZQUFzQjtRQUN0QixJQUFJLENBQUMsY0FBYyxDQUFDLGNBQWMsQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNoRCxJQUFJLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQztZQUMvQixJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNsQyxDQUFDLENBQUMsQ0FBQTtJQUNOLENBQ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QTtZQUNyQyxZQUFZLEVBQUUsQ0FBQTtRQUNsQixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUNwQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLFlBQVksRUFBRSxDQUFBLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDaEUsQ0FBQztJQUNMLENBQUM7Q0FDSjtBQW5GRCw4QkFtRkMifQ==
|
|
6
dist/smartchok.plugins.d.ts
vendored
6
dist/smartchok.plugins.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
export import chokidar = require('chokidar');
|
|
||||||
export import lik = require('lik');
|
|
||||||
export import path = require('path');
|
|
||||||
export import q = require('q');
|
|
||||||
export import rx = require('rxjs/Rx');
|
|
8
dist/smartchok.plugins.js
vendored
8
dist/smartchok.plugins.js
vendored
@ -1,8 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
exports.chokidar = require("chokidar");
|
|
||||||
exports.lik = require("lik");
|
|
||||||
exports.path = require("path");
|
|
||||||
exports.q = require("q");
|
|
||||||
exports.rx = require("rxjs/Rx");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVDQUE0QztBQUM1Qyw2QkFBa0M7QUFDbEMsK0JBQW9DO0FBQ3BDLHlCQUE4QjtBQUM5QixnQ0FBcUMifQ==
|
|
@ -1,5 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
"npmci": {
|
||||||
"mode": "default"
|
"npmGlobalTools": [],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartchok",
|
||||||
|
"description": "smart wrapper for chokidar",
|
||||||
|
"npmPackagename": "@push.rocks/smartchokidar",
|
||||||
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
60
package.json
60
package.json
@ -1,36 +1,54 @@
|
|||||||
{
|
{
|
||||||
"name": "smartchok",
|
"name": "@push.rocks/smartchok",
|
||||||
"version": "1.0.1",
|
"version": "1.0.31",
|
||||||
|
"private": false,
|
||||||
"description": "smart wrapper for chokidar",
|
"description": "smart wrapper for chokidar",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npm run prepareTest && 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.4.29",
|
"@push.rocks/lik": "^6.0.2",
|
||||||
"@types/q": "0.0.31",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"chokidar": "^1.6.0",
|
"@push.rocks/smartrx": "^3.0.2",
|
||||||
"lik": "^1.0.20",
|
"@tempfix/watcher": "^2.3.0"
|
||||||
"q": "^1.4.1",
|
|
||||||
"rxjs": "^5.0.0-beta.12",
|
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"should": "^11.1.0",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"smartfile": "^4.0.20",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"typings-test": "^1.0.3"
|
"@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)
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
35
test/test.js
35
test/test.js
@ -1,35 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const should = require("should");
|
|
||||||
const smartfile = require("smartfile");
|
|
||||||
const smartchok = require("../dist/index");
|
|
||||||
describe('smartchok', function () {
|
|
||||||
let testSmartchok;
|
|
||||||
let testAddObservable;
|
|
||||||
let testSubscription;
|
|
||||||
it('should create a new instance', function () {
|
|
||||||
testSmartchok = new smartchok.Smartchok([]);
|
|
||||||
should(testSmartchok).be.instanceof(smartchok.Smartchok);
|
|
||||||
});
|
|
||||||
it('should add some files to watch and start', function (done) {
|
|
||||||
testSmartchok.add(['./test/assets/**/*.txt']);
|
|
||||||
testSmartchok.start().then(() => { done(); }).catch(err => { console.log(err); });
|
|
||||||
});
|
|
||||||
it('should get an observable for a certain event', function (done) {
|
|
||||||
testSmartchok.getObservableFor('add').then((observableArg) => {
|
|
||||||
testAddObservable = observableArg;
|
|
||||||
done();
|
|
||||||
}).catch(err => { console.log(err); });
|
|
||||||
});
|
|
||||||
it('should register an add operation', function (done) {
|
|
||||||
this.timeout(5000);
|
|
||||||
testSubscription = testAddObservable.subscribe(x => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
smartfile.memory.toFs('HI', './test/assets/hi.txt');
|
|
||||||
});
|
|
||||||
it('should stop the watch process', function () {
|
|
||||||
testSmartchok.stop();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsdUNBQXNDO0FBRXRDLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyxFQUFDO0lBQ2pCLElBQUksYUFBa0MsQ0FBQTtJQUN0QyxJQUFJLGlCQUFxQyxDQUFBO0lBQ3pDLElBQUksZ0JBQWlDLENBQUE7SUFDckMsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1FBQzlCLGFBQWEsR0FBRyxJQUFJLFNBQVMsQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLENBQUE7UUFDM0MsTUFBTSxDQUFDLGFBQWEsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQyxDQUFBO0lBQzVELENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLDBDQUEwQyxFQUFDLFVBQVMsSUFBSTtRQUN2RCxhQUFhLENBQUMsR0FBRyxDQUFDLENBQUMsd0JBQXdCLENBQUMsQ0FBQyxDQUFBO1FBQzdDLGFBQWEsQ0FBQyxLQUFLLEVBQUUsQ0FBQyxJQUFJLENBQUMsUUFBUSxJQUFJLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFD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
import * as should from 'should'
|
import * as smartchok from '../ts/index.js';
|
||||||
import * as smartfile from 'smartfile'
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as rx from 'rxjs/Rx'
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as smartchok from '../dist/index'
|
import * as smartrx from '@push.rocks/smartrx';
|
||||||
|
|
||||||
describe('smartchok',function(){
|
import * as fs from 'fs';
|
||||||
let testSmartchok: smartchok.Smartchok
|
|
||||||
let testAddObservable: rx.Observable<any>
|
// the module to test
|
||||||
let testSubscription: rx.Subscription
|
if (process.env.CI) {
|
||||||
it('should create a new instance',function(){
|
process.exit(0);
|
||||||
testSmartchok = new smartchok.Smartchok([])
|
}
|
||||||
should(testSmartchok).be.instanceof(smartchok.Smartchok)
|
|
||||||
})
|
let testSmartchok: smartchok.Smartchok;
|
||||||
it('should add some files to watch and start',function(done){
|
let testAddObservable: smartrx.rxjs.Observable<[string, fs.Stats]>;
|
||||||
testSmartchok.add(['./test/assets/**/*.txt'])
|
let testSubscription: smartrx.rxjs.Subscription;
|
||||||
testSmartchok.start().then(() => { done() }).catch(err => { console.log(err) })
|
tap.test('should create a new instance', async () => {
|
||||||
})
|
testSmartchok = new smartchok.Smartchok([]);
|
||||||
it('should get an observable for a certain event',function(done){
|
expect(testSmartchok).toBeInstanceOf(smartchok.Smartchok);
|
||||||
testSmartchok.getObservableFor('add').then((observableArg) => {
|
});
|
||||||
testAddObservable = observableArg
|
|
||||||
done()
|
tap.test('should add some files to watch and start', async () => {
|
||||||
}).catch(err => { console.log(err) })
|
testSmartchok.add(['./test/assets/**/*.txt']);
|
||||||
})
|
await testSmartchok.start()
|
||||||
it('should register an add operation',function(done){
|
testSmartchok.add(['./test/assets/**/*.md']);
|
||||||
this.timeout(5000)
|
});
|
||||||
testSubscription = testAddObservable.subscribe(x => {
|
|
||||||
done()
|
tap.test('should get an observable for a certain event', async () => {
|
||||||
})
|
await testSmartchok.getObservableFor('add').then(async (observableArg) => {
|
||||||
smartfile.memory.toFs('HI','./test/assets/hi.txt')
|
testAddObservable = observableArg;
|
||||||
})
|
});
|
||||||
it('should stop the watch process',function() {
|
});
|
||||||
testSmartchok.stop()
|
|
||||||
})
|
tap.test('should register an add operation', async () => {
|
||||||
})
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
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.31',
|
||||||
|
description: 'smart wrapper for chokidar'
|
||||||
|
}
|
83
ts/index.ts
83
ts/index.ts
@ -1,82 +1 @@
|
|||||||
import * as plugins from './smartchok.plugins'
|
export * from './smartchok.classes.smartchok.js';
|
||||||
import { Stringmap } from 'lik'
|
|
||||||
|
|
||||||
export type TSmartchokStatus = 'idle' | 'starting' | 'watching'
|
|
||||||
export type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
|
|
||||||
|
|
||||||
export class Smartchok {
|
|
||||||
watchStringmap = new Stringmap()
|
|
||||||
chokidarOptions: plugins.chokidar.WatchOptions
|
|
||||||
status: TSmartchokStatus
|
|
||||||
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
|
|
||||||
|
|
||||||
constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
|
|
||||||
this.watchStringmap.addStringArray(watchArrayArg)
|
|
||||||
this.chokidarOptions = optionsArg
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds files to the list of watched files
|
|
||||||
*/
|
|
||||||
add(pathArrayArg: string[]) {
|
|
||||||
this.watchStringmap.addStringArray(pathArrayArg)
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.add(pathArrayArg)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* removes files from the list of watched files
|
|
||||||
*/
|
|
||||||
remove(pathArg: string) {
|
|
||||||
this.watchStringmap.removeString('') // TODO
|
|
||||||
this.watchingDeferred.promise.then(() => {
|
|
||||||
this.watcher.unwatch(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>>()
|
|
||||||
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(): plugins.q.Promise<void> {
|
|
||||||
let done = plugins.q.defer<void>()
|
|
||||||
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() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
123
ts/smartchok.classes.smartchok.ts
Normal file
123
ts/smartchok.classes.smartchok.ts
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smartchok allows easy wathcing of files
|
||||||
|
*/
|
||||||
|
export class Smartchok {
|
||||||
|
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[]) {
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
public add(pathArrayArg: string[]) {
|
||||||
|
this.watchStringmap.addStringArray(pathArrayArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes files from the list of watched files
|
||||||
|
*/
|
||||||
|
public remove(pathArg: string) {
|
||||||
|
this.watchStringmap.removeString(pathArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets an observable for a certain event
|
||||||
|
*/
|
||||||
|
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.getSubjectForEmitterEvent(
|
||||||
|
this.watcher,
|
||||||
|
fsEvent
|
||||||
|
);
|
||||||
|
done.resolve(eventObservable);
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the watcher
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
public start(): Promise<void> {
|
||||||
|
const done = plugins.smartpromise.defer<void>();
|
||||||
|
this.status = 'starting';
|
||||||
|
this.watcher = new plugins.watcher(
|
||||||
|
this.watchStringmap.getStringArray().map((string) => this.getGlobBase(string))
|
||||||
|
);
|
||||||
|
this.watcher.on('ready', () => {
|
||||||
|
this.status = 'watching';
|
||||||
|
this.watchingDeferred.resolve();
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop the watcher process if watching
|
||||||
|
*/
|
||||||
|
public async stop() {
|
||||||
|
const closeWatcher = async () => {
|
||||||
|
await this.watcher.close();
|
||||||
|
};
|
||||||
|
if (this.status === 'watching') {
|
||||||
|
console.log('closing while watching');
|
||||||
|
await closeWatcher();
|
||||||
|
} else if (this.status === 'starting') {
|
||||||
|
await this.watchingDeferred.promise;
|
||||||
|
await closeWatcher();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,27 @@
|
|||||||
import 'typings-global'
|
// node native
|
||||||
export import chokidar = require('chokidar')
|
import * as fs from 'fs';
|
||||||
export import lik = require('lik')
|
import * as path from 'path';
|
||||||
export import path = require('path')
|
|
||||||
export import q = require('q')
|
export {
|
||||||
export import rx = require('rxjs/Rx')
|
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