/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/

/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

/*******************************************************************************
 * @license
 * Copyright (c) 2011, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

/*******************************************************************************
 * @license
 * Copyright (c) 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/

/*

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2011, 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation

 Copyright (c) 2013 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation
*/
(function(e,c){typeof define==="function"&&define.amd?define("orion/Deferred",c):typeof exports==="object"?module.exports=c():(e.orion=e.orion||{},e.orion.Deferred=c())})(this,function(){function e(){for(var i;i=d.shift();)i();a=!1}function c(i){d.push(i);a||(a=!0,setTimeout(e,0))}function j(a){return function(){a.apply(void 0,arguments)}}function f(){function a(){for(var b;b=k.shift();){var g=b.deferred,i=l==="fulfilled"?"resolve":"reject";if(typeof b[i]==="function")try{var f=(0,b[i])(p),h=f&&(typeof f===
"object"||typeof f==="function")&&f.then;if(typeof h==="function")if(f===g.promise)g.reject(new TypeError);else{var c=f.cancel;typeof c==="function"?g._protected(d).parentCancel=c.bind(f):delete g._protected(d).parentCancel;h.call(f,j(g.resolve),j(g.reject),j(g.progress))}else g.resolve(f)}catch(e){g.reject(e)}else g[i](p)}}function n(b){delete g.parentCancel;l="rejected";p=b;k.length&&c(a)}function e(b){function d(m){return function(b){j||(j=!0,m(b))}}var j=!1;delete g.parentCancel;try{var o=b&&
(typeof b==="object"||typeof b==="function")&&b.then;if(typeof o==="function")if(b===h)n(new TypeError);else{l="assumed";var t=b&&b.cancel;if(typeof t!=="function"){var q=new f,b=q.promise;try{o(q.resolve,q.reject,q.progress)}catch(r){q.reject(r)}t=b.cancel;o=b.then}p=b;o.call(b,d(e),d(n));g.parentCancel=t.bind(b)}else l="fulfilled",p=b,k.length&&c(a)}catch(m){d(n)(m)}}function o(){var b=g.parentCancel;if(b)delete g.parentCancel,b();else if(!l)b=Error("Cancel"),b.name="Cancel",n(b)}var p,l,k=[],h=
this,g={};Object.defineProperty(this,"_protected",{value:function(b){if(b!==d)throw Error("protected");return g}});this.resolve=function(b){l||e(b);return h};this.reject=function(b){l||n(b);return h};this.progress=function(b){l||k.forEach(function(a){if(a.progress)try{a.progress(b)}catch(g){}});return h.promise};this.cancel=function(){g.parentCancel?setTimeout(o,0):o();return h};this.then=function(b,g,e){b={resolve:b,reject:g,progress:e,deferred:new f};k.push(b);b.deferred._protected(d).parentCancel=
h.promise.cancel.bind(h);(l==="fulfilled"||l==="rejected")&&c(a);return b.deferred.promise};this.promise={then:h.then,cancel:h.cancel}}var d=[],a=!1;f.all=function(a,d){function c(a,b){k||(l[a]=b,--j===0&&h.resolve(l))}function e(a,b){if(!k){if(d)try{c(a,d(b));return}catch(f){b=f}h.reject(b)}}var j=a.length,l=[],k=!1,h=new f;h.then(void 0,function(){k=!0;a.forEach(function(a){a.cancel&&a.cancel()})});j===0?h.resolve(l):a.forEach(function(a,b){a.then(c.bind(void 0,b),e.bind(void 0,b))});return h.promise};
f.when=function(a,d,c,e){var j;if(!(a&&typeof a.then==="function"))j=new f,j.resolve(a),a=j.promise;return a.then(d,c,e)};return f});
define("orion/xhr",["orion/Deferred"],function(e){function c(c,f,d,a){var e=typeof d.response!=="undefined"?d.response:d.responseText,n;try{n=d.status}catch(s){n=0}c={args:f,response:e,responseText:typeof e==="string"?e:null,status:n,url:c,xhr:d};if(typeof a!=="undefined")c.error=a;return c}return function(j,f,d){var d=d||{},a=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,i=new e,n=d.headers||{},s=d.log||!1,o;typeof n["X-Requested-With"]==="undefined"&&(n["X-Requested-With"]="XMLHttpRequest");
if(typeof d.data!=="undefined"&&(j==="POST"||j==="PUT"))o=d.data;var p=!1,l=!1;i.promise.then(void 0,function(d){p=!0;!l&&d instanceof Error&&d.name==="Cancel"&&a.abort()});a.onabort=function(){l=!0;if(!p){var a=Error("Cancel");a.name="Cancel";i.reject(a)}};a.onload=function(){var g=c(f,d,a);200<=a.status&&a.status<400?i.resolve(g):(i.reject(g),s&&typeof console!=="undefined"&&console.log(Error(a.statusText)))};a.onerror=function(){var g=c(f,d,a);i.reject(g);s&&typeof console!=="undefined"&&console.log(Error(a.statusText))};
a.onprogress=function(d){d.xhr=a;i.progress(d)};try{a.open(j,f,!0);if(typeof d.responseType==="string")a.responseType=d.responseType;if(typeof d.timeout==="number")if(typeof a.timeout==="number")a.timeout=d.timeout,a.addEventListener("timeout",function(){i.reject(c(f,d,a,"Timeout exceeded"))});else{var k=setTimeout(function(){i.reject(c(f,d,a,"Timeout exceeded"))},d.timeout);i.promise.then(clearTimeout.bind(null,k),clearTimeout.bind(null,k))}Object.keys(n).forEach(function(d){a.setRequestHeader(d,
n[d])});a.send(o||null)}catch(h){i.reject(c(f,d,a,h))}return i.promise}});
(function(e,c){typeof define==="function"&&define.amd?define("orion/plugin",["orion/Deferred"],c):typeof exports==="object"?module.exports=c(require("orion/Deferred")):(e.orion=e.orion||{},e.orion.PluginProvider=c(e.orion.Deferred))})(this,function(e){function c(c,f){this.__objectId=c;this.__methods=f}return function(j){function f(m){h&&(typeof ArrayBuffer==="undefined"&&(m=JSON.stringify(m)),h===self?h.postMessage(m):h.postMessage(m,"*"))}function d(){var m=[];Object.keys(q).forEach(function(a){var b=
q[a];m.push({serviceId:a,names:b.names,methods:b.methods,properties:b.properties})});return{headers:l||{},services:m}}function a(m,a){if(a&&a instanceof XMLHttpRequest){var b,d;try{b=a.status,d=a.statusText}catch(c){b=0,d=""}return{status:b||0,statusText:d}}return a}function i(m){var b=m?JSON.parse(JSON.stringify(m,a)):m;if(m instanceof Error)b.__isError=!0,b.message=b.message||m.message,b.name=b.name||m.name;return b}function n(a){if(!h)return(new e).reject(Error("plugin not connected"));a.id=String(g++);
var d=new e;v[a.id]=d;d.then(null,function(b){k&&b instanceof Error&&b.name==="Cancel"&&r({requestId:a.id,method:"cancel",params:b.message?[b.message]:[]})});var f=Object.prototype.toString;a.params.forEach(function(e,h){if(f.call(e)==="[object Object]"&&!(e instanceof c)){var g,i;for(g in e)f.call(e[g])==="[object Function]"&&(i=i||[],i.push(g));if(i){var j=b++;t[j]=e;g=function(){delete t[j]};d.then(g,g);a.params[h]=new c(j,i)}}});r(a);return d.promise}function s(a,b){a||a===0?r({id:a,result:null,
error:b}):console.log(b)}function o(a,b,d,f){f.forEach(function(a,b){if(a&&typeof a.__objectId!=="undefined"){var d={};a.__methods.forEach(function(b){d[b]=function(){return n({objectId:a.__objectId,method:b,params:Array.prototype.slice.call(arguments)})}});f[b]=d}});var c=typeof a===void 0?null:{id:a,result:null,error:null};try{var e=d.apply(b,f);if(c)e&&typeof e.then==="function"?(u[a]=e,e.then(function(b){delete u[a];c.result=b;r(c)},function(b){if(u[a])delete u[a],c.error=i(b),r(c)},function(){r({responseId:a,
method:"progress",params:Array.prototype.slice.call(arguments)})})):(c.result=e,r(c))}catch(g){if(c)c.error=i(g),r(c)}}function p(a){if(a.source===h){a=typeof a.data!=="string"?a.data:JSON.parse(a.data);try{if(a.method){var b=a.method,d=a.params||[];if("serviceId"in a){var c=q[a.serviceId];c||s(a.id,"service not found");c=c.implementation;b in c?o(a.id,c,c[b],d):s(a.id,"method not found")}else if("objectId"in a){var f=t[a.objectId];f||s(a.id,"object not found");!b in f?o(a.id,f,f[b],d):s(a.id,"method not found")}else if("requestId"in
a){var e=u[a.requestId];e&&b==="cancel"&&e.cancel&&e.cancel.apply(e,d)}else if("responseId"in a){var g=v[a.responseId];g&&b==="progress"&&g.progress&&g.progress.apply(g,d)}else throw Error("Bad method: "+a.method);}else{var i=v[String(a.id)];delete v[String(a.id)];a.error?i.reject(a.error):i.resolve(a.result)}}catch(j){console.log("Plugin._messageHandler "+j)}}}var l=j,k=!1,h=null,g=0,b=0,w=0,u={},v={},t={},q={},r=f;this.updateHeaders=function(a){if(k)throw Error("Cannot update headers. Plugin Provider is connected");
l=a};this.registerServiceProvider=this.registerService=function(a,b,d){if(k)throw Error("Cannot register service. Plugin Provider is connected");typeof a==="string"?a=[a]:Array.isArray(a)||(a=[]);var c=null,f=[];for(c in b)typeof b[c]==="function"&&f.push(c);q[w++]={names:a,methods:f,implementation:b,properties:d||{},listeners:{}}};this.connect=function(a,b){if(!k){if(typeof window==="undefined")h=self;else if(window!==window.parent)h=window.parent;else if(window.opener!==null)h=window.opener;else{b&&
b("No valid plugin target");return}addEventListener("message",p,!1);var c={method:"plugin",params:[d()]};f(c);k=!0}a&&a()};this.disconnect=function(){k&&(removeEventListener("message",p),h=null,k=!1)}}});
define('built-npmPlugin.js',["orion/xhr","orion/Deferred","orion/plugin"],function(e,c,j){c=new j({name:"Orion NPM",version:"1.0",description:"Orion NPM"});c.registerServiceProvider("orion.shell.command",null,{name:"npm",description:"Commands for interacting with node npm"});c.registerServiceProvider("orion.shell.command",{callback:function(c,d){c.cwd=d.cwd;c.type="shrinkwrap";return e("POST","/npm",{headers:{"Orion-Version":"1"},data:JSON.stringify(c),timeout:3E5}).then(function(a){return a.response?
JSON.parse(a.response).cmdOutput:""},function(a){return a.error})}},{name:"npm shrinkwrap",description:"npm shrinkwrap",parameters:null});c.registerServiceProvider("orion.shell.command",{callback:function(c,d){c.cwd=d.cwd;c.type="install";return e("POST","/npm",{headers:{"Orion-Version":"1"},data:JSON.stringify(c),timeout:3E5}).then(function(a){return a.response?JSON.parse(a.response).cmdOutput:""},function(a){return a.error})}},{name:"npm install",description:"npm install",parameters:[{name:"package",
type:"string",description:"package to install",defaultValue:null}]});c.connect()});