Created
January 13, 2018 22:01
-
-
Save luwes/0c6205b09ea7ac5dd1c2ff78fcd26c8c 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
/* eslint-env node */ | |
const fs = require('fs'); | |
const path = require('path'); | |
const camelCase = require('lodash/camelcase'); | |
const pkg = require(path.resolve('package.json')); | |
const defaultOptions = { | |
regex: /^rollup-plugin-/, | |
path: './' | |
}; | |
module.exports = (options = defaultOptions) => { | |
const local = fs.readdirSync(path.resolve(__dirname, options.path)) | |
.filter((name) => /\.js$/.test(name)) | |
.reduce((acc, curr) => { | |
const key = curr.replace('.js', ''); | |
acc[camelCase(key)] = require(path.resolve(__dirname, curr)); | |
return acc; | |
}, {}); | |
const npm = Object.keys(pkg.devDependencies) | |
.filter((name) => options.regex.test(name)) | |
.reduce((acc, curr) => { | |
const key = curr.replace(options.regex, ''); | |
acc[camelCase(key)] = require(curr); | |
return acc; | |
}, {}); | |
return Object.assign(npm, local); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment