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from 'fs';\nimport * as path from 'path';\n\n/**\n * Recursively read the contents of a directory.\n *\n * @param targetDir Absolute or relative path of the directory to scan. All returned paths will be relative to this\n * directory.\n * @returns Array holding all relative paths\n */\nexport function deepReadDirSync(targetDir: string): string[] {\n const targetDirAbsPath = path.resolve(targetDir);\n\n if (!fs.existsSync(targetDirAbsPath)) {\n throw new Error(`Cannot read contents of ${targetDirAbsPath}. Directory does not exist.`);\n }\n\n if (!fs.statSync(targetDirAbsPath).isDirectory()) {\n throw new Error(`Cannot read contents of ${targetDirAbsPath}, because it is not a directory.`);\n }\n\n // This does the same thing as its containing function, `deepReadDirSync` (except that - purely for convenience - it\n // deals in absolute paths rather than relative ones). We need this to be separate from the outer function to preserve\n // the difference between `targetDirAbsPath` and `currentDirAbsPath`.\n const deepReadCurrentDir = (currentDirAbsPath: string): string[] => {\n return fs.readdirSync(currentDirAbsPath).reduce((absPaths: string[], itemName: string) => {\n const itemAbsPath = path.join(currentDirAbsPath, itemName);\n\n if (fs.statSync(itemAbsPath).isDirectory()) {\n return [...absPaths, ...deepReadCurrentDir(itemAbsPath)];\n }\n\n return [...absPaths, itemAbsPath];\n }, []);\n };\n\n return deepReadCurrentDir(targetDirAbsPath).map(absPath => path.relative(targetDirAbsPath, absPath));\n}\n"]}
\No newline at end of file