<spanclass="nv">CoffeeScript = </span><spanclass="nx">require</span><spanclass="s1">'./coffee-script'</span></pre></div></td></tr><trid="section-3"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-3">¶</a></div><p>Keep track of the list of defined tasks, the accepted options, and so on.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">tasks = </span><spanclass="p">{}</span>
<spanclass="nv">oparse = </span><spanclass="kc">null</span></pre></div></td></tr><trid="section-4"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-4">¶</a></div><p>Mixin the top-level Cake functions for Cakefiles to use directly.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">helpers</span><spanclass="p">.</span><spanclass="nx">extend</span><spanclass="nx">global</span><spanclass="p">,</span></pre></div></td></tr><trid="section-5"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-5">¶</a></div><p>Define a Cake task with a short name, an optional sentence description,
and the function to run as the action itself.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">task: </span><spanclass="nf">(name, description, action) -></span>
<spanclass="nx">tasks</span><spanclass="p">[</span><spanclass="nx">name</span><spanclass="p">]</span><spanclass="o">=</span><spanclass="p">{</span><spanclass="nx">name</span><spanclass="p">,</span><spanclass="nx">description</span><spanclass="p">,</span><spanclass="nx">action</span><spanclass="p">}</span></pre></div></td></tr><trid="section-6"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-6">¶</a></div><p>Define an option that the Cakefile accepts. The parsed options hash,
as the first argument to the action.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">option: </span><spanclass="nf">(letter, flag, description) -></span>
<spanclass="nx">switches</span><spanclass="p">.</span><spanclass="nx">push</span><spanclass="p">[</span><spanclass="nx">letter</span><spanclass="p">,</span><spanclass="nx">flag</span><spanclass="p">,</span><spanclass="nx">description</span><spanclass="p">]</span></pre></div></td></tr><trid="section-7"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-7">¶</a></div><p>Invoke another task in the current Cakefile.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">invoke: </span><spanclass="nf">(name) -></span>
<spanclass="nx">tasks</span><spanclass="p">[</span><spanclass="nx">name</span><spanclass="p">].</span><spanclass="nx">action</span><spanclass="nx">options</span></pre></div></td></tr><trid="section-8"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-8">¶</a></div><p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node's
If no tasks are passed, print the help screen. Keep a reference to the
original directory name, when running Cake tasks from subdirectories.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.run = </span><spanclass="o">-></span>
<spanclass="nx">invoke</span><spanclass="nx">arg</span><spanclass="k">for</span><spanclass="nx">arg</span><spanclass="k">in</span><spanclass="nx">options</span><spanclass="p">.</span><spanclass="nx">arguments</span></pre></div></td></tr><trid="section-9"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-9">¶</a></div><p>Display the list of Cake tasks in a format similar to <code>rake -T</code></p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">printTasks = </span><spanclass="o">-></span>
<spanclass="nx">console</span><spanclass="p">.</span><spanclass="nx">log</span><spanclass="s2">"#{cakefilePath} defines the following tasks:\n"</span>
<spanclass="nx">console</span><spanclass="p">.</span><spanclass="nx">log</span><spanclass="nx">oparse</span><spanclass="p">.</span><spanclass="nx">help</span><spanclass="p">()</span><spanclass="k">if</span><spanclass="nx">switches</span><spanclass="p">.</span><spanclass="nx">length</span></pre></div></td></tr><trid="section-10"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-10">¶</a></div><p>Print an error and exit when attempting to use an invalid task/option.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">fatalError = </span><spanclass="nf">(message) -></span>
<spanclass="nx">console</span><spanclass="p">.</span><spanclass="nx">log</span><spanclass="s1">'To see a list of all tasks/options, run "cake"'</span>
<spanclass="nv">missingTask = </span><spanclass="nf">(task) -></span><spanclass="nx">fatalError</span><spanclass="s2">"No such task: #{task}"</span></pre></div></td></tr><trid="section-11"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-11">¶</a></div><p>When <code>cake</code> is invoked, search in the current and all parent directories
to find the relevant Cakefile.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">cakefileDirectory = </span><spanclass="nf">(dir) -></span>
<spanclass="k">throw</span><spanclass="k">new</span><spanclass="nb">Error</span><spanclass="s2">"Cakefile not found in #{process.cwd()}"</span>