Last active
November 30, 2022 17:24
-
-
Save danielkv/c040f948ecd03e128b919ee597920ace to your computer and use it in GitHub Desktop.
Revisions
-
danielkv revised this gist
Nov 30, 2022 . 1 changed file with 0 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,3 @@ const path = require('path') const fs = require('fs') const { format } = require('prettier') -
danielkv created this gist
Nov 30, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ const path = require('path') const fs = require('fs') const { format } = require('prettier') const folder = path.resolve(__dirname) const outputFile = path.resolve(__dirname, 'index.ts') function generateExport(name, findings) { let exportString = 'export {' findings.forEach((finding, index) => { if (index > 0) exportString += ',' exportString += `\n ${finding.component}` }) exportString += `\n} from './${name}'` return exportString } fs.readdir(folder, (err, files) => { if (err) return const exports = [] files.forEach((file) => { const dirPath = `${folder}/${file}` if (!fs.statSync(dirPath).isDirectory()) return const filePath = `${dirPath}/index.tsx` if (!fs.existsSync(dirPath) || !fs.statSync(filePath).isFile()) return const content = fs.readFileSync(filePath, 'utf-8') const exportRegExp = /export[\s]+(type|const|default|function)[\s]+([a-zA-Z]+):?[\s]+/gm const match = [...content.matchAll(exportRegExp)] const findings = match.reduce((acc, match) => { const newFinding = { model: match[1], component: match[2], } acc.push(newFinding) return acc }, []) exports.push(generateExport(file, findings)) }) const formatedContent = format(exports.join('\n')) fs.writeFileSync(outputFile, formatedContent) })