ember-cli-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd138b5cec9d03c0f000ee67ff10f619149621f2
4
- data.tar.gz: 4ea97ed5ab28d9bfc8ef9cd7ccca5da187cbb67e
3
+ metadata.gz: 1ef9ebf40bb8a292bd4bbb5616564418e3dbec67
4
+ data.tar.gz: 588fe62b8b81b49dad39b9669a7985c1d63220da
5
5
  SHA512:
6
- metadata.gz: ec01c1f6f77d4be06792d0a7e0e64cb0b635bf61e0dfb17439b506e69319fa808aed7816be0d2281a901b5dea28d5453a3563ad8aeb4b172a869b2d2f2d80367
7
- data.tar.gz: 1255243bed0ad2743300013fe5908efecfd0d2cf42d3c2eb64aa492a79deb0c3c9c2224dffa809c84adeb41b55119040ff18daeb1d918308cb334deb8d320044
6
+ metadata.gz: 0ae1d31dc429f5bbde157e193aca190b6ed03b96243c205f3f273c3dbb3231ad31ce7b71c4d8fc6da6d03c151268b99388b53b7df70de6318c500ab18fa9611f
7
+ data.tar.gz: d5810b513cc52ad2f7621a6905a93d022ca3f8dfc0a81e2d34a0fad9902f602ead9c051c4e781072b2a2547f7983ae5ea7cb8e2f19bcc356ae9ae1d4618fa403
@@ -3,7 +3,7 @@ require "ember-cli/railtie" if defined?(Rails)
3
3
  module EmberCLI
4
4
  extend self
5
5
 
6
- autoload :BuildServer, "ember-cli/build_server"
6
+ autoload :App, "ember-cli/app"
7
7
  autoload :Configuration, "ember-cli/configuration"
8
8
  autoload :RackServer, "ember-cli/rack_server"
9
9
  autoload :ViewHelpers, "ember-cli/view_helpers"
@@ -18,17 +18,33 @@ module EmberCLI
18
18
  end
19
19
 
20
20
  def prepare!
21
- Rack::Server.send :prepend, RackServer
22
- Rails.configuration.assets.paths << root.join("assets").to_s
23
- at_exit{ cleanup }
21
+ @prepared ||= begin
22
+ Rails.configuration.assets.paths << root.join("assets").to_s
23
+ at_exit{ cleanup }
24
+ true
25
+ end
24
26
  end
25
27
 
26
- def start!
27
- configuration.apps.values.each(&:start)
28
+ def enable!
29
+ if Rails.env.development?
30
+ prepare!
31
+ Rack::Server.send :prepend, RackServer
32
+ else
33
+ compile!
34
+ end
35
+ end
36
+
37
+ def run!
38
+ each_app &:run
39
+ end
40
+
41
+ def compile!
42
+ prepare!
43
+ each_app &:compile
28
44
  end
29
45
 
30
46
  def stop!
31
- configuration.apps.values.each(&:stop)
47
+ each_app &:stop
32
48
  end
33
49
 
34
50
  def root
@@ -44,4 +60,8 @@ module EmberCLI
44
60
  def cleanup
45
61
  root.rmtree if root.exist?
46
62
  end
63
+
64
+ def each_app
65
+ configuration.apps.values.each{ |a| yield a }
66
+ end
47
67
  end
@@ -1,15 +1,22 @@
1
1
  module EmberCLI
2
- class BuildServer
2
+ class App
3
3
  attr_reader :name, :options, :pid
4
4
 
5
5
  def initialize(name, **options)
6
6
  @name, @options = name.to_s, options
7
7
  end
8
8
 
9
- def start
9
+ def compile
10
10
  symlink_to_assets_root
11
11
  add_assets_to_precompile_list
12
- @pid = spawn(command, chdir: app_path, err: :out)
12
+ silence_stream STDOUT do
13
+ system command, chdir: app_path, err: :out
14
+ end
15
+ end
16
+
17
+ def run
18
+ compile
19
+ @pid = spawn(command(watch: true), chdir: app_path, err: :out)
13
20
  at_exit{ stop }
14
21
  end
15
22
 
