class DPL::Provider::NPM

Constants

DEFAULT_NPM_REGISTRY
NPMRC_FILE

Public Instance Methods

api_key() click to toggle source
# File lib/dpl/provider/npm.rb, line 63
def api_key
  option(:api_key, :api_token)
end
check_app() click to toggle source
# File lib/dpl/provider/npm.rb, line 14
def check_app
end
check_auth() click to toggle source
# File lib/dpl/provider/npm.rb, line 23
def check_auth
  setup_auth
  log "Authenticated with email #{option(:email)} and API key #{api_key[-4..-1].rjust(20, '*')}"
end
needs_key?() click to toggle source
# File lib/dpl/provider/npm.rb, line 10
def needs_key?
  false
end
npm_version() click to toggle source
# File lib/dpl/provider/npm.rb, line 59
def npm_version
  `npm --version`
end
npmrc_file_content() click to toggle source
# File lib/dpl/provider/npm.rb, line 50
def npmrc_file_content
  log "NPM version: #{npm_version}"
  if npm_version =~ /^1/
    "_auth = ${NPM_API_KEY}\nemail = #{option(:email)}"
  else
    "//#{package_registry}/:_authToken=${NPM_API_KEY}"
  end
end
package_registry() click to toggle source
# File lib/dpl/provider/npm.rb, line 39
def package_registry
  if File.exists?('package.json')
    data = JSON.parse(File.read('package.json'))
    if data['publishConfig'] && data['publishConfig']['registry']
      return URI(data['publishConfig']['registry']).host
    end
  end

  DEFAULT_NPM_REGISTRY
end
push_app() click to toggle source
# File lib/dpl/provider/npm.rb, line 28
def push_app
  log "NPM API key format changed recently. If your deployment fails, check your API key in ~/.npmrc."
  log "http://docs.travis-ci.com/user/deployment/npm/"
  log "#{NPMRC_FILE} size: #{File.size(File.expand_path(NPMRC_FILE))}"

  command = "env NPM_API_KEY=#{api_key} npm publish"
  command << " --tag #{option(:tag)}" if options[:tag]
  context.shell "#{command}"
  FileUtils.rm(File.expand_path(NPMRC_FILE))
end
setup_auth() click to toggle source
# File lib/dpl/provider/npm.rb, line 17
def setup_auth
  file = File.open(File.expand_path(NPMRC_FILE), 'w')
  file.puts(npmrc_file_content)
  file.flush
end