Class: DPL::Provider::NPM

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/npm.rb

Constant Summary collapse

NPMRC_FILE =
'~/.npmrc'
DEFAULT_NPM_REGISTRY =
'registry.npmjs.org'

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #cleanup, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#check_appObject



14
15
# File 'lib/dpl/provider/npm.rb', line 14

def check_app
end

#check_authObject



23
24
25
26
# File 'lib/dpl/provider/npm.rb', line 23

def check_auth
  setup_auth
  log "Authenticated with email #{option(:email)}"
end

#needs_key?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/dpl/provider/npm.rb', line 10

def needs_key?
  false
end

#npm_versionObject



56
57
58
# File 'lib/dpl/provider/npm.rb', line 56

def npm_version
  `npm --version`
end

#npmrc_file_contentObject



47
48
49
50
51
52
53
54
# File 'lib/dpl/provider/npm.rb', line 47

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_registryObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/dpl/provider/npm.rb', line 36

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_appObject



28
29
30
31
32
33
34
# 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))}"
  context.shell "env NPM_API_KEY=#{option(:api_key)} npm publish"
  FileUtils.rm(File.expand_path(NPMRC_FILE))
end

#setup_authObject



17
18
19
20
21
# 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