Skip to content

Commit

Permalink
stop storing items in tmp/ directory,
Browse files Browse the repository at this point in the history
only copy ember from gem when local over-ride / update not present
  • Loading branch information
alexblom committed Apr 20, 2014
1 parent 9f2f956 commit b6d54e3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/ember_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,30 @@ class Railtie < ::Rails::Railtie

initializer "ember_rails.setup_vendor", :after => "ember_rails.setup", :group => :all do |app|
variant = app.config.ember.variant || (::Rails.env.production? ? :production : :development)

# Copy over the desired ember, ember-data, and handlebars bundled in
# ember-source, ember-data-source, and handlebars-source to a tmp folder.
tmp_path = app.root.join("tmp/ember-rails")
ext = variant == :production ? ".prod.js" : ".js"
FileUtils.mkdir_p(tmp_path)
FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ext}"), tmp_path.join("ember.js"))
FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ext}"), tmp_path.join("ember-data.js"))
app.assets.append_path(tmp_path)

#Allow for over-rides and updates, empty /bundler to avoid duplicate files
ember_path = app.root.join("vendor/assets/ember/#{variant}")
bundled_path = ember_path.join("bundler")
FileUtils.mkdir_p(bundled_path)
FileUtils.rm_rf(Dir.glob("#{bundled_path}/*"))

# Check for over-rides, else store the bundled ember and ember-data in /bundler
if !File.exist?(ember_path.join("ember.js"))
FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ext}"),
bundled_path.join("ember.js"))
end
if !File.exist?(ember_path.join("ember-data.js"))
FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ext}"),
bundled_path.join('ember-data.js'))
end

app.assets.prepend_path(ember_path)
app.assets.append_path(bundled_path)

# Make the handlebars.js and handlebars.runtime.js bundled
# in handlebars-source available.
app.assets.append_path(File.expand_path('../', ::Handlebars::Source.bundled_path))

# Allow a local variant override
ember_path = app.root.join("vendor/assets/ember/#{variant}")
app.assets.prepend_path(ember_path.to_s) if ember_path.exist?
end

initializer "ember_rails.es5_default", :group => :all do |app|
Expand Down

0 comments on commit b6d54e3

Please sign in to comment.