Permalink
Browse files

Bumping to 0.2.0 with a number of improvements over 0.1.0

  • Loading branch information...
KrisJordan committed Jan 7, 2011
1 parent 384653b commit 5d86d78cb400b4bcea24e44f70c9354ebad0f465
Showing with 71 additions and 40 deletions.
  1. +2 −2 Cakefile
  2. +12 −10 docs/icing.html
  3. +11 −6 docs/rules.html
  4. +10 −3 lib/icing.js
  5. +12 −8 lib/rules.js
  6. +1 −1 package.json
  7. +13 −5 src/icing.coffee
  8. +10 −5 src/rules.coffee
View
@@ -17,13 +17,13 @@ task 'test', ['spec/*','src/*'], (options) ->
]
task 'compile', ['task(test)','src/*'],
- exec: -> this.exec "coffee -c -o lib/ #{this.modifiedPrereqs.join(' ')}"
+ recipe: -> this.exec "coffee -c -o lib/ #{this.modifiedPrereqs.join(' ')}"
outputs: ->
for prereq in this.filePrereqs
prereq.replace /src\/(.*).coffee/,"lib/$1.js"
task 'docs', 'Generate docco documentation', ['src/*'],
- exec: (options) ->
+ recipe: (options) ->
this.exec "docco #{this.modifiedPrereqs.join(' ')}"
outputs: ->
for prereq in this.filePrereqs
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>rules.coffee</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="dag.html"> dag.coffee </a> <a class="source" href="icing.html"> icing.coffee </a> <a class="source" href="rules.html"> rules.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> rules.coffee </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> <p><strong>rules</strong> models task pipelines using directed acyclic graph (<strong>dag.coffee</strong>) primitives.
+<!DOCTYPE html> <html> <head> <title>rules.coffee</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="icing.html"> icing.coffee </a> <a class="source" href="rules.html"> rules.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> rules.coffee </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> <p><strong>rules</strong> models task pipelines using directed acyclic graph (<strong>dag.coffee</strong>) primitives.
Following in the heritage of <em>make</em>, rules have a target, prerequisites, and a recipe.
Unlike <em>make</em> target is a symbolic name and prerequisites can refer to other rules or to
files on disk.</p>
@@ -46,13 +46,18 @@
<span class="nv">target = </span><span class="k">new</span> <span class="nx">RecipeNode</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">target</span><span class="p">,</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">recipe</span>
<span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="nx">target</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>Glob Prereqs</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">rule.prereqs = </span><span class="nx">_</span><span class="p">(</span><span class="nx">rule</span><span class="p">.</span><span class="nx">prereqs</span><span class="p">)</span>
<span class="p">.</span><span class="nx">chain</span><span class="p">()</span>
+ <span class="p">.</span><span class="nx">flatten</span><span class="p">()</span>
<span class="p">.</span><span class="nx">map</span><span class="p">(</span> <span class="nf">(prereq) -&gt;</span>
- <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="k">if</span> <span class="sr">/\*/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">prereq</span>
+ <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="k">else</span>
+ <span class="kc">undefined</span>
<span class="k">else</span>
<span class="nx">prereq</span>
<span class="p">)</span>
+ <span class="p">.</span><span class="nx">compact</span><span class="p">()</span>
<span class="p">.</span><span class="nx">flatten</span><span class="p">()</span>
<span class="p">.</span><span class="nx">value</span><span class="p">()</span>
@@ -100,7 +105,7 @@
<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-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#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">@recipe = </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-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#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>
@@ -145,7 +150,7 @@
<span class="k">return</span> <span class="o">not</span> <span class="k">this</span><span class="p">.</span><span class="nx">modifiedPrereqs</span><span class="p">(</span><span class="nx">graph</span><span class="p">).</span><span class="nx">isEmpty</span><span class="p">()</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>
+ <span class="nv">run: </span><span class="nf">(context, options) -&gt;</span> <span class="nx">@recipe</span><span class="p">.</span><span class="nx">recipe</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">options</span>
<span class="k">class</span> <span class="nx">FileNode</span> <span class="k">extends</span> <span class="nx">Node</span>
<span class="nv">constructor: </span><span class="nf">(@name) -&gt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">refresh</span><span class="p">()</span>
View
@@ -1,5 +1,5 @@
(function() {
- var RecipeNode, Rule, RuleGraph, cakeTask, exec, fs, graph, runRecipeContext, stylize, _ref;
+ var RecipeNode, Rule, RuleGraph, cakeTask, exec, fs, graph, icing, runRecipeContext, stylize, _, _ref;
if (!(typeof option != "undefined" && option !== null)) {
console.error("require('icing') can only be used in Cakefiles\n");
process.exit(1);
@@ -9,8 +9,12 @@
_ref = require('./rules'), RuleGraph = _ref.RuleGraph, Rule = _ref.Rule, RecipeNode = _ref.RecipeNode;
exec = require('child_process').exec;
fs = require('fs');
+ _ = require('underscore');
cakeTask = global.task;
graph = new RuleGraph;
+ icing = {
+ beforeTask: function(options) {}
+ };
global.task = function(target, description, prereqs, recipe) {
if (prereqs == null) {
prereqs = void 0;
@@ -36,6 +40,7 @@
graph.rule(new Rule(target, prereqs, recipe));
return cakeTask(target, description, function(options) {
var aRecipeRan, allRecipesProcessed, fileSources, recipeNode, recipeNodes, runTask, taskIsRunning;
+ icing.beforeTask(options);
taskIsRunning = false;
recipeNodes = {
isEmpty: function() {
@@ -83,7 +88,7 @@
}
} else {
allRecipesProcessed = true;
- if (!aRecipeRan && (options.verbose != null)) {
+ if (!aRecipeRan && !(options.watch != null)) {
console.error(stylize("cake: Nothing to be done for `" + target + "'.", 'yellow'));
}
if (options.watch != null) {
@@ -101,7 +106,7 @@
}
fileSources.forEach(function(file) {
return fs.watchFile(file, {
- interval: 250
+ interval: 100
}, function(curr, prev) {
if (taskIsRunning) {
return;
@@ -169,6 +174,7 @@
failed: failedFn,
prereqs: recipeNode.prereqs(graph).names(),
modifiedPrereqs: recipeNode.modifiedPrereqs(graph).names(),
+ outputs: recipeNode.outputs(graph).names(),
exec: execFn
};
};
@@ -187,4 +193,5 @@
};
return "\033[" + styles[style][0] + "m" + str + "\033[" + styles[style][1] + "m";
};
+ global.icing = icing;
}).call(this);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -2,7 +2,7 @@
"name": "icing",
"description": "Dependency management for cake command.",
"keywords": ["cake","dependency","build","watch"],
- "version": "0.1.0",
+ "version": "0.2.0",
"repository": "git://github.com/KrisJordan/icing.git",
"author": "Kris Jordan",
"directories": {
View
@@ -49,7 +49,6 @@
# TODO: In watch mode run from modified source rather than beginning
# TODO: Watch mode with globbed prereqs should watch for globbed changes and rebuild
# graph.
-# TODO: Test with non-existant inputs.
# ### Options
if not option?
@@ -63,11 +62,13 @@ option '-w', '--watch', 'Monitor files for changes and automatically reb
{ RuleGraph, Rule, RecipeNode } = require './rules'
{ exec } = require 'child_process'
fs = require 'fs'
+_ = require 'underscore'
-# Preserve a reference to cake's task, we'll be using it.
+# Preserve a reference to cake's task function, we'll be leveraging it.
cakeTask = global.task
-
graph = new RuleGraph
+icing =
+ beforeTask: (options)->
global.task = (target, description, prereqs=undefined, recipe=undefined) ->
if not prereqs? and not recipe?
@@ -89,6 +90,9 @@ global.task = (target, description, prereqs=undefined, recipe=undefined) ->
# Bootstrap into cake's task book keeping!
cakeTask target, description, (options) ->
+ # Call the pre-task hook
+ icing.beforeTask options
+
# Runtime State
taskIsRunning = false
recipeNodes = { isEmpty: -> true }
@@ -125,7 +129,7 @@ global.task = (target, description, prereqs=undefined, recipe=undefined) ->
do runNextRecipeCallback
else
allRecipesProcessed = true
- if not aRecipeRan and options.verbose?
+ if not aRecipeRan and not options.watch?
# Homage
console.error stylize "cake: Nothing to be done for `#{target}'.", 'yellow'
if options.watch?
@@ -139,7 +143,7 @@ global.task = (target, description, prereqs=undefined, recipe=undefined) ->
console.error stylize "cake: Nothing to watch for `#{target}'", 'yellow'
fileSources.forEach (file) ->
- fs.watchFile file, {interval:250}, (curr,prev) ->
+ fs.watchFile file, {interval:100}, (curr,prev) ->
if taskIsRunning then return
if curr.mtime > prev.mtime
console.log stylize "! `#{file}` Changed", 'green'
@@ -191,6 +195,7 @@ runRecipeContext = (graph, recipeNode, runNextRecipeCallback, options) ->
failed: failedFn
prereqs: recipeNode.prereqs(graph).names()
modifiedPrereqs: recipeNode.modifiedPrereqs(graph).names()
+ outputs: recipeNode.outputs(graph).names()
exec: execFn
}
@@ -207,3 +212,6 @@ stylize = (str, style) ->
'grey' : [90, 39]
'green-hi' : [92, 32]
"\033[#{styles[style][0]}m#{str}\033[#{styles[style][1]}m"
+
+#### Exports
+global.icing = icing
View
@@ -50,13 +50,18 @@ class RuleGraph extends Graph
# Glob Prereqs
rule.prereqs = _(rule.prereqs)
.chain()
+ .flatten()
.map( (prereq) ->
- globbed = globSync prereq
- if globbed.length > 0
- globbed
+ if /\*/.test prereq
+ globbed = globSync prereq
+ if globbed.length > 0
+ globbed
+ else
+ undefined
else
prereq
)
+ .compact()
.flatten()
.value()
@@ -114,7 +119,7 @@ class Rule
@prereqs = @prereqs.reverse() # Because we push they'll get reversed again
class Recipe
- constructor: (@exec = (->), @outputs = (->[])) ->
+ constructor: (@recipe = (->), @outputs = (->[])) ->
#### Additional Graph Nodes
class RecipeNode extends Node
@@ -169,7 +174,7 @@ class RecipeNode extends Node
return not this.modifiedPrereqs(graph).isEmpty()
- run: (context, options) -> @recipe.exec.call context, options
+ run: (context, options) -> @recipe.recipe.call context, options
class FileNode extends Node
constructor: (@name) -> this.refresh()

0 comments on commit 5d86d78

Please sign in to comment.