Skip to content
Browse files

new build system & sizes on readme

  • Loading branch information...
1 parent 259b2fa commit 4033016e95236f5a48cfcbbb148f168b5089287e @rvagg committed Nov 3, 2012
Showing with 63 additions and 28 deletions.
  1. +0 −26 Makefile
  2. +2 −0 README.md
  3. +56 −0 build.js
  4. +2 −0 package.json
  5. +1 −1 traversty.js
  6. +2 −1 traversty.min.js
View
26 Makefile
@@ -1,26 +0,0 @@
-.PHONY: build test server
-
-build:
- @echo "Minified size before: "
- @echo -n "\t"
- @du -b ./traversty.min.js
- @gzip ./traversty.min.js
- @echo -n "\t"
- @du -b ./traversty.min.js.gz
- @gunzip ./traversty.min.js.gz
- @jshint ./traversty.js
- @uglifyjs ./traversty.js > ./traversty.min.js
- @echo "Minified size after: "
- @echo -n "\t"
- @du -b ./traversty.min.js
- @gzip ./traversty.min.js
- @echo -n "\t"
- @du -b ./traversty.min.js.gz
- @gunzip ./traversty.min.js.gz
-
-test:
- buster test -R
-
-server:
- buster server &
-
View
2 README.md
@@ -2,6 +2,8 @@
Traversty is a library-agnostic DOM utility for traversal and element collection manipulation. Traversty doesn't provide any DOM manipulation features; instead, Traversty is used for managing collections of DOM elements and navigating the DOM.
+**Current file size:** 15.5 kB raw, 5.7 kB min, **2.1 kB gzip**
+
<a href="#api"><i>Just show me the API!</i></a>
## Traversal
View
56 build.js
@@ -0,0 +1,56 @@
+var fs = require('fs')
+ , gz = require('zlib').gzip
+ , colorsTmpl = require('colors-tmpl')
+ , uglify = require('uglify-js')
+
+ , inFile = 'traversty.js'
+ , outFile = 'traversty.min.js'
+ , readme = 'README.md'
+
+ , readmeContents = fs.readFileSync(readme).toString()
+ , rawContents = fs.readFileSync(inFile)
+ , copyright = rawContents.toString().match(/\/\*[\s\S]+?\*\//i)[0]
+ , minContentsPrev = fs.readFileSync(outFile)
+ , minContents = copyright + '\n' + uglify(rawContents.toString())
+
+ , sizes = {
+ raw: rawContents.length
+ , minPrev: minContentsPrev.length
+ , min: minContents.length
+ }
+
+ , s2s = function (size) {
+ size = Math.round(size / 1024 * 10) / 10;
+ return size + ' kB'
+ }
+
+sizes.min = minContents.length
+
+gz(minContentsPrev, function (err, gzContentsPrev) {
+ if (err) throw err;
+ gz(minContents, function (err, gzContents) {
+ if (err) throw err;
+
+ sizes.gz = gzContents.length
+ sizes.gzPrev = gzContentsPrev.length
+
+ for (var p in sizes) {
+ readmeContents = readmeContents.replace(
+ new RegExp(
+ '(?:(?:[\\d\\.]*|NaN)\\s*kB)\\s*(' + p + ')'
+ , 'g')
+ , s2s(sizes[p]) + ' $1');
+ }
+
+ fs.writeFileSync(outFile, minContents)
+ fs.writeFileSync(readme, readmeContents)
+
+ console.log(colorsTmpl(
+ '{bold}{green}Build successful!{/green}{/bold}\n'
+ + '\t{yellow}Previous min size:{/yellow} ' + sizes.minPrev + ' bytes\n'
+ + '\t{green}New min size :{/green} ' + sizes.min + ' bytes\n'
+ + '\t{yellow}Previous gz size :{/yellow} ' + sizes.gzPrev + ' bytes\n'
+ + '\t{green}New gz size :{/green} ' + sizes.gz + ' bytes'
+ ))
+ })
+})
View
2 package.json
@@ -15,6 +15,8 @@
}
, "devDependencies" : {
"buster" : "*"
+ , "uglify-js" : "*"
+ , "colors-tmpl" : "*"
}
, "license" : "MIT"
}
View
2 traversty.js
@@ -431,4 +431,4 @@
}())
return traversty
-}));
+}));
View
3 traversty.min.js
@@ -3,4 +3,5 @@
* (c) Rod Vagg (@rvagg) 2012
* https://github.com/rvagg/traversty
* License: MIT
- */!function(e,t){typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(e,t):this[e]=t()}("traversty",function(){var e=this,t=e.traversty,n=window.document,r=n.documentElement,i=Object.prototype.toString,s=Array.prototype,o=s.slice,u=function(e,t,n,r,i){while(r<t.length)if(e[i=t[r++]+n])return i}(r,["msM","webkitM","mozM","oM","m"],"atchesSelector",0),a=function(){return!1},f=function(e){return i.call(e)==="[object Number]"},l=function(e){return i.call(e)==="[object String]"},c=function(e){return i.call(e)==="[object Function]"},h=function(e){return e===void 0},p=function(e){return e&&e.nodeType===1},d=function(e,t){return h(e)&&!f(t)?0:f(e)?e:f(t)?t:null},v=function(e){return l(e)?e:"*"},m=function(e,t){return o.call(t.querySelectorAll(e),0)},g=function(e,t){return e==="*"||t[u](e)},y=m,b=g,w=function(e,t){return function(n,r){if(/,/.test(n)){var i=[],s=-1,o=r.getElementsByTagName("*");while(++s<o.length)p(o[s])&&t(n,o[s])&&i.push(o[s]);return i}return e(n,r)}},E="compareDocumentPosition"in r?function(e,t){return(t.compareDocumentPosition(e)&16)==16}:"contains"in r?function(e,t){return t=t.nodeType===9||t==window?r:t,t!==e&&t.contains(e)}:function(e,t){while(e=e.parentNode)if(e===t)return 1;return 0},S=function(e){var t=[],n=-1,r,i;while(++n<e.length){r=-1,i=!1;while(++r<t.length)if(t[r]===e[n]){i=!0;break}i||t.push(e[n])}return t},x=function(e,t){var n=[],r,i=0,s,o=e.length,u;while(i<o){s=0,u=(r=t(e[i],i++)).length;while(s<u)n.push(r[s++])}return n},T=function(e,t,n,r,i){return r=d(n,r),n=v(n),x(e,function(e,s){var o=r||0,u=[];i||(e=e[t]);while(e&&(r===null||o>=0))p(e)&&(!i||i===!0||i(e,s))&&b(n,e)&&(r===null||o--===0)&&(r===null&&t!=="nextSibling"?u=[e].concat(u):u.push(e)),e=e[t];return u})},N=function(e,t,n){return t<0&&(t=e+t),t<0||t>=e?null:!t&&t!==0?n:t},C=function(e,t){var n=[],r=0,i=e.length;for(;r<i;r++)t(e[r],r)&&n.push(e[r]);return n},k=function(e){var t;return p(e)?function(t){return t===e}:(t=typeof e)=="function"?function(t,n){return e.call(t,n)}:t=="string"&&e.length?function(t){return b(e,t)}:a},L=function(e){return function(){return!e.apply(this,arguments)}},A=function(){function r(e){this.length=0;if(e){e=S(!e.nodeType&&!h(e.length)?e:[e]);var t=this.length=e.length;while(t--)this[t]=e[t]}}function i(e){return new r(l(e)?y(e,n):e)}return r.prototype={down:function(e,t){return t=d(e,t),e=v(e),A(x(this,function(n){var r=y(e,n);return t===null?r:[r[t]]||[]}))},up:function(e,t){return A(T(this,"parentNode",e,t))},parents:function(){return r.prototype.up.apply(this,arguments.length?arguments:["*"])},closest:function(e,t){if(f(e))t=e,e="*";else{if(!l(e))return A([]);f(t)||(t=0)}return A(T(this,"parentNode",e,t,!0))},previous:function(e,t){return A(T(this,"previousSibling",e,t))},next:function(e,t){return A(T(this,"nextSibling",e,t))},siblings:function(e,t){var n=this,r=o.call(this,0),i=0,s=r.length;for(;i<s;i++){r[i]=r[i].parentNode.firstChild;while(!p(r[i]))r[i]=r[i].nextSibling}return h(e)&&(e="*"),A(T(r,"nextSibling",e||"*",t,function(e,t){return e!==n[t]}))},children:function(e,t){return A(T(r.prototype.down.call(this),"nextSibling",e||"*",t,!0))},first:function(){return r.prototype.eq.call(this,0)},last:function(){return r.prototype.eq.call(this,-1)},eq:function(e){return A(this.get(e))},get:function(e){return this[N(this.length,e,0)]},slice:function(e,t){var n=t,r=this.length,i=[];e=N(r,Math.max(-this.length,e),0),n=N(t<0?r:r+1,t,r),t=n===null||n>r?t<0?0:r:n;while(e!==null&&e<t)i.push(this[e++]);return A(i)},filter:function(e){return A(C(this,k(e)))},not:function(e){return A(C(this,L(k(e))))},has:function(e){return A(C(this,p(e)?function(t){return E(e,t)}:typeof e=="string"&&e.length?function(t){return y(e,t).length}:a))},is:function(e){var t=0,n=this.length,r=k(e);for(;t<n;t++)if(r(this[t],t))return!0;return!1},toArray:function(){return s.slice.call(this)},size:function(){return this.length},each:function(e,t){var n=0,r=this.length;for(;n<r;n++)e.call(t||this[n],this[n],n,this);return this},push:s.push,sort:s.sort,splice:s.splice},r.prototype.prev=r.prototype.previous,i.aug=function(e){var t,n;for(t in e)n=e[t],typeof n=="function"&&(r.prototype[t]=n)},i.setSelectorEngine=function(e){var t,r,s,o,u,a=n.createElement("p"),f=e.select||e.sel||e;a.innerHTML="<a/><i/><b/>",s=a.firstChild;try{o=c(e.matching)?function(t,n){return e.matching([n],t).length>0}:c(e.is)?function(t,n){return e.is(n,t)}:c(e.matchesSelector)?function(t,n){return e.matchesSelector(n,t)}:c(e.match)?function(t,n){return e.match(n,t)}:c(e.matches)?function(t,n){return e.matches(n,t)}:null,o||(t=e("a",a),o=c(t._is)?function(t,n){return e(n)._is(t)}:c(t.matching)?function(t,n){return e(n).matching(t).length>0}:c(t.is)&&!t.is.__ignore?function(t,n){return e(n).is(t)}:c(t.matchesSelector)?function(t,n){return e(n).matchesSelector(t)}:c(t.match)?function(t,n){return e(n).match(t)}:c(t.matches)?function(t,n){return e(n).matches(t)}:null);if(!o)throw new Error("Traversty: couldn't find selector engine's `matchesSelector`");if(o("x,y",a)||!o("a,p",a))throw new Error("Traversty: couldn't make selector engine's `matchesSelector` work");if((r=f("b,a",a)).length!==2)throw new Error("Traversty: don't know how to use this selector engine");u=r[0]===s?f:w(f,o);if((r=u("b,a",a)).length!==2||r[0]!==s)throw new Error("Traversty: couldn't make selector engine work");b=o,y=u}catch(h){throw l(h)?h:new Error("Traversty: error while figuring out how the selector engine works: "+(h.message||h))}finally{a=null}return i},i.noConflict=function(){return e.traversty=t,this},i}();return A});
+ */
+!function(e,t){typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(e,t):this[e]=t()}("traversty",function(){var e=this,t=e.traversty,n=window.document,r=n.documentElement,i=Object.prototype.toString,s=Array.prototype,o=s.slice,u=function(e,t,n,r,i){while(r<t.length)if(e[i=t[r++]+n])return i}(r,["msM","webkitM","mozM","oM","m"],"atchesSelector",0),a=function(){return!1},f=function(e){return i.call(e)==="[object Number]"},l=function(e){return i.call(e)==="[object String]"},c=function(e){return i.call(e)==="[object Function]"},h=function(e){return e===void 0},p=function(e){return e&&e.nodeType===1},d=function(e,t){return h(e)&&!f(t)?0:f(e)?e:f(t)?t:null},v=function(e){return l(e)?e:"*"},m=function(e,t){return o.call(t.querySelectorAll(e),0)},g=function(e,t){return e==="*"||t[u](e)},y=m,b=g,w=function(e,t){return function(n,r){if(/,/.test(n)){var i=[],s=-1,o=r.getElementsByTagName("*");while(++s<o.length)p(o[s])&&t(n,o[s])&&i.push(o[s]);return i}return e(n,r)}},E="compareDocumentPosition"in r?function(e,t){return(t.compareDocumentPosition(e)&16)==16}:"contains"in r?function(e,t){return t=t.nodeType===9||t==window?r:t,t!==e&&t.contains(e)}:function(e,t){while(e=e.parentNode)if(e===t)return 1;return 0},S=function(e){var t=[],n=-1,r,i;while(++n<e.length){r=-1,i=!1;while(++r<t.length)if(t[r]===e[n]){i=!0;break}i||t.push(e[n])}return t},x=function(e,t){var n=[],r,i=0,s,o=e.length,u;while(i<o){s=0,u=(r=t(e[i],i++)).length;while(s<u)n.push(r[s++])}return n},T=function(e,t,n,r,i){return r=d(n,r),n=v(n),x(e,function(e,s){var o=r||0,u=[];i||(e=e[t]);while(e&&(r===null||o>=0))p(e)&&(!i||i===!0||i(e,s))&&b(n,e)&&(r===null||o--===0)&&(r===null&&t!=="nextSibling"?u=[e].concat(u):u.push(e)),e=e[t];return u})},N=function(e,t,n){return t<0&&(t=e+t),t<0||t>=e?null:!t&&t!==0?n:t},C=function(e,t){var n=[],r=0,i=e.length;for(;r<i;r++)t(e[r],r)&&n.push(e[r]);return n},k=function(e){var t;return p(e)?function(t){return t===e}:(t=typeof e)=="function"?function(t,n){return e.call(t,n)}:t=="string"&&e.length?function(t){return b(e,t)}:a},L=function(e){return function(){return!e.apply(this,arguments)}},A=function(){function r(e){this.length=0;if(e){e=S(!e.nodeType&&!h(e.length)?e:[e]);var t=this.length=e.length;while(t--)this[t]=e[t]}}function i(e){return new r(l(e)?y(e,n):e)}return r.prototype={down:function(e,t){return t=d(e,t),e=v(e),A(x(this,function(n){var r=y(e,n);return t===null?r:[r[t]]||[]}))},up:function(e,t){return A(T(this,"parentNode",e,t))},parents:function(){return r.prototype.up.apply(this,arguments.length?arguments:["*"])},closest:function(e,t){if(f(e))t=e,e="*";else{if(!l(e))return A([]);f(t)||(t=0)}return A(T(this,"parentNode",e,t,!0))},previous:function(e,t){return A(T(this,"previousSibling",e,t))},next:function(e,t){return A(T(this,"nextSibling",e,t))},siblings:function(e,t){var n=this,r=o.call(this,0),i=0,s=r.length;for(;i<s;i++){r[i]=r[i].parentNode.firstChild;while(!p(r[i]))r[i]=r[i].nextSibling}return h(e)&&(e="*"),A(T(r,"nextSibling",e||"*",t,function(e,t){return e!==n[t]}))},children:function(e,t){return A(T(r.prototype.down.call(this),"nextSibling",e||"*",t,!0))},first:function(){return r.prototype.eq.call(this,0)},last:function(){return r.prototype.eq.call(this,-1)},eq:function(e){return A(this.get(e))},get:function(e){return this[N(this.length,e,0)]},slice:function(e,t){var n=t,r=this.length,i=[];e=N(r,Math.max(-this.length,e),0),n=N(t<0?r:r+1,t,r),t=n===null||n>r?t<0?0:r:n;while(e!==null&&e<t)i.push(this[e++]);return A(i)},filter:function(e){return A(C(this,k(e)))},not:function(e){return A(C(this,L(k(e))))},has:function(e){return A(C(this,p(e)?function(t){return E(e,t)}:typeof e=="string"&&e.length?function(t){return y(e,t).length}:a))},is:function(e){var t=0,n=this.length,r=k(e);for(;t<n;t++)if(r(this[t],t))return!0;return!1},toArray:function(){return s.slice.call(this)},size:function(){return this.length},each:function(e,t){var n=0,r=this.length;for(;n<r;n++)e.call(t||this[n],this[n],n,this);return this},push:s.push,sort:s.sort,splice:s.splice},r.prototype.prev=r.prototype.previous,i.aug=function(e){var t,n;for(t in e)n=e[t],typeof n=="function"&&(r.prototype[t]=n)},i.setSelectorEngine=function(e){var t,r,s,o,u,a=n.createElement("p"),f=e.select||e.sel||e;a.innerHTML="<a/><i/><b/>",s=a.firstChild;try{o=c(e.matching)?function(t,n){return e.matching([n],t).length>0}:c(e.is)?function(t,n){return e.is(n,t)}:c(e.matchesSelector)?function(t,n){return e.matchesSelector(n,t)}:c(e.match)?function(t,n){return e.match(n,t)}:c(e.matches)?function(t,n){return e.matches(n,t)}:null,o||(t=e("a",a),o=c(t._is)?function(t,n){return e(n)._is(t)}:c(t.matching)?function(t,n){return e(n).matching(t).length>0}:c(t.is)&&!t.is.__ignore?function(t,n){return e(n).is(t)}:c(t.matchesSelector)?function(t,n){return e(n).matchesSelector(t)}:c(t.match)?function(t,n){return e(n).match(t)}:c(t.matches)?function(t,n){return e(n).matches(t)}:null);if(!o)throw new Error("Traversty: couldn't find selector engine's `matchesSelector`");if(o("x,y",a)||!o("a,p",a))throw new Error("Traversty: couldn't make selector engine's `matchesSelector` work");if((r=f("b,a",a)).length!==2)throw new Error("Traversty: don't know how to use this selector engine");u=r[0]===s?f:w(f,o);if((r=u("b,a",a)).length!==2||r[0]!==s)throw new Error("Traversty: couldn't make selector engine work");b=o,y=u}catch(h){throw l(h)?h:new Error("Traversty: error while figuring out how the selector engine works: "+(h.message||h))}finally{a=null}return i},i.noConflict=function(){return e.traversty=t,this},i}();return A})

0 comments on commit 4033016

Please sign in to comment.
Something went wrong with that request. Please try again.