Skip to content

Commit

Permalink
Merge pull request #273 from hajee/install_named_releases
Browse files Browse the repository at this point in the history
Added support for installing the beta and the canary release
  • Loading branch information
rwjblue committed Oct 31, 2013
2 parents 7cc0d94 + b4cf201 commit e65f053
Show file tree
Hide file tree
Showing 8 changed files with 162,074 additions and 29 deletions.
15 changes: 10 additions & 5 deletions README.md
Expand Up @@ -35,10 +35,10 @@ Notes:

To install the latest builds of ember and ember-data. It should be noted that the
examples in the [getting started guide](http://emberjs.com/guides/getting-started/)
have been designed to use the latest version of ember:
have been designed to use the released version of ember:

```shell
rails generate ember:install --head
rails generate ember:install
```

You'll probably need to clear out your cache after doing this with
Expand Down Expand Up @@ -264,11 +264,16 @@ you've specified in your app's configuration, e.g.:

## Updating Ember

If at any point you need to update Ember.js from master, you can do that with
If at any point you need to update Ember.js from any of the release channels, you can do that with

rails generate ember:install --head
rails generate ember:install --channel=<channel>

This will fetch both Ember.js and Ember Data from [http://builds.emberjs.com/](http://builds.emberjs.com/) and copy to the right directory.
This will fetch both Ember.js and Ember Data from [http://builds.emberjs.com/](http://builds.emberjs.com/) and copy to the right directory. You can choose between the following channels:
* canary - This references the 'master' branch and is not recommended for production use.
* beta - This references the 'beta' branch, and will ultimately become the next stable version. It is not recommended for production use.
* release - This references the 'stable' branch, and is recommended for production use.

When you don't specify a channel, the release channel is used.

## Note on Patches/Pull Requests

Expand Down
2 changes: 2 additions & 0 deletions ember-rails.gemspec
Expand Up @@ -28,6 +28,8 @@ Gem::Specification.new do |s|
s.add_development_dependency "ember-source", '~> 1.1.0'
s.add_development_dependency "handlebars-source", '~> 1.0.0'
s.add_development_dependency "sprockets-rails"
s.add_development_dependency "vcr"
s.add_development_dependency "webmock", "< 1.14.0"

s.files = %w(README.md LICENSE) + Dir["lib/**/*", "vendor/**/*"]

Expand Down
115 changes: 92 additions & 23 deletions lib/generators/ember/install_generator.rb
Expand Up @@ -3,50 +3,119 @@
require 'uri'
require 'fileutils'


module Ember
module Generators
class InstallGenerator < ::Rails::Generators::Base

class InvalidChannel < ::Thor::Error; end
class ConflictingOptions < ::Thor::Error; end
class Deprecated < ::Thor::Error; end

::InvalidChannel = InvalidChannel
::ConflictingOptions = ConflictingOptions
::Deprecated = Deprecated

class EmberGenerator
def ember
super()
end
end

desc "Install Ember.js into your vendor folder"
class_option :head, :type => :boolean, :default => false, :desc => "Download latest Ember.js from GitHub and fetch it into your project"
class_option :release, :type => :string, :required => false, :desc => "Release type of ember. Choose between 'head', 'beta' or 'canary'"
class_option :head, :type => :boolean, :default => false, :desc => "Download Ember.js & Ember data from canary channel. This is deprecated. Use channel instead."
class_option :channel, :type => :string, :required => false, :desc => "Ember release channel Choose between 'release', 'beta' or 'canary'"
class_option :ember_only, :type => :boolean, :required => false, :desc => "Only download Ember."
class_option :ember_data_only, :type => :boolean, :required => false, :desc => "Onky download ember-data"

def initialize(args = [], options = {}, config = {})
super(args, options, config)
check_options
process_options
end


def release_type
if options.head? && options.release
say_status('conflicting options', '--head prevailed over --release option' , :red)
def ember
unless options.ember_data_only?
get_ember_js_for(:development)
get_ember_js_for(:production)
end
if options.head?
''
else
options['release'] + '/'
end

def ember_data
begin
unless options.ember_only?
get_ember_data_for(:development)
get_ember_data_for(:production)
end
rescue Thor::Error
say('WARNING: no ember-data files on this channel yet' , :yellow)
end
end

def fetch_ember
fetch "http://builds.emberjs.com/#{release_type}ember-latest.js", 'vendor/assets/ember/development/ember.js'
fetch "http://builds.emberjs.com/#{release_type}ember-latest.min.js", 'vendor/assets/ember/production/ember.js'
private

def get_ember_data_for(environment)
create_file "vendor/assets/ember/#{environment}/ember-data.js" do
fetch "#{base_url}/#{channel}/ember-data.js", "vendor/assets/ember/#{environment}/ember-data.js"
end
end

def fetch_ember_data
fetch "http://builds.emberjs.com/#{release_type}ember-data-latest.js", 'vendor/assets/ember/development/ember-data.js'
fetch "http://builds.emberjs.com/#{release_type}ember-data-latest.min.js", 'vendor/assets/ember/production/ember-data.js'
def get_ember_js_for(environment)
create_file "vendor/assets/ember/#{environment}/ember.js" do
fetch "#{base_url}/#{channel}/ember.js", "vendor/assets/ember/#{environment}/ember.js"
end
end

def check_options
if options.head?
say('WARNING: --head option is deprecated in favor of --channel=cannary' , :yellow)
end
if options.head? && options.channel?
say 'ERROR: conflicting options. --head and --channel. Use either --head or --channel=<channel>', :red
raise ConflictingOptions
end
if options.channel? && !%w(release beta canary).include?(options[:channel])
say 'ERROR: channel can either be release, beta or canary', :red
raise InvalidChannel
end
end

def process_options
if options.head?
@channel = :canary
end
end

def base_url
'http://builds.emberjs.com'
end

def channel
if options.channel
@channel ||= options[:channel]
else
@channel ||= :release
end
end

private

def fetch(from, to)
message = "#{from} -> #{to}"
say_status("downloading:", message , :green)

uri = URI(from)

FileUtils.mkdir_p File.dirname(to)

open(to, 'w+') do |output|
output.puts "// Fetched from: " + uri.to_s
output.puts "// Fetched on: " + Time.now.utc.iso8601.to_s
output.puts Net::HTTP.get(uri).force_encoding("UTF-8")
output = StringIO.new
output.puts "// Fetched from: " + uri.to_s
output.puts "// Fetched on: " + Time.now.utc.iso8601.to_s
output.puts Net::HTTP.get(uri).force_encoding("UTF-8")
output.rewind
content = output.read
if content.include?('404')
say "ERROR: Error reading the content from the channel with url #{from}." , :red
raise raise Thor::Error
end
content
end
end
end
Expand Down

0 comments on commit e65f053

Please sign in to comment.