1#!/usr/bin/ruby
2
3require 'fileutils'
4
5def usage
6  puts "usage: #{File.basename $0} <destination-to-update>"
7  puts
8  puts "<destination-to-update> values:"
9  puts
10  puts "  Tools         - Copy the UserInterface files to the Tools directory"
11  puts "  UserInterface - Copy the Tools files to the UserInterface directory"
12  exit 1
13end
14
15if ARGV.size != 1
16  usage
17end
18
19destination = ARGV[0]
20if destination != "Tools" && destination != "UserInterface"
21  usage
22end
23
24# Copy the formatter and CodeMirror files from UserInterface to Tools.
25USER_INTERFACE_TO_TOOLS_MAP = {
26  "UserInterface/Views/CodeMirrorFormatters.js"          => "Tools/PrettyPrinting/CodeMirrorFormatters.js",
27  "UserInterface/Controllers/Formatter.js"               => "Tools/PrettyPrinting/Formatter.js",
28  "UserInterface/Controllers/FormatterContentBuilder.js" => "Tools/PrettyPrinting/FormatterContentBuilder.js",
29
30  "UserInterface/External/CodeMirror/codemirror.css"     => "Tools/PrettyPrinting/codemirror.css",
31  "UserInterface/External/CodeMirror/codemirror.js"      => "Tools/PrettyPrinting/codemirror.js",
32  "UserInterface/External/CodeMirror/javascript.js"      => "Tools/PrettyPrinting/javascript.js",
33  "UserInterface/External/CodeMirror/css.js"             => "Tools/PrettyPrinting/css.js",
34}
35
36# Copy only the formatter files from Tools to UserInterface.
37TOOLS_TO_USER_INTERFACE_MAP = {
38  "Tools/PrettyPrinting/CodeMirrorFormatters.js"         => "UserInterface/Views/CodeMirrorFormatters.js",
39  "Tools/PrettyPrinting/Formatter.js"                    => "UserInterface/Controllers/Formatter.js",
40  "Tools/PrettyPrinting/FormatterContentBuilder.js"      => "UserInterface/Controllers/FormatterContentBuilder.js"
41}
42
43web_inspector_path = File.expand_path File.join(File.dirname(__FILE__), "..")
44map = destination == "Tools" ? USER_INTERFACE_TO_TOOLS_MAP : TOOLS_TO_USER_INTERFACE_MAP
45
46all_success = true
47
48map.each do |from, to|
49  from_path = File.join web_inspector_path, from
50  to_path = File.join web_inspector_path, to
51  begin
52    puts "Copying #{from} to #{to}..."
53    FileUtils.cp from_path, to_path
54  rescue Exception => e
55    puts "WARNING: #{e}"
56    all_success = false
57  end
58end
59
60exit all_success ? 0 : 1
61