UNPKG

dcp-client

Version:

Core libraries for accessing DCP network

45 lines (42 loc) 1.68 kB
/** * @file generate-worktime-info.js * Get the name and version of all worktime files in the libexec directory and export as an array. * Worktime files are distinguished from other sandbox scripts by the sandbox-definitions.json worktimes field * * @author Severn Lortie <severn@distributive.network> * @date February 2024 */ /** * Require the sandbox scripts and extract the version and name from each worktime. Worktime setup * scripts differentiated from normal sandbox scripts by the worktimes field in sandbox-definitions.json * Each of these scripts expects self.wrapScriptLoading and protectedStorage to be available, so they * are mocked as necessary. * * @returns {object[]} Worktime info objects ({name: String, version: String}) in descending version order */ function getWorktimes() { const semver = require('semver'); const worktimeScripts = require('../generated/sandbox-definitions.json').worktimes; const worktimes = []; function wrapScriptLoading(_, fn) { fn(protectedStorage); } function registerWorktime(worktime) { worktimes.push({ name: worktime.name, version: worktime.version }) } const protectedStorage = {}; protectedStorage.worktimes = {}; protectedStorage.worktimes.registerWorktime = registerWorktime; globalThis.self = {}; globalThis.self.wrapScriptLoading = wrapScriptLoading; for (const script of worktimeScripts) require(`../libexec/sandbox/${script}`); worktimes.sort((a, b) => semver.compare(b.version, a.version, true)); delete globalThis.self; return worktimes; } const worktimes = getWorktimes(); module.exports.worktimes = worktimes;