You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.2 KiB

3 years ago
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