Permalink
Browse files

add build system for easily make distributable version

  • Loading branch information...
1 parent e2665c1 commit 6b80408d8f003192618a0545232c98f06756245b @madrobby committed Jan 13, 2011
View
@@ -0,0 +1,67 @@
+require 'rake'
+
+DOMMONSTER_VERSION = "1.2.2"
+
+DOMMONSTER_ROOT = File.expand_path(File.dirname(__FILE__))
+DOMMONSTER_SRC_DIR = File.join(DOMMONSTER_ROOT, 'src')
+DOMMONSTER_DIST_DIR = File.join(DOMMONSTER_ROOT, 'dist')
+
+DOMMONSTER_FILES = [
+ File.join(DOMMONSTER_SRC_DIR,'dommonster.js'),
+]
+
+task :default => [:clean, :concat, :dist]
+
+desc "Clean the distribution directory."
+task :clean do
+ rm_rf DOMMONSTER_DIST_DIR
+ mkdir DOMMONSTER_DIST_DIR
+end
+
+def normalize_whitespace(filename)
+ contents = File.readlines(filename)
+ contents.each { |line| line.sub!(/\s+$/, "") }
+ File.open(filename, "w") do |file|
+ file.write contents.join("\n").sub(/(\n+)?\Z/m, "\n")
+ end
+end
+
+desc "Strip trailing whitespace and ensure each file ends with a newline"
+task :whitespace do
+ Dir["*", "src/**/*", "test/**/*", "examples/**/*"].each do |filename|
+ normalize_whitespace(filename) if File.file?(filename)
+ end
+end
+
+desc "Concatenate DOM Monster files to build a distributable dommonster.js file"
+task :concat => :whitespace do
+ File.open(File.join(DOMMONSTER_DIST_DIR,'dommonster.js'),"w") do |f|
+ f.puts DOMMONSTER_FILES.map{ |s| IO.read(s) }
+ end
+end
+
+def google_compiler(src, target)
+ puts "Minifying #{src} with Google Closure Compiler..."
+ `java -jar vendor/google-compiler/compiler.jar --js #{src} --summary_detail_level 3 --js_output_file #{target}`
+end
+
+def process_minified(src, target)
+ cp target, File.join(DOMMONSTER_DIST_DIR,'temp.js')
+ msize = File.size(File.join(DOMMONSTER_DIST_DIR,'temp.js'))
+ `gzip -9 #{File.join(DOMMONSTER_DIST_DIR,'temp.js')}`
+
+ osize = File.size(src)
+ dsize = File.size(File.join(DOMMONSTER_DIST_DIR,'temp.js.gz'))
+ rm_rf File.join(DOMMONSTER_DIST_DIR,'temp.js.gz')
+
+ puts "Original version: %.3fk" % (osize/1024.0)
+ puts "Minified: %.3fk" % (msize/1024.0)
+ puts "Minified and gzipped: %.3fk, compression factor %.3f" % [dsize/1024.0, osize/dsize.to_f]
+end
+
+desc "Generates a minified version for distribution."
+task :dist do
+ src, target = File.join(DOMMONSTER_DIST_DIR,'dommonster.js'), File.join(DOMMONSTER_DIST_DIR,'dommonster.min.js')
+ google_compiler src, target
+ process_minified src, target
+end
View
@@ -5,7 +5,7 @@
<meta http-equiv="imagetoolbar" content="no" />
<meta charset="utf-8" />
<style media="screen">
- body {
+ body {
font:14px/18px 'Lucida Grande', Verdana, sans-serif;
margin: 40px 0 25px 50px;
}
@@ -71,7 +71,7 @@
<p>
If there are problems, <b>DOM Monster</b> will point them out — and even make suggestions on how to fix ’em.
</p>
-
+
<p class="important">
Drag the
<script>
@@ -80,28 +80,28 @@
</script>
to your bookmarks bar! This version of the DOM Monster is loaded from your local development folder.
</p>
-
+
<p>
DOM Monster! is the brainchild of <a href="http://unicornfree.com/">Amy Hoy</a> and
was programmed by <a href="http://mir.aculo.us/">Thomas Fuchs</a>.
</p>
-
+
<p>
<em>We'll keep the DOM Monster! up to date</em> and feed it with the latest in page analyzing features for you! <em>You don't have to update or reinstall</em> the bookmarklet to always get the latest and greatest version! Be sure to drag the DOM Monster! to your bookmarks bar in <em>all browsers</em> you want to test in!
</p>
-
+
<p>
<em>The DOM Monster is open source.</em> Contribute your own tips and tests. Visit the <a href="http://github.com/madrobby/dom-monster">DOM Monster repository on GitHub</a>.
</p>
-
+
<p class="learn-more">
<a href="http://javascriptrocks.com/performance/"><img src="assets/jsrocks.png" alt="JavaScript Rocks!"></a>
Learn more about the DOM Monster! and how to deal with DOM and JavaScript performance issues!
- Grab a copy of our<br> <a href="http://javascriptrocks.com/performance/">JavaScript Rocks! performance ebook</a>.
+ Grab a copy of our<br> <a href="http://javascriptrocks.com/performance/">JavaScript Rocks! performance ebook</a>.
</p>
-
+
<p class="copyright starts-section">
Copyright © 2009-2011 <a href="http://unicornfree.com/">Amy Hoy</a> and <a href="http://mir.aculo.us/">Thomas Fuchs</a>
</p>
</body>
-</html>
+</html>
View
@@ -5,7 +5,7 @@
<meta http-equiv="imagetoolbar" content="no" />
<meta charset="utf-8" />
<style media="screen">
- body {
+ body {
font:14px/18px 'Lucida Grande', Verdana, sans-serif;
margin: 40px 0 25px 50px;
}
@@ -71,32 +71,32 @@
<p>
If there are problems, <b>DOM Monster</b> will point them out — and even make suggestions on how to fix ’em.
</p>
-
+
<p class="important">
Drag the <a class="bookmarklet" href="javascript:(function(){var%20script=document.createElement('script');script.src='http://mir.aculo.us/dom-monster/dommonster.js?'+Math.floor((+new Date)/(864e5));document.body.appendChild(script);})()">DOM Monster!</a> to your bookmarks bar!
</p>
-
+
<p>
DOM Monster! is the brainchild of <a href="http://unicornfree.com/">Amy Hoy</a> and
was programmed by <a href="http://mir.aculo.us/">Thomas Fuchs</a>.
</p>
-
+
<p>
<em>We'll keep the DOM Monster! up to date</em> and feed it with the latest in page analyzing features for you! <em>You don't have to update or reinstall</em> the bookmarklet to always get the latest and greatest version! Be sure to drag the DOM Monster! to your bookmarks bar in <em>all browsers</em> you want to test in!
</p>
-
+
<p>
<em>The DOM Monster is open source.</em> Contribute your own tips and tests. Visit the <a href="http://github.com/madrobby/dom-monster">DOM Monster repository on GitHub</a>.
</p>
-
+
<p class="learn-more">
<a href="http://javascriptrocks.com/performance/"><img src="assets/jsrocks.png" alt="JavaScript Rocks!"></a>
Learn more about the DOM Monster! and how to deal with DOM and JavaScript performance issues!
- Grab a copy of our<br> <a href="http://javascriptrocks.com/performance/">JavaScript Rocks! performance ebook</a>.
+ Grab a copy of our<br> <a href="http://javascriptrocks.com/performance/">JavaScript Rocks! performance ebook</a>.
</p>
-
+
<p class="copyright starts-section">
Copyright © 2009-2011 <a href="http://unicornfree.com/">Amy Hoy</a> and <a href="http://mir.aculo.us/">Thomas Fuchs</a>
</p>
</body>
-</html>
+</html>
Oops, something went wrong.

0 comments on commit 6b80408

Please sign in to comment.