bin/jsus in jsus-0.2.0 vs bin/jsus in jsus-0.2.1
- old
+ new
@@ -1,157 +1,153 @@
#!/usr/bin/env ruby
require 'rubygems'
-begin
- require 'jsus'
-rescue LoadError
- $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
- require "jsus"
+
+if File.exists?('./lib/jsus.rb') # override with local version of jsus
+ $:.unshift File.expand_path(Dir.pwd) + "/lib"
+elsif File.exists?(File.expand_path(File.dirname(__FILE__)) + "/../lib/jsus.rb")
+ $:.unshift File.expand_path(File.dirname(__FILE__)) + "/../lib"
end
+require 'jsus'
require "fileutils"
-require 'choice'
+require "optparse"
+
start_time = Time.now
-Choice.options do
- header "Jsus version #{Jsus.version}"
+options = {}
+cli = OptionParser.new do |opts|
+ opts.banner = "jsus #{Jsus.version}. Usage: jsus [options] <input_dir> <output_dir>"
- option 'input_directory', :required => true do
- short "-i"
- long "--input-directory=DIRECTORY"
- desc "Path to directory containing your package to compile."
+ opts.on('-i', '--input-directory [DIR]', '[DEPRECATED] path to input directory ') do |dir|
+ $stderr.puts "DEPRECATION NOTICE: please do not use -i command-line argument"
+ options[:input_dir] = dir
end
-
- option 'output_directory', :required => true do
- short "-o"
- long "--output-directory=DIRECTORY"
- desc "Path to directory to output the compiled package."
+
+ opts.on('-o', '--input-directory [DIR]', '[DEPRECATED] path to output directory ') do |dir|
+ $stderr.puts "DEPRECATION NOTICE: please do not use -o command-line argument"
+ options[:output_dir] = dir
end
+
+ opts.on('-d', '--with-dependencies [DEPS]', 'path to directory containing dependency packages') do |dir|
+ options[:deps_dir] = dir
+ end
- option "dependencies", :required => false do
- short "-d"
- long "--with-dependencies=DIRECTORY"
- desc "Path to directory containing packages this package relies on. " <<
- "If set, all the packages will be compiled into a single file."
+ opts.on('-g', '--generate-includes', 'generates includes.js file that you may use for ad-hoc requiring of dependencies') do
+ options[:generate_includes] = true
end
-
- option "without_scripts_info", :required => false do
- long "--without-scripts-info"
- desc "When this flag is set, jsus doesn't generate scripts.json" <<
- "file with general info about your package."
+
+ opts.on('--generate-docs [*CLASSES]', Array, "generate docs for some of the sources. When given empty array, defaults to /**/*") do |docs|
+ if !docs
+ options[:documented_classes] = ["/**/*"]
+ else
+ options[:documented_classes] = docs
+ end
end
-
- option "without_tree", :required => false do
- long "--without-tree"
- desc "When this flag is set, jsus doesn't generate tree.json file" <<
- "with tree structure of your package."
+
+ opts.on('--no-syntax-highlight', 'if you turned on docs generation, it will use syntax highlighting by default. This option prevents it') do
+ options[:no_syntax_highlight] = true
end
-
- option "generate_includes", :required => false do
- short "-g"
- long "--generate-includes=[ROOT]"
- desc "Generates includes.js file that you may use for ad-hoc requiring" <<
- "of the needed javascripts. Defaults to output_directory."
+
+ opts.on('--validate-with [*VALIDATORS]', Array, 'performs a check against some of the validators. Available validators: mooforge') do |validators|
+ options[:validators] = (validators || []).map {|v| v.downcase }
end
-
- option "benchmark", :required => false do
- long "--benchmark"
- short "-b"
- desc "Performs a benchmark, indicating how much time you needed to" <<
- "compile the package"
+
+ opts.on_tail('-v', '--verbose', 'verbose mode, shows various debug messages') do
+ options[:verbose] = true
end
- option "docs_classes", :required => false do
- default []
- long "--generate-docs *CLASSES"
- desc "Generate documentation for classes via murdoc. You need to use FULL PATHS, e.g.: " <<
- "/mootools/*, /LSD/*, /**/*"
-
+ opts.on_tail('-b', '--benchmark', 'shows time spent on various stages') do
+ options[:benchmark] = true
end
-
- option "no_syntax_highlight", :required => false do
- default false
- long "--no-syntax-highlight"
- desc "Disable syntax highlighting in murdoc. Greatly increases docs generation speed. " <<
- "Note: This option won't have any effect unless you have Pygments installed."
+
+ opts.on_tail('--without-scripts-info', 'do not generate scripts.json') do
+ options[:without_scripts_info] = true
end
-
- option "verbose", :required => false do
- default false
- short "-v"
- long "--verbose"
- desc "When verbose mode is enabled, some debug information is displayed. Defaults to false."
+
+ opts.on_tail('--without-tree-info', 'do not generate tree.json') do
+ options[:without_tree_info] = true
end
-
- option "validate_with", :required => false do
- default []
- long "--validate-with *VALIDATORS"
- desc "performs validation of the resulting source. " <<
- "Available validators: mooforge"
+
+
+
+ opts.on_tail('-h', '--help', 'Show this message') do
+ puts opts
+ exit
end
end
+cli.parse!
-compile_start_time = Time.now
+options[:input_dir] ||= ARGV[0]
+options[:output_dir] ||= ARGV[1]
-Jsus.verbose = Choice.choices[:verbose]
+if !(options[:input_dir] && options[:output_dir])
+ puts cli
+ exit
+end
+compile_start_time = Time.now
+
+Jsus.verbose = options[:verbose]
+
pool_load_start_time = Time.now
-pool = if Choice.choices[:dependencies]
- Jsus::Pool.new(Choice.choices[:dependencies])
+pool = if options[:deps_dir]
+ Jsus::Pool.new(options[:deps_dir])
else
Jsus::Pool.new
end
pool_load_finish_time = Time.now
-package = Jsus::Package.new(Choice.choices[:input_directory], :pool => pool)
-package.include_dependencies! if Choice.choices[:dependencies]
-output_directory = Choice.choices[:output_directory]
-package.compile(output_directory)
-package.generate_scripts_info(output_directory) unless Choice.choices[:without_scripts_info]
-package.generate_tree(output_directory) unless Choice.choices[:without_tree]
+package = Jsus::Package.new(options[:input_dir], :pool => pool)
+package.include_dependencies!
+output_dir = options[:output_dir]
+package.compile(output_dir)
+package.generate_scripts_info(output_dir) unless options[:without_scripts_info]
+package.generate_tree(output_dir) unless options[:without_tree_info]
# Validations
validators_map = {"mooforge" => Jsus::Validator::Mooforge}
-Choice.choices[:validate_with].each do |validator_name|
- if validator = validators_map[validator_name.downcase]
+(options[:validators] || []).each do |validator_name|
+ if validator = validators_map[validator_name]
errors = validator.new(pool.sources.to_a & package.source_files.to_a).validation_errors
unless errors.empty?
- puts "Validator found errors: "
+ puts "Validator #{validator_name} found errors: "
errors.each {|e| puts " * #{e}"}
end
else
puts "No such validator: #{validator_name}"
end
end
# Hack, hack, hack :[
-if Choice.choices[:generate_includes]
- root = Choice.choices[:generate_includes] == true ? Choice.choices[:output_directory] : Choice.choices[:generate_includes]
- File.open(File.join(Choice.choices[:output_directory], "includes.js"), "w") do |f|
+if options[:generate_includes]
+ File.open(File.join(output_dir, "includes.js"), "w") do |f|
c = Jsus::Container.new(*(package.source_files.to_a + package.linked_external_dependencies.to_a))
script = %{(function(prefix) {
var sources = %sources%;
for (var i = 0, j = sources.length; i < j; i++) document.write('<scr' + 'ipt src="' + (prefix || '') + sources[i] + '"></script>');
- })(window.prefix);}.sub("%sources%", JSON.pretty_generate(c.required_files(root)))
+ })(window.prefix);}.sub("%sources%", JSON.pretty_generate(c.required_files(output_dir)))
f.puts script
end
end
+docs_start_time = Time.now
# Generate documentation
-unless Choice.choices[:docs_classes].empty?
- documenter = Jsus::Documenter.new(:highlight_source => !Choice.choices[:no_syntax_highlight])
+if options[:documented_classes] && !options[:documented_classes].empty?
+ documenter = Jsus::Documenter.new(:highlight_source => !options[:no_syntax_highlight])
package.source_files.each {|source| documenter << source }
pool.sources.each {|source| documenter << source } if pool
- documenter.only(Choice.choices[:docs_classes]).generate(Choice.choices[:output_directory] + "/docs")
+ documenter.only(options[:documented_classes]).generate(output_dir + "/docs")
end
+docs_finish_time = Time.now
-
finish_time = Time.now
-if Choice.choices[:benchmark]
+if options[:benchmark]
puts "Benchmarking results:"
puts "Total execution time: #{format("%.3f" ,finish_time - start_time)}s"
puts ""
puts "Of them:"
puts "Pool preloading time: #{format("%.3f", pool_load_finish_time - pool_load_start_time)}s"
+ puts "Docs generation time: #{format("%.3f", docs_finish_time - docs_start_time)}s" if options[:documented_classes]
puts "Total compilation time: #{format("%.3f", finish_time - compile_start_time - (pool_load_finish_time - pool_load_start_time))}s"
end