forked from emberjs/ember-rails
/
install_generator.rb
91 lines (69 loc) · 2.65 KB
/
install_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module EmberRails
module Generators
class InstallGenerator < Rails::Generators::Base
EMBER_FILES = [ "ember.js", "ember-dev.js" ]
RUNTIME_FILES = [ "ember-runtime.js", "ember-runtime-dev.js" ]
ALL_FILES = [ *EMBER_FILES, *RUNTIME_FILES ]
desc "Install Ember.js into your vendor folder"
class_option :head, :type => :boolean, :default => false, :desc => "Download latest Ember.js from GitHub and copy it into your project"
class_option :runtime, :type => :boolean, :default => false, :desc => "Include the Ember.js runtime only"
def remove_ember
ALL_FILES.each do |name|
file = "vendor/assets/javascripts/#{name}"
remove_file file if File.exist?(file)
end
end
def copy_ember
if options.head?
git_root = File.expand_path "~/.ember"
gem_file = File.join git_root, "Gemfile"
# If it doesn't exist yet
unless File.exist?(git_root)
command = %{git clone git://github.com/emberjs/ember.js.git "#{git_root}"}
say_status("downloading", command, :green)
cmd command
else
Dir.chdir git_root do
command = "git fetch --force --quiet --tags && git reset HEAD --hard"
say_status("updating", command, :green)
cmd command
end
end
Dir.chdir git_root do
say_status("building", "bundle && bundle exec rake", :green)
Bundler.with_clean_env do
cmd "bundle --gemfile #{gem_file}"
cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake}
end
end
self.class.source_root File.join(git_root, "dist")
ember_files.each do |name|
source_file = if name.match /-dev/
name.gsub /-dev/, ''
else
name.gsub /.js/, '.min.js'
end
copy_file source_file, "vendor/assets/javascripts/#{name}"
end
else
self.class.source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
say_status("copying", "Ember.js (#{EmberRails::EMBER_VERSION})", :green)
ember_files.each do |name|
copy_file name, "vendor/assets/javascripts/#{name}"
end
end
end
private
def ember_files
options.runtime? ? RUNTIME_FILES : EMBER_FILES
end
def cmd(command)
out = `#{command}`
if $?.exitstatus != 0
raise "Command error: command `#{command}` in directory #{Dir.pwd} has failed."
end
out
end
end
end
end