Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const compileExt = (name, environment, skipped) => {
if (fs.existsSync(`lib/asciidoctor/js/${name}_ext/${environment}.rb`)) {
const module = `asciidoctor/js/${name}_ext/${environment}`
log.debug(module)
// Build a new instance each time, otherwise the context is shared.
const target = `build/${name}-ext-${environment}.js`
if (fs.existsSync(target)) {
skipped.push(target)
return
}
const opalBuilder = OpalBuilder.create()
opalBuilder.appendPaths('lib')
opalBuilder.setCompilerOptions({ dynamic_require_severity: 'ignore', requirable: true })
// For performance reason we build "asciidoctor_ext" without "asciidoctor" core.
// As a result Ruby modules required in "asciidoctor_ext" won't be found at compile time but will be resolved at runtime.
opalBuilder.missing_require_severity = 'ignore'
let data = opalBuilder.build(module).toString()
fs.writeFileSync(target, data, 'utf8')
}
}
const compileAsciidoctorCore = (asciidoctorCoreDependency) => {
log.task('compile core lib')
const module = `asciidoctor/lib`
log.debug(module)
const target = asciidoctorCoreDependency.target
if (fs.existsSync(target)) {
log.info(`${target} file already exists, skipping "compile" task.\nTIP: Use "npm run clean:core" to compile again from Asciidoctor Ruby.`)
return
}
const opalBuilder = OpalBuilder.create()
opalBuilder.appendPaths('build/asciidoctor/lib')
opalBuilder.appendPaths('node_modules/opal-compiler/src/stdlib')
opalBuilder.appendPaths('lib')
opalBuilder.setCompilerOptions({ dynamic_require_severity: 'ignore' })
fs.writeFileSync(target, opalBuilder.build('asciidoctor').toString(), 'utf8')
replaceUnsupportedFeatures(asciidoctorCoreDependency)
applyPatches(asciidoctorCoreDependency)
}
const compileExamples = () => {
log.task('compile examples')
bfs.mkdirsSync(builder.examplesBuildDir)
const opalBuilder = OpalBuilder.create()
opalBuilder.appendPaths('build/asciidoctor/lib')
opalBuilder.appendPaths('node_modules/opal-compiler/src/stdlib')
opalBuilder.appendPaths('lib')
fs.writeFileSync(path.join(builder.examplesBuildDir, 'userguide_test.js'), opalBuilder.build('examples/userguide_test.rb').toString(), 'utf8')
}