import { sync } from "globby" ; import * as multimatch from "multimatch" ; import { pipe , compact , uniq , sortBy , identity , map , isEqual } from "lodash/fp" ; import { rootPrepend , splitLines } from "./utility" ; import { getChangesNotStaged } from "./git" ; export function fromGlobsToFilesArray ( globArray , options ? ) { return sync ( globArray , { ... options , caseSensitiveMatch : false } ) . map ( rootPrepend ) ; } export function getGlobMatches ( globArray , matchArray ) { return multimatch ( matchArray , globArray , { nocase : true } ) ; } export function isGlobMatch ( globArray , matchArray ) { const matches = multimatch ( matchArray , globArray , { nocase : true } ) ; return isEqual ( matchArray , matches ) ; } export function fromStdoutToFilesArray ( stdout ) { return pipe ( splitLines , compact , uniq , sortBy ( identity ) , map ( rootPrepend ) ) ( stdout ) ; } export const getOnlyChangedFiles = async ( source ) => { const stdout = await getChangesNotStaged ( ) ; const changed = fromStdoutToFilesArray ( stdout ) ; return getGlobMatches ( source , changed ) ; } ;