breaking up distribution tasks; moving version to a template to have a simpler concat function

This commit is contained in:
Davis W. Frank
2011-06-14 08:30:14 -07:00
parent 2ba0aa371c
commit e59171935f
9 changed files with 93 additions and 23 deletions

View File

@@ -5,11 +5,20 @@ Dir["#{File.dirname(__FILE__)}/tasks/**/*.rb"].each do |file|
require file
end
task :default => :spec
task :require_pages_submodule do
raise "Submodule for Github Pages isn't present. Run git submodule update --init" unless File.exist?('pages/download.html')
end
task :require_node do
raise "\nNode.js is required to develop code for Jasmine. Please visit http://nodejs.org to install.\n\n" unless node_installed?
end
task :default => :spec
def node_installed?
`which node` =~ /node/
end
#namespace :jasmine do
#

View File

@@ -2467,5 +2467,5 @@ jasmine.version_= {
"major": 1,
"minor": 1,
"build": 0,
"revision": 1307978448
"revision": 1308065344
}

View File

@@ -0,0 +1,6 @@
jasmine.version_= {
"major": <%= major %>,
"minor": <%= minor %>,
"build": <%= build %>,
"revision": <%= revision %>
}

6
src/version.js Normal file
View File

@@ -0,0 +1,6 @@
jasmine.version_= {
"major": 1,
"minor": 1,
"build": 0,
"revision": 1308065344
}

View File

@@ -1,20 +1,20 @@
desc "Build core jasmine.js"
task :build_dist => :lint do
task :build_dist => [:lint, :write_version_file] do
puts 'Building Jasmine distribution from source'
concat_into('lib/jasmine.js') { [core_sources, version_source] }
require 'pp'
concat_into('lib/jasmine.js') { core_sources + version_source_file }
concat_into('lib/jasmine-html.js') { html_sources }
FileUtils.cp('src/html/jasmine.css', 'lib/jasmine.css')
end
def concat_into(output_file, &block)
files, extra = yield
files = yield
File.open(output_file, 'w') do |out|
files.each do |f|
out << File.read(f)
end
out << extra if extra
end
end
@@ -25,3 +25,20 @@ task :lint do
end
task :hint => :lint
task :write_version_file do
template = Tilt.new('src/templates/version.erb')
scope = OpenStruct.new(:major => version_hash["major"],
:minor => version_hash["minor"],
:build => version_hash["build"],
:revision => Time.now.to_i)
File.open('src/version.js', 'w+') do |f|
f << template.render(scope)
end
end
def version_source_file
Dir.glob('src/version.js')
end

View File

@@ -32,21 +32,6 @@ def version_string
"#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
end
def version_source
<<-JS
jasmine.version_= {
"major": #{version_hash['major'].to_json},
"minor": #{version_hash['minor'].to_json},
"build": #{version_hash['build'].to_json},
"revision": #{Time.now.to_i}
}
JS
end
def version_hash
@version ||= JSON.parse(File.new("src/core/version.json").read);
end
def node_installed?
`which node` =~ /node/
end
@version ||= JSON.parse(File.new("src/version.json").read);
end

13
tasks/pages.rb Normal file
View File

@@ -0,0 +1,13 @@
desc "Build the Github pages HTML"
task :build_pages => :require_pages_submodule do
Dir.chdir("pages") do
FileUtils.rm_r('pages_output') if File.exist?('pages_output')
Dir.chdir('pages_source') do
system("frank export ../pages_output")
end
puts "\n"
puts "Copying built website to the root of the gh-pages branch"
puts "\n\n"
system("cp -r pages_output/* .")
end
end

34
tasks/standalone.rb Normal file
View File

@@ -0,0 +1,34 @@
desc "Build example project"
task :build_example_project => :need_pages_submodule do
require 'tmpdir'
temp_dir = File.join(Dir.tmpdir, 'jasmine-standalone-project')
puts "Building Example Project in #{temp_dir}"
FileUtils.rm_r temp_dir if File.exist?(temp_dir)
Dir.mkdir(temp_dir)
root = File.expand_path(File.dirname(__FILE__))
FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir)
substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html"))
lib_dir = File.join(temp_dir, "lib/jasmine-#{jasmine_version}")
FileUtils.mkdir_p(lib_dir)
{
"lib/jasmine.js" => "jasmine.js",
"lib/jasmine-html.js" => "jasmine-html.js",
"src/html/jasmine.css" => "jasmine.css",
"MIT.LICENSE" => "MIT.LICENSE"
}.each_pair do |src, dest|
FileUtils.cp(File.join(root, src), File.join(lib_dir, dest))
end
dist_dir = File.join(root, 'pages/downloads')
zip_file_name = File.join(dist_dir, "jasmine-standalone-#{jasmine_version}.zip")
puts "Zipping Example Project and moving to #{zip_file_name}"
FileUtils.mkdir(dist_dir) unless File.exist?(dist_dir)
if File.exist?(zip_file_name)
puts "WARNING!!! #{zip_file_name} already exists!"
FileUtils.rm(zip_file_name)
end
exec "cd #{temp_dir} && zip -r #{zip_file_name} . -x .[a-zA-Z0-9]*"
end