Sha256: c4b3980432f4d81be2fc8615ba6f7154ade657f053437893ad645c7e7501316c

Contents?: true

Size: 1.51 KB

Versions: 32

Compression:

Stored size: 1.51 KB

Contents

require 'json'

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 data['publishConfig']['registry']
          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.gsub(/\/+$/,'')}/:_authToken=${NPM_API_KEY}"
        end
      end

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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
dpl-1.8.7.travis.1143.4 lib/dpl/provider/npm.rb
dpl-1.8.7.travis.1125.4 lib/dpl/provider/npm.rb
dpl-1.8.6.travis.1124.4 lib/dpl/provider/npm.rb
dpl-1.8.6 lib/dpl/provider/npm.rb
dpl-1.8.6.travis.1116.4 lib/dpl/provider/npm.rb
dpl-1.8.5 lib/dpl/provider/npm.rb
dpl-1.8.5.travis.1114.4 lib/dpl/provider/npm.rb
dpl-1.8.5.travis.1113.4 lib/dpl/provider/npm.rb
dpl-1.8.5.travis.1112.4 lib/dpl/provider/npm.rb
dpl-1.8.5.travis.1104.4 lib/dpl/provider/npm.rb
dpl-1.8.5.travis.1101.4 lib/dpl/provider/npm.rb
dpl-1.8.5.travis.1097.4 lib/dpl/provider/npm.rb
dpl-1.8.4 lib/dpl/provider/npm.rb
dpl-1.8.4.travis.1090.4 lib/dpl/provider/npm.rb
dpl-1.8.3 lib/dpl/provider/npm.rb
dpl-1.8.3.travis.1088.4 lib/dpl/provider/npm.rb
dpl-1.8.3.travis.1087.4 lib/dpl/provider/npm.rb
dpl-1.8.3.travis.1078.4 lib/dpl/provider/npm.rb
dpl-1.8.2 lib/dpl/provider/npm.rb
dpl-1.8.2.travis.1075.4 lib/dpl/provider/npm.rb