From 207b76a880913f9e3ffb2c9f4921d50226563139 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 4 Nov 2013 10:06:26 -0800 Subject: [PATCH] Fix some Rake tasks, cleanup Rakefile --- Rakefile | 59 +++++++++++++++++++------------------- test/mustache-spec-test.js | 4 +-- test/spec | 1 - 3 files changed, 32 insertions(+), 32 deletions(-) delete mode 160000 test/spec diff --git a/Rakefile b/Rakefile index bc32175..c019087 100644 --- a/Rakefile +++ b/Rakefile @@ -3,66 +3,67 @@ require 'rake/clean' task :default => :test -ROOT = File.expand_path('..', __FILE__) -MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js')) +def minified_file + ENV['FILE'] || 'mustache.min.js' +end -def mustache_version - match = MUSTACHE_JS.match(/exports\.version = "([^"]+)";/) - match[1] +task :install_mocha do + sh "npm install -g mocha" if `which mocha`.empty? end -def minified_file - ENV['FILE'] || 'mustache.min.js' +task :install_uglify do + sh "npm install -g uglify-js" if `which uglifyjs`.empty? end -desc "Run all tests, requires vows (see http://vowsjs.org)" -task :test do - sh "vows --spec" +task :install_jshint do + sh "npm install -g jshint" if `which jshint`.empty? end -desc "Minify to #{minified_file}, requires UglifyJS (see http://marijnhaverbeke.nl/uglifyjs)" -task :minify do +desc "Run all tests" +task :test => :install_mocha do + sh "mocha test" +end + +desc "Make a compressed build in #{minified_file}" +task :minify => :install_uglify do sh "uglifyjs mustache.js > #{minified_file}" end -desc "Run JSHint, requires jshint (see http://www.jshint.com)" -task :lint do +desc "Run JSHint" +task :hint => :install_jshint do sh "jshint mustache.js" end # Creates a task that uses the various template wrappers to make a wrapped # output file. There is some extra complexity because Dojo and YUI use # different final locations. -def templated_build(name, opts={}) +def templated_build(name, final_location=nil) short = name.downcase source = File.join("wrappers", short) dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*") - target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js" - - CLEAN.include(opts[:location] ? opts[:location] : target_js) + target_js = final_location.nil? ? "#{short}.mustache.js" : "mustache.js" desc "Package for #{name}" task short.to_sym => dependencies do puts "Packaging for #{name}" - mkdir_p opts[:location] if opts[:location] + mkdir_p final_location unless final_location.nil? - files = [ - "#{source}/mustache.js.pre", - 'mustache.js', - "#{source}/mustache.js.post" - ] + sources = [ "#{source}/mustache.js.pre", 'mustache.js', "#{source}/mustache.js.post" ] + relative_name = "#{final_location || '.'}/#{target_js}" - open("#{opts[:location] || '.'}/#{target_js}", 'w') do |f| - files.each {|file| f << File.read(file) } + open(relative_name, 'w') do |f| + sources.each {|source| f << File.read(source) } end - puts "Done, see #{opts[:location] || '.'}/#{target_js}" + puts "Done, see #{relative_name}" end + + CLEAN.include(final_location.nil? ? target_js : final_location) end templated_build "jQuery" templated_build "MooTools" -templated_build "Dojo", :location => "dojox/string" -templated_build "YUI3", :location => "yui3/mustache" +templated_build "Dojo", "dojox/string" +templated_build "YUI3", "yui3/mustache" templated_build "qooxdoo" diff --git a/test/mustache-spec-test.js b/test/mustache-spec-test.js index 1050ea4..0c6e537 100644 --- a/test/mustache-spec-test.js +++ b/test/mustache-spec-test.js @@ -41,7 +41,7 @@ var noSkip = process.env.NOSKIP; // variable (e.g. TEST=interpolation mocha test/mustache-spec-test.js) var fileToRun = process.env.TEST; -// Mustache should work on node 0.6 that doesn't have fs.exisisSync +// Mustache should work on node 0.6 that doesn't have fs.existsSync function existsDir(path) { try { return fs.statSync(path).isDirectory(); @@ -86,4 +86,4 @@ describe('Mustache spec compliance', function() { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/spec b/test/spec deleted file mode 160000 index 72233f3..0000000 --- a/test/spec +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72233f3ffda9e33915fd3022d0a9ebbcce265acd