Class: DPL::Provider::NPM
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::NPM
- Defined in:
- lib/dpl/provider/npm.rb
Constant Summary collapse
- NPMRC_FILE =
'~/.npmrc'
- DEFAULT_NPM_REGISTRY =
'registry.npmjs.org'
Instance Method Summary collapse
- #api_key ⇒ Object
- #check_app ⇒ Object
- #check_auth ⇒ Object
- #needs_key? ⇒ Boolean
- #npm_version ⇒ Object
- #npmrc_file_content ⇒ Object
- #package_registry ⇒ Object
- #push_app ⇒ Object
- #setup_auth ⇒ Object
Instance Method Details
#api_key ⇒ Object
63 64 65 |
# File 'lib/dpl/provider/npm.rb', line 63 def api_key option(:api_key, :api_token) end |
#check_app ⇒ Object
14 15 |
# File 'lib/dpl/provider/npm.rb', line 14 def check_app end |
#check_auth ⇒ Object
23 24 25 26 |
# 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? ⇒ Boolean
10 11 12 |
# File 'lib/dpl/provider/npm.rb', line 10 def needs_key? false end |
#npm_version ⇒ Object
59 60 61 |
# File 'lib/dpl/provider/npm.rb', line 59 def npm_version `npm --version` end |
#npmrc_file_content ⇒ Object
50 51 52 53 54 55 56 57 |
# 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 ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# 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.(NPMRC_FILE))}" command = "env NPM_API_KEY=#{api_key} npm publish" command << " --tag #{option(:tag)}" if [:tag] context.shell "#{command}" FileUtils.rm(File.(NPMRC_FILE)) end |
#setup_auth ⇒ Object
17 18 19 20 21 |
# File 'lib/dpl/provider/npm.rb', line 17 def setup_auth file = File.open(File.(NPMRC_FILE), 'w') file.puts(npmrc_file_content) file.flush end |