#!/usr/bin/env ruby
# encoding: utf-8
#

# Note: This is a coder file. It generates the min js and tarred packages for download by end users.
#

# Javascripts
#
picky_files = %w{
  extensions
  translations
  data
  view
  backend
  controller
  client
  addination
  results_renderer
  allocation_renderer
  allocations_cloud
}.map { |name| "javascripts/source/picky.#{name}.js" }

js = picky_files.map { |filename| "--js=#{filename}" }.join(' ')
compiler_command = "java -jar javascripts/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS #{js} --js_output_file=javascripts/picky.min.js"
puts compiler_command
system compiler_command

# Copy the latest javascripts into the generators' js directory.
#
min_js_copy_command = "cp javascripts/*.min.js ../generators/prototypes/shared/client/javascripts/"
puts min_js_copy_command
system min_js_copy_command

# Copy the latest javascripts into the test project.
#
min_js_copy_command = "cp javascripts/source/picky.*.js test_project/javascripts/"
puts min_js_copy_command
system min_js_copy_command
min_js_copy_command = "cp javascripts/{history,jquery}*.min.js test_project/javascripts/"
puts min_js_copy_command
system min_js_copy_command

# Tar the js files for downloads.
#
gzip_command = "tar -cf javascripts/picky.source.js.tar #{picky_files.join(' ')}"
puts gzip_command
system gzip_command

# Stylesheets
#
# Copied into the test project.
# Copied also into the generator prototypes.
#
stylesheets_command = <<-STYLESHEETS
# sass -C test_project/stylesheets/picky.sass test_project/stylesheets/picky.css;
# sass -C test_project/stylesheets/application.sass test_project/stylesheets/application.css;
# cp test_project/stylesheets/picky.css ../generators/prototypes/client/sinatra/stylesheets/picky.css;
# cp test_project/stylesheets/application.css ../generators/prototypes/client/sinatra/stylesheets/application.css;
STYLESHEETS
puts stylesheets_command
system stylesheets_command

puts "\nSUCCESS!"