Created
August 19, 2016 23:30
-
-
Save anthonynichols/6b6fde816b1767933b0c67ce4bc2ef35 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
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