Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Globbing file prerequisites.

  • Loading branch information...
commit bc7b7c24b6747d4406383fcf9646e22bc4f6caaa 1 parent 236ebfc
Kris Jordan authored
10 Cakefile
View
@@ -2,14 +2,16 @@ require './src/icing'
option '-s','--spec','Run vows with spec option'
-task 'test', (options) ->
+task 'version', -> console.log '0.1'
+
+task 'test', ['spec/*'], (options) ->
args = []
if options.spec?
args.push '--spec'
- command = "vows #{args.join ' '} spec/*"
+ command = "vows #{args.join ' '} #{this.prereqs.join(' ')}"
this.exec command
-task 'docs', 'Generate docco documentation', (options) ->
- this.exec "docco src/*"
+task 'docs', 'Generate docco documentation', ['src/*'], (options) ->
+ this.exec "docco #{this.prereqs.join(' ')}"
task 'all', 'Test and Document', ['test','docs'], (options) -> this.finished()
1  docs/dag.html
View
@@ -145,6 +145,7 @@
<span class="k">class</span> <span class="nx">NodeList</span> <span class="k">extends</span> <span class="nx">List</span>
<span class="nv">ofType: </span><span class="nf">(type) -&gt;</span> <span class="k">new</span> <span class="nx">NodeList</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">filter</span> <span class="nf">(node) -&gt;</span> <span class="nx">node</span> <span class="k">instanceof</span> <span class="nx">type</span>
<span class="nv">clone: </span><span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">NodeList</span> <span class="k">super</span><span class="p">().</span><span class="nx">items</span>
+ <span class="nv">names: </span><span class="o">-&gt;</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">pluck</span> <span class="s1">&#39;name&#39;</span>
<span class="k">class</span> <span class="nx">ArcList</span> <span class="k">extends</span> <span class="nx">List</span>
<span class="nv">from: </span><span class="nf">(node) -&gt;</span>
15 docs/icing.html
View
@@ -54,15 +54,20 @@
<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="nv">global.task = </span><span class="nf">(target, description, prereqs=undefined, 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">recipe = </span><span class="nx">description</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="k">if</span> <span class="nx">description</span><span class="p">.</span><span class="nx">shift</span><span class="o">?</span>
+ <span class="nv">recipe = </span><span class="nx">prereqs</span>
+ <span class="nv">prereqs = </span><span class="nx">description</span>
+ <span class="nv">description = </span><span class="nx">target</span>
+ <span class="k">else</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>
@@ -124,7 +129,7 @@
<span class="nv">callback: </span> <span class="nx">runNextRecipeCallback</span>
<span class="nv">finished: </span> <span class="nx">finishedFn</span>
<span class="nv">failed: </span> <span class="nx">failedFn</span>
- <span class="nv">prereqs: </span> <span class="nx">recipeNode</span><span class="p">.</span><span class="nx">prereqs</span> <span class="nx">graph</span>
+ <span class="nv">prereqs: </span> <span class="nx">recipeNode</span><span class="p">.</span><span class="nx">prereqs</span><span class="p">(</span><span class="nx">graph</span><span class="p">).</span><span class="nx">names</span><span class="p">()</span>
<span class="nv">exec: </span> <span class="nx">execFn</span>
<span class="p">}</span>
26 docs/rules.html
View
@@ -20,6 +20,7 @@
if they exist.</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> <p><strong>Dependencies</strong></p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span> <span class="nx">Graph</span><span class="p">,</span> <span class="nx">Node</span><span class="p">,</span> <span class="nx">Arc</span><span class="p">,</span> <span class="nx">NodeList</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;./dag&#39;</span>
<span class="nv">_ = </span><span class="nx">require</span> <span class="s1">&#39;underscore&#39;</span>
<span class="nv">assert = </span><span class="nx">require</span> <span class="s1">&#39;assert&#39;</span>
+<span class="p">{</span> <span class="nx">globSync</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;glob&#39;</span>
<span class="k">class</span> <span class="nx">RuleGraph</span> <span class="k">extends</span> <span class="nx">Graph</span>
<span class="nv">recipeNodesTo: </span><span class="nf">(target) -&gt;</span>
@@ -46,10 +47,17 @@
<span class="nx">inputsOutputs</span><span class="p">.</span><span class="nx">forEach</span> <span class="nf">(inputsOutput) -&gt;</span>
<span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">inputsOutput</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span>
<span class="k">return</span>
- <span class="k">else</span>
- <span class="nv">input = </span><span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">prereq</span>
- <span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="nx">input</span>
- <span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">input</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span>
+ <span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">input</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span>
+ <span class="k">else</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>see if there's an expansion for it</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">globbed = </span><span class="nx">globSync</span> <span class="nx">prereq</span>
+ <span class="k">if</span> <span class="nx">globbed</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span>
+ <span class="nx">globbed</span><span class="p">.</span><span class="nx">forEach</span> <span class="nf">(file) -&gt;</span>
+ <span class="nv">input = </span><span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">file</span>
+ <span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="nx">input</span>
+ <span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">input</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span>
+ <span class="k">else</span>
+ <span class="nv">input = </span><span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">prereq</span>
+ <span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="nx">input</span>
+ <span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">input</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span>
<span class="nv">outputs = </span><span class="nx">rule</span><span class="p">.</span><span class="nx">recipe</span><span class="p">.</span><span class="nx">outputs</span><span class="p">.</span><span class="nx">call</span> <span class="nx">rule</span>
<span class="nx">outputs</span><span class="p">.</span><span class="nx">forEach</span> <span class="nf">(output) -&gt;</span>
@@ -57,19 +65,19 @@
<span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="nx">output</span>
<span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">output</span><span class="p">.</span><span class="nx">name</span>
- <span class="k">this</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>Rule Graph Elements</h3> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">Rule</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>Rule Graph Elements</h3> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">Rule</span>
<span class="nv">constructor: </span><span class="nf">(@target, @prereqs, @recipe) -&gt;</span>
<span class="k">if</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@recipe</span><span class="p">).</span><span class="nx">isFunction</span><span class="p">()</span>
<span class="vi">@recipe = </span><span class="k">new</span> <span class="nx">Recipe</span> <span class="nx">@recipe</span>
- <span class="vi">@prereqs = </span><span class="nx">@prereqs</span><span class="p">.</span><span class="nx">reverse</span><span class="p">()</span>
+ <span class="vi">@prereqs = </span><span class="nx">@prereqs</span><span class="p">.</span><span class="nx">reverse</span><span class="p">()</span> <span class="c1"># Because we push they&#39;ll get reversed again</span>
<span class="k">class</span> <span class="nx">Recipe</span>
- <span class="nv">constructor: </span><span class="p">(</span><span class="vi">@exec = </span><span class="p">(</span><span class="o">-&gt;</span><span class="p">),</span> <span class="vi">@outputs = </span><span class="p">(</span><span class="o">-&gt;</span><span class="p">[]))</span> <span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>Additional Graph Nodes</h3> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">RecipeNode</span> <span class="k">extends</span> <span class="nx">Node</span>
+ <span class="nv">constructor: </span><span class="p">(</span><span class="vi">@exec = </span><span class="p">(</span><span class="o">-&gt;</span><span class="p">),</span> <span class="vi">@outputs = </span><span class="p">(</span><span class="o">-&gt;</span><span class="p">[]))</span> <span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>Additional Graph Nodes</h3> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">RecipeNode</span> <span class="k">extends</span> <span class="nx">Node</span>
<span class="nv">constructor: </span><span class="nf">(@name, @recipe) -&gt;</span>
<span class="nv">equals: </span><span class="nf">(node) -&gt;</span>
<span class="k">super</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span> <span class="k">instanceof</span> <span class="nx">RecipeNode</span>
<span class="nv">clone: </span><span class="nf">(node) -&gt;</span> <span class="k">new</span> <span class="nx">RecipeNode</span> <span class="nx">@name</span><span class="p">,</span> <span class="nx">@recipe</span>
- <span class="nv">prereqs: </span><span class="nf">(graph) -&gt;</span> <span class="p">[]</span> <span class="c1">#TODO implement</span>
+ <span class="nv">prereqs: </span><span class="nf">(graph) -&gt;</span> <span class="nx">graph</span><span class="p">.</span><span class="nx">arcs</span><span class="p">.</span><span class="nx">to</span><span class="p">(</span><span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">).</span><span class="nx">from</span><span class="p">().</span><span class="nx">ofType</span> <span class="nx">FileNode</span>
<span class="nv">shouldRun: </span><span class="nf">(graph) -&gt;</span> <span class="kc">true</span>
<span class="nv">run: </span><span class="nf">(context, options) -&gt;</span> <span class="nx">@recipe</span><span class="p">.</span><span class="nx">exec</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">options</span>
@@ -77,6 +85,6 @@
<span class="nv">constructor: </span><span class="nf">(@name) -&gt;</span>
<span class="nv">equals: </span><span class="nf">(node) -&gt;</span>
<span class="k">super</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span> <span class="k">instanceof</span> <span class="nx">FileNode</span>
- <span class="nv">clone: </span><span class="nf">(node) -&gt;</span> <span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">@name</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>Exports</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">_</span><span class="p">(</span><span class="nx">exports</span><span class="p">).</span><span class="nx">extend</span> <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="nx">FileNode</span><span class="p">,</span> <span class="nx">Recipe</span> <span class="p">}</span>
+ <span class="nv">clone: </span><span class="nf">(node) -&gt;</span> <span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">@name</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>Exports</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">_</span><span class="p">(</span><span class="nx">exports</span><span class="p">).</span><span class="nx">extend</span> <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="nx">FileNode</span><span class="p">,</span> <span class="nx">Recipe</span> <span class="p">}</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
1  src/dag.coffee
View
@@ -187,6 +187,7 @@ class List
class NodeList extends List
ofType: (type) -> new NodeList _(@items).filter (node) -> node instanceof type
clone: -> new NodeList super().items
+ names: -> _(@items).pluck 'name'
class ArcList extends List
from: (node) ->
11 src/icing.coffee
View
@@ -65,8 +65,13 @@ global.task = (target, description, prereqs=undefined, recipe=undefined) ->
prereqs = []
if not recipe?
- recipe = prereqs
- prereqs = []
+ if description.shift?
+ recipe = prereqs
+ prereqs = description
+ description = target
+ else
+ recipe = prereqs
+ prereqs = []
# Add a rule to the rule graph.
graph.rule new Rule target, prereqs, recipe
@@ -141,6 +146,6 @@ runRecipeContext = (graph, recipeNode, runNextRecipeCallback, options) ->
callback: runNextRecipeCallback
finished: finishedFn
failed: failedFn
- prereqs: recipeNode.prereqs graph
+ prereqs: recipeNode.prereqs(graph).names()
exec: execFn
}
20 src/rules.coffee
View
@@ -21,6 +21,7 @@
{ Graph, Node, Arc, NodeList } = require './dag'
_ = require 'underscore'
assert = require 'assert'
+{ globSync } = require 'glob'
class RuleGraph extends Graph
recipeNodesTo: (target) ->
@@ -51,10 +52,19 @@ class RuleGraph extends Graph
inputsOutputs.forEach (inputsOutput) ->
graph.arc inputsOutput.name, target.name
return
+ graph.arc input.name, target.name
else
- input = new FileNode prereq
- graph.node input
- graph.arc input.name, target.name
+ # see if there's an expansion for it
+ globbed = globSync prereq
+ if globbed.length > 0
+ globbed.forEach (file) ->
+ input = new FileNode file
+ graph.node input
+ graph.arc input.name, target.name
+ else
+ input = new FileNode prereq
+ graph.node input
+ graph.arc input.name, target.name
outputs = rule.recipe.outputs.call rule
outputs.forEach (output) ->
@@ -69,7 +79,7 @@ class Rule
constructor: (@target, @prereqs, @recipe) ->
if _(@recipe).isFunction()
@recipe = new Recipe @recipe
- @prereqs = @prereqs.reverse()
+ @prereqs = @prereqs.reverse() # Because we push they'll get reversed again
class Recipe
constructor: (@exec = (->), @outputs = (->[])) ->
@@ -80,7 +90,7 @@ class RecipeNode extends Node
equals: (node) ->
super(node) && node instanceof RecipeNode
clone: (node) -> new RecipeNode @name, @recipe
- prereqs: (graph) -> [] #TODO implement
+ prereqs: (graph) -> graph.arcs.to(graph.node this.name).from().ofType FileNode
shouldRun: (graph) -> true
run: (context, options) -> @recipe.exec.call context, options
Please sign in to comment.
Something went wrong with that request. Please try again.