Documentation for incorporating helpers within extensions
-
Hi,
jsreport-xlsx utilises several mechanisms for incorporating
helpers.js
(see below fromjsreport-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!
Danielif (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
andreporter.execution.resource('helpers.js')
. This adds support for running the recipe from within jsreport compiled into single executable. We need to mark thehelpers.js
file to include it in the finaljsreport.exe
during compilation throughreporter.compilation.resource()
and also later extract it during the executable runtime usingreporter.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!