Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: adding rake tasks to engine #42

Closed
onemanstartup opened this issue Nov 12, 2013 · 14 comments
Closed

Feature: adding rake tasks to engine #42

onemanstartup opened this issue Nov 12, 2013 · 14 comments

Comments

@onemanstartup
Copy link

When I'm add bower-rails to engine there is no rake tasks.

@SergeyKishenin
Copy link
Collaborator

Checkout #39

@SergeyKishenin
Copy link
Collaborator

@cj, @onemanstartup You can do the following in your Rakefile:

spec = Gem::Specification.find_by_name 'bower-rails'
load "#{spec.gem_dir}/lib/tasks/bower.rake"

Then try rake -T

@onemanstartup
Copy link
Author

@SergeyKishenin thanks, now i have rake tasks, but they only work on dummy app. even when I call tasks like rake bower:install
rake app:bower:install - works the same way.

@SergeyKishenin
Copy link
Collaborator

Does rake -T at your engine root say that you have bower's tasks?

@onemanstartup
Copy link
Author

Yes.

I've inserted like this

spec = Gem::Specification.find_by_name 'bower-rails'
load "#{spec.gem_dir}/lib/tasks/bower.rake"
Bundler::GemHelper.install_tasks
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
load 'rails/tasks/engine.rake'

then i have
rake bower:install
and then Bowerfile from engine/test/dummy/Bowerfile used

@SergeyKishenin
Copy link
Collaborator

Well, I'm not sure what's wrong with your engine. I've just tried the same and all was fine.

My engine's Rakefile looks like:

#!/usr/bin/env rake
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'bower-rails'

spec = Gem::Specification.find_by_name 'bower-rails'
load "#{spec.gem_dir}/lib/tasks/bower.rake"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

rake -T at the engine's root produces:

$ rake -T
rake bower:install        # Install components from bower
rake bower:install:force  # Install components with -F option
rake bower:list           # List bower components
rake bower:update         # Update bower components
rake bower:update:prune   # Update existing components and uninstalls extraneous components
rake build                # Build xxx-0.2.3.gem into the pkg directory
rake install              # Build and install xxx-0.2.3.gem into system gems
rake release              # Create tag v0.2.3 and build and push xxx-0.2.3.gem to Rubygems
rake spec                 # Run RSpec code examples

My engine's Bowerfile contains just asset 'moment'. rake bower:install at the engine's root installs moment to vendor/assets/bower_components as expected. Just make sure you have /vendor/assets dir.

Just to test I've created Bowerfile at dummy's root that contains asset 'backbone' and it was ignored when I run rake bower:install at engine's root and evaluated for the same command at dummy's root. As expected.

So make sure you have everything all right! Good luck :)

@onemanstartup
Copy link
Author

You don't have

APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
load 'rails/tasks/engine.rake'

https://github.com/rails/docrails/blob/master/railties/lib/rails/tasks/engine.rake - this file load dummy rails and your rake task set root to that dummy app

@SergeyKishenin
Copy link
Collaborator

Are you sure that dummy's Rakefile should be loaded to engine? Maybe engine's one to dummy?

@onemanstartup
Copy link
Author

It is default behaviour, when you generate mountable engine
rails plugin new engines/engine --mountable
and this rails/tasks/engine.rake file add app namespaces rake tasks(which belongs to dummy) to engine folder.
P.S. можно и по русски :)

@SergeyKishenin
Copy link
Collaborator

Yes, I see now. Let me check out.

PS: по-русски тут неформат немного :)

@SergeyKishenin
Copy link
Collaborator

Check out the edge version

@onemanstartup
Copy link
Author

Now I have this issue

# Bowerfile
assets_path "assets/javascript"

# Puts files under ./lib/assets/javascript/components
group :lib, :assets_path => "assets/js" do
  asset "jquery"
end
** Invoke load_app (first_time)
** Execute load_app
** Invoke bower:install (first_time)
** Execute bower:install
rake aborted!
only generation of JSON objects or arrays allowed
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/json/common.rb:285:in `generate'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/json/common.rb:285:in `pretty_generate'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/bundler/gems/bower-rails-ba50e52bb220/lib/bower-rails/dsl.rb:65:in `block (2 levels) in write_dotbowerrc'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/bundler/gems/bower-rails-ba50e52bb220/lib/bower-rails/dsl.rb:64:in `open'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/bundler/gems/bower-rails-ba50e52bb220/lib/bower-rails/dsl.rb:64:in `block in write_dotbowerrc'
// generated bower.json
{
  "name": "dsl-generated dependencies",
  "dependencies": {
    "jquery": "latest"
  }
}

@SergeyKishenin
Copy link
Collaborator

Fixed with 8465b06

@onemanstartup
Copy link
Author

It's working, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants