Created
February 19, 2021 15:55
-
-
Save bgoonz/e2afcb7be4da9f3442484fffc2b57501 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {lstatSync, readdirSync} = require('fs'); | |
const {basename, join, resolve} = require('path'); | |
const denyList = ['images']; | |
const isDirectory = (source) => lstatSync(source).isDirectory(); | |
const getDirectories = (source) => | |
readdirSync(source) | |
.map((name) => join(source, name)) | |
.filter(isDirectory); | |
function readScreenshotDirectory( | |
components = [], | |
path = resolve(__dirname, '../test/screenshot'), | |
parentDirectory = '' | |
) { | |
const directories = getDirectories(path); | |
directories.forEach((directory) => { | |
const packageName = basename(directory); | |
if (denyList.includes(packageName)) return; | |
// recursively get sub directories | |
const subDirectories = getDirectories(resolve(path, packageName)); | |
if (subDirectories.length > 0) { | |
readScreenshotDirectory( | |
components, | |
resolve(path, packageName), | |
packageName | |
); | |
} | |
components.push( | |
`${parentDirectory ? parentDirectory + '/' : ''}${packageName}` | |
); | |
}); | |
return components; | |
} | |
module.exports = {read: readScreenshotDirectory, getDirectories}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment