How to use opal-compiler - 7 common examples

To help you get started, we’ve selected a few opal-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asciidoctor / asciidoctor.js / packages / core / tasks / module / compiler.js View on Github external
'use strict'
const fs = require('fs')
const path = require('path')
const bfs = require('bestikk-fs')
const log = require('bestikk-log')
const OpalBuilder = require('opal-compiler').Builder

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.
github asciidoctor / asciidoctor.js / packages / core / tasks / module / compiler.js View on Github external
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')
  }
}
github asciidoctor / asciidoctor.js / packages / core / tasks / examples.js View on Github external
'use strict'

const path = require('path')
const fs = require('fs')
const log = require('bestikk-log')
const bfs = require('bestikk-fs')
const Download = require('bestikk-download')
const download = new Download({})
const OpalBuilder = require('opal-compiler').Builder
const BuilderModule = require('./module/builder')

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')
}

const getContentFromAsciiDocRepo = (source, target) => {
  return download.getContentFromURL(`${builder.asciidocRepoBaseURI}/doc/${source}`, target)
github asciidoctor / asciidoctor.js / npm / opal-compiler.js View on Github external
var log = require('bestikk-log');
var Builder = require('opal-compiler').Builder;
var fs = require('fs');

module.exports = OpalCompiler;

function OpalCompiler(config) {
  this.config = config || {};
  this.dynamicRequireLevel = this.config.dynamicRequireLevel || 'warning';
  Opal.config.unsupported_features_severity = 'ignore';
}

OpalCompiler.prototype.compile = function(require, outputFile, includes) {
  var builder = Builder.$new();
  builder.$append_paths('node_modules/opal-compiler/src/stdlib', 'lib', 'build/asciidoctor/lib');
  builder.compiler_options = Opal.hash({'dynamic_require_severity': this.dynamicRequireLevel});
  if (typeof includes !== 'undefined') {
    var includesLength = includes.length;
github asciidoctor / asciidoctor.js / packages / core / tasks / module / compiler.js View on Github external
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)
}
github asciidoctor / asciidoctor.js / packages / core / tasks / examples.js View on Github external
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')
}
github asciidoctor / asciidoctor.js / npm / opal-compiler.js View on Github external
OpalCompiler.prototype.compile = function(require, outputFile, includes) {
  var builder = Builder.$new();
  builder.$append_paths('node_modules/opal-compiler/src/stdlib', 'lib', 'build/asciidoctor/lib');
  builder.compiler_options = Opal.hash({'dynamic_require_severity': this.dynamicRequireLevel});
  if (typeof includes !== 'undefined') {
    var includesLength = includes.length;
    for (var i = 0; i < includesLength; i++) {
      builder.$append_paths(includes[i]);
    }
  }
  log.debug('compile ' + require);
  var result = builder.$build(require);
  fs.writeFileSync(outputFile, result.$to_s(), 'utf8');
}

opal-compiler

Opal compiler

MIT
Latest version published 2 years ago

Package Health Score

36 / 100
Full package analysis