Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing ruby gems in a npm project

Tags:

node.js

npm

ruby

I have a node.js project that depends on a ruby gem. Is it possible somehow to create an installation process that installs the gem dependencies in an easy way? Ideally, when I do

npm install

to install the npm dependencies, it would be great if the required ruby gems were installed as well.

Is there some kind of bridge between the two? If not, has anyone investigated this and found a suggested best practice or work around in these situations?

like image 881
Mikael Lindqvist Avatar asked May 19 '14 15:05

Mikael Lindqvist


People also ask

How do I install a gem file?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from. Save this answer.

Where are RubyGems installed?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.

Is a Gemfile like package JSON?

package.json is roughly equivalent to Bundler's Gemfile . Project dependencies and their required versions are listed here, as well as configuration, and customized scripts relating to the project. When entering an unfamiliar project, this is the first place to look.


1 Answers

Theoretically, npm-scripts provides the facilities to run scripts during npm install. You could for example add these lines to your package.json:

{ "scripts" :
  { "preinstall" : "/usr/bin/env gem install some_gem_name" }
}

Of course, you may want to add a more complex script that handles the case where Ruby and/or Rubygems are not installed, the Gem installation fails etc. etc. Installing dependencies can get arbitrarily complex, which is why many package developers (in any given language) often just assume that the required dependencies are already up and running on the target system. Finally, the npm-scripts documentation states that

INSTALL SCRIPTS ARE AN ANTIPATTERN

and

The only valid use of install or preinstall scripts is for compilation which must be done on the target architecture.

All in all, I suggest that you instead focus your energy on adding proper installation instructions to your Readme.

like image 189
Patrick Oscity Avatar answered Sep 23 '22 02:09

Patrick Oscity