Permalink
Browse files

Allowing 2 arg task like Cakefile

  • Loading branch information...
1 parent 4c513e2 commit 236ebfcd9ea594e35c73e02faf5298d29d4e2f5b @KrisJordan committed Jan 4, 2011
Showing with 40 additions and 6 deletions.
  1. +1 −1 Cakefile
  2. +20 −3 docs/icing.html
  3. +19 −2 src/icing.coffee
View
@@ -2,7 +2,7 @@ require './src/icing'
option '-s','--spec','Run vows with spec option'
-task 'test', 'Run icing tests', (options) ->
+task 'test', (options) ->
args = []
if options.spec?
args.push '--spec'
View
@@ -47,17 +47,26 @@
<pre><code>require 'icing'
task 'B', 'run B', -&gt; console.log 'B'
task 'A', 'run A', ['B'], -&gt; console.log 'A'
-</code></pre> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>Options</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">option</span> <span class="s1">&#39;-v&#39;</span><span class="p">,</span><span class="s1">&#39;--verbose&#39;</span><span class="p">,</span><span class="s1">&#39;Display progress as tasks are executed&#39;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>coming soon - option '-w','--watch','Monitor files for changes and automatically rebuild'</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>Dependencies and Globals</h3> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span> <span class="nx">RuleGraph</span><span class="p">,</span> <span class="nx">Rule</span><span class="p">,</span> <span class="nx">RecipeNode</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;./rules&#39;</span>
+</code></pre>
+
+<p>Recipes' <em>this</em> context provides special </p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>Options</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">option</span> <span class="s1">&#39;-v&#39;</span><span class="p">,</span><span class="s1">&#39;--verbose&#39;</span><span class="p">,</span><span class="s1">&#39;Display progress as tasks are executed&#39;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>coming soon - option '-w','--watch','Monitor files for changes and automatically rebuild'</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>Dependencies and Globals</h3> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span> <span class="nx">RuleGraph</span><span class="p">,</span> <span class="nx">Rule</span><span class="p">,</span> <span class="nx">RecipeNode</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;./rules&#39;</span>
<span class="p">{</span> <span class="nx">exec</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;child_process&#39;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Preserve a reference to cake's task, we'll be using it.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">cakeTask = </span><span class="nx">global</span><span class="p">.</span><span class="nx">task</span>
<span class="nv">graph = </span><span class="k">new</span> <span class="nx">RuleGraph</span>
<span class="nv">global.task = </span><span class="nf">(target, description, prereqs, recipe=undefined) -&gt;</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">prereqs</span><span class="o">?</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">recipe</span><span class="o">?</span>
+ <span class="nv">description = </span><span class="nx">target</span>
+ <span class="nv">recipe = </span><span class="nx">prereqs</span>
+ <span class="nv">prereqs = </span><span class="p">[]</span>
+
<span class="k">if</span> <span class="o">not</span> <span class="nx">recipe</span><span class="o">?</span>
<span class="nv">recipe = </span><span class="nx">prereqs</span>
<span class="nv">prereqs = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Add a rule to the rule graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">graph</span><span class="p">.</span><span class="nx">rule</span> <span class="k">new</span> <span class="nx">Rule</span> <span class="nx">target</span><span class="p">,</span> <span class="nx">prereqs</span><span class="p">,</span> <span class="nx">recipe</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Bootstrap into cake's task book keeping</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">cakeTask</span> <span class="nx">target</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nf">(options) -&gt;</span>
<span class="nv">recipeNodes = </span><span class="nx">graph</span><span class="p">.</span><span class="nx">recipeNodesTo</span> <span class="nx">target</span>
<span class="nv">aRecipeRan = </span><span class="kc">false</span>
+ <span class="nv">allRecipesRan = </span><span class="kc">false</span>
+ <span class="nv">recipeNode = </span><span class="p">{}</span>
<span class="nv">runNextRecipeCallback = </span><span class="nf">( ok = true, report = {} ) -&gt;</span>
<span class="k">if</span> <span class="o">not</span> <span class="nx">ok</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s2">&quot;===== #{report.rule.target} Failed =====&quot;</span>
@@ -74,9 +83,17 @@
<span class="k">else</span>
<span class="nx">do</span> <span class="nx">runNextRecipeCallback</span>
<span class="k">else</span>
- <span class="k">if</span> <span class="o">not</span> <span class="nx">aRecipeRan</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Homage to make</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;cake: Nothing to be done for `#{target}&#39;.&quot;</span>
+ <span class="nv">allRecipesRan = </span><span class="kc">true</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">aRecipeRan</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Homage</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;cake: Nothing to be done for `#{target}&#39;.&quot;</span>
+
+ <span class="nx">do</span> <span class="nx">runNextRecipeCallback</span>
- <span class="nx">do</span> <span class="nx">runNextRecipeCallback</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>Helpers</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Set-up the context that a recipe exec is run in.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">runRecipeContext = </span><span class="nf">(graph, recipeNode, runNextRecipeCallback, options) -&gt;</span>
+ <span class="nx">process</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;exit&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">allRecipesRan</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">recipeNodes</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span>
+ <span class="nv">tasksLeft = </span><span class="nx">recipeNodes</span><span class="p">.</span><span class="nx">pluck</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s2">&quot;\nError: task `#{recipeNode.name}` did not complete.\n&quot;</span> <span class="o">+</span>
+ <span class="s2">&quot;Tasks [#{tasksLeft}] should have run, but did not.\n&quot;</span> <span class="o">+</span>
+ <span class="s2">&quot;Task `#{recipeNode.name}` should call this.finished() or this.failed(message).\n&quot;</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>Helpers</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Set-up the context that a recipe exec is run in.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">runRecipeContext = </span><span class="nf">(graph, recipeNode, runNextRecipeCallback, options) -&gt;</span>
<span class="nv">finishedFn = </span><span class="o">-&gt;</span> <span class="nx">do</span> <span class="nx">runNextRecipeCallback</span>
View
@@ -42,6 +42,8 @@
# require 'icing'
# task 'B', 'run B', -> console.log 'B'
# task 'A', 'run A', ['B'], -> console.log 'A'
+#
+# Recipes' *this* context provides special
# ### Options
option '-v','--verbose','Display progress as tasks are executed'
@@ -56,7 +58,12 @@ cakeTask = global.task
graph = new RuleGraph
-global.task = (target, description, prereqs, recipe=undefined) ->
+global.task = (target, description, prereqs=undefined, recipe=undefined) ->
+ if not prereqs? and not recipe?
+ recipe = description
+ description = target
+ prereqs = []
+
if not recipe?
recipe = prereqs
prereqs = []
@@ -68,6 +75,8 @@ global.task = (target, description, prereqs, recipe=undefined) ->
cakeTask target, description, (options) ->
recipeNodes = graph.recipeNodesTo target
aRecipeRan = false
+ allRecipesRan = false
+ recipeNode = {}
runNextRecipeCallback = ( ok = true, report = {} ) ->
if not ok
console.error "===== #{report.rule.target} Failed ====="
@@ -84,12 +93,20 @@ global.task = (target, description, prereqs, recipe=undefined) ->
else
do runNextRecipeCallback
else
+ allRecipesRan = true
if not aRecipeRan
- # Homage to make
+ # Homage
console.log "cake: Nothing to be done for `#{target}'."
do runNextRecipeCallback
+ process.on 'exit', ->
+ if not allRecipesRan and not recipeNodes.isEmpty()
+ tasksLeft = recipeNodes.pluck('name').join(',')
+ console.error "\nError: task `#{recipeNode.name}` did not complete.\n" +
+ "Tasks [#{tasksLeft}] should have run, but did not.\n" +
+ "Task `#{recipeNode.name}` should call this.finished() or this.failed(message).\n"
+
#### Helpers
# Set-up the context that a recipe exec is run in.

0 comments on commit 236ebfc

Please sign in to comment.