Sha256: b556533f897ebbce137e0a08aca8150b1bc056cbf713f2a34ac043f1306f52f4

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require "ember_cli/command"

module EmberCli
  class Shell
    def initialize(paths:, env: {}, options: {})
      @paths = paths
      @env = env
      @ember = Command.new(
        paths: paths,
        options: options,
      )
      @on_exit ||= at_exit { stop }
    end

    def compile
      silence_build { exec ember.build }
    end

    def build_and_watch
      unless running?
        lock_buildfile
        self.pid = spawn ember.build(watch: true)
        detach
      end
    end

    def stop
      if pid.present?
        Process.kill(:INT, pid)
        self.pid = nil
      end
    end

    def install
      if paths.gemfile.exist?
        exec "#{paths.bundler} install"
      end

      exec "#{paths.npm} prune && #{paths.npm} install"
      exec "#{paths.bower} prune && #{paths.bower} install"
    end

    def test
      exec ember.test
    end

    private

    attr_accessor :pid
    attr_reader :ember, :env, :options, :paths

    def spawn(command)
      exec(command, method: :spawn)
    end

    def exec(command, method: :system)
      Dir.chdir paths.root do
        Kernel.public_send(method, env, command) || exit(1)
      end
    end

    def running?
      pid.present? && Process.getpgid(pid)
    rescue Errno::ESRCH
      false
    end

    def lock_buildfile
      FileUtils.touch(paths.lockfile)
    end

    def detach
      Process.detach pid
    end

    def silence_build(&block)
      if ENV.fetch("EMBER_CLI_RAILS_VERBOSE") { EmberCli.env.production? }
        yield
      else
        silence_stream(STDOUT, &block)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ember-cli-rails-0.5.5 lib/ember_cli/shell.rb
ember-cli-rails-0.5.4 lib/ember_cli/shell.rb
ember-cli-rails-0.5.3 lib/ember_cli/shell.rb