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