Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

66 lines (55 sloc) 16.013 kB
<!DOCTYPE html> <html> <head> <title>haibu.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="haibu/cli/apps.html"> haibu/cli/apps.html </a> <a class="source" href="haibu/cli/config.html"> haibu/cli/config.html </a> <a class="source" href="haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="haibu/utils/npm.html"> haibu/utils/npm.html </a> <a class="source" href="haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> haibu.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * haibu.js: Top level include for the haibu module</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
<span class="nx">events</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;events&#39;</span><span class="p">),</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;path&#39;</span><span class="p">),</span>
<span class="nx">hookio</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;hook.io&#39;</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">haibu</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">();</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">log</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;cliff&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/core/config&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">utils</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/utils&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">Spawner</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/core/spawner&#39;</span><span class="p">).</span><span class="nx">Spawner</span><span class="p">;</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">repository</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/repositories&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">balancer</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/balancer&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">drone</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/drone&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">initialized</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">running</span> <span class="o">=</span> <span class="p">{};</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">plugins</span> <span class="o">=</span> <span class="p">{};</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">activePlugins</span> <span class="o">=</span> <span class="p">{};</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>function init (options, callback)
Initializes haibu directories and models</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">haibu</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">haibu</span><span class="p">.</span><span class="nx">initialized</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">();</span>
<span class="p">}</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">utils</span><span class="p">.</span><span class="nx">initDirectories</span><span class="p">(</span><span class="kd">function</span> <span class="nx">initialized</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">initialized</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">callback</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function use (plugin)</h3>
<h4>@plugin {Object} Instance of a plugin from <code>haibu.plugins</code></h4>
<p>Adds the specified <code>plugin</code> to the set of active plugins used by haibu.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">haibu</span><span class="p">.</span><span class="nx">use</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">plugin</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">),</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="k">typeof</span> <span class="nx">args</span><span class="p">[</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">(),</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{};</span>
<span class="p">}</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">activePlugins</span><span class="p">[</span><span class="nx">plugin</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">plugin</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">plugin</span><span class="p">.</span><span class="nx">init</span>
<span class="o">?</span> <span class="nx">plugin</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span>
<span class="o">:</span> <span class="nx">callback</span><span class="p">();</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Define each of our plugins as a lazy loaded <code>require</code> statement</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s1">&#39;/haibu/plugins&#39;</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">plugin</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">plugin</span> <span class="o">=</span> <span class="nx">plugin</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;.js&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
<span class="nx">haibu</span><span class="p">.</span><span class="nx">plugins</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="nx">plugin</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/plugins/&#39;</span> <span class="o">+</span> <span class="nx">plugin</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">});</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Jump to Line
Something went wrong with that request. Please try again.