fix(core): update
This commit is contained in:
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.28',
|
||||
description: 'smart wrapper for chokidar'
|
||||
}
|
@ -1 +1 @@
|
||||
export * from './smartchok.classes.smartchok';
|
||||
export * from './smartchok.classes.smartchok.js';
|
||||
|
@ -1,6 +1,5 @@
|
||||
import * as plugins from './smartchok.plugins';
|
||||
import { Stringmap } from '@pushrocks/lik';
|
||||
import { Observablemap } from '@pushrocks/smartrx';
|
||||
import * as plugins from './smartchok.plugins.js';
|
||||
import { Stringmap } from '@push.rocks/lik';
|
||||
|
||||
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
|
||||
export type TFsEvent =
|
||||
@ -18,18 +17,43 @@ export type TFsEvent =
|
||||
*/
|
||||
export class Smartchok {
|
||||
public watchStringmap = new Stringmap();
|
||||
public chokidarOptions: plugins.chokidar.WatchOptions;
|
||||
public status: TSmartchokStatus = 'idle';
|
||||
private watcher: plugins.chokidar.FSWatcher;
|
||||
private watcher: plugins.watcher;
|
||||
private watchingDeferred = plugins.smartpromise.defer<void>(); // used to run things when watcher is initialized
|
||||
private eventObservablemap = new plugins.smartrx.Observablemap(); // register one observable per event
|
||||
|
||||
/**
|
||||
* constructor of class smartchok
|
||||
*/
|
||||
constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
|
||||
constructor(watchArrayArg: string[]) {
|
||||
this.watchStringmap.addStringArray(watchArrayArg);
|
||||
this.chokidarOptions = optionsArg;
|
||||
}
|
||||
|
||||
private getGlobBase(globPattern: string) {
|
||||
// Characters that mark the beginning of a glob pattern
|
||||
const globChars = ['*', '?', '[', ']', '{', '}'];
|
||||
|
||||
// Find the index of the first glob character
|
||||
const firstGlobCharIndex = globPattern.split('').findIndex((char) => globChars.includes(char));
|
||||
|
||||
// If no glob characters are found, return the entire string
|
||||
if (firstGlobCharIndex === -1) {
|
||||
return globPattern;
|
||||
}
|
||||
|
||||
// Extract the substring up to the first glob character
|
||||
const basePathPortion = globPattern.substring(0, firstGlobCharIndex);
|
||||
|
||||
// Find the last slash before the glob pattern starts
|
||||
const lastSlashIndex = basePathPortion.lastIndexOf('/');
|
||||
|
||||
// If there is no slash, return the basePathPortion as is
|
||||
if (lastSlashIndex === -1) {
|
||||
return basePathPortion;
|
||||
}
|
||||
|
||||
// Return the base path up to and including the last slash
|
||||
return basePathPortion.substring(0, lastSlashIndex + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,10 +73,12 @@ export class Smartchok {
|
||||
/**
|
||||
* gets an observable for a certain event
|
||||
*/
|
||||
public getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<[string, plugins.fs.Stats]>> {
|
||||
public getObservableFor(
|
||||
fsEvent: TFsEvent
|
||||
): Promise<plugins.smartrx.rxjs.Observable<[string, plugins.fs.Stats]>> {
|
||||
const done = plugins.smartpromise.defer<plugins.smartrx.rxjs.Observable<any>>();
|
||||
this.watchingDeferred.promise.then(() => {
|
||||
const eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
|
||||
const eventObservable = this.eventObservablemap.getSubjectForEmitterEvent(
|
||||
this.watcher,
|
||||
fsEvent
|
||||
);
|
||||
@ -68,9 +94,8 @@ export class Smartchok {
|
||||
public start(): Promise<void> {
|
||||
const done = plugins.smartpromise.defer<void>();
|
||||
this.status = 'starting';
|
||||
this.watcher = plugins.chokidar.watch(
|
||||
this.watchStringmap.getStringArray(),
|
||||
this.chokidarOptions
|
||||
this.watcher = new plugins.watcher(
|
||||
this.watchStringmap.getStringArray().map((string) => this.getGlobBase(string))
|
||||
);
|
||||
this.watcher.on('ready', () => {
|
||||
this.status = 'watching';
|
||||
|
@ -8,9 +8,9 @@ export {
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrx from '@pushrocks/smartrx';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrx from '@push.rocks/smartrx';
|
||||
|
||||
export {
|
||||
lik,
|
||||
@ -19,8 +19,8 @@ export {
|
||||
}
|
||||
|
||||
// thirdparty scope
|
||||
import * as chokidar from 'chokidar';
|
||||
import watcher from 'watcher';
|
||||
|
||||
export {
|
||||
chokidar
|
||||
}
|
||||
watcher,
|
||||
}
|
||||
|
Reference in New Issue
Block a user