Sha256: 418f303fcee64ff708ddc99b13addf8cfb10142b1cf15cc966b60ef016ecf1ea

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require 'aliyun/oss'

module Pod
  class Command
    class TuyaOssPublish < Command

      def archive
        pod_package_path = "#{@podspec.name}-#{@podspec.version}"
        file_path = "#{pod_package_path}.zip"
        UI.puts("Archiving #{file_path}")

        Dir.chdir(pod_package_path) do
          `rm -rf #{file_path}`
          `zip -ry #{file_path} Headers #{@podspec.available_platforms.map{|p| p.name}.join(" ")}`
        end

        return "#{pod_package_path}/#{file_path}"
      end

      def upload_to_oss(file_path, force)
        if not File.exist?(file_path)
          raise "#{file_path} not exists"
        end

        file_name = File.basename(file_path)
        object_key = "#{@oss_base_path}/#{file_name}"

        client = Aliyun::OSS::Client.new(
          :endpoint => @oss_endpoint,
          :access_key_id => @oss_access_key_id,
          :access_key_secret => @oss_access_key_secret)
        bucket = client.get_bucket(@oss_bucket_name)

        url = bucket.object_url(object_key, false)

        if bucket.object_exists?(object_key) && force == false
          # 正式版上传不覆盖
          raise "#{url} already exists" unless file_name.index(/\balpha|\bbeta|\brc|\bSNAPSHOT/)
        end

        UI.puts("Uploading #{file_path}")
        begin
          bucket.put_object(object_key, :file => file_path)
        rescue => exception
          UI.puts(exception)
          raise "#{file_name} upload failed."
        end

        puts(url)
        return url
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cocoapods-tuya-oss-publish-0.1.5 lib/cocoapods-tuya-oss-publish/command/upload.rb
cocoapods-tuya-oss-publish-0.1.4 lib/cocoapods-tuya-oss-publish/command/upload.rb
cocoapods-tuya-oss-publish-0.1.2 lib/cocoapods-tuya-oss-publish/command/upload.rb