@@ -36,8 +43,9 @@ module EmberCLI
36
43
  Rails.configuration.assets.precompile << /(?:\/|\A)#{name}\//
37
44
  end
38
45
 
39
- def command
40
- "#{ember_path} build --watch --output-path #{dist_path} #{log_pipe}"
46
+ def command(watch: nil)
47
+ watch = "--watch" if watch
48
+ "#{ember_path} build #{watch} --environment #{environment} --output-path #{dist_path} #{log_pipe}"
41
49
  end
42
50
 
43
51
  def log_pipe
@@ -65,5 +73,9 @@ module EmberCLI
65
73
  def assets_path
66
74
  @assets_path ||= EmberCLI.root.join("assets").tap(&:mkpath)
67
75
  end
76
+
77
+ def environment
78
+ Rails.env.in?(%w[development test]) ? Rails.env : "production"
79
+ end
68
80
  end
69
81
  end
@@ -5,7 +5,7 @@ module EmberCLI
5
5
  include Singleton
6
6
 
7
7
  def app(name, **options)
8
- apps.store name, BuildServer.new(name, **options)
8
+ apps.store name, App.new(name, **options)
9
9
  end
10
10
 
11
11
  def apps
@@ -14,5 +14,15 @@ module EmberCLI
14
14
 
15
15
  nil
16
16
  end
17
+
18
+ def override_assets_precompile_task!
19
+ Rake.application.instance_eval do
20
+ @tasks["assets:precompile:original"] = @tasks.delete("assets:precompile")
21
+ Rake::Task.define_task "assets:precompile", %i[assets precompile] => :environment do
22
+ EmberCLI.compile!
23
+ Rake::Task["assets:precompile:original"].execute
24
+ end
25
+ end
26
+ end
17
27
  end
18
28
  end
@@ -1,7 +1,7 @@
1
1
  module EmberCLI
2
2
  module RackServer
3
3
  def start
4
- EmberCLI.start! if defined?(Rails.application) && app == Rails.application
4
+ EmberCLI.run! if defined?(Rails.application) && app == Rails.application
5
5
  super
6
6
  ensure
7
7
  EmberCLI.stop!
@@ -1,9 +1,5 @@
1
1
  module EmberCLI
2
2
  class Railtie < Rails::Railtie
3
- initializer "ember-cli-rails.rack-server" do
4
- EmberCLI.prepare! if development_mode?
5
- end
6
-
7
3
  initializer "ember-cli-rails.view_helpers" do
8
4
  ActionView::Base.send :include, ViewHelpers
9
5
  end
@@ -14,7 +10,15 @@ module EmberCLI
14
10
  end
15
11
  end
16
12
 
17
- def development_mode?
13
+ initializer "ember-cli-rails.rack-server" do
14
+ EmberCLI.enable! if non_production?
15
+ end
16
+
17
+ rake_tasks do
18
+ require "ember-cli/rake_task"
19
+ end
20
+
21
+ def non_production?
18
22
  !Rails.env.production? && Rails.configuration.consider_all_requests_local
19
23
  end
20
24
  end
@@ -0,0 +1,3 @@
1
+ require "sprockets/rails/task"
2
+
3
+ EmberCLI::Helpers.override_assets_precompile_task!
@@ -1,3 +1,3 @@
1
1
  module EmberCLI
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-cli-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pravosud
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-04 00:00:00.000000000 Z
12
+ date: 2014-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -36,11 +36,12 @@ files:
36
36
  - LICENSE.txt
37
37
  - README.md
38
38
  - lib/ember-cli-rails.rb
39
- - lib/ember-cli/build_server.rb
39
+ - lib/ember-cli/app.rb
40
40
  - lib/ember-cli/configuration.rb
41
41
  - lib/ember-cli/helpers.rb
42
42
  - lib/ember-cli/rack_server.rb
43
43
  - lib/ember-cli/railtie.rb
44
+ - lib/ember-cli/rake_task.rb
44
45
  - lib/ember-cli/version.rb
45
46
  - lib/ember-cli/view_helpers.rb
46
47
  - lib/generators/ember-cli/init/USAGE