Class: Closure::Compiler
- Inherits:
-
Object
- Object
- Closure::Compiler
- Defined in:
- lib/closure/compiler.rb
Defined Under Namespace
Classes: Compilation, Error
Constant Summary
- OUTPUT_OPTIONS =
These are filename options and will be expanded to a new base.
--js_output_file --create_source_map --output_manifest --property_map_output_file --variable_map_output_file --module_output_path_prefix }
- INPUT_OPTIONS =
These are filename options and will be expanded to a new base. These will have their modification times checked against js_output_file.
--js --externs --property_map_input_file --variable_map_input_file }
Class Method Summary (collapse)
-
+ compile(args, dependencies = [], env = {})
Compile Javascript.
Class Method Details
+ compile(args, dependencies = [], env = {})
Compile Javascript. Checks file modification times but does not support namespaces like Goog#compile does.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/closure/compiler.rb', line 50 def self.compile(args, dependencies = [], env = {}) if Util.arg_values(args, '--js').empty? return Compilation.new env, nil, 'No source javascript specified' end # We don't bother compiling if we can detect that no sources were modified js_output_file = Util.arg_values(args, '--js_output_file').last if js_output_file js_mtime = File.mtime js_output_file rescue Errno::ENOENT compiled = !!File.size?(js_output_file) # catches empty files too files = Util.arg_values(args, INPUT_OPTIONS) + dependencies files.each do |filename| break unless compiled mtime = File.mtime filename compiled = false if !mtime or mtime > js_mtime end if compiled return Compilation.new env, js_output_file end File.unlink js_output_file rescue Errno::ENOENT end stdout, log = Closure.run_java Closure.config.compiler_jar, 'com.google.javascript.jscomp.CommandLineRunner', args if log.empty? log = nil else # Totals at the end make sense for the command line. But at # the start makes more sense for html and the Javascript console split_log = log.split("\n") if split_log.last =~ /^\d+ err/i = split_log.pop else = split_log.shift end if split_log.empty? log = else log = + "\n\n" + split_log.join("\n") end raise Error, log unless =~ /^0 err/i end Compilation.new(env, js_output_file, log) << stdout end |