Installing ruby ​​gems in an npm project

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

npm install 

to establish npm dependencies, it would be great if the necessary ruby ​​gems were installed.

Is there any bridge between them? If not, did anyone research this and find recommended good practices or work in these situations?

+8
ruby npm
source share
2 answers

Theoretically, npm-scripts provides a means to run scripts during npm install . You can, for example, add these lines to your package.json :

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

Of course, you might want to add a more complex script that handles the case where Ruby and / or Rubygems are not installed, the installation of Gem does not work, etc. etc. Setting dependencies can be arbitrarily complex, so many package developers (in any language) often simply assume that the required dependencies are already running and running on the target system. Finally, the documentation for npm scripts states that

INSTALLING SCRIPTS - ANTIPATTERN

and

The only permissible use of installation or pre-installation scripts is compilation, which must be performed on the target architecture.

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

+7
source share

If you have several stones needed to execute a ruby ​​script in your node.js application, you can create a Gemfile and then add this preinstall / postinstall script to your package.json package.

 "scripts": { "postinstall": "/usr/bin/env bundle install" }, 
0
source share

All Articles