Merge pull request #2 from magicienap/master

Improving building tasks
This commit is contained in:
ericdrowell 2012-03-07 23:20:00 -08:00
commit 3525aecf6b
8 changed files with 88 additions and 58 deletions

View File

@ -1,5 +1,5 @@
source :rubygems
gem 'json-pure'
gem 'rake'
gem 'json_pure'
gem 'thor'
gem 'uglifier'

View File

@ -3,8 +3,9 @@ GEM
specs:
execjs (1.3.0)
multi_json (~> 1.0)
json_pure (1.6.5)
multi_json (1.1.0)
rake (0.9.2.2)
thor (0.14.6)
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
@ -13,5 +14,6 @@ PLATFORMS
ruby
DEPENDENCIES
rake
json_pure
thor
uglifier

View File

@ -12,7 +12,7 @@ Check out the official [KineticJS Tutorials](http://www.html5canvastutorials.com
# Building the library
To build the library, you need to have Ruby and Rubygems installed. After that, install the dependencies by running `bundle install`.
To build a development version of the library, run `rake build:dev`. To build a minify version of the library, run `rake build:prod`.
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is in the format MAJOR.MINOR.PATCH. To build a minify version of the library, run `thor build:prod VERSION`. If you want to add a release date other than the current day, use `-d="DATE"` (e.g. `-d="Mar 07 2012`).
# Adding a new file in the src directory
If you add a file in the src directory, add into the array in the Rakefile.
If you add a file in the src directory, add into the array in the Thorfile.

View File

@ -1,40 +0,0 @@
require 'json/pure'
# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory.
FILES = [
"license.js", "src/GlobalObject.js", "src/Node.js", "src/Container.js", "src/Stage.js",
"src/Layer.js", "src/Group.js", "src/geometries/Shape.js", "src/geometries/Rect.js", "src/geometries/Circle.js", "src/geometries/Image.js",
"src/geometries/Polygon.js", "src/geometries/RegularPolygon.js", "src/geometries/Star.js", "src/geometries/Text.js"
]
def concatenate
content = ""
FILES.each do |file|
content << IO.read(File.expand_path(file)) << "\n"
end
return content
end
namespace :build do
desc "Concatenate all the js files into /dist/kinetic.js."
task :dev do
puts ":: Building the file /dist/kinetic.js..."
File.open("dist/kinetic.js", "w") do |file|
file.puts concatenate()
end
puts " -> Done!"
end
desc "Concatenate all the js files in into /dist/kinetic.min.js and minify it."
task :prod do
puts ":: Building the file /dist/kinetic.min.js..."
require 'json/pure'
require 'uglifier'
File.open("dist/kinetic.min.js", "w") do |file|
file.puts Uglifier.compile(concatenate())
end
puts ":: Minifying the file /dist/kinetic.min.js..."
puts " -> Done!"
end
end

74
Thorfile Normal file
View File

@ -0,0 +1,74 @@
require 'json/pure'
class Build < Thor
# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory.
FILES = [
"license.js", "src/GlobalObject.js", "src/Node.js", "src/Container.js", "src/Stage.js",
"src/Layer.js", "src/Group.js", "src/geometries/Shape.js", "src/geometries/Rect.js", "src/geometries/Circle.js", "src/geometries/Image.js",
"src/geometries/Polygon.js", "src/geometries/RegularPolygon.js", "src/geometries/Star.js", "src/geometries/Text.js"
]
desc "dev", "Concatenate all the js files into /dist/kinetic-vVERSION.js."
method_option :date, aliases: "-d", required: false, type: :string, desc: "The release date"
def dev(version)
file_name = "dist/kinetic-v#{version}.js"
puts ":: Deleting other development files..."
Dir.foreach("dist") do |file|
if file.match(/kinetic-v.+\.(\d|\.)+\.js/)
File.delete("dist/" + file)
end
end
puts ":: Building the file /#{file_name}..."
File.open(file_name, "w") do |file|
file.puts concatenate(version, options[:date])
end
puts " -> Done!"
end
desc "prod", "Concatenate all the js files in into /dist/kinetic-vVERSION.min.js and minify it."
method_option :date, aliases: "-d", required: false, type: :string, desc: "The release date"
def prod(version)
file_name = "dist/kinetic-v#{version}.min.js"
puts ":: Deleting other development files..."
Dir.foreach("dist") do |file|
if file.match(/kinetic-v.+\.min\.js/)
File.delete("dist/" + file)
end
end
puts ":: Building the file /#{file_name}..."
require 'json/pure'
require 'uglifier'
File.open(file_name, "w") do |file|
uglify = Uglifier.compile(concatenate(version, options[:date]))
uglify.sub!(/\*\/ .+ \*\//xm, "*/")
file.puts uglify
end
puts ":: Minifying the file /#{file_name}..."
puts " -> Done!"
end
private
def concatenate(version, date)
date ||= Time.now.strftime("%b %d %Y")
content = ""
FILES.each do |file|
content << IO.read(File.expand_path(file)) << "\n"
end
# Add the version number
content.sub!("@version", version)
# Add the date
content.sub!("@date", date)
return content
end
end

View File

@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Mar 03 2012
* Date: Mar 07 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@ -25,6 +25,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
///////////////////////////////////////////////////////////////////////
// Global Object
///////////////////////////////////////////////////////////////////////

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,9 @@
/**
* KineticJS JavaScript Library v3.8.3
* KineticJS JavaScript Library v@version
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Mar 03 2012
* Date: @date
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*