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.6 KiB

import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml'
import slug from 'slug'
/**
* resolve action class
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://git.node001.net/HerrHase/super-hog.git
*
*/
function resolveActionClass(className) {
let classPath = path.join(path.resolve(), 'resources/actions/' + className + '.ts')
let result = undefined
if (fs.existsSync(classPath)) {
result = classPath
}
if (!result) {
throw new Error('Action Class ' + className + ' / ' + classPath + ' not found!')
}
return result
}
/**
* loading all configs from enabled directory
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://git.node001.net/HerrHase/super-hog.git
*
*/
function resolveEnabledConfig(name?: string) {
const configs = []
const directoryPath = path.join(path.resolve(), 'resources/config')
// load files from enabled
const files = fs.readdirSync(directoryPath + '/enabled')
for (let index in files) {
let file = files[index]
if (!file.endsWith('.yml')) {
continue
}
if (name !== undefined && file !== (name + '.yml')) {
continue
}
const result = yaml.load(fs.readFileSync(directoryPath + '/enabled/' + file))
if (result) {
result.slug = slug(result.name)
configs.push(result)
}
}
return configs
}
export {
resolveActionClass,
resolveEnabledConfig
}