class NPM2Gem::NPMInstall
Public Class Methods
new(package_name)
click to toggle source
# File lib/npm2gem/npm_install.rb, line 5 def initialize(package_name) create_node_modules_directory unless system("npm install #{package_name}") raise NPM2Gem::Exception, "Couldn't install..." end @package_name = package_name end
Public Instance Methods
package_version()
click to toggle source
# File lib/npm2gem/npm_install.rb, line 19 def package_version parse_json_file("package.json")["version"] end
path()
click to toggle source
# File lib/npm2gem/npm_install.rb, line 15 def path File.join("node_modules", @package_name) end
Private Instance Methods
create_node_modules_directory()
click to toggle source
If npm cannot create a ‘node_modules` folder, it will fallback to installing globally. We don’t want that.
# File lib/npm2gem/npm_install.rb, line 28 def create_node_modules_directory Dir.mkdir("node_modules") unless Dir.exist?("node_modules") end
parse_json_file(json_file_name)
click to toggle source
# File lib/npm2gem/npm_install.rb, line 32 def parse_json_file(json_file_name) JSON.parse(File.read(File.join(path, json_file_name))) end