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

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/LoadLibraryHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/LoadLibraryHandler.js