MCPcopy Create free account
hub / github.com/MirrowApp/mirrow / watchMirrow

Function watchMirrow

packages/cli/src/runner.ts:170–207  ·  view source on GitHub ↗
(
  options: CliOptions,
  signal?: AbortSignal
)

Source from the content-addressed store, hash-verified

168}
169
170export async function watchMirrow(
171 options: CliOptions,
172 signal?: AbortSignal
173): Promise<void> {
174 const { input, output, depth } = options;
175 const abortSignal = signal ?? new AbortController().signal;
176
177 const inputStats = await fs.stat(input).catch(() => {
178 throw new Error(`Input not found: ${input}`);
179 });
180
181 const outputStats = await fs.stat(output).catch(() => undefined);
182
183 if (inputStats.isDirectory()) {
184 if (outputStats && !outputStats.isDirectory()) {
185 throw new Error("Input is a directory, but output is not");
186 }
187 } else if (outputStats && outputStats.isDirectory()) {
188 throw new Error("Input is a file, but output is a directory");
189 }
190
191 await runMirrow(options);
192 console.log(
193 `Watching ${formatPath(input)} (depth: ${depth === Infinity ? "unbound" : depth
194 })`
195 );
196 console.log("Press Ctrl+C to stop.\n");
197
198 const enqueue = createTaskQueue();
199
200 if (inputStats.isDirectory()) {
201 await watchDirectory(input, output, depth, abortSignal, enqueue);
202 } else {
203 await watchFile(input, output, abortSignal, enqueue);
204 }
205
206 console.log("Watcher stopped.");
207}
208
209async function watchDirectory(
210 inputDir: string,

Callers 2

cli.test.jsFile · 0.85
runCliFunction · 0.85

Calls 5

runMirrowFunction · 0.85
formatPathFunction · 0.85
createTaskQueueFunction · 0.85
watchDirectoryFunction · 0.85
watchFileFunction · 0.85

Tested by

no test coverage detected