{"version":3,"file":"get_file_if_exists.js","sourceRoot":"","sources":["../../src/parser_scripts/get_file_if_exists.ts"],"names":[],"mappings":";;AAIA,0CAaC;AAjBD,2BAAgC;AAChC,iDAAwC;AAExC,qFAAqF;AACrF,SAAgB,eAAe,CAAC,GAAW,EAAE,MAAc;IACzD,gEAAgE;IAChE,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACjE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,CAAC,CAAA;QAExC,MAAM,KAAK,GAAG,IAAA,gBAAW,EAAC,GAAG,CAAC,CAAA;QAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAEpD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,IAAA,wBAAQ,EAAC,4BAA4B,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACjG,CAAC;AACH,CAAC","sourcesContent":["import { readdirSync } from 'fs'\nimport { execSync } from 'child_process'\n\n// Check if a file matching a search pattern exists, and return the first match if so\nexport function getFileIfExists(cwd: string, search: string): string {\n // \"find\" command is not available on Windows. Use a fs instead.\n if (process.platform === 'win32') {\n const pattern = search.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*')\n const regex = new RegExp(`^${pattern}$`)\n\n const files = readdirSync(cwd)\n const match = files.find((file) => regex.test(file))\n\n return match ? `./${match}` : ''\n } else {\n return execSync(`find . -maxdepth 1 -name ${search}`, { cwd }).toString().trim().split('\\n')[0]\n }\n}\n"]}