Commit 4c5bbb56 authored by Yehuda Katz's avatar Yehuda Katz

Merge branch 'build-using-es6-module-transpiler' of...

Merge branch 'build-using-es6-module-transpiler' of https://github.com/eventualbuddha/rsvp.js into eventualbuddha-build-using-es6-module-transpiler

Conflicts:
	browser/rsvp.min.js
parents 33b00c23 f358d910
# A sample Gemfile
source "https://rubygems.org" source "https://rubygems.org"
gem "js_module_transpiler", github: "wycats/js_module_transpiler", branch: "master"
gem "rake" gem "rake"
GIT
remote: git://github.com/wycats/js_module_transpiler.git
revision: c9f0ada0f7b7ec654ddec25f4a1fb07bcf41c9f7
branch: master
specs:
js_module_transpiler (0.0.1)
thor
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
rake (10.0.2) rake (10.0.2)
thor (0.16.0)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
js_module_transpiler!
rake rake
require "bundler/setup" require "bundler/setup"
require "js_module_transpiler"
ENV['PATH'] = "#{Dir.pwd}/node_modules/.bin:#{ENV['PATH']}"
directory "browser" directory "browser"
directory "node_modules/rsvp" directory "node_modules/rsvp"
...@@ -16,9 +17,7 @@ def amd_module(filename) ...@@ -16,9 +17,7 @@ def amd_module(filename)
library = File.read(input) library = File.read(input)
open output, "w" do |file| open output, "w" do |file|
require "js_module_transpiler" file.puts %x{compile-modules --type amd --anonymous -s < #{input}}
converter = JsModuleTranspiler::Compiler.new(library)
file.puts converter.to_amd
end end
end end
...@@ -32,9 +31,7 @@ def node_module(filename, output="node_modules/rsvp/#{filename}.js") ...@@ -32,9 +31,7 @@ def node_module(filename, output="node_modules/rsvp/#{filename}.js")
library = File.read(input) library = File.read(input)
open output, "w" do |file| open output, "w" do |file|
require "js_module_transpiler" file.puts %x{compile-modules --type cjs --anonymous -s < #{input}}
converter = JsModuleTranspiler::Compiler.new(library)
file.puts converter.to_cjs
end end
end end
...@@ -83,16 +80,28 @@ file node_main => ["node_modules/rsvp", node_async, node_events] ...@@ -83,16 +80,28 @@ file node_main => ["node_modules/rsvp", node_async, node_events]
# Minified build # Minified build
file "browser/rsvp.min.js" => "browser/rsvp.js" do file "browser/rsvp.min.js" => "browser/rsvp.js" do
output = `cat browser/rsvp.js | uglifyjs` output = `uglifyjs browser/rsvp.js --mangle`
open "browser/rsvp.min.js", "w" do |file| open "browser/rsvp.min.js", "w" do |file|
file.puts output file.puts output
end end
end end
task :install_transpiler do
if `which compile-modules`.empty?
sh "npm install es6-module-transpiler -g"
end
end
task :install_uglify do
if `which uglifyjs`.empty?
sh "npm install uglify-js -g"
end
end
# Build everything # Build everything
task :dist => [amd_async, amd_events, amd_rsvp, "browser/rsvp.js", "browser/rsvp.min.js", node_main] task :dist => [:install_transpiler, :install_uglify, amd_async, amd_events, amd_rsvp, "browser/rsvp.js", "browser/rsvp.min.js", node_main]
# Testing # Testing
...@@ -134,7 +143,7 @@ task :update_tests => "promises-tests" do ...@@ -134,7 +143,7 @@ task :update_tests => "promises-tests" do
end end
desc "Run the tests using Node" desc "Run the tests using Node"
task :test => [:update_tests, node_main] do task :test => [:install_transpiler, :update_tests, node_main] do
cd "promises-tests" do cd "promises-tests" do
sh "node ./lib/cli.js ../tests/test-adapter.js" sh "node ./lib/cli.js ../tests/test-adapter.js"
end end
......
...@@ -48,5 +48,6 @@ define( ...@@ -48,5 +48,6 @@ define(
}; };
} }
__exports__.async = async; __exports__.async = async;
}); });
...@@ -96,5 +96,6 @@ define( ...@@ -96,5 +96,6 @@ define(
} }
}; };
__exports__.EventTarget = EventTarget; __exports__.EventTarget = EventTarget;
}); });
define( define(
["rsvp/async", "rsvp/events", "exports"], ["rsvp/async","rsvp/events","exports"],
function(__dependency1__, __dependency2__, __exports__) { function(__dependency1__, __dependency2__, __exports__) {
"use strict"; "use strict";
var async = __dependency1__.async; var async = __dependency1__.async;
...@@ -190,6 +190,7 @@ define( ...@@ -190,6 +190,7 @@ define(
return deferred; return deferred;
} }
__exports__.Promise = Promise; __exports__.Promise = Promise;
__exports__.all = all; __exports__.all = all;
__exports__.defer = defer; __exports__.defer = defer;
......
...@@ -81,6 +81,7 @@ define("rsvp/async", ...@@ -81,6 +81,7 @@ define("rsvp/async",
}; };
} }
__exports__.async = async; __exports__.async = async;
}); });
...@@ -182,11 +183,12 @@ define("rsvp/events", ...@@ -182,11 +183,12 @@ define("rsvp/events",
} }
}; };
__exports__.EventTarget = EventTarget; __exports__.EventTarget = EventTarget;
}); });
define("rsvp", define("rsvp",
["rsvp/async", "rsvp/events", "exports"], ["rsvp/async","rsvp/events","exports"],
function(__dependency1__, __dependency2__, __exports__) { function(__dependency1__, __dependency2__, __exports__) {
"use strict"; "use strict";
var async = __dependency1__.async; var async = __dependency1__.async;
...@@ -377,6 +379,7 @@ define("rsvp", ...@@ -377,6 +379,7 @@ define("rsvp",
return deferred; return deferred;
} }
__exports__.Promise = Promise; __exports__.Promise = Promise;
__exports__.all = all; __exports__.all = all;
__exports__.defer = defer; __exports__.defer = defer;
......
(function(){var a,b;(function(){var c={},d={};a=function(a,b,d){c[a]={deps:b,callback:d}},b=function(a){if(d[a])return d[a];d[a]={};var e=c[a],f=e.deps,g=e.callback,h=[],i;for(var j=0,k=f.length;j<k;j++)f[j]==="exports"?h.push(i={}):h.push(b(f[j]));var l=g.apply(this,h);return d[a]=i||l}})(),a("rsvp/async",["exports"],function(a){"use strict";var b=typeof window!="undefined"?window:{},c=b.MutationObserver||b.WebKitMutationObserver,d;if(typeof process!="undefined"&&{}.toString.call(process)==="[object process]")d=function(a,b){process.nextTick(function(){a.call(b)})};else if(c){var e=[],f=new c(function(){var a=e.slice();e=[],a.forEach(function(a){var b=a[0],c=a[1];b.call(c)})}),g=document.createElement("div");f.observe(g,{attributes:!0}),window.addEventListener("unload",function(){f.disconnect(),f=null}),d=function(a,b){e.push([a,b]),g.setAttribute("drainQueue","drainQueue")}}else d=function(a,b){setTimeout(function(){a.call(b)},1)};a.async=d}),a("rsvp/events",["exports"],function(a){"use strict";var b=function(a,b){this.type=a;for(var c in b){if(!b.hasOwnProperty(c))continue;this[c]=b[c]}},c=function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c][0]===b)return c;return-1},d=function(a){var b=a._promiseCallbacks;b||(b=a._promiseCallbacks={});return b},e={mixin:function(a){a.on=this.on,a.off=this.off,a.trigger=this.trigger;return a},on:function(a,b,e){var f=d(this),g,h;a=a.split(/\s+/),e=e||this;while(h=a.shift())g=f[h],g||(g=f[h]=[]),c(g,b)===-1&&g.push([b,e])},off:function(a,b){var e=d(this),f,g,h;a=a.split(/\s+/);while(g=a.shift()){if(!b){e[g]=[];continue}f=e[g],h=c(f,b),h!==-1&&f.splice(h,1)}},trigger:function(a,c){var e=d(this),f,g,h,i,j;if(f=e[a])for(var k=0;k<f.length;k++)g=f[k],h=g[0],i=g[1],typeof c!="object"&&(c={detail:c}),j=new b(a,c),h.call(i,j)}};a.EventTarget=e}),a("rsvp",["rsvp/async","rsvp/events","exports"],function(a,b,c){function o(){var a={},b=new h(function(b,c){a.resolve=b,a.reject=c});a.promise=b;return a}function n(a,b){f[a]=b}function m(a){var b,c=[],d=new h(function(){}),e=a.length;e===0&&j(d,[]);var f=function(a){return function(b){g(a,b)}},g=function(a,b){c[a]=b,--e===0&&j(d,c)},i=function(a){l(d,a)};for(b=0;b<a.length;b++)a[b]&&typeof a[b].then=="function"?a[b].then(f(b),i):g(b,a[b]);return d}function l(a,b){f.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedReason=b})}function k(a,b){f.async(function(){a.trigger("promise:resolved",{detail:b}),a.isFulfilled=!0,a.fulfillmentValue=b})}function j(a,b){b&&typeof b.then=="function"?b.then(function(b){j(a,b)},function(b){l(a,b)}):k(a,b)}"use strict";var d=a.async,e=b.EventTarget,f={};f.async=d;var g=function(){},h=function(a){var b=this;if(typeof a!="function")throw new TypeError("You must pass a resolver function as the sole argument to the promise constructor");if(!(b instanceof h))return new h(a);var c=function(a){j(b,a),c=g,d=g},d=function(a){l(b,a),c=g,d=g};this.on("promise:resolved",function(a){this.trigger("success",{detail:a.detail})},this),this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this),a(c,d)},i=function(a,b,c,d){var e=typeof c=="function",f,g,h,i;if(e)try{f=c(d.detail),h=!0}catch(k){i=!0,g=k}else f=d.detail,h=!0;f&&typeof f.then=="function"?f.then(function(a){j(b,a)},function(a){l(b,a)}):e&&h?j(b,f):i?l(b,g):a==="resolve"?j(b,f):a==="reject"&&l(b,f)};h.prototype={constructor:h,then:function(a,b){var c=new h(function(){});this.isFulfilled&&f.async(function(){i("resolve",c,a,{detail:this.fulfillmentValue})},this),this.isRejected&&f.async(function(){i("reject",c,b,{detail:this.rejectedReason})},this),this.on("promise:resolved",function(b){i("resolve",c,a,b)}),this.on("promise:failed",function(a){i("reject",c,b,a)});return c}},e.mixin(h.prototype),c.Promise=h,c.all=m,c.defer=o,c.configure=n}),window.RSVP=b("rsvp")})() (function(){var t,e;(function(){var n={},i={};t=function(t,e,i){n[t]={deps:e,callback:i}};e=function(t){if(i[t]){return i[t]}i[t]={};var r=n[t],o=r.deps,s=r.callback,f=[],c;for(var u=0,a=o.length;u<a;u++){if(o[u]==="exports"){f.push(c={})}else{f.push(e(o[u]))}}var l=s.apply(this,f);return i[t]=c||l}})();t("rsvp/async",["exports"],function(t){"use strict";var e=typeof window!=="undefined"?window:{};var n=e.MutationObserver||e.WebKitMutationObserver;var i;if(typeof process!=="undefined"&&{}.toString.call(process)==="[object process]"){i=function(t,e){process.nextTick(function(){t.call(e)})}}else if(n){var r=[];var o=new n(function(){var t=r.slice();r=[];t.forEach(function(t){var e=t[0],n=t[1];e.call(n)})});var s=document.createElement("div");o.observe(s,{attributes:true});window.addEventListener("unload",function(){o.disconnect();o=null});i=function(t,e){r.push([t,e]);s.setAttribute("drainQueue","drainQueue")}}else{i=function(t,e){setTimeout(function(){t.call(e)},1)}}t.async=i});t("rsvp/events",["exports"],function(t){"use strict";var e=function(t,e){this.type=t;for(var n in e){if(!e.hasOwnProperty(n)){continue}this[n]=e[n]}};var n=function(t,e){for(var n=0,i=t.length;n<i;n++){if(t[n][0]===e){return n}}return-1};var i=function(t){var e=t._promiseCallbacks;if(!e){e=t._promiseCallbacks={}}return e};var r={mixin:function(t){t.on=this.on;t.off=this.off;t.trigger=this.trigger;return t},on:function(t,e,r){var o=i(this),s,f;t=t.split(/\s+/);r=r||this;while(f=t.shift()){s=o[f];if(!s){s=o[f]=[]}if(n(s,e)===-1){s.push([e,r])}}},off:function(t,e){var r=i(this),o,s,f;t=t.split(/\s+/);while(s=t.shift()){if(!e){r[s]=[];continue}o=r[s];f=n(o,e);if(f!==-1){o.splice(f,1)}}},trigger:function(t,n){var r=i(this),o,s,f,c,u;if(o=r[t]){for(var a=0;a<o.length;a++){s=o[a];f=s[0];c=s[1];if(typeof n!=="object"){n={detail:n}}u=new e(t,n);f.call(c,u)}}}};t.EventTarget=r});t("rsvp",["rsvp/async","rsvp/events","exports"],function(t,e,n){"use strict";var i=t.async;var r=e.EventTarget;var o={};o.async=i;var s=function(){};var f=function(t){var e=this;if(typeof t!=="function"){throw new TypeError("You must pass a resolver function as the sole argument to the promise constructor")}if(!(e instanceof f)){return new f(t)}var n=function(t){u(e,t);n=s;i=s};var i=function(t){l(e,t);n=s;i=s};this.on("promise:resolved",function(t){this.trigger("success",{detail:t.detail})},this);this.on("promise:failed",function(t){this.trigger("error",{detail:t.detail})},this);t(n,i)};var c=function(t,e,n,i){var r=typeof n==="function",o,s,f,c;if(r){try{o=n(i.detail);f=true}catch(a){c=true;s=a}}else{o=i.detail;f=true}if(o&&typeof o.then==="function"){o.then(function(t){u(e,t)},function(t){l(e,t)})}else if(r&&f){u(e,o)}else if(c){l(e,s)}else if(t==="resolve"){u(e,o)}else if(t==="reject"){l(e,o)}};f.prototype={constructor:f,then:function(t,e){var n=new f(function(){});if(this.isFulfilled){o.async(function(){c("resolve",n,t,{detail:this.fulfillmentValue})},this)}if(this.isRejected){o.async(function(){c("reject",n,e,{detail:this.rejectedReason})},this)}this.on("promise:resolved",function(e){c("resolve",n,t,e)});this.on("promise:failed",function(t){c("reject",n,e,t)});return n}};function u(t,e){if(e&&typeof e.then==="function"){e.then(function(e){u(t,e)},function(e){l(t,e)})}else{a(t,e)}}function a(t,e){o.async(function(){t.trigger("promise:resolved",{detail:e});t.isFulfilled=true;t.fulfillmentValue=e})}function l(t,e){o.async(function(){t.trigger("promise:failed",{detail:e});t.isRejected=true;t.rejectedReason=e})}function v(t){var e,n=[];var i=new f(function(){});var r=t.length;if(r===0){u(i,[])}var o=function(t){return function(e){s(t,e)}};var s=function(t,e){n[t]=e;if(--r===0){u(i,n)}};var c=function(t){l(i,t)};for(e=0;e<t.length;e++){if(t[e]&&typeof t[e].then==="function"){t[e].then(o(e),c)}else{s(e,t[e])}}return i}r.mixin(f.prototype);function h(t,e){o[t]=e}function p(){var t={};var e=new f(function(e,n){t.resolve=e;t.reject=n});t.promise=e;return t}n.Promise=f;n.all=v;n.defer=p;n.configure=h});window.RSVP=e("rsvp")})();
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
"devDependencies": { "devDependencies": {
"jshint": "~0.9", "jshint": "~0.9",
"promise-tests": "2.0.0", "promise-tests": "2.0.0",
"uglify-js": "~2.2" "uglify-js": "~2.2",
"es6-module-transpiler": "~0.1.2"
}, },
"scripts": { "scripts": {
"test": "promise-tests all ./tests/test-adapter", "test": "promise-tests all ./tests/test-adapter",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment