@baseplate-dev/sync
Version:
Library for syncing Baseplate descriptions
25 lines • 1.14 kB
JavaScript
import micromatch from 'micromatch';
import { normalizePathToOutputPath } from '#src/utils/canonical-path.js';
/**
* Filter post-write commands
*
* @param commands - The commands to filter
* @param options - Filter options
* @param options.modifiedRelativePaths - The modified relative paths
* @param options.rerunCommands - The rerun commands
* @returns The filtered commands
*/
export function filterPostWriteCommands(commands, { modifiedRelativePaths, rerunCommands, }) {
return commands.filter((command) => {
const { onlyIfChanged = [] } = command.options ?? {};
const onlyIfChangedArr = Array.isArray(onlyIfChanged)
? onlyIfChanged
: [onlyIfChanged];
return (command.options?.onlyIfChanged == null ||
onlyIfChangedArr.some((pattern) =>
// Check if any modified path matches the pattern (supports globs)
[...modifiedRelativePaths].some((modifiedPath) => micromatch.isMatch(normalizePathToOutputPath(modifiedPath), pattern))) ||
rerunCommands.includes(command.command));
});
}
//# sourceMappingURL=filter-commands.js.map