Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return arrayify(pluginNames).map(pluginName => {
let createPlugin
if (typeof pluginName === 'string') {
const loadModule = require('load-module')
const globalModules = require('global-modules')
createPlugin = loadModule(pluginName, {
paths: [path.resolve(__dirname, 'plugin'), '.', globalModules],
prefix: 'renamer-'
})
} else {
createPlugin = pluginName
}
if (!(typeof createPlugin === 'function' && !t.isClass(createPlugin))) {
throw new Error('Invalid plugin: plugin module must export a function')
}
const Plugin = createPlugin(require('./plugin-base'))
if (!t.isClass(Plugin)) {
throw new Error('Invalid plugin: plugin module must export a function which returns a class')
}
if (!Plugin.prototype.replace) {
throw new Error('Invalid plugin: plugin class must implement a replace method')
}
return new Plugin()
})
}
let createPlugin
if (typeof pluginName === 'string') {
const loadModule = require('load-module')
const globalModules = require('global-modules')
createPlugin = loadModule(pluginName, {
paths: [path.resolve(__dirname, 'plugin'), '.', globalModules],
prefix: 'renamer-'
})
} else {
createPlugin = pluginName
}
if (!(typeof createPlugin === 'function' && !t.isClass(createPlugin))) {
throw new Error('Invalid plugin: plugin module must export a function')
}
const Plugin = createPlugin(require('./plugin-base'))
if (!t.isClass(Plugin)) {
throw new Error('Invalid plugin: plugin module must export a function which returns a class')
}
if (!Plugin.prototype.replace) {
throw new Error('Invalid plugin: plugin class must implement a replace method')
}
return new Plugin()
})
}
expand () {
for (const [ name, cmd ] of this) {
if (typeof cmd === 'string') {
const Command = require(cmd)
this.set(name, new Command())
} else if (t.isClass(cmd)) {
this.set(name, new cmd())
}
}
}