Sha256: c68ea191fea37d738d07a62113192127fc3ecbd6222e7664c6401a8792de9859

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Opal

  class Command

    # Valid command line arguments
    COMMANDS = [:help, :irb, :compile, :bundle, :exec, :eval, :install]

    def initialize(args)
      command = args.shift

      if command and COMMANDS.include?(command.to_sym)
        __send__ command.to_sym, *args
      elsif command and File.exists? command
        eval command
      else
        help
      end
    end

    def help
      puts "need to print help"
    end

    # desc "irb", "Opens interactive opal/ruby repl"
    def irb
      ctx = Opal::Context.new
      ctx.start_repl
    end

    def eval(path = nil)
      return "no path given for eval" unless path

      abort "path does not exist `#{path}'" unless File.exist? path

      ctx = Opal::Context.new
      ctx.require_file File.expand_path(path)
    end

    def compile(path)
      puts Opal::Parser.new(File.read(path)).parse!.generate_top
    end

    def install
      install = RBP::Install.new
      install.install
    end

    # Bundle the gem (browserify) ready for the browser
    def bundle
      # lazy load incase user does not have rbp installed
      require 'opal/bundle'

      path    = File.join Dir.getwd, 'package.yml'
      package = Rbp::Package.load_path path
      bundle  = Bundle.new package

      puts bundle
      puts bundle.package

      puts bundle.build
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-0.3.10 lib/opal/command.rb