Repair preserves-schema-ts watch mode
This commit is contained in:
parent
5d24902de1
commit
e3a1be80e9
|
@ -55,10 +55,7 @@ export function computeBase(paths: string[]): string {
|
|||
}
|
||||
}
|
||||
|
||||
export function findSchemas(userInput: string): ({
|
||||
names: string[],
|
||||
base: string,
|
||||
}) {
|
||||
export function inputToInputGlob(userInput: string): { baseDir: string, glob: string } {
|
||||
const colonPos = userInput.lastIndexOf(':');
|
||||
let [base, g] = (colonPos === -1)
|
||||
? [userInput, '**/*.prs']
|
||||
|
@ -66,6 +63,14 @@ export function findSchemas(userInput: string): ({
|
|||
if (base[base.length - 1] !== '/') {
|
||||
base = base + '/';
|
||||
}
|
||||
return { baseDir: base, glob: g };
|
||||
}
|
||||
|
||||
export function findSchemas(userInput: string): ({
|
||||
names: string[],
|
||||
base: string,
|
||||
}) {
|
||||
const { baseDir: base, glob: g } = inputToInputGlob(userInput);
|
||||
const names = glob.sync(base + g);
|
||||
return { names, base };
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import * as M from '../meta';
|
|||
import chalk from 'chalk';
|
||||
import { is, Position } from '@preserves/core';
|
||||
import chokidar from 'chokidar';
|
||||
import { changeExt, Diagnostic, expandInputGlob, formatFailures } from './cli-utils';
|
||||
import { changeExt, Diagnostic, inputToInputGlob, expandInputGlob, formatFailures } from './cli-utils';
|
||||
|
||||
export type CommandLineArguments = {
|
||||
inputs: string[];
|
||||
|
@ -65,7 +65,11 @@ export function run(options: CommandLineArguments): void {
|
|||
const watchers = r.baseDirs.map(base => chokidar.watch(base, {
|
||||
ignoreInitial: true,
|
||||
}).on('all', (_event, filename) => {
|
||||
if (options.inputs.some(i => minimatch(filename, i))) {
|
||||
const relevant = options.inputs.some(i => {
|
||||
const { baseDir, glob } = inputToInputGlob(i);
|
||||
return minimatch(filename, baseDir + glob);
|
||||
});
|
||||
if (relevant) {
|
||||
if (!triggered) {
|
||||
triggered = true;
|
||||
watchers.map(w => w.close());
|
||||
|
|
Loading…
Reference in New Issue