rubygems / bundler-features

Bundler feature requests and discussion
28 stars 8 forks source link

Run command after install #83

Closed rzane closed 9 years ago

rzane commented 9 years ago

NPM lets you add postinstall commands to your package.json that run every time you use npm install.

Say I use bower for my assets, I might want to do something like this:

source "http://rubygems.org"
gem 'blahblahblah'

postinstall "bower install"
TimMoore commented 9 years ago

This is kind of covered by the plans for the plugin system (#8) but I like the simplicity of just being able to run a single shell command without having to build an entire plugin.

indirect commented 9 years ago

@rzane can you describe what you want to use the post-install hook to do? The example from NPM makes complete sense, but there's nothing like bower in Ruby.

rzane commented 9 years ago

I'm personally looking to install bower after bundling. I prefer to avoid gems that vendor JS and CSS files when possible.

Using bower with Rails seems to be a pretty common task, so that is the most practical example I can think of. I've also seen blogs where people have ditched Rails' asset pipeline entirely and use Gulp/Grunt. They might want to npm install after bundling. Post install tasks would save some steps.

Libraries like JBundler and BowerRails would probably benefit from this kind of thing as well.

Bundling is the first thing people do when they work on a project for the first time, so maybe the maintainer of a project wants to print instructions on how to get started.

I've also seen people use environment variables in their Gemfile. Take a look at https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/Gemfile. A before_install hook would allow developers to print "Bundling with such and such" or maybe even abort a bundle if certain preconditions aren't met.

I'm out of ideas, but I'm sure there are more. Given that Gemfiles are Ruby, the possibilities are endless.

indirect commented 9 years ago

I mean, Gemfiles are also Ruby, so you could just use puts instead of before_install. :) But to hopefully make my question clearer—Rails itself creates a file, bin/setup, whenever you generate a Rails app. Rails expects you to make sure any needed databases exist, run bundle install, and run any other commands you need to turn a git clone into a working app. Why do you feel like Bundler is a better place to put your bower install command, when Rails already provides a place to do that?

rzane commented 9 years ago

You're right about the before_install, but that puts would also run when Bundler requires.

bin/setup would also accomplish what I'm looking for. For some strange reason, I've never thought to do that haha. If someone gave me a Rails app, here's what I'd do instinctively:

I guess I just think of it as dependencies are dependencies, and I want to get them taken care of in one step.

indirect commented 9 years ago

Interesting. Since bin/setup is supposed to run both bundle install and rake db:setup, how do you feel about using that to accomplish this goal?

On Wed, Mar 11, 2015 at 10:18 PM, Ray Zane notifications@github.com wrote:

You're right about the before_install, but that puts would also run when Bundler requires. bin/setup would also accomplish what I'm looking for. For some strange reason, I've never thought to do that haha. If someone gave me a Rails app, here's what I'd do instinctively:

rzane commented 9 years ago

Works for me.