Davis W. Frank
2012-04-01 10:47:29 -07:00
parent 4a1a2123a3
commit 626da5a112
38 changed files with 1203 additions and 579 deletions

56
tasks/jasmine_dev/base.rb Normal file
View File

@@ -0,0 +1,56 @@
class JasmineDev < Thor
include Thor::Actions
def self.source_root
File.dirname(__FILE__)
end
def self.source_paths
[
File.join(JasmineDev.project_root, 'lib', 'jasmine-core'),
JasmineDev.project_root
]
end
def self.project_root
File.join(JasmineDev.source_root, '..', '..')
end
def self.spacer
"\n--------------------"
end
no_tasks do
# allows merged stdout in test with low-harassment
def run_with_output(*run_args)
say run *run_args
end
def node_installed?
return true if has_node?
say "Node.js is required to develop Jasmine. Please visit http://nodejs.org to install. ",
:red
false
end
def has_node?
run "which node", :verbose => false, :capture => true
last_exit_code = $?.to_s[-1]
last_exit_code == '0'
end
def pages_submodule_installed?
return true if has_pages_submodule?
say "Submodule for Github Pages isn't present. Run git submodule update --init",
:red
false
end
def has_pages_submodule?
File.exist?(File.join(JasmineDev.project_root, 'pages', 'download.html'))
end
end
end

View File

@@ -0,0 +1,66 @@
class JasmineDev < Thor
desc "build_distribution", "Build Jasmine js & css files"
def build_distribution(directory = "./lib/jasmine-core")
invoke :js_hint
say JasmineDev.spacer
say "Building Jasmine distribution from source into #{directory}", :cyan
say 'Building JavaScript...', :yellow
inside directory do
create_file "jasmine.js",
concat_contents_of(jasmine_js_paths),
:force => true
create_file "jasmine-html.js",
concat_contents_of(jasmine_html_js_paths),
:force => true
end
say 'Building CSS...', :yellow
run "compass compile", :capture => true
copy_file File.join("#{JasmineDev.project_root}", 'src', 'html', 'jasmine.css'),
File.join(directory, 'jasmine.css')
end
no_tasks do
def jasmine_js_paths
sources_list = File.read(File.join(JasmineDev.project_root, 'src', 'SourcesList.json'))
first_paths = JSON.parse(sources_list).collect do |f|
File.join(JasmineDev.project_root, 'src', 'core', f)
end
remaining_paths = Dir.glob(File.join(JasmineDev.project_root, 'src', 'core', '*.js'))
remaining_paths << File.join(JasmineDev.project_root, 'src', 'version.js')
add_only_new_elements(first_paths, remaining_paths)
end
def jasmine_html_js_paths
first_paths = []
first_paths << File.join(JasmineDev.project_root, 'src', 'html', 'HtmlReporterHelpers.js')
first_paths += Dir.glob(File.join('.', 'src', 'html', '*.js'))
remaining_paths = Dir.glob(File.join(JasmineDev.project_root, 'src', 'html', '*.js'))
add_only_new_elements(first_paths, remaining_paths)
end
def add_only_new_elements(first, remaining)
remaining.inject(first) do |result, element|
result << element unless result.include?(element)
result
end
end
def concat_contents_of(paths)
paths.inject("") do |string, path|
string << File.read(path)
string
end
end
end
end

View File

@@ -0,0 +1,18 @@
class JasmineDev < Thor
desc "build_github_pages", "Build static pages for pivotal.github.com/jasmine"
def build_github_pages(pages_dir = File.expand_path(File.join('.', 'pages')))
say JasmineDev.spacer
say "Building Github Pages...", :cyan
return unless pages_submodule_installed?
pages_output = File.join(pages_dir, 'pages_output')
FileUtils.rm_r(pages_output) if File.exist?(pages_output)
inside File.join('pages', 'pages_source') do
run_with_output "frank export #{pages_output}", :capture => true
end
end
end

View File

@@ -0,0 +1,49 @@
class JasmineDev < Thor
include Thor::Actions
desc "build_standalone_distribution", "Build Jasmine standalone distribution"
def build_standalone_distribution(download_dir = File.expand_path(File.join('.', 'pages', 'downloads')))
invoke :build_distribution
say JasmineDev.spacer
say "Building standalone distribution...", :cyan
say "Staging files...", :yellow
lib_files.each do |f|
copy_file f, File.join(standalone_temp_dir, 'lib', "jasmine-#{version_string}", f)
end
['src', 'spec'].each do |dir|
directory File.join('lib', 'jasmine-core', 'example', dir),
File.join(standalone_temp_dir, dir)
end
invoke :build_standalone_runner
say "Zipping distribution...", :yellow
inside standalone_temp_dir do
run_with_output "zip -rq ../jasmine-standalone-#{jasmine_version}.zip ."
say "Copying Zip file to downloads directory", :yellow
run "cp ../jasmine-standalone-#{jasmine_version}.zip #{download_dir}"
end
end
no_tasks do
def standalone_temp_dir
@standalone_temp_dir ||= File.join(Dir.tmpdir, 'jasmine_standalone', "jasmine-standalone-#{version_string}")
end
def lib_files
%w{ jasmine.js jasmine-html.js jasmine.css MIT.LICENSE }
end
def example_path
File.join('lib', "jasmine-#{version_string}")
end
end
end

View File

