Created
November 8, 2020 03:47
-
-
Save Roms1383/f1934b6906751c2f555c5a8a4b4cd89d to your computer and use it in GitHub Desktop.
Write a TypeScript barrel file from files found in directory
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 path = require('path') | |
const fs = require('fs') | |
const source = process.env.PWD | |
const filenames = fs.readdirSync(source) | |
.filter(filename => filename.indexOf('.ts') !== -1 && filename !== 'index.ts') | |
.map(filename => filename.replace('.ts', '')) | |
const content = filenames | |
.map(filename => `export * from './${filename}'`) | |
.join('\n') | |
fs.writeFileSync(path.join(source, 'index.ts'), content, { encoding: 'utf8' }) | |
console.log(`wrote to ${source}/index.ts`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment