ember-cli-rails 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ module EmberCli
2
+ class BuildMonitor
3
+ def initialize(name, paths)
4
+ @name = name
5
+ @paths = paths
6
+ end
7
+
8
+ def check!
9
+ if build_error?
10
+ raise_build_error!
11
+ end
12
+
13
+ true
14
+ end
15
+
16
+ def reset
17
+ if build_error?
18
+ error_file.delete
19
+ end
20
+ end
21
+
22
+ def wait!
23
+ loop do
24
+ check!
25
+ break if complete?
26
+ sleep 0.1
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :name, :paths
33
+
34
+ def complete?
35
+ !paths.lockfile.exist?
36
+ end
37
+
38
+ def build_error?
39
+ error_file.exist? && error_file.size?
40
+ end
41
+
42
+ def error_file
43
+ paths.build_error_file
44
+ end
45
+
46
+ def raise_build_error!
47
+ backtrace = error_file.readlines.reject(&:blank?)
48
+ message = "#{name.inspect} has failed to build: #{backtrace.first}"
49
+
50
+ error = BuildError.new(message)
51
+ error.set_backtrace(backtrace)
52
+
53
+ fail error
54
+ end
55
+ end
56
+ end
@@ -1,25 +1,11 @@
1
1
  module EmberCli
2
- SKIP_CAPTURE = ["", ""].freeze
3
-
4
2
  class Capture
5
3
  def initialize(sprockets:, &block)
6
4
  @sprockets = sprockets
7
- @block = block
5
+ @block = block || NullBlock.new
8
6
  end
9
7
 
10
8
  def capture
11
- if block.present?
12
- capture_content
13
- else
14
- SKIP_CAPTURE
15
- end
16
- end
17
-
18
- private
19
-
20
- attr_reader :block, :sprockets
21
-
22
- def capture_content
23
9
  if block.arity > 0
24
10
  block.call(*block_arguments)
25
11
  end
@@ -27,6 +13,10 @@ module EmberCli
27
13
  [head.content, body.content]
28
14
  end
29
15
 
16
+ private
17
+
18
+ attr_reader :block, :sprockets
19
+
30
20
  def block_arguments
31
21
  [head, body].first(block.arity)
32
22
  end
@@ -73,5 +63,15 @@ module EmberCli
73
63
  end
74
64
  end
75
65
  private_constant :Block
66
+
67
+ class NullBlock
68
+ def arity
69
+ 1
70
+ end
71
+
72
+ def call(*)
73
+ end
74
+ end
75
+ private_constant :NullBlock
76
76
  end
77
77
  end
@@ -0,0 +1,63 @@
1
+ module EmberCli
2
+ class Command
3
+ def initialize(paths:, options: {})
4
+ @paths = paths
5
+ @options = options
6
+ end
7
+
8
+ def test
9
+ "#{paths.ember} test --environment test"
10
+ end
11
+
12
+ def build(watch: false)
13
+ [
14
+ "#{paths.ember} build",
15
+ "#{watch_flag(watch)}",
16
+ "--environment #{build_environment}",
17
+ "--output-path #{paths.dist}",
18
+ pipe_errors_to_file,
19
+ pipe_to_log_files,
20
+ ].join(" ")
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :options, :paths
26
+
27
+ def process_watcher
28
+ options.fetch(:watcher) { EmberCli.configuration.watcher }
29
+ end
30
+
31
+ def watch_flag(watch)
32
+ watch_flag = ""
33
+
34
+ if watch
35
+ watch_flag = "--watch"
36
+
37
+ if process_watcher
38
+ watch_flag += " --watcher #{process_watcher}"
39
+ end
40
+ end
41
+
42
+ watch_flag
43
+ end
44
+
45
+ def pipe_errors_to_file
46
+ "2> #{paths.build_error_file}"
47
+ end
48
+
49
+ def pipe_to_log_files
50
+ if paths.tee
51
+ "| #{paths.tee} -a #{paths.log}"
52
+ end
53
+ end
54
+
55
+ def build_environment
56
+ if EmberCli.env == "production"
57
+ "production"
58
+ else
59
+ "development"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -5,6 +5,14 @@ module EmberCli
5
5
  include Singleton
6
6
 
7
7
  def app(name, **options)
8
+ if options.has_key? :build_timeout
9
+ deprecate_timeout
10
+ end
11
+
12
+ if options.has_key? :enable
13
+ deprecate_enable
14
+ end
15
+
8
16
  apps.store name, App.new(name, options)
9
17
  end
10
18
 
@@ -29,11 +37,34 @@ module EmberCli
29
37
  @bundler_path ||= Helpers.which("bundler")
30
38
  end
31
39
 
32
- def build_timeout
33
- @build_timeout ||= 5
40
+ def build_timeout=(*)
41
+ deprecate_timeout
34
42
  end
35
43
 
36
- attr_writer :build_timeout
37
44
  attr_accessor :watcher
45
+
46
+ private
47
+
48
+ def deprecate_enable
49
+ warn <<-WARN.strip_heredoc
50
+
51
+ The `enable` lambda configuration has been removed.
52
+
53
+ Please read https://github.com/thoughtbot/ember-cli-rails/pull/261 for
54
+ details.
55
+
56
+ WARN
57
+ end
58
+
59
+ def deprecate_timeout
60
+ warn <<-WARN.strip_heredoc
61
+
62
+ The `build_timeout` configuration has been removed.
63
+
64
+ Please read https://github.com/thoughtbot/ember-cli-rails/pull/259 for
65
+ details.
66
+
67
+ WARN
68
+ end
38
69
  end
39
70
  end
@@ -0,0 +1,9 @@
1
+ module EmberCli
2
+ class Constraint
3
+ def matches?(request)
4
+ matches = request.format.to_s =~ /html/ || -1
5
+
6
+ matches > -1
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module EmberCli
2
+ module ControllerExtension
3
+ def self.included(base)
4
+ base.before_action do
5
+ app = params[:ember_app]
6
+
7
+ if app.present?
8
+ EmberCli[app].build
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,12 +1,23 @@
1
1
  module EmberCli
2
2
  class Engine < Rails::Engine
3
+ initializer "ember-cli-rails.rendering" do
4
+ require "ember-cli/ember_controller"
5
+ require "ember-cli/route_helpers"
6
+ end
7
+
3
8
  initializer "ember-cli-rails.enable" do
4
9
  EmberCli.enable! unless EmberCli.skip?
5
10
  end
6
11
 
7
- initializer "ember-cli-rails.helpers" do
8
- config.to_prepare do
9
- ActionController::Base.helper EmberRailsHelper
12
+ config.to_prepare do
13
+ ActionController::Base.helper EmberRailsHelper
14
+ end
15
+
16
+ config.after_initialize do
17
+ if defined?(ApplicationController)
18
+ require "ember-cli/controller_extension"
19
+
20
+ ApplicationController.include(EmberCli::ControllerExtension)
10
21
  end
11
22
  end
12
23
  end
@@ -0,0 +1,4 @@
1
+ module EmberCli
2
+ class BuildError < StandardError; end
3
+ class DependencyError < BuildError; end
4
+ end
@@ -2,15 +2,6 @@ module EmberCli
2
2
  module Helpers
3
3
  extend self
4
4
 
5
- def match_version?(version, requirements)
6
- version = Gem::Version.new(version)
7
-
8
- Array.wrap(requirements).any? do |requirement|
9
- requirement = Gem::Requirement.new(requirement)
10
- requirement.satisfied_by?(version)
11
- end
12
- end
13
-
14
5
  def which(cmd)
15
6
  exts = ENV.fetch("PATHEXT", ?;).split(?;, -1).uniq
16
7
 
@@ -41,8 +32,11 @@ module EmberCli
41
32
  end
42
33
 
43
34
  def rails_config_for(key)
44
- config = Rails.configuration
45
- config.respond_to?(key) ? config.public_send(key) : yield
35
+ if Rails.configuration.respond_to?(key)
36
+ Rails.configuration.public_send(key)
37
+ else
38
+ yield
39
+ end
46
40
  end
47
41
  end
48
42
  end
@@ -1,8 +1,7 @@
1
1
  module EmberCli
2
2
  class HtmlPage
3
- def initialize(content:, asset_resolver:, head: "", body: "")
3
+ def initialize(content:, head: "", body: "")
4
4
  @content = content
5
- @asset_resolver = asset_resolver
6
5
  @head = head
7
6
  @body = body
8
7
  end
@@ -16,11 +15,13 @@ module EmberCli
16
15
  insert_body_content
17
16
  end
18
17
 
19
- html
18
+ content
20
19
  end
21
20
 
22
21
  private
23
22
 
23
+ attr_reader :content
24
+
24
25
  def has_head_tag?
25
26
  head_tag_index >= 0
26
27
  end
@@ -30,27 +31,19 @@ module EmberCli
30
31
  end
31
32
 
32
33
  def insert_head_content
33
- html.insert(head_tag_index, @head.to_s)
34
+ content.insert(head_tag_index, @head.to_s)
34
35
  end
35
36
 
36
37
  def insert_body_content
37
- html.insert(body_tag_index, @body.to_s)
38
- end
39
-
40
- def html
41
- @html ||= resolved_html
38
+ content.insert(body_tag_index, @body.to_s)
42
39
  end
43
40
 
44
41
  def head_tag_index
45
- html.index("</head") || -1
42
+ content.index("</head") || -1
46
43
  end
47
44
 
48
45
  def body_tag_index
49
- html.index("</body") || -1
50
- end
51
-
52
- def resolved_html
53
- @asset_resolver.resolve_urls(@content)
46
+ content.index("</body") || -1
54
47
  end
55
48
  end
56
49
  end
@@ -11,14 +11,22 @@ module EmberCli
11
11
  end
12
12
  end
13
13
 
14
- def initialize(app)
14
+ def initialize(app:, rails_root:, ember_cli_root:, environment:, configuration:)
15
15
  @app = app
16
+ @configuration = configuration
17
+ @rails_root = rails_root
18
+ @environment = environment
19
+ @ember_cli_root = ember_cli_root
16
20
  end
17
21
 
18
22
  define_path :root do
19
23
  path = app_options.fetch(:path){ default_root }
20
24
  pathname = Pathname.new(path)
21
- pathname.absolute?? pathname : Rails.root.join(path)
25
+ if pathname.absolute?
26
+ pathname
27
+ else
28
+ rails_root.join(path)
29
+ end
22
30
  end
23
31
 
24
32
  define_path :tmp do
@@ -26,43 +34,45 @@ module EmberCli
26
34
  end
27
35
 
28
36
  define_path :log do
29
- Rails.root.join("log", "ember-#{app_name}.#{Rails.env}.log")
37
+ rails_root.join("log", "ember-#{app_name}.#{environment}.log")
30
38
  end
31
39
 
32
40
  define_path :dist do
33
- EmberCli.root.join("apps", app_name).tap(&:mkpath)
41
+ ember_cli_root.join("apps", app_name).tap(&:mkpath)
34
42
  end
35
43
 
36
44
  define_path :assets do
37
- EmberCli.root.join("assets").tap(&:mkpath)
45
+ ember_cli_root.join("assets").tap(&:mkpath)
46
+ end
47
+
48
+ define_path :app_assets do
49
+ assets.join(app_name)
38
50
  end
39
51
 
40
52
  define_path :applications do
41
- Rails.root.join("public", "_apps").tap(&:mkpath)
53
+ rails_root.join("public", "_apps").tap(&:mkpath)
42
54
  end
43
55
 
44
56
  define_path :gemfile do
45
57
  root.join("Gemfile")
46
58
  end
47
59
 
48
- define_path :tests do
49
- dist.join("tests")
50
- end
51
-
52
60
  define_path :package_json_file do
53
61
  root.join("package.json")
54
62
  end
55
63
 
56
- define_path :node_modules do
57
- root.join("node_modules")
58
- end
59
-
60
64
  define_path :ember do
61
65
  root.join("node_modules", ".bin", "ember").tap do |path|
62
- fail <<-MSG.strip_heredoc unless path.executable?
63
- No local ember executable found. You should run `npm install`
64
- inside the #{app_name} app located at #{root}
65
- MSG
66
+ unless path.executable?
67
+ fail DependencyError.new <<-MSG.strip_heredoc
68
+ No `ember-cli` executable found for `#{app_name}`.
69
+
70
+ Install it:
71
+
72
+ $ cd #{root}
73
+ $ npm install
74
+ MSG
75
+ end
66
76
  end
67
77
  end
68
78
 
@@ -75,34 +85,39 @@ module EmberCli
75
85
  end
76
86
 
77
87
  define_path :tee do
78
- app_options.fetch(:tee_path){ configuration.tee_path }
88
+ app_options.fetch(:tee_path) { configuration.tee_path }
79
89
  end
80
90
 
81
91
  define_path :bower do
82
- app_options.fetch(:bower_path) { configuration.bower_path }
92
+ app_options.fetch(:bower_path) { configuration.bower_path }.tap do |path|
93
+ unless Pathname(path).executable?
94
+ fail DependencyError.new <<-MSG.strip_heredoc
95
+ Bower is required by EmberCLI
96
+
97
+ Install it with:
98
+
99
+ $ npm install -g bower
100
+ MSG
101
+ end
102
+ end
83
103
  end
84
104
 
85
105
  define_path :npm do
86
- app_options.fetch(:npm_path){ configuration.npm_path }
106
+ app_options.fetch(:npm_path) { configuration.npm_path }
87
107
  end
88
108
 
89
109
  define_path :bundler do
90
- app_options.fetch(:bundler_path){ configuration.bundler_path }
91
- end
92
-
93
- define_path :addon_package_json_file do
94
- root.join("node_modules", "ember-cli-rails-addon", "package.json")
110
+ app_options.fetch(:bundler_path) { configuration.bundler_path }
95
111
  end
96
112
 
97
113
  private
98
114
 
99
- attr_reader :app
115
+ attr_reader :app, :configuration, :ember_cli_root, :environment, :rails_root
100
116
 
101
117
  delegate :name, :options, to: :app, prefix: true
102
- delegate :configuration, to: EmberCli
103
118
 
104
119
  def default_root
105
- Rails.root.join(app_name)
120
+ rails_root.join(app_name)
106
121
  end
107
122
  end
108
123
  end