require 'json' require "yard" require 'rake/testtask' require 'rubygems' require 'gems' require 'fileutils' Rake::TestTask.new do |t| t.pattern = "spec/*.rb" end lib_dir = 'lib' gen_dir = 'gen' task :clean do rm_rf gen_dir rm_rf lib_dir end YARD::Rake::YardocTask.new do |t| YARD::Templates::Engine.register_template_path 'doc/template' t.files = ['lib/**/*.rb', '-', 'README.md'] t.options = ['--output-dir','doc_out', '-p', 'doc/template'] end GEM_VERSION = ENV['SDK_VERSION'] ||= "0.0.0" task :buildgem do Dir.mkdir(gen_dir) unless File.exists?(gen_dir) `gem build PureCloud.gemspec` FileUtils.mv "purecloud-#{GEM_VERSION}.gem", "#{gen_dir}" end task :generate do codegenConfig = { "gemVersion" => GEM_VERSION, "gemName" => "purecloud", "moduleName" => "PureCloud", "gemLicense" => "MIT", "gemSummary" => "PureCloud Platform API Library", "gemDescription" => "A Ruby library to interface with the PureCloud Platform API", "gemHomepage" => "http://developer.mypurecloud.com", "gemAuthor" => "Kevin Glinski", "gemAuthorEmail" => "Kevin.Glinski@inin.com" } File.open("config-ruby.json", 'w') { |file| file.write(codegenConfig.to_json) } `java -jar external/swagger-codegen-cli.jar generate -i ./swagger.json -l ruby -c config-ruby.json` Dir.glob('*.gemspec') do |filepath| IO.write(filepath, File.open(filepath) {|f| f.read.gsub(/s\.files.*$/, 's.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? && !f.include?("node_module") }')}) end #HACK!! #PureCloud.const_get caused a runtime exception, replacing it with #not sure if this a ruby versioning issue or what #Object.const_get("PureCloud").const_get fixes it up. Dir.glob('lib/**/*.rb') do |filepath| IO.write(filepath, File.open(filepath) {|f| f.read.gsub(/PureCloud\.const_get/, "Object.const_get(\"PureCloud\").const_get")}) end `cat lib/purecloud.rb extensions/auth.rb > lib/purecloud.tmp` `mv lib/purecloud.tmp lib/purecloud.rb` end task :rename_and_zip do Dir.glob('doc_out/index.html') do |filepath| IO.write(filepath, File.open(filepath) {|f| f.read.gsub(/title:.*/, 'title: Ruby SDK Home')}) end Dir.glob('doc_out/**/*.html') do |filepath| IO.write(filepath, File.open(filepath) {|f| f.read.gsub(/(title:\s+\w+):\s+(.*)/, '\1 - \2').gsub(/PureCloud::/, '')}) end Dir.glob("doc_out/**/*.html") do |f| #filename = File.basename(f, File.extname(f)) File.rename(f, f + ".erb") end end task :release do version = ENV['SDK_VERSION'] puts "releasing #{version}" Gems.configure do |config| config.key = ENV['GEM_KEY'] end puts Gems.push File.new "gen/purecloud-#{version}.gem" end task :doc => [:yard, :rename_and_zip] task :default => [:clean, :generate, :buildgem]# :test,