Sha256: f6260fc9d2356a49600c1c012fbbde8efda48c41db7d8d5eb4ef02b2903ab2e5
Contents?: true
Size: 1.21 KB
Versions: 19
Compression:
Stored size: 1.21 KB
Contents
const AbstractHandler = require('./AbstractHandler') class LoadLibraryHandler extends AbstractHandler { requiredParametersCount = 1 constructor() { super() } process(command) { if (command.payload.length < this.requiredParametersCount) { throw new Error("Load Library parameters mismatch") } let {payload} = command let [lib] = payload let pathArray = lib.split(/[/\\]/) let libraryName = pathArray.length > 1 ? pathArray[pathArray.length - 1] : pathArray[0] libraryName = libraryName.replace('.js', '') let moduleExports try { moduleExports = require(lib) } catch (error) { try { moduleExports = require(`${process.cwd()}/${lib}`) } catch (error) { throw this.process_stack_trace(error, this.constructor.name) } } global[libraryName] = moduleExports for (const [key, value] of Object.entries(moduleExports)) { // Here, `key` is the name of the export, and `value` is the exported type itself. global[key] = value } return 0 } } module.exports = new LoadLibraryHandler()
Version data entries
19 entries across 14 versions & 1 rubygems