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, #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



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

def check_app
end

#check_authObject



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

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

#needs_key?Boolean

Returns:

  • (Boolean)


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

def needs_key?
  false
end

#package_registryObject



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

def package_registry
  if File.exists?('package.json')
    data = JSON.parse(File.read('package.json'))
    if data['publishConfig'] && data['publishConfig']['registry']
      return data['publishConfig']['registry']
    end
  end

  DEFAULT_NPM_REGISTRY
end

#push_appObject



27
28
29
30
31
32
# File 'lib/dpl/provider/npm.rb', line 27

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/"
  context.shell "env NPM_API_KEY=#{option(:api_key)} npm publish"
  FileUtils.rm(File.expand_path(NPMRC_FILE))
end

#setup_authObject



16
17
18
19
20
# File 'lib/dpl/provider/npm.rb', line 16

def setup_auth
  file = File.open(File.expand_path(NPMRC_FILE), 'w')
  file.puts("//#{package_registry}/:_authToken=${NPM_API_KEY}")
  file.flush
end