Skip to content

Commit

Permalink
reorganizing Rakefile, adding check task using JSLint
Browse files Browse the repository at this point in the history
  • Loading branch information
gdagley committed Apr 30, 2009
1 parent 796464b commit 51771e4
Show file tree
Hide file tree
Showing 3 changed files with 532 additions and 36 deletions.
88 changes: 52 additions & 36 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,79 @@
require 'rake/clean'
require 'erb'
require 'BlueCloth'

LIBPATH = File.expand_path(File.dirname(__FILE__)) + File::SEPARATOR
CLEAN.include('lib')
CLOBBER.include('doc/*.html')

LIBPATH = File.expand_path(File.dirname(__FILE__))

#
# builds and tests
#
desc 'writes lib/xui.js and lib/xui-min.js from src then launches specs'
task :default do
task :default => :spec

desc 'writes out an uncompiled version of xui'
task :build do
write
min
spec
end
end

desc 'creates lib/xui-min.js (tho not obfuscates)'
task :min => :build do
puts 'minifying js'
min_file = File.join(LIBPATH, 'lib', 'xui-min.js')
doc_file = File.join(LIBPATH, 'lib', 'xui.js')
yui_jar = File.join(LIBPATH, 'util', 'yuicompressor-2.3.6.jar')
sh "java -jar #{yui_jar} --charset UTF-8 -o #{min_file} #{doc_file}"
end

desc 'opens up the specs'
task :spec => :min do
puts 'running automated test suite'
spec_file = File.join(LIBPATH, 'spec', 'index.html')
sh "open -a WebKit file://#{spec_file}"
sh "open -a '/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app' file://#{spec_file}"
end

desc 'use JSLint to validate source code'
task :check => :build do
puts 'checking js for lint'
doc_file = File.join(LIBPATH, 'lib', 'xui.js')
rhino_jar = File.join(LIBPATH, 'util', 'js.jar')
jslint_file = File.join(LIBPATH, 'util', 'jslint.js')
sh "java -classpath #{rhino_jar} org.mozilla.javascript.tools.shell.Main #{jslint_file} #{doc_file}"
end

#
# TODO open in MobileSafari, Fennec and MobileOpera
#
desc 'launches the semi official but seriously example app example'
task :example do
write unless File.exist? "#{ LIBPATH }#{ File::SEPARATOR }lib#{ File::SEPARATOR }xui.js"
sh "open -a WebKit #{ LIBPATH }/example/index.html"
task :example => :build do
example_file = File.join(LIBPATH, 'example', 'index.html')
sh "open -a WebKit #{example_file}"
end

#
# docs are inline to the code (as markdown)
#
desc 'bulds documentation from inline comments into README.md'
task :doc do
write
file = "#{ LIBPATH }#{ File::SEPARATOR }lib#{ File::SEPARATOR }xui.js"
sauce = File.open(file).read
task :doc => :build do
sauce = File.open(File.join(LIBPATH, 'lib', 'xui.js')).read
# fetches all multiline comments
comments = sauce.gsub( /\s+\/\/.*/,'' ).scan(/\/(?:\*(?:.)*?\*\/|\/[^\n]*)/m)
# removes comment debris
comments = comments.map{|r| r.gsub('*/','').gsub(/^\s+\* |\* |\/\*+|^\*|^\s+\*|^\s+\/\*+/, '')}
# build a readme
readme = comments.join("\n")
# write out the README.md
open("#{ LIBPATH }#{ File::SEPARATOR }README.md", 'w'){|f| f.puts(readme) }

open(File.join(LIBPATH, 'README.md'), 'w'){|f| f.puts(readme) }
# write out the doc/index.html
FileUtils.mkdir_p "#{ LIBPATH }#{ File::SEPARATOR }doc"
open("#{ LIBPATH }#{ File::SEPARATOR }doc#{ File::SEPARATOR }index.html", 'w'){|f| f.puts(BlueCloth.new(readme).to_html) }
FileUtils.mkdir_p(File.join(LIBPATH, 'doc'))
index_file = File.join(LIBPATH, 'doc', 'index.html')
open(index_file, 'w') { |f| f.puts(BlueCloth.new(readme).to_html) }
# launch docs in safari
sh "open -a WebKit #{ LIBPATH }#{ File::SEPARATOR }doc#{ File::SEPARATOR }index.html"
sh "open -a WebKit #{index_file}"
end


Expand All @@ -52,10 +82,10 @@ end
# writes out an uncompiled version of xui
def write
puts 'writing the full source into lib/xui.js'
path = "#{ LIBPATH }src#{ File::SEPARATOR }js#{ File::SEPARATOR }xui.js"
final = "#{ LIBPATH }lib#{ File::SEPARATOR }xui.js"
FileUtils.mkdir_p(File.join(LIBPATH, 'lib'))
path = File.join(LIBPATH, 'src', 'js', 'xui.js')
final = File.join(LIBPATH, 'lib', 'xui.js')
html = ERB.new(open(path).read).result
FileUtils.mkdir_p "#{ LIBPATH }lib"
open(final,'w'){|f| f.puts( html )}
end

Expand All @@ -68,7 +98,8 @@ end
def build_sub_libraries
s = ""
libs_to_build.each do |lib|
s << import("#{ LIBPATH }src#{ File::SEPARATOR }js#{ File::SEPARATOR }lib#{ File::SEPARATOR }#{ lib }.js")
lib_file = File.join(LIBPATH, 'src', 'js', 'lib', lib + '.js')
s << import(lib_file)
end
s
end
Expand All @@ -80,19 +111,4 @@ def import(lib)
open(lib) { |f| s << "\n#{f.read}\n\n" }
s.each_line {|l| r << " #{l}"}
r
end

# creates lib/xui-min.js (tho not obfuscates)
def min
puts 'minifying js'
min_file = "#{ LIBPATH }lib#{ File::SEPARATOR }xui-min.js"
doc_file = "#{ LIBPATH }lib#{ File::SEPARATOR }xui.js"
sh "java -jar #{LIBPATH}/util/yuicompressor-2.3.6.jar --charset UTF-8 -o #{min_file} #{doc_file}"
end

# opens up the specs
def spec
puts 'running automated test suite'
sh "open -a WebKit file://#{ LIBPATH }/spec/index.html"
sh "open -a '/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app' file://#{ LIBPATH }spec/index.html"
end
end
Binary file added util/js.jar
Binary file not shown.
Loading

0 comments on commit 51771e4

Please sign in to comment.