#!/usr/bin/env ruby require 'rubygems' require 'pathname' begin gem_home = Pathname.new(ENV["GEM_HOME"]).realpath.to_s current_dir = Pathname.new(__FILE__).realpath.dirname if current_dir.to_s.index(gem_home) != 0 && current_dir.join('../lib/jsus.rb').exist? # If we are outside gem home, # override whatever they got there # with local version of jsus $:.unshift((current_dir + "../lib").expand_path.to_s) end rescue Exception => e raise e # Something weird happened during our checks, # but it's probably nothing. end require 'jsus' require "optparse" Jsus.logger = Jsus::Util::Logger.new(STDOUT) Jsus.logger.formatter = lambda {|severity, time, progname, msg| prefix = case severity when /error/i, /fatal/i, /warn/i then "[#{severity}]: " else "" end "#{prefix}#{msg}\n" } options = {} cli = OptionParser.new do |opts| opts.banner = "jsus #{Jsus.version}. Usage: jsus [options] " opts.on('-i', '--input-directory [DIR]', '[DEPRECATED] path to input directory ') do |dir| Jsus.logger.warn "DEPRECATION NOTICE: please do not use -i command-line argument" options[:input_dir] = dir end opts.on('-o', '--output-directory [DIR]', '[DEPRECATED] path to output directory ') do |dir| Jsus.logger.warn "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 opts.on('-g', '--generate-includes [ROOT]', 'generates includes.js file that you may use for ad-hoc requiring of dependencies, defaults to output directory') do |dir| options[:generate_includes] = true options[:includes_root] = dir end 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 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 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 opts.on('--postproc [*PROCESSORS]', Array, 'performs postprocessing. Available postprocs:\n* moocompat12 -- removes mootools 1.2compat tags and their contents\n* mooltIE8 -- removes mootools ltIE8 compat tags and their contents') do |postprocs| options[:postproc] = postprocs end opts.on('--compress', 'compresses resulting file') do options[:compress] = true end opts.on('--compression-method [METHOD]', 'compression method: yui, closure, frontcompiler or uglifier') do |method| options[:compression_method] = method end opts.on_tail('-v', '--verbose', 'verbose mode, shows various debug messages') do Jsus.verbose = true end opts.on_tail('--very-verbose', 'very verbose mode, shows pool stats beside usual verbose stuff') do Jsus.verbose = true options[:display_pool_stats] = true end opts.on_tail('-b', '--benchmark', 'shows time spent on various stages') do options[:benchmark] = true end opts.on_tail('--without-scripts-info', 'do not generate scripts.json') do options[:without_scripts_info] = true end opts.on_tail('--without-tree-info', 'do not generate tree.json') do options[:without_tree_info] = true end opts.on_tail('--watch', 'watch file system events for *.js files in subdirectories and rerun jsus with the same parameters') do options[:watch] = true end opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end cli.parse! options[:input_dir] ||= ARGV[0] options[:output_dir] ||= ARGV[1] unless options[:input_dir] && options[:output_dir] puts cli exit end options[:input_dir] = File.expand_path(options[:input_dir]) options[:output_dir] = File.expand_path(options[:output_dir]) Jsus::CLI.run!(options)