Skip to content

Instantly share code, notes, and snippets.

@anthonynichols
Created August 19, 2016 23:30
Show Gist options
  • Save anthonynichols/6b6fde816b1767933b0c67ce4bc2ef35 to your computer and use it in GitHub Desktop.
Save anthonynichols/6b6fde816b1767933b0c67ce4bc2ef35 to your computer and use it in GitHub Desktop.
import fs from 'fs-extra'
import _ from 'lodash'
import path from 'path'
let componentsPath = path.resolve('src/components')
const contents = fs.readdirSync(componentsPath)
let _files = []
let _directories = []
if (contents) {
_.forEach(contents, file => {
let filePath = path.resolve(componentsPath, file)
let stats = fs.statSync(filePath)
let extension = path.extname(file);
let filename = path.basename(file, extension)
if (stats.isFile()) {
_files.push(filename)
} else if (stats.isDirectory()) {
_directories.push(filename)
}
})
}
fs.writeFileSync(`${componentsPath}/index.js`, (() => {
let output = ''
_.forEach(_directories, name => {
if (name === 'index') return
output += `export * from './${name}';\n`
})
_.forEach(_files, name => {
if (name === 'index') return
output += `export * from './${name}';\n`
})
return output
})())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment