Documentation for incorporating helpers within extensions



  • Hi,

    jsreport-xlsx utilises several mechanisms for incorporating helpers.js (see below from jsreport-xlsx/src/index.js). Can you please point me in the direction of the documentation for when these various mechanisms might apply and any specific documentation on their operation?

    Thanks!
    Daniel

     if (reporter.compilation) {
        reporter.compilation.resource('defaultXlsxTemplate.json', path.join(__dirname, '../static', 'defaultXlsxTemplate.json'))
        reporter.compilation.resource('helpers.js', path.join(__dirname, '../static', 'helpers.js'))
      }
    

    and

    return (reporter.execution ? Promise.resolve(reporter.execution.resource('helpers.js')) : FS.readFileAsync(path.join(__dirname, '../', 'static', 'helpers.js'), 'utf8')).then(
            (content) => {
              if (req.template.helpers && typeof req.template.helpers === 'object') {
                // this is the case when the jsreport is used with in-process strategy
                // and additinal helpers are passed as object
                // in this case we need to merge in xlsx helpers
                req.template.helpers.require = require
                req.template.helpers.fsproxy = require(path.join(__dirname, 'fsproxy.js'))
                return vm.runInNewContext(content, req.template.helpers)
              }
    
              req.template.helpers = content + '\n' + (req.template.helpers || '')
            })
    


  • This is quite internal and new thing and we don't have it documented yet. I'll add it to our notes to improve this in short time.

    Your main confusion is probably the reporter.compilation and reporter.execution.resource('helpers.js'). This adds support for running the recipe from within jsreport compiled into single executable. We need to mark the helpers.js file to include it in the final jsreport.exe during compilation through reporter.compilation.resource() and also later extract it during the executable runtime using reporter.execution.resource(). This package could help to understand this process.

    https://github.com/jsreport/jsreport-compile
    https://jsreport.net/learn/single-file-executable



  • Excellent, thanks!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.