UNPKG

backend_dashboard-utils

Version:

A utility for allowing other components of HolyCorn Software's code easily integrate with the backend_dashboard faculty

38 lines (25 loc) 1.21 kB
import fs from 'node:fs' import libPath from 'node:path' export default async function addScripts({ path } = {}) { if(!path){ throw new Error(`Please specify the path to scan for dashboard scripts`) } const dashboard_faculty = (await FacultyPlatform.get().connectionManager.connect('backend_dashboard')).remote let scripts = fs.readdirSync(path).filter(x => fs.statSync(`${path}${libPath.sep}${x}`).isFile() && (x.endsWith('.mjs') || x.endsWith('.js'))).map(x => `${path}${libPath.sep}${x}`); for (let _script of scripts) { const script = _script const add_script = (script) => { dashboard_faculty.addScript({ name: /.+\/(.+)\.mjs$/.exec(script)[1], base64: fs.readFileSync(script).toString('base64'), override: true }); //By then, the backend_dashboard will have been initialized } //Add the script to the backend_dashboard, and then add it again if it changes add_script(script); fs.watch(script, function () { console.log(`${script} changed, so adding it again to the admin dashboard`) add_script(script); }) } }