ember-cli-rails 0.5.6 → 0.5.7

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: 0375a7a477a2b32d5c0dd2b1d89e99d8115d76ff
4
- data.tar.gz: 8e6d4ad0336ef0698c375fa4f5d9446a43e14aca
3
+ metadata.gz: 99dc36789be1f062b68a2b4341cbadbf6b97f0b2
4
+ data.tar.gz: 02ab4e4d1976191469d1f2405b808fd47f399117
5
5
  SHA512:
6
- metadata.gz: cc9cdbcba58c5b17af2b553f06cf6f19372669485f4c791b64155b5b2074a93f9f632e5b435b57db2cdc85d8e54645f96ee183f1cffd7756563e5dbf0108139d
7
- data.tar.gz: 81452d07ba9111c3731b71d1a7e11d1cc29177451019dcc3a58793d477c6bebadc24e63ad1b6a183e944ac5fd78ad9758a6f28d779ff5ff4ac7af1a83ecf379a
6
+ metadata.gz: 1d036b60998244ef267913027b2049fc5ce8865b202fbf67a13b79fe8fb434b0af7257c788e8be33a2c11c20ab667fecaf6194e588e02e936caf599b76df09f1
7
+ data.tar.gz: 80bfd0e5c8d4a294fe85d9e80de7a64e513659f5b723505e619924947c1ee1dd166ad11cc2b6d9ff9b4dabcf75a4b621f5b13d1d801f5deaffeb412ff3aca174
@@ -1,6 +1,18 @@
1
1
  master
2
2
  ------
3
3
 
4
+ 0.5.7
5
+ -----
6
+
7
+ * Improve command failure reporting. [#324]
8
+ * Use latest EmberCLI-generated asset files. [#316]
9
+ * Delete previous build output on application boot instead of on process exit.
10
+ [#308]
11
+
12
+ [#324]: https://github.com/thoughtbot/ember-cli-rails/pull/324
13
+ [#316]: https://github.com/thoughtbot/ember-cli-rails/pull/316
14
+ [#308]: https://github.com/thoughtbot/ember-cli-rails/pull/308
15
+
4
16
  0.5.6
5
17
  -----
6
18
 
data/README.md CHANGED
@@ -63,7 +63,7 @@ c.app :frontend, path: "~/projects/my-ember-app"
63
63
  * generate a new Ember project:
64
64
 
65
65
  ```bash
66
- $ ember new frontend
66
+ $ ember new frontend --skip-git
67
67
  ```
68
68
 
69
69
  **Initializer options**
@@ -92,7 +92,7 @@ Be sure that the addon's [`MAJOR` and `MINOR` version][semver] matches the gem's
92
92
  `MAJOR` and `MINOR` versions.
93
93
 
94
94
  For instance, if you're using the `0.5.x` version of the gem, specify
95
- `~> 0.5.0` ion in your Ember app's `package.json`:
95
+ `~> 0.5.0` in your Ember app's `package.json`:
96
96
 
97
97
  ```json
98
98
  {
@@ -178,6 +178,15 @@ class ApplicationController < ActionController::Base
178
178
  end
179
179
  ```
180
180
 
181
+ **NOTE**
182
+
183
+ When specifying a controller of your own, make sure [the controller is a
184
+ descendant of `ApplicationController`][#321], and [`ApplicationController` is a
185
+ descendant of `ActionController::Base`][#320].
186
+
187
+ [#320]: https://github.com/thoughtbot/ember-cli-rails/issues/320
188
+ [#321]: https://github.com/thoughtbot/ember-cli-rails/issues/321
189
+
181
190
  ### Rendering the EmberCLI generated JS and CSS
182
191
 
183
192
  In addition to rendering the EmberCLI generated `index.html`, you can inject the
@@ -189,6 +198,10 @@ In addition to rendering the EmberCLI generated `index.html`, you can inject the
189
198
  <%= include_ember_stylesheet_tags :frontend %>
190
199
  ```
191
200
 
201
+ **NOTE**
202
+
203
+ These helpers are only available for Rails versions `>= 4.0`.
204
+
192
205
  ### Multiple Ember CLI apps
193
206
 
194
207
  In the initializer you may specify multiple Ember CLI apps, each of which can be
@@ -242,19 +255,6 @@ module.exports = function(environment) {
242
255
  }
243
256
  ```
244
257
 
245
- Finally, configure each app's `router.js` file so that `rootURL` refers to the
246
- new `baseURL`:
247
-
248
- ```javascript
249
- /* app/frontend/app/router.js */
250
- var Router = Ember.Router.extend({
251
- rootURL: config.baseURL, // add this line
252
- location: config.locationType
253
- });
254
- ```
255
-
256
- Repeat the process for `admin_panel/app/router.js`.
257
-
258
258
  ## CSRF Tokens
259
259
 
260
260
  Your Rails controllers, by default, are expecting a valid authenticity token to be submitted with non-`GET` requests.
@@ -523,10 +523,14 @@ jQuery and Handlebars are the main use cases for this flag.
523
523
  This project supports:
524
524
 
525
525
  * Ruby versions `>= 2.1.0`
526
- * Rails `3.2.x` and `>=4.1.x`.
526
+ * Rails versions `3.2.x` and `>=4.1.x`.
527
+
528
+ [Rendering EmberCLI-generated assets through Sprockets](asset-helpers) is
529
+ **NOT** supported for Rails `3.2.x`.
527
530
 
528
531
  To learn more about supported versions and upgrades, read the [upgrading guide].
529
532
 
533
+ [asset-helpers]: #rendering-the-embercli-generated-js-and-css
530
534
  [upgrading guide]: /UPGRADING.md
531
535
 
532
536
  ## Contributing
@@ -2,11 +2,7 @@ require "ember_cli/capture"
2
2
 
3
3
  module EmberRailsHelper
4
4
  def include_ember_index_html(name, &block)
5
- warn <<-MSG.strip_heredoc
6
- The `include_ember_index_html` helper has been deprecated.
7
-
8
- Rename all invocations to `render_ember_app`
9
- MSG
5
+ Warnings.warn_include_index_html
10
6
 
11
7
  render_ember_app(name, &block)
12
8
  end
@@ -20,10 +16,44 @@ module EmberRailsHelper
20
16
  end
21
17
 
22
18
  def include_ember_script_tags(name, **options)
23
- javascript_include_tag(*EmberCli[name].sprockets.assets, options)
19
+ Warnings.warn_asset_helper
20
+
21
+ javascript_include_tag(*EmberCli[name].sprockets.javascript_assets, options)
24
22
  end
25
23
 
26
24
  def include_ember_stylesheet_tags(name, **options)
27
- stylesheet_link_tag(*EmberCli[name].sprockets.assets, options)
25
+ Warnings.warn_asset_helper
26
+
27
+ stylesheet_link_tag(*EmberCli[name].sprockets.stylesheet_assets, options)
28
+ end
29
+
30
+ module Warnings
31
+ def self.warn_include_index_html
32
+ warn <<-MSG.strip_heredoc
33
+ The `include_ember_index_html` helper has been deprecated.
34
+
35
+ Rename all invocations to `render_ember_app`
36
+ MSG
37
+ end
38
+
39
+ def self.warn_asset_helper
40
+ if Rails::VERSION::MAJOR < 4
41
+ warn <<-MSG.strip_heredoc
42
+ `ember-cli-rails` no longer supports Sprockets-based helpers for Rails
43
+ versions below 4.0.
44
+
45
+ Replace usage of
46
+ * `include_ember_script_tags`
47
+ * `include_ember_stylesheet_tags`
48
+
49
+ with `render_ember_app` invocations.
50
+
51
+ To learn more, please read:
52
+
53
+ * https://github.com/thoughtbot/ember-cli-rails#configuring-the-ember-controller
54
+ * https://github.com/thoughtbot/ember-cli-rails/pull/316
55
+ MSG
56
+ end
57
+ end
28
58
  end
29
59
  end
@@ -32,7 +32,7 @@ module EmberCli
32
32
  def enable!
33
33
  @enabled ||= begin
34
34
  Rails.configuration.assets.paths << root.join("assets").to_s
35
- at_exit{ cleanup }
35
+ cleanup
36
36
  true
37
37
  end
38
38
  end
@@ -53,7 +53,7 @@ module EmberCli
53
53
  end
54
54
 
55
55
  def root
56
- @root ||= Rails.root.join("tmp", "ember-cli-#{uid}")
56
+ @root ||= tmp.join("ember-cli-#{uid}")
57
57
  end
58
58
 
59
59
  def env
@@ -64,12 +64,20 @@ module EmberCli
64
64
 
65
65
  private
66
66
 
67
- def uid
68
- @uid ||= SecureRandom.uuid
67
+ def cleanup
68
+ previous_builds.each(&:rmtree)
69
69
  end
70
70
 
71
- def cleanup
72
- root.rmtree if root.exist?
71
+ def previous_builds
72
+ Pathname.glob(tmp.join("ember-cli-*"))
73
+ end
74
+
75
+ def tmp
76
+ Rails.root.join("tmp")
77
+ end
78
+
79
+ def uid
80
+ @uid ||= SecureRandom.uuid
73
81
  end
74
82
 
75
83
  def each_app
@@ -0,0 +1,66 @@
1
+ module EmberCli
2
+ class Assets
3
+ def initialize(app_name:, ember_app_name:, manifest:)
4
+ @app_name = app_name
5
+ @ember_app_name = ember_app_name
6
+ @manifest = manifest
7
+ end
8
+
9
+ def javascripts
10
+ if empty_manifest?
11
+ fallback_assets
12
+ else
13
+ [
14
+ latest_matching(%r{#{app_name}/assets/vendor(.*)\.js\z}),
15
+ latest_matching(%r{#{app_name}/assets/#{ember_app_name}(.*)\.js\z}),
16
+ ]
17
+ end
18
+ end
19
+
20
+ def stylesheets
21
+ if empty_manifest?
22
+ fallback_assets
23
+ else
24
+ [
25
+ latest_matching(%r{#{app_name}/assets/vendor(.*)\.css\z}),
26
+ latest_matching(%r{#{app_name}/assets/#{ember_app_name}(.*)\.css\z}),
27
+ ]
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :app_name, :ember_app_name, :manifest
34
+
35
+ def fallback_assets
36
+ ["#{app_name}/assets/vendor", "#{app_name}/assets/#{ember_app_name}"]
37
+ end
38
+
39
+ def empty_manifest?
40
+ files.empty?
41
+ end
42
+
43
+ def latest_matching(regex)
44
+ asset, = assets.detect { |(_, digest)| digest == latest_file_for(regex) }
45
+
46
+ asset
47
+ end
48
+
49
+ def latest_file_for(regex)
50
+ file, = files.
51
+ select { |key, _| key =~ regex }.
52
+ sort_by { |_, data| data["mtime"] }.
53
+ last
54
+
55
+ file
56
+ end
57
+
58
+ def assets
59
+ manifest.assets
60
+ end
61
+
62
+ def files
63
+ manifest.files
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,11 @@
1
+ module EmberCli
2
+ class MissingManifest
3
+ def files
4
+ {}
5
+ end
6
+
7
+ def assets
8
+ {}
9
+ end
10
+ end
11
+ end
@@ -1,16 +1,5 @@
1
1
  module EmberCli
2
2
  class PathSet
3
- def self.define_path(name, &definition)
4
- define_method name do
5
- ivar = "@_#{name}_path"
6
- if instance_variable_defined?(ivar)
7
- instance_variable_get(ivar)
8
- else
9
- instance_exec(&definition).tap{ |value| instance_variable_set ivar, value }
10
- end
11
- end
12
- end
13
-
14
3
  def initialize(app:, rails_root:, ember_cli_root:, environment:, configuration:)
15
4
  @app = app
16
5
  @configuration = configuration
@@ -19,7 +8,7 @@ module EmberCli
19
8
  @ember_cli_root = ember_cli_root
20
9
  end
21
10
 
22
- define_path :root do
11
+ def root
23
12
  path = app_options.fetch(:path){ default_root }
24
13
  pathname = Pathname.new(path)
25
14
  if pathname.absolute?
@@ -29,81 +18,89 @@ module EmberCli
29
18
  end
30
19
  end
31
20
 
32
- define_path :tmp do
33
- root.join("tmp").tap(&:mkpath)
21
+ def tmp
22
+ @tmp ||= root.join("tmp").tap(&:mkpath)
34
23
  end
35
24
 
36
- define_path :log do
37
- rails_root.join("log", "ember-#{app_name}.#{environment}.log")
25
+ def log
26
+ @log ||= rails_root.join("log", "ember-#{app_name}.#{environment}.log")
38
27
  end
39
28
 
40
- define_path :dist do
41
- ember_cli_root.join("apps", app_name).tap(&:mkpath)
29
+ def dist
30
+ @dist ||= ember_cli_root.join("apps", app_name).tap(&:mkpath)
42
31
  end
43
32
 
44
- define_path :assets do
45
- ember_cli_root.join("assets").tap(&:mkpath)
33
+ def assets
34
+ @assets ||= ember_cli_root.join("assets").tap(&:mkpath)
46
35
  end
47
36
 
48
- define_path :app_assets do
49
- assets.join(app_name)
37
+ def app_assets
38
+ @app_assets ||= assets.join(app_name)
50
39
  end
51
40
 
52
- define_path :applications do
53
- rails_root.join("public", "_apps").tap(&:mkpath)
41
+ def applications
42
+ @applications ||= rails_root.join("public", "_apps").tap(&:mkpath)
54
43
  end
55
44
 
56
- define_path :gemfile do
57
- root.join("Gemfile")
45
+ def gemfile
46
+ @gemfile ||= root.join("Gemfile")
58
47
  end
59
48
 
60
- define_path :package_json_file do
61
- root.join("package.json")
49
+ def package_json_file
50
+ @package_json_file ||= root.join("package.json")
62
51
  end
63
52
 
64
- define_path :ember do
65
- root.join("node_modules", ".bin", "ember").tap do |path|
66
- unless path.executable?
67
- fail DependencyError.new <<-MSG.strip_heredoc
68
- No `ember-cli` executable found for `#{app_name}`.
53
+ def ember
54
+ @ember ||= begin
55
+ root.join("node_modules", ".bin", "ember").tap do |path|
56
+ unless path.executable?
57
+ fail DependencyError.new <<-MSG.strip_heredoc
58
+ No `ember-cli` executable found for `#{app_name}`.
69
59
 
70
- Install it:
60
+ Install it:
71
61
 
72
- $ cd #{root}
73
- $ npm install
74
- MSG
62
+ $ cd #{root}
63
+ $ npm install
64
+ MSG
65
+ end
75
66
  end
76
67
  end
77
68
  end
78
69
 
79
- define_path :lockfile do
80
- tmp.join("build.lock")
70
+ def lockfile
71
+ @lockfile ||= tmp.join("build.lock")
81
72
  end
82
73
 
83
- define_path :build_error_file do
84
- tmp.join("error.txt")
74
+ def build_error_file
75
+ @build_error_file ||= tmp.join("error.txt")
85
76
  end
86
77
 
87
- define_path :bower do
88
- app_options.fetch(:bower_path) { configuration.bower_path }.tap do |path|
89
- unless Pathname(path).executable?
90
- fail DependencyError.new <<-MSG.strip_heredoc
91
- Bower is required by EmberCLI
78
+ def bower
79
+ @bower ||= begin
80
+ bower_path = app_options.fetch(:bower_path) { configuration.bower_path }
81
+
82
+ bower_path.tap do |path|
83
+ unless Pathname(path).executable?
84
+ fail DependencyError.new <<-MSG.strip_heredoc
85
+ Bower is required by EmberCLI
92
86
 
93
- Install it with:
87
+ Install it with:
94
88
 
95
- $ npm install -g bower
96
- MSG
89
+ $ npm install -g bower
90
+ MSG
91
+ end
97
92
  end
98
93
  end
99
94
  end
100
95
 
101
- define_path :npm do
102
- app_options.fetch(:npm_path) { configuration.npm_path }
96
+ def npm
97
+ @npm ||= app_options.fetch(:npm_path) { configuration.npm_path }
103
98
  end
104
99
 
105
- define_path :bundler do
106
- app_options.fetch(:bundler_path) { configuration.bundler_path }
100
+ def bundler
101
+ @bundler ||= app_options.fetch(:bundler_path) do
102
+ configuration.bundler_path
103
+ end
107
104
  end
108
105
 
109
106
  private
@@ -0,0 +1,30 @@
1
+ require "open3"
2
+
3
+ module EmberCli
4
+ class Runner
5
+ def initialize(env: {}, out:, err:, options: {})
6
+ @env = env
7
+ @out = out
8
+ @err = err
9
+ @options = options
10
+ end
11
+
12
+ def run!(command)
13
+ output, status = Open3.capture2e(@env, command, @options)
14
+
15
+ @out.write(output)
16
+
17
+ unless status.success?
18
+ @err.write <<-MSG.strip_heredoc
19
+ ERROR: Failed command: `#{command}`
20
+ OUTPUT:
21
+ #{output}
22
+ MSG
23
+
24
+ exit 1
25
+ end
26
+
27
+ true
28
+ end
29
+ end
30
+ end
@@ -1,4 +1,5 @@
1
1
  require "ember_cli/command"
2
+ require "ember_cli/runner"
2
3
 
3
4
  module EmberCli
4
5
  class Shell
@@ -13,7 +14,7 @@ module EmberCli
13
14
  end
14
15
 
15
16
  def compile
16
- silence_build { exec ember.build }
17
+ exec ember.build
17
18
  end
18
19
 
19
20
  def build_and_watch
@@ -50,18 +51,17 @@ module EmberCli
50
51
  attr_reader :ember, :env, :options, :paths
51
52
 
52
53
  def spawn(command)
53
- Kernel.spawn(env, command, process_options) || exit(1)
54
+ Kernel.spawn(env, command, chdir: paths.root.to_s, out: paths.log.to_s) ||
55
+ exit(1)
54
56
  end
55
57
 
56
58
  def exec(command)
57
- Kernel.system(env, command, process_options) || exit(1)
58
- end
59
-
60
- def process_options
61
- {
62
- chdir: paths.root.to_s,
63
- out: paths.log.to_s,
64
- }
59
+ Runner.new(
60
+ options: { chdir: paths.root.to_s },
61
+ out: paths.log,
62
+ err: $stderr,
63
+ env: env,
64
+ ).run!(command)
65
65
  end
66
66
 
67
67
  def running?
@@ -77,13 +77,5 @@ module EmberCli
77
77
  def detach
78
78
  Process.detach pid
79
79
  end
80
-
81
- def silence_build(&block)
82
- if ENV.fetch("EMBER_CLI_RAILS_VERBOSE") { EmberCli.env.production? }
83
- yield
84
- else
85
- silence_stream(STDOUT, &block)
86
- end
87
- end
88
80
  end
89
81
  end
@@ -1,10 +1,14 @@
1
+ require "sprockets"
1
2
  require "ember_cli/errors"
2
3
  require "non-stupid-digest-assets"
3
4
  require "ember_cli/html_page"
5
+ require "ember_cli/missing_manifest"
6
+ require "ember_cli/assets"
4
7
 
5
8
  module EmberCli
6
9
  class Sprockets
7
10
  class AssetPipelineError < BuildError; end
11
+
8
12
  def initialize(app)
9
13
  @app = app
10
14
  end
@@ -24,14 +28,26 @@ module EmberCli
24
28
  html_page.render
25
29
  end
26
30
 
27
- def assets
28
- ["#{app.name}/assets/vendor", "#{app.name}/assets/#{ember_app_name}"]
31
+ def javascript_assets
32
+ assets.javascripts
33
+ end
34
+
35
+ def stylesheet_assets
36
+ assets.stylesheets
29
37
  end
30
38
 
31
39
  private
32
40
 
33
41
  attr_reader :app
34
42
 
43
+ def assets
44
+ Assets.new(
45
+ app_name: app.name,
46
+ ember_app_name: ember_app_name,
47
+ manifest: rails_manifest,
48
+ )
49
+ end
50
+
35
51
  def ember_app_name
36
52
  @ember_app_name ||= app.options.fetch(:name) { package_json.fetch(:name) }
37
53
  end
@@ -41,6 +57,14 @@ module EmberCli
41
57
  JSON.parse(app.paths.package_json_file.read).with_indifferent_access
42
58
  end
43
59
 
60
+ def rails_manifest
61
+ if Rails.application.respond_to?(:assets_manifest)
62
+ Rails.application.assets_manifest
63
+ else
64
+ MissingManifest.new
65
+ end
66
+ end
67
+
44
68
  def asset_matcher
45
69
  %r{\A#{app.name}/}
46
70
  end
@@ -1,3 +1,3 @@
1
1
  module EmberCli
2
- VERSION = "0.5.6".freeze
2
+ VERSION = "0.5.7".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.5.6
4
+ version: 0.5.7
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-24 00:00:00.000000000 Z
13
+ date: 2015-12-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -91,6 +91,7 @@ files:
91
91
  - app/views/ember_cli/ember/index.html.erb
92
92
  - lib/ember-cli-rails.rb
93
93
  - lib/ember_cli/app.rb
94
+ - lib/ember_cli/assets.rb
94
95
  - lib/ember_cli/build_monitor.rb
95
96
  - lib/ember_cli/capture.rb
96
97
  - lib/ember_cli/command.rb
@@ -101,8 +102,10 @@ files:
101
102
  - lib/ember_cli/errors.rb
102
103
  - lib/ember_cli/helpers.rb
103
104
  - lib/ember_cli/html_page.rb
105
+ - lib/ember_cli/missing_manifest.rb
104
106
  - lib/ember_cli/path_set.rb
105
107
  - lib/ember_cli/route_helpers.rb
108
+ - lib/ember_cli/runner.rb
106
109
  - lib/ember_cli/shell.rb
107
110
  - lib/ember_cli/sprockets.rb
108
111
  - lib/ember_cli/version.rb