lib/ember-cli/app.rb in ember-cli-rails-0.1.13 vs lib/ember-cli/app.rb in ember-cli-rails-0.2.0
- old
+ new
@@ -5,20 +5,19 @@
ADDON_VERSION = "0.0.11"
EMBER_CLI_VERSION = "~> 0.1.5", "~> 0.2.0"
class BuildError < StandardError; end
- attr_reader :name, :options, :pid
+ attr_reader :name, :options, :paths, :pid
+ delegate :root, to: :paths
+
def initialize(name, options={})
@name, @options = name.to_s, options
+ @paths = PathSet.new(self)
end
- def tests_path
- dist_path.join("tests")
- end
-
def compile
prepare
silence_build { exec command }
check_for_build_error!
end
@@ -35,12 +34,11 @@
at_exit{ stop }
end
def run_tests
prepare
- tests_pass = exec("#{ember_path} test")
- exit 1 unless tests_pass
+ exit 1 unless exec("#{ember_path} test")
end
def stop
Process.kill "INT", pid if pid
@pid = nil
@@ -82,98 +80,79 @@
============================= WARNING! =============================
MSG
end
- def ember_path
- @ember_path ||= app_path.join("node_modules", ".bin", "ember").tap do |path|
- fail <<-MSG.strip_heredoc unless path.executable?
- No local ember executable found. You should run `npm install`
- inside the #{name} app located at #{app_path}
- MSG
+ def method_missing(method_name, *)
+ if path_method = supported_path_method(method_name)
+ paths.public_send(path_method)
+ else
+ super
end
end
+ def respond_to_missing?(method_name, *)
+ if supported_path_method(method_name)
+ true
+ else
+ super
+ end
+ end
+
private
- delegate :match_version?, :non_production?, to: Helpers
- delegate :configuration, to: EmberCLI
- delegate :tee_path, :npm_path, :bundler_path, to: :configuration
-
- def default_app_path
- path = Rails.root.join("app", name)
-
- return name unless path.directory?
-
- ActiveSupport::Deprecation.warn <<-MSG.strip_heredoc
- We have found that placing your EmberCLI
- application inside Rails' app has negative performance implications.
-
- Please see, https://github.com/rwz/ember-cli-rails/issues/66 for more
- detailed information.
-
- It is now recommended to place your EmberCLI application into the Rails
- root path.
- MSG
-
- path
+ def supported_path_method(original)
+ path_method = original.to_s[/\A(.+)_path\z/, 1]
+ path_method if path_method && paths.respond_to?(path_method)
end
def silence_build(&block)
- if ENV.fetch("EMBER_CLI_RAILS_VERBOSE"){ !non_production? }
+ if ENV.fetch("EMBER_CLI_RAILS_VERBOSE"){ EmberCLI.env.production? }
yield
else
- silence_stream(STDOUT, &block)
+ silence_stream STDOUT, &block
end
end
def build_timeout
options.fetch(:build_timeout){ configuration.build_timeout }
end
- def lockfile
- @lockfile ||= tmp_path.join("build.lock")
- end
-
def check_for_build_error!
raise_build_error! if build_error?
end
- def build_error_file
- @build_error_file ||= tmp_path.join("error.txt")
- end
-
def reset_build_error!
- build_error_file.delete if build_error?
+ build_error_file_path.delete if build_error?
end
def build_error?
- build_error_file.exist?
+ build_error_file_path.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)
+ error.set_backtrace build_error_file_path.read.split(?\n)
fail error
end
def prepare
@prepared ||= begin
check_addon!
check_ember_cli_version!
reset_build_error!
- FileUtils.touch lockfile
+ FileUtils.touch lockfile_path
symlink_to_assets_root
add_assets_to_precompile_list
true
end
end
def check_ember_cli_version!
version = dev_dependencies.fetch("ember-cli").split(?-).first
- unless match_version?(version, EMBER_CLI_VERSION)
+ unless Helpers.match_version?(version, EMBER_CLI_VERSION)
fail <<-MSG.strip_heredoc
EmberCLI Rails require ember-cli NPM package version to be
#{EMBER_CLI_VERSION} to work properly. From within your EmberCLI directory
please update your package.json accordingly and run:
@@ -190,11 +169,11 @@
From within your EmberCLI directory please run:
$ npm install --save-dev ember-cli-rails-addon@#{ADDON_VERSION}
- in you Ember application root: #{app_path}
+ in you Ember application root: #{root}
MSG
end
end
def symlink_to_assets_root
@@ -219,49 +198,25 @@
def ember_app_name
@ember_app_name ||= options.fetch(:name){ package_json.fetch(:name) }
end
- def app_path
- @app_path ||= begin
- path = options.fetch(:path){ default_app_path }
- pathname = Pathname.new(path)
- pathname.absolute?? pathname : Rails.root.join(path)
- end
- end
-
- def tmp_path
- @tmp_path ||= app_path.join("tmp").tap(&:mkpath)
- end
-
- def log_path
- Rails.root.join("log", "ember-#{name}.#{Rails.env}.log")
- end
-
- def dist_path
- @dist_path ||= EmberCLI.root.join("apps", name).tap(&:mkpath)
- end
-
- def assets_path
- @assets_path ||= EmberCLI.root.join("assets").tap(&:mkpath)
- end
-
def environment
- non_production?? "development" : "production"
+ EmberCLI.env.production?? "production" : "development"
end
def package_json
- @package_json ||= JSON.parse(app_path.join("package.json").read).with_indifferent_access
+ @package_json ||= JSON.parse(package_json_file_path.read).with_indifferent_access
end
def dev_dependencies
package_json.fetch("devDependencies", {})
end
def addon_present?
dev_dependencies["ember-cli-rails-addon"] == ADDON_VERSION &&
- app_path.join("node_modules", "ember-cli-rails-addon", "package.json").exist?
+ addon_package_json_file_path.exist?
end
def excluded_ember_deps
Array.wrap(options[:exclude_ember_deps]).join(?,)
end
@@ -272,25 +227,21 @@
vars.store "EXCLUDE_EMBER_ASSETS", excluded_ember_deps
vars.store "BUNDLE_GEMFILE", gemfile_path.to_s if gemfile_path.exist?
end
end
- def gemfile_path
- app_path.join("Gemfile")
- end
-
def exec(cmd, options={})
method_name = options.fetch(:method, :system)
- Dir.chdir app_path do
+ Dir.chdir root 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?
+ break unless lockfile_path.exist?
sleep 0.1
end
end
end
end