import path from 'path' import fs from 'fs' /** * * * */ class ResolverClass { /** * * @param {String} prefix * */ constructor(prefix) { this.prefix = prefix } /** * * * @param {String} className * @param {Boolean} [isCustom=false] * @return {String} * */ lookupPath(className, isCustom = false) { let custom = '' if (isCustom) { custom = '/custom/' } return path.join(path.resolve(), custom + this.prefix + '/' + className + '.js') } /** * * @param {[type]} className * @return {[type]} [description] */ find(className) { // getting let classPath = this.lookupPath(className, true) // results let result = false if (fs.existsSync(classPath)) { result = classPath } else { classPath = this.lookupPath(className) if (fs.existsSync(classPath)) { result = classPath } } if (!result) { throw new Error('Class ' + className + ' not found!') } return result } } export default ResolverClass