Sha256: 7cdce2f6ae6a97ab23a928ed860b90f60c209e57c2b86b57ce870e90f21d2eed

Contents?: true

Size: 1.52 KB

Versions: 121

Compression:

Stored size: 1.52 KB

Contents

require 'json'
require 'uri'

module DPL
  class Provider
    class NPM < Provider
      NPMRC_FILE = '~/.npmrc'
      DEFAULT_NPM_REGISTRY = 'registry.npmjs.org'

      def needs_key?
        false
      end

      def check_app
      end

      def setup_auth
        file = File.open(File.expand_path(NPMRC_FILE), 'w')
        file.puts(npmrc_file_content)
        file.flush
      end

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

      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

      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

      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

      def npm_version
        `npm --version`
      end
    end
  end
end

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
dpl-1.8.26.travis.1753.3 lib/dpl/provider/npm.rb
dpl-1.8.25.travis.1743.3 lib/dpl/provider/npm.rb
dpl-1.8.25 lib/dpl/provider/npm.rb
dpl-1.8.24 lib/dpl/provider/npm.rb
dpl-1.8.24.travis.1718.3 lib/dpl/provider/npm.rb
dpl-1.8.24.travis.1715.3 lib/dpl/provider/npm.rb
dpl-1.8.24.travis.1709.3 lib/dpl/provider/npm.rb
dpl-1.8.23 lib/dpl/provider/npm.rb
dpl-1.8.23.travis.1706.3 lib/dpl/provider/npm.rb
dpl-1.8.23.travis.1701.3 lib/dpl/provider/npm.rb
dpl-1.8.23.travis.1694.3 lib/dpl/provider/npm.rb
dpl-1.8.22 lib/dpl/provider/npm.rb
dpl-1.8.22.travis.1692.3 lib/dpl/provider/npm.rb
dpl-1.8.22.travis.1686.3 lib/dpl/provider/npm.rb
dpl-1.8.21 lib/dpl/provider/npm.rb
dpl-1.8.22.travis.1670.3 lib/dpl/provider/npm.rb
dpl-1.8.21.travis.1669.3 lib/dpl/provider/npm.rb
dpl-1.8.21.travis.1668.3 lib/dpl/provider/npm.rb
dpl-1.8.20.travis.1666.3 lib/dpl/provider/npm.rb
dpl-1.8.20.travis.1667.3 lib/dpl/provider/npm.rb