bin/2cdn in 2cdn-0.1.0 vs bin/2cdn in 2cdn-0.1.2

- old
+ new

@@ -10,23 +10,65 @@ -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$/ - puts "current_path:#{`pwd`}" + + 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 \ No newline at end of file