class Npm::Rails::PackageManager
Public Class Methods
build(root_path, package_file, env)
click to toggle source
# File lib/npm/rails/package_manager.rb, line 5 def self.build(root_path, package_file, env) package_file_path = "#{ root_path }/#{ package_file }" packages = PackageFileParser.parse(package_file_path) new(packages, root_path, env) end
new(packages, root_path, env)
click to toggle source
# File lib/npm/rails/package_manager.rb, line 11 def initialize(packages, root_path, env) @packages = packages @root_path = root_path @env = env end
Public Instance Methods
to_npm_format()
click to toggle source
Return string of packages for ‘npm install’ command
# File lib/npm/rails/package_manager.rb, line 29 def to_npm_format @packages.inject "" do |string, package| # do not add development packages in production environment if (@env.production? and package.development?) string else string << "#{ package.name }@\"#{ package.version }\" " end end end
write_bundle_file()
click to toggle source
# File lib/npm/rails/package_manager.rb, line 17 def write_bundle_file bundle_file_path = "#{ @root_path }/tmp/npm-rails/bundle.js" Dir.mkdir("tmp/npm-rails") unless File.exist?("tmp/npm-rails") File.open(bundle_file_path, "w") do |file| packages_for_bundle_file.each do |package| file.write "window.#{ package.build_name } = require('#{ package.name }')\n" end end bundle_file_path end
Private Instance Methods
packages_for_bundle_file()
click to toggle source
# File lib/npm/rails/package_manager.rb, line 42 def packages_for_bundle_file if @env.production? @packages.select do |package| package.should_require? && !package.development? end else @packages.select do |package| package.should_require? end end end