mit-license/lib/load-user.js
Richie Bendall bd71a57b7a
Refactor
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
2021-05-22 22:43:22 +12:00

26 lines
564 B
JavaScript

import {fileURLToPath} from 'node:url'
import path, {dirname} from 'node:path'
import loadJsonFile from 'load-json-file'
const directoryName = dirname(fileURLToPath(import.meta.url))
const loadUser = async hostname => {
const [id] = hostname.split('.')
const user = {
copyright: '<copyright holders>' // Fallback
}
try {
return {
...user,
...await loadJsonFile(path.join(directoryName, '..', 'users', `${id}.json`))
}
} catch (error) {
if (error.code !== 'ENOENT') {
throw error
}
}
}
export default loadUser