Sha256: 6604c68ae1e3d46e75e52eb89a8046698f9537cfdd26909707dacb44c4aeff9a

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

#!/usr/bin/env ruby

require 'auto_ali_cdn'

def help
  puts <<-EOB
2cdn v#{AutoAliCDN::VERSION}

Options:
  -h, --help        Show help
  -V, --version     Show program version

Basic usage:
  2cdn help    # Show help
  2cdn setup   # Init oss file paths
  2cdn upload  # Upload resources to Aliyun Oss
  2cdn debug   # Change resources path to local path
  EOB
end

def app_path
  @app_path ||= `pwd`.gsub("\n", '')
end

def config_file
  app_path+'/config/2cdn.yml'
end


if ARGV.empty? || ARGV[0] =~ /^(-h)|(--help)|(help)$/
  help
  exit
end

if ARGV[0] =~ /^(-v)|(--version)$/
  puts AutoAliCDN::VERSION
  exit
end

if ARGV[0] =~ /^setup$/
  (system "mkdir #{app_path}/config") unless File.directory?("#{app_path}/config")
  (system "mkdir #{app_path}/images") unless File.directory?("#{app_path}/images")
  (system "mkdir #{app_path}/javascripts") unless File.directory?("#{app_path}/javascripts")
  (system "mkdir #{app_path}/css") unless File.directory?("#{app_path}/css")
  system "touch #{config_file}"
  if File.read(config_file).length<=0
    File.open(config_file, 'w') do |f|
      f.puts <<-EOB
access_key_id: YOUR_ACCESS_ID
access_key_secret: YOUR_ACCESS_KEY
endpoint: YOUR_OSS_SERVICE_ADDRESS
domain_name: http://cdn.your.server.name
bucket: YOUR_BUCKET_NAME
site_resource_path: /sites/your.server.name
      EOB
    end
    puts "config/2cdn.yml init ok.\nPlease fillup the keys.\n#{`cat #{config_file}`}"
  end
  AutoAliCDN::Oss.oss_setup(config_file)
end

if ARGV[0] =~ /^upload$/

  unless File.exist?(config_file)
    puts "#{config_file} does not exist\nPlease run `2cdn init` first."
    exit
  end

  AutoAliCDN::Oss.oss_upload(config_file, app_path)
end

if ARGV[0] =~ /^debug$/
  AutoAliCDN::Oss.oss_debug(config_file, app_path)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
2cdn-0.1.7 bin/2cdn
2cdn-0.1.6 bin/2cdn
2cdn-0.1.5 bin/2cdn
2cdn-0.1.4 bin/2cdn
2cdn-0.1.3 bin/2cdn
2cdn-0.1.2 bin/2cdn