-
-
Save lysenko-sergey-developer/3997e0697727ee0fb4443c72c92ecbaf to your computer and use it in GitHub Desktop.
dd
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 fs = require('fs') | |
const fsPromises = require('fs').promises | |
const path = require('path') | |
const promisifyStat = (path) => new Promise((resolve, reject) => { | |
fs.stat(path, (err, stat) => { | |
if (err) reject(err) | |
resolve(stat) | |
}) | |
}) | |
const extractComponents = async (extractPath = '') => { | |
try { | |
const directories = await fsPromises.readdir(extractPath) | |
return directories.reduce(async (returnedOutput, output) => { | |
const stat = await promisifyStat(path.join(extractPath, output)) | |
console.log(output) | |
const isFile = await stat.isFile() | |
const filePath = path.join(extractPath, output) | |
console.log('>>>', stat) | |
const nextReturnedOutput = await isFile ? | |
{ filePath: output } : | |
{ filePath: await extractComponents(path.join(extractPath, output)) } | |
return { ...returnedOutput, ...nextReturnedOutput } | |
}) | |
} catch (err) { | |
console.log('error:', err) | |
} | |
} | |
extractComponents(path.join(__dirname, '..', 'stories')).then(x => console.log('end', x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment