Skip to content

Commit

Permalink
Enhance rake ember:install to fully reinstall if necessary.
Browse files Browse the repository at this point in the history
Closes [#394].

EmberCLI ships with [`ember-cli-dependency-checker`][addon], which
exposes the `ember version` command.

`ember version` is akin to `bundle check`.

This commit enhances the `ember:install` Rake task to cleanup frontend
 dependencies before installing if `ember version` returns a non-zero
exit status.

This (in conjunction with [`npm shrinkwrap`][shrinkwrap]) helps to
ensure that every machine has the same dependencies installed.

[#394]: #394
[addon]: https://github.com/quaertym/ember-cli-dependency-checker
[shrinkwrap]: https://github.com/quaertym/ember-cli-dependency-checker#deployment-with-shrinkwrap
  • Loading branch information
botandrose-machine authored and seanpdoyle committed Feb 8, 2016
1 parent 7e901b3 commit 6eceea8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
master
------

* Enhance `rake ember:install` to fully reinstall if necessary. [#396]
* `EmberCli::Deploy::File` serves assets with Rails' `static_cache_control`
value. [#403]

[#396]: https://github.com/thoughtbot/ember-cli-rails/pull/396
[#403]: https://github.com/thoughtbot/ember-cli-rails/pull/403

0.7.1
Expand Down
8 changes: 8 additions & 0 deletions lib/ember_cli/path_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ def bower
end
end

def bower_components
@bower_components ||= root.join("bower_components")
end

def npm
@npm ||= app_options.fetch(:npm_path) { which("npm") }
end

def node_modules
@node_modules ||= root.join("node_modules")
end

def tee
@tee ||= app_options.fetch(:tee_path) { which("tee") }
end
Expand Down
10 changes: 8 additions & 2 deletions lib/ember_cli/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ def initialize(env: {}, out:, err:, options: {})
@options = options
end

def run!(command)
def run(command)
output, status = Open3.capture2e(@env, command, @options)

@out.write(output)

[output, status]
end

def run!(command)
output, status = run(command)

unless status.success?
@err.write <<-MSG.strip_heredoc
ERROR: Failed command: `#{command}`
OUTPUT:
#{output}
MSG

exit 1
exit status.exitstatus
end

true
Expand Down
37 changes: 30 additions & 7 deletions lib/ember_cli/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(paths:, env: {}, options: {})
end

def compile
exec ember.build
run! ember.build
end

def build_and_watch
Expand All @@ -34,22 +34,45 @@ def stop

def install
if paths.gemfile.exist?
exec "#{paths.bundler} install"
run! "#{paths.bundler} install"
end

exec "#{paths.npm} prune && #{paths.npm} install"
exec "#{paths.bower} prune && #{paths.bower} install"
if invalid_ember_dependencies?
clean_ember_dependencies!
end

run! "#{paths.npm} prune && #{paths.npm} install"
run! "#{paths.bower} prune && #{paths.bower} install"
end

def test
exec ember.test
run! ember.test
end

private

attr_accessor :pid
attr_reader :ember, :env, :options, :paths

delegate :run, :run!, to: :runner

def invalid_ember_dependencies?
!run("#{paths.ember} version")
rescue DependencyError
false
end

def clean_ember_dependencies!
ember_dependency_directories.select(&:exist?).each(&:rmtree)
end

def ember_dependency_directories
[
paths.node_modules,
paths.bower_components,
]
end

def spawn(command)
Kernel.spawn(
env,
Expand All @@ -59,13 +82,13 @@ def spawn(command)
) || exit(1)
end

def exec(command)
def runner
Runner.new(
options: { chdir: paths.root.to_s },
out: paths.log,
err: $stderr,
env: env,
).run!(command)
)
end

def running?
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/ember_cli/path_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@
end
end

describe "#bower_components" do
it "is a child of #root" do
app = build_app(name: "foo")

path_set = build_path_set(app: app)

expect(path_set.bower_components).
to eq rails_root.join("foo", "bower_components")
end
end

describe "#npm" do
it "can be overridden" do
app = build_app(options: { npm_path: "npm-path" })
Expand All @@ -145,6 +156,16 @@
end
end

describe "#node_modules" do
it "is a child of #root" do
app = build_app(name: "foo")

path_set = build_path_set(app: app)

expect(path_set.node_modules).to eq rails_root.join("foo", "node_modules")
end
end

describe "#tee" do
it "can be overridden" do
app = build_app(options: { tee_path: "tee-path" })
Expand Down

0 comments on commit 6eceea8

Please sign in to comment.