Skip to content

Instantly share code, notes, and snippets.

View nautical's full-sized avatar
👨‍💻
Working from home

Piyush nautical

👨‍💻
Working from home
View GitHub Profile
const { promises: fs } = require('fs');
const path = require('path');
// find plugins in a directory, matching a pattern, ignoring registered plugins
function findPlugins(dir, pattern, registered) {
let segments = pattern.split('/');
let regexp = new RegExp(`^${segments.pop().replace('*', '.*')}`);
dir = path.join(dir, ...segments);
return fs.readdir(dir).then(f => f.reduce((plugins, dirname) => {