class Dpl::Providers::Npm

Constants

NPMRC
REGISTRY

Public Instance Methods

deploy() click to toggle source
# File lib/dpl/providers/npm.rb, line 51
def deploy
  if run_script?
    run_scripts
  else
    shell :publish
  end
end
finish() click to toggle source
# File lib/dpl/providers/npm.rb, line 59
def finish
  remove_npmrc
end
login() click to toggle source
# File lib/dpl/providers/npm.rb, line 44
def login
  info :version
  info :login
  write_npmrc
  shell :registry
end

Private Instance Methods

auth_endpoint() click to toggle source
# File lib/dpl/providers/npm.rb, line 99
def auth_endpoint
  str = registry
  str = strip_path(str) if str.include?('npm.pkg.github.com')
  str = strip_protocol(str).sub(%r{/$}, '')
  str
end
host(url) click to toggle source
# File lib/dpl/providers/npm.rb, line 124
def host(url)
  URI(url).host
end
npmrc() click to toggle source
# File lib/dpl/providers/npm.rb, line 88
def npmrc
  npm_version_major = npm_version.split('.').first.to_i
  if npm_version_major >= 10
    "//#{auth_endpoint}/:_auth=#{api_token}\nemail = #{email}"
  elsif npm_version =~ /^1/ || auth_method == 'auth'
    "_auth = #{api_token}\nemail = #{email}"
  else
    "//#{auth_endpoint}/:_authToken=#{api_token}"
  end
end
npmrc_path() click to toggle source
# File lib/dpl/providers/npm.rb, line 84
def npmrc_path
  expand(NPMRC)
end
package_json() click to toggle source
# File lib/dpl/providers/npm.rb, line 128
def package_json
  File.exist?('package.json') ? JSON.parse(File.read('package.json')) : {}
end
publish_opts() click to toggle source
# File lib/dpl/providers/npm.rb, line 71
def publish_opts
  opts_for(%i[access tag dry_run], dashed: true)
end
registry() click to toggle source
Calls superclass method
# File lib/dpl/providers/npm.rb, line 106
def registry
  super || registry_from_package_json || REGISTRY
end
registry_from_package_json() click to toggle source
# File lib/dpl/providers/npm.rb, line 110
def registry_from_package_json
  return unless data = package_json

  data && data.fetch('publishConfig', {})['registry']
end
remove_npmrc() click to toggle source
# File lib/dpl/providers/npm.rb, line 80
def remove_npmrc
  rm_f npmrc_path
end
run_scripts() click to toggle source
# File lib/dpl/providers/npm.rb, line 65
def run_scripts
  run_script.each do |script|
    shell :run, script:
  end
end
strip_path(url) click to toggle source
# File lib/dpl/providers/npm.rb, line 116
def strip_path(url)
  url.sub(URI(url).path, '')
end
strip_protocol(url) click to toggle source
# File lib/dpl/providers/npm.rb, line 120
def strip_protocol(url)
  url.sub("#{URI(url).scheme}://", '')
end
write_npmrc() click to toggle source
# File lib/dpl/providers/npm.rb, line 75
def write_npmrc
  write_file(npmrc_path, npmrc)
  info "#{NPMRC} size: #{file_size(npmrc_path)}"
end