@@ -0,0 +1,59 @@
class JasmineDev < Thor
include Thor::Actions
desc "build_standalone_runner", "Build HTML spec runner for Jasmine standalone distribution"
def build_standalone_runner
say JasmineDev.spacer
say "Building standalone runner HTML...", :cyan
create_file File.join(standalone_temp_dir, 'SpecRunner.html') do
template = Tilt.new(File.join('spec', 'templates','runner.html.erb'))
scope = OpenStruct.new(:title => "Jasmine Spec Runner",
:favicon => example_favicon,
:jasmine_tags => example_jasmine_tags,
:source_tags => example_source_tags,
:spec_file_tags => example_spec_tags)
template.render(scope)
end
end
no_tasks do
def standalone_temp_dir
@standalone_temp_dir ||= File.join(Dir.tmpdir, 'jasmine_standalone', "jasmine-standalone-#{version_string}")
end
def example_path
File.join('lib', "jasmine-#{version_string}")
end
def example_favicon
%Q{<link rel="shortcut icon" type="image/png" href="#{example_path}/jasmine_favicon.png">}
end
def script_tags_for(files)
srcs = (files.is_a?(String) ? [files] : files)
srcs.inject([]) do |tags, file|
tags << %Q{<script type="text/javascript" src="#{file}"></script>}
tags
end.join("\n ")
end
def example_jasmine_tags
tags = %Q{<link rel="stylesheet" type="text/css" href="#{example_path}/jasmine.css">}
tags << "\n "
tags << script_tags_for(["#{example_path}/jasmine.js", "#{example_path}/jasmine-html.js"])
tags
end
def example_source_tags
script_tags_for ['spec/SpecHelper.js', 'spec/PlayerSpec.js']
end
def example_spec_tags
script_tags_for ['src/Player.js', 'src/Song.js']
end
end
end

View File

@@ -0,0 +1,29 @@
class JasmineDev < Thor
desc "count_specs", "Count the number of specs for each test runner"
def count_specs
say JasmineDev.spacer
say "Counting specs...", :cyan
core_spec_count = count_specs_in(File.join('spec', 'core'))
console_spec_count = count_specs_in(File.join('spec', 'console'))
html_spec_count = count_specs_in(File.join('spec', 'html'))
say "#{(core_spec_count + console_spec_count).to_s} ", :yellow
say "specs for Node.js runner (exclude DOM-related specs)"
say "#{(core_spec_count + console_spec_count + html_spec_count).to_s} ", :yellow
say "specs for Browser runner (all specs)"
say "\n"
say "Please verify that these numbers match the runner output."
end
no_tasks do
def count_specs_in(relative_path)
files = Dir.glob(File.join(JasmineDev.project_root, relative_path, '*.js'))
files.inject(0) do |count, file|
File.read(file).scan(/\sit\s*\(/) { |s| count += 1 }
count
end
end
end
end

View File

@@ -0,0 +1,52 @@
class JasmineDev < Thor
desc "execute_specs_in_node", "Run all relevant specs in Node.js"
def execute_specs_in_node
return unless node_installed?
invoke :build_distribution
invoke :count_specs
say JasmineDev.spacer
say "Running all appropriate specs via Node.js...", :cyan
with_color_option = Term::ANSIColor.coloring? ? "--color" : "--noColor"
run_with_output "node spec/node_suite.js #{with_color_option}", :capture => true
end
desc "execute_specs_in_browser", "Run all relevent specs in your default browser"
def execute_specs_in_browser
invoke :build_distribution
invoke :count_specs
say JasmineDev.spacer
say "Running all appropriate specs via the default web browser...", :cyan
open_specs_in_browser
end
desc "execute_specs", "Run all of Jasmine's specs"
def execute_specs
invoke :execute_specs_in_node
invoke :execute_specs_in_browser
end
no_tasks do
def open_specs_in_browser
require 'rbconfig'
case Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG['host_os']
when /linux/
run "xdg-open spec/runner.html"
else
run "open spec/runner.html"
end
end
end
end

View File

@@ -0,0 +1,13 @@
class JasmineDev < Thor
desc "js_hint", "Run Jasmine source through JSHint"
def js_hint
say JasmineDev.spacer
return unless node_installed?
say "Running JSHint on Jasmine source and specs...", :cyan
run_with_output "node jshint/run.js", :capture => true
end
end

View File

@@ -0,0 +1,16 @@
class JasmineDev < Thor
desc 'release_prep', "Update version and build distributions"
def release_prep
say JasmineDev.spacer
say "Building Release...", :cyan
return unless pages_submodule_installed?
invoke :write_version_files
invoke :build_distribution
invoke :build_standalone_distribution
invoke :build_github_pages
end
end

View File

@@ -0,0 +1,54 @@
class JasmineDev < Thor
desc "write_version_files", "Write out version files"
def write_version_files
say JasmineDev.spacer
say "Building version files", :cyan
scope = OpenStruct.new(:major => version_object["major"],
:minor => version_object["minor"],
:build => version_object["build"],
:release_candidate => version_object["release_candidate"],
:revision => Time.now.to_i)
js_template = Tilt.new(File.join(JasmineDev.project_root, 'src', 'templates', 'version.js.erb'))
create_file File.join(JasmineDev.project_root, 'src', 'version.js'), :force => true do
js_template.render(scope)
end
end
desc "display_version", "Display version currently stored in source"
def display_version
say "Current version information from src/version.json", :cyan
say "Display version: "
say "#{version_string}", :yellow
say "Version object: "
say "#{version_object_old}", :yellow
end
no_tasks do
def version
@version ||= File.read(File.join(JasmineDev.project_root, 'src', 'version.json'))
end
def version_string
display = "#{version_object['major']}.#{version_object['minor']}.#{version_object['build']}"
display += ".rc#{version_object['release_candidate']}" if version_object['release_candidate']
display
end
def version_object
@version_object ||= JSON.parse(version)
end
def version_object_old
version.gsub("\n", " ").
gsub(/\s+/, " ").
gsub(/\}\s+$/, "}")
end
end
end