lib/ember-cli/app.rb in ember-cli-rails-0.0.18 vs lib/ember-cli/app.rb in ember-cli-rails-0.1.0

- old
+ new

@@ -1,23 +1,30 @@ require "timeout" module EmberCLI class App - ADDON_VERSION = "0.0.8" + ADDON_VERSION = "0.0.9" EMBER_CLI_VERSION = "~> 0.1.5" + class BuildError < StandardError; end + attr_reader :name, :options, :pid def initialize(name, options={}) @name, @options = name.to_s, options end def compile prepare silence_stream(STDOUT){ exec command } + check_for_build_error! end + def install_dependencies + exec "#{npm_path} install" + end + def run prepare cmd = command(watch: true) @pid = exec(cmd, method: :spawn) at_exit{ stop } @@ -36,11 +43,11 @@ %W[#{name}/vendor #{name}/#{ember_app_name}] end def wait Timeout.timeout(build_timeout) do - sleep 0.1 while lockfile.exist? + wait_for_build_complete_or_error end rescue Timeout::Error suggested_timeout = build_timeout + 5 warn <<-MSG.strip_heredoc @@ -76,25 +83,48 @@ end private delegate :match_version?, :non_production?, to: Helpers - delegate :tee_path, to: :configuration + delegate :tee_path, :npm_path, to: :configuration delegate :configuration, to: :EmberCLI def build_timeout options.fetch(:build_timeout){ configuration.build_timeout } end def lockfile tmp_path.join("build.lock") end + def check_for_build_error! + raise_build_error! if build_error_file.exist? + end + + def build_error_file + tmp_path.join("error.txt") + end + + def reset_build_error! + build_error_file.delete if build_error? + end + + def build_error? + build_error_file.exist? + end + + def raise_build_error! + error = BuildError.new("EmberCLI app #{name.inspect} has failed to build") + error.set_backtrace build_error_file.read.split(?\n) + fail error + end + def prepare @prepared ||= begin check_addon! check_ember_cli_version! + reset_build_error! FileUtils.touch lockfile symlink_to_assets_root add_assets_to_precompile_list true end @@ -211,9 +241,17 @@ def exec(cmd, options={}) method_name = options.fetch(:method, :system) Dir.chdir app_path do Kernel.public_send(method_name, env_hash, cmd, err: :out) + end + end + + def wait_for_build_complete_or_error + loop do + check_for_build_error! + break unless lockfile.exist? + sleep 0.1 end end end end