Skip to content

Instantly share code, notes, and snippets.

@luwes
Created January 13, 2018 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luwes/0c6205b09ea7ac5dd1c2ff78fcd26c8c to your computer and use it in GitHub Desktop.
Save luwes/0c6205b09ea7ac5dd1c2ff78fcd26c8c to your computer and use it in GitHub Desktop.
/* 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