Skip to content

Instantly share code, notes, and snippets.

@rozd
Created July 29, 2016 09:13
Show Gist options
  • Save rozd/0c8f4a47ea72bf0b958f9f416792da14 to your computer and use it in GitHub Desktop.
Save rozd/0c8f4a47ea72bf0b958f9f416792da14 to your computer and use it in GitHub Desktop.
Starling-Framework/util/idea/copy_resources.rb
#!/usr/bin/ruby
require "rexml/document"
require "fileutils"
include REXML
platforms = ["ios", "android", "air-desktop"]
script_name = File.basename(__FILE__)
if ARGV.count < 3
puts "Usage: #{script_name} module.iml platform build_configuration_name"
puts " (platform being one of: #{platforms.join(', ')})"
exit
end
module_file = ARGV[0]
platform = ARGV[1].downcase
configuration_name = ARGV[2]
unless (platforms.include? platform)
puts "Invalid platform: #{platform}"
exit
end
unless File.exist?(module_file)
puts "Module file not found: #{module_file}"
exit
end
puts "Copying resources for #{File.basename(module_file)} (#{platform})"
module_dir = File.dirname(module_file)
module_doc = Document.new(File.open(module_file))
configuration = XPath.first(module_doc, "//configuration[@name='#{configuration_name}']")
output_folder = configuration.attributes["output-folder"].gsub("$MODULE_DIR$", module_dir)
XPath.each(module_doc, "//packaging-#{platform}/files-to-package/FilePathAndPathInPackage") do |entry|
file_path = entry.attributes["file-path"].gsub("$MODULE_DIR$", module_dir)
path_in_package = entry.attributes["path-in-package"]
if File.directory?(file_path)
file_path = File.join(file_path, ".")
end
puts " #{File.expand_path(file_path)} -> #{path_in_package}"
FileUtils.cp_r file_path, File.join(output_folder, path_in_package)
end
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment