Skip to content

Commit

Permalink
feat(automd): expose unwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 21, 2024
1 parent 361cd50 commit 6ee0d6b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/automd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export interface AutomdResult extends TransformResult {
output: string;
}

export async function automd(
_config: Config = {},
): Promise<{ results: AutomdResult[]; _config: ResolvedConfig; time: number }> {
export async function automd(_config: Config = {}): Promise<{
results: AutomdResult[];
time: number;
config: ResolvedConfig;
unwatch?: () => void | Promise<void>;
}> {
const start = performance.now();
const config = await loadConfig(_config.dir, _config);

Expand All @@ -39,16 +42,18 @@ export async function automd(
inputFiles.map((i) => _automd(i, config, multiFiles, cache)),
);

let unwatch;
if (config.watch) {
await _watch(inputFiles, config, multiFiles, cache);
unwatch = await _watch(inputFiles, config, multiFiles, cache);
}

const time = performance.now() - start;

return {
_config: config,
time,
results,
config,
unwatch,
};
}

Expand Down Expand Up @@ -119,4 +124,6 @@ async function _watch(
process.on("SIGINT", () => {
subscription.unsubscribe();
});

return subscription.unsubscribe;
}

0 comments on commit 6ee0d6b

Please sign in to comment.