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,25 @@
1
+ require "ember-cli/constraint"
2
+
3
+ module ActionDispatch
4
+ module Routing
5
+ class Mapper
6
+ def mount_ember_app(app_name, to:, **options)
7
+ routing_options = options.deep_merge(
8
+ defaults: { ember_app: app_name },
9
+ )
10
+
11
+ routing_options.reverse_merge!(
12
+ controller: "ember_cli/ember",
13
+ action: "index",
14
+ format: :html,
15
+ )
16
+
17
+ Rails.application.routes.draw do
18
+ scope constraints: EmberCli::Constraint.new do
19
+ get("#{to}(*rest)", routing_options)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,84 @@
1
+ require "ember-cli/command"
2
+
3
+ module EmberCli
4
+ class Shell
5
+ def initialize(paths:, env: {}, options: {})
6
+ @paths = paths
7
+ @env = env
8
+ @ember = Command.new(
9
+ paths: paths,
10
+ options: options,
11
+ )
12
+ @on_exit ||= at_exit { stop }
13
+ end
14
+
15
+ def compile
16
+ silence_build { exec ember.build }
17
+ end
18
+
19
+ def build_and_watch
20
+ unless running?
21
+ lock_buildfile
22
+ self.pid = spawn ember.build(watch: true)
23
+ detach
24
+ end
25
+ end
26
+
27
+ def stop
28
+ if pid.present?
29
+ Process.kill(:INT, pid)
30
+ self.pid = nil
31
+ end
32
+ end
33
+
34
+ def install
35
+ if paths.gemfile.exist?
36
+ exec "#{paths.bundler} install"
37
+ end
38
+
39
+ exec "#{paths.npm} prune && #{paths.npm} install"
40
+ exec "#{paths.bower} prune && #{paths.bower} install"
41
+ end
42
+
43
+ def test
44
+ exec ember.test
45
+ end
46
+
47
+ private
48
+
49
+ attr_accessor :pid
50
+ attr_reader :ember, :env, :options, :paths
51
+
52
+ def spawn(command)
53
+ exec(command, method: :spawn)
54
+ end
55
+
56
+ def exec(command, method: :system)
57
+ Dir.chdir paths.root do
58
+ Kernel.public_send(method, env, command, err: :out) || exit(1)
59
+ end
60
+ end
61
+
62
+ def running?
63
+ pid.present? && Process.getpgid(pid)
64
+ rescue Errno::ESRCH
65
+ false
66
+ end
67
+
68
+ def lock_buildfile
69
+ FileUtils.touch(paths.lockfile)
70
+ end
71
+
72
+ def detach
73
+ Process.detach pid
74
+ end
75
+
76
+ def silence_build(&block)
77
+ if ENV.fetch("EMBER_CLI_RAILS_VERBOSE") { EmberCli.env.production? }
78
+ yield
79
+ else
80
+ silence_stream(STDOUT, &block)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,44 @@
1
+ require "non-stupid-digest-assets"
2
+ require "ember-cli/html_page"
3
+
4
+ module EmberCli
5
+ class Sprockets
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def register!
11
+ assets = %r{\A#{app.name}/}
12
+
13
+ Rails.configuration.assets.precompile << assets
14
+ NonStupidDigestAssets.whitelist << assets
15
+ end
16
+
17
+ def index_html(head:, body:)
18
+ html_page = HtmlPage.new(
19
+ content: app.index_file.read,
20
+ head: head,
21
+ body: body,
22
+ )
23
+
24
+ html_page.render
25
+ end
26
+
27
+ def assets
28
+ ["#{app.name}/assets/vendor", "#{app.name}/assets/#{ember_app_name}"]
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :app
34
+
35
+ def ember_app_name
36
+ @ember_app_name ||= app.options.fetch(:name) { package_json.fetch(:name) }
37
+ end
38
+
39
+ def package_json
40
+ @package_json ||=
41
+ JSON.parse(app.paths.package_json_file.read).with_indifferent_access
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module EmberCli
2
- VERSION = "0.4.3".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -13,6 +13,16 @@ module EmberCli
13
13
  run "chmod a+x bin/heroku_install"
14
14
  end
15
15
 
16
+ def config_js_compressor
17
+ production_config = "config/environments/production.rb"
18
+
19
+ inject_into_file production_config, before: "end\n" do
20
+ <<-RUBY
21
+ config.assets.js_compressor = nil
22
+ RUBY
23
+ end
24
+ end
25
+
16
26
  def inject_12factor_gem
17
27
  gem "rails_12factor", group: [:staging, :production]
18
28
  end
@@ -6,7 +6,7 @@ namespace :ember do
6
6
 
7
7
  desc "Runs `ember test` for each App"
8
8
  task test: :environment do
9
- EmberCli.run_tests!
9
+ EmberCli.test!
10
10
  end
11
11
 
12
12
  desc "Installs each EmberCLI app's dependencies"
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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pravosud
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-06 00:00:00.000000000 Z
13
+ date: 2015-11-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -32,6 +32,20 @@ dependencies:
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '5'
35
+ - !ruby/object:Gem::Dependency
36
+ name: non-stupid-digest-assets
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 1.0.0
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: sprockets
37
51
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +72,25 @@ files:
58
72
  - CHANGELOG.md
59
73
  - LICENSE.txt
60
74
  - README.md
61
- - app/controllers/ember_tests_controller.rb
75
+ - app/controller/ember-cli/ember_controller.rb
62
76
  - app/helpers/ember_rails_helper.rb
63
- - config/routes.rb
77
+ - app/views/ember_cli/ember/index.html.erb
64
78
  - lib/ember-cli-rails.rb
65
79
  - lib/ember-cli/app.rb
66
- - lib/ember-cli/asset_resolver.rb
80
+ - lib/ember-cli/build_monitor.rb
67
81
  - lib/ember-cli/capture.rb
82
+ - lib/ember-cli/command.rb
68
83
  - lib/ember-cli/configuration.rb
84
+ - lib/ember-cli/constraint.rb
85
+ - lib/ember-cli/controller_extension.rb
69
86
  - lib/ember-cli/engine.rb
87
+ - lib/ember-cli/errors.rb
70
88
  - lib/ember-cli/helpers.rb
71
89
  - lib/ember-cli/html_page.rb
72
- - lib/ember-cli/middleware.rb
73
90
  - lib/ember-cli/path_set.rb
74
- - lib/ember-cli/runner.rb
91
+ - lib/ember-cli/route_helpers.rb
92
+ - lib/ember-cli/shell.rb
93
+ - lib/ember-cli/sprockets.rb
75
94
  - lib/ember-cli/version.rb
76
95
  - lib/generators/ember-cli/heroku/USAGE
77
96
  - lib/generators/ember-cli/heroku/heroku_generator.rb
@@ -1,31 +0,0 @@
1
- class EmberTestsController < ActionController::Base
2
- def index
3
- render text: test_html_with_corrected_asset_urls, layout: false
4
- end
5
-
6
- private
7
-
8
- def test_html_with_corrected_asset_urls
9
- test_html.gsub(%r{assets/}i, "#{asset_prefix}/#{app_name}/")
10
- end
11
-
12
- def test_html
13
- tests_index_path.read
14
- end
15
-
16
- def tests_index_path
17
- app.tests_path.join("index.html")
18
- end
19
-
20
- def app
21
- EmberCli[app_name]
22
- end
23
-
24
- def app_name
25
- params.fetch(:app_name)
26
- end
27
-
28
- def asset_prefix
29
- Rails.configuration.assets.prefix
30
- end
31
- end
data/config/routes.rb DELETED
@@ -1,3 +0,0 @@
1
- EmberCli::Engine.routes.draw do
2
- get ":app_name", to: "ember_tests#index", format: false
3
- end
@@ -1,54 +0,0 @@
1
- module EmberCli
2
- class AssetResolver
3
- def initialize(app:, sprockets:)
4
- @app = app
5
- @sprockets = sprockets
6
- end
7
-
8
- def resolve_urls(html_content)
9
- mappings.reduce(html_content) do |resolved_content, (asset, new_path)|
10
- resolved_content.gsub(%{"assets/#{asset}"}, %{"#{new_path}"})
11
- end
12
- end
13
-
14
- private
15
-
16
- def mappings
17
- {
18
- "#{name}.js" => application.js,
19
- "#{name}.css" => application.css,
20
- "vendor.js" => vendor.js,
21
- "vendor.css" => vendor.css,
22
- }
23
- end
24
-
25
- def name
26
- @app.name
27
- end
28
-
29
- def application
30
- AssetPath.new(@sprockets, @app.application_assets)
31
- end
32
-
33
- def vendor
34
- AssetPath.new(@sprockets, @app.vendor_assets)
35
- end
36
-
37
- class AssetPath
38
- def initialize(sprockets, assets)
39
- @sprockets = sprockets
40
- @assets = assets
41
- end
42
-
43
- def js
44
- @sprockets.asset_path(@assets, type: :javascript)
45
- end
46
-
47
- def css
48
- @sprockets.asset_path(@assets, type: :stylesheet)
49
- end
50
- end
51
-
52
- private_constant :AssetPath
53
- end
54
- end
@@ -1,18 +0,0 @@
1
- module EmberCli
2
- class Middleware
3
- def initialize(app)
4
- @app = app
5
- end
6
-
7
- def call(env)
8
- path = env["PATH_INFO"].to_s
9
-
10
- if path == "/testem.js"
11
- [ 200, { "Content-Type" => "text/javascript" }, [""] ]
12
- else
13
- EmberCli.process_path path
14
- @app.call(env)
15
- end
16
- end
17
- end
18
- end
@@ -1,53 +0,0 @@
1
- module EmberCli
2
- class Runner
3
- TRUE_PROC = ->(*){ true }
4
-
5
- attr_reader :app, :path
6
-
7
- def initialize(app, path)
8
- @app, @path = app, path
9
- end
10
-
11
- def process
12
- return if skip?
13
-
14
- if EmberCli.env.development?
15
- start_or_restart!
16
- else
17
- compile!
18
- end
19
-
20
- wait!
21
- end
22
-
23
- private
24
-
25
- def skip?
26
- invoker = app.options.fetch(:enable, TRUE_PROC)
27
- !invoker.call(path)
28
- end
29
-
30
- def start_or_restart!
31
- run! unless app.pid && still_running?
32
- end
33
-
34
- def still_running?
35
- Process.getpgid app.pid
36
- true
37
- rescue Errno::ESRCH # no such process
38
- false
39
- end
40
-
41
- def wait!
42
- app.wait
43
- end
44
-
45
- def compile!
46
- app.compile
47
- end
48
-
49
- def run!
50
- app.run
51
- end
52
- end
53
- end