Comparing version 0.16.0 to 0.16.1
# master | ||
# 0.16.1 | ||
* Add Node interface to Builder, to enable building visualizations | ||
* Export `Builder.getDescription(tree)` helper function | ||
* Add footer to directory listings, so people know where they come from | ||
# 0.16.0 | ||
@@ -4,0 +10,0 @@ |
@@ -14,4 +14,24 @@ var path = require('path') | ||
function wrapStringErrors(reason) { | ||
var err | ||
if (typeof reason === 'string') { | ||
err = new Error(reason + ' [string exception]') | ||
} else { | ||
err = reason | ||
} | ||
throw err | ||
} | ||
function summarize(node) { | ||
return { | ||
directory: node.directory, | ||
graph: node, | ||
totalTime: node.totalTime | ||
} | ||
} | ||
Builder.prototype.build = function (willReadStringTree) { | ||
var self = this | ||
var builder = this | ||
@@ -21,22 +41,18 @@ var newTreesRead = [] | ||
return RSVP.resolve() | ||
return RSVP.Promise.resolve() | ||
.then(function () { | ||
return readAndReturnNodeFor(self.tree) // call self.tree.read() | ||
return readAndReturnNodeFor(builder.tree) // call builder.tree.read() | ||
}) | ||
.then(function (node) { | ||
return { directory: node.directory, graph: node, totalTime: node.totalTime } | ||
}) | ||
.finally(function () { | ||
for (var i = 0; i < newTreesRead.length; i++) { | ||
if (self.allTreesRead.indexOf(newTreesRead[i]) === -1) { | ||
self.allTreesRead.push(newTreesRead[i]) | ||
} | ||
.then(summarize) | ||
.finally(appendNewTreesRead) | ||
.catch(wrapStringErrors); | ||
function appendNewTreesRead() { | ||
for (var i = 0; i < newTreesRead.length; i++) { | ||
if (builder.allTreesRead.indexOf(newTreesRead[i]) === -1) { | ||
builder.allTreesRead.push(newTreesRead[i]) | ||
} | ||
}) | ||
.catch(function (err) { | ||
if (typeof err === 'string') { | ||
err = new Error(err + ' [string exception]') | ||
} | ||
throw err | ||
}) | ||
} | ||
} | ||
@@ -46,5 +62,6 @@ // Read the `tree` and return its node, which in particular contains the | ||
function readAndReturnNodeFor (tree) { | ||
tree = self.wrapIfNecessary(tree) | ||
tree = builder.wrapIfNecessary(tree) | ||
var index = newTreesRead.indexOf(tree) | ||
if (index !== -1) { | ||
// Return node from cache to deduplicate `.read` | ||
@@ -56,15 +73,16 @@ if (nodeCache[index].directory == null) { | ||
} | ||
return RSVP.resolve(nodeCache[index]) | ||
return RSVP.Promise.resolve(nodeCache[index]) | ||
} | ||
var node = { | ||
tree: tree, | ||
subtrees: [], | ||
selfTime: 0, | ||
totalTime: 0 | ||
} | ||
var node = new Node(tree) | ||
// we don't actually support duplicate trees, as such we should likely tag them.. | ||
// and kill the parallel array structure | ||
newTreesRead.push(tree) | ||
nodeCache.push(node) | ||
var treeDirPromise | ||
if (typeof tree === 'string') { | ||
treeDirPromise = RSVP.resolve() | ||
treeDirPromise = RSVP.Promise.resolve() | ||
.then(function () { | ||
@@ -81,3 +99,3 @@ if (willReadStringTree) willReadStringTree(tree) | ||
var readTreeRunning = false | ||
treeDirPromise = RSVP.resolve() | ||
treeDirPromise = RSVP.Promise.resolve() | ||
.then(function () { | ||
@@ -90,3 +108,3 @@ return tree.read(function readTree (subtree) { | ||
// Pause self timer | ||
// Pause builder timer | ||
var now = process.hrtime() | ||
@@ -96,3 +114,3 @@ node.selfTime += (now[0] - selfStartTime[0]) * 1e9 + (now[1] - selfStartTime[1]) | ||
return RSVP.resolve() | ||
return RSVP.Promise.resolve() | ||
.then(function () { | ||
@@ -102,3 +120,3 @@ return readAndReturnNodeFor(subtree) // recurse | ||
.then(function (childNode) { | ||
node.subtrees.push(childNode) | ||
node.addChild(childNode) | ||
return childNode.directory | ||
@@ -124,2 +142,3 @@ }) | ||
} | ||
return treeDirPromise | ||
@@ -134,9 +153,9 @@ .then(function (treeDir) { | ||
Builder.prototype.cleanup = function () { | ||
function cleanupTree(tree) { | ||
if (typeof tree !== 'string') { | ||
return tree.cleanup() | ||
} | ||
function cleanupTree(tree) { | ||
if (typeof tree !== 'string') { | ||
return tree.cleanup() | ||
} | ||
} | ||
Builder.prototype.cleanup = function () { | ||
return mapSeries(this.allTreesRead, cleanupTree) | ||
@@ -170,5 +189,46 @@ } | ||
var nodeId = 0 | ||
function Node(tree) { | ||
this.id = nodeId++ | ||
this.subtrees = [] | ||
this.selfTime = 0 | ||
this.totalTime = 0 | ||
this.tree = tree | ||
this.parents = [] | ||
} | ||
Node.prototype.addChild = function Node$addChild(child) { | ||
this.subtrees.push(child) | ||
} | ||
Node.prototype.inspect = function() { | ||
return 'Node:' + this.id + | ||
' subtrees: ' + this.subtrees.length + | ||
' selfTime: ' + this.selfTime + | ||
' totalTime: ' + this.totalTime | ||
} | ||
Node.prototype.toJSON = function() { | ||
var description = getDescription(this.tree) | ||
var subtrees = this.subtrees.map(function(node) { | ||
return node.id | ||
}) | ||
return { | ||
id: this.id, | ||
description: description, | ||
subtrees: subtrees, | ||
selfTime: this.selfTime, | ||
totalTime: this.totalTime | ||
} | ||
} | ||
exports.loadBrocfile = loadBrocfile | ||
function loadBrocfile () { | ||
var brocfile = findup('Brocfile.js', {nocase: true}) | ||
var brocfile = findup('Brocfile.js', { | ||
nocase: true | ||
}) | ||
if (brocfile == null) throw new Error('Brocfile.js not found') | ||
@@ -188,2 +248,3 @@ | ||
exports.getDescription = getDescription | ||
function getDescription (tree) { | ||
@@ -190,0 +251,0 @@ return (tree && tree.description) || |
{ | ||
"name": "broccoli", | ||
"description": "Fast client-side asset builder", | ||
"version": "0.16.0", | ||
"version": "0.16.1", | ||
"author": "Jo Liss <joliss42@gmail.com>", | ||
@@ -22,6 +22,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"broccoli-kitchen-sink-helpers": "^0.2.0", | ||
"broccoli-slow-trees": "^1.1.0", | ||
"commander": "^2.0.0", | ||
"connect": "^3.2.0", | ||
"broccoli-kitchen-sink-helpers": "^0.2.5", | ||
"broccoli-slow-trees": "^1.0.0", | ||
"commander": "^2.5.0", | ||
"connect": "^3.3.3", | ||
"copy-dereference": "^1.0.0", | ||
@@ -31,3 +31,2 @@ "findup-sync": "^0.2.1", | ||
"mime": "^1.2.11", | ||
"promise-map-series": "^0.2.1", | ||
"quick-temp": "^0.1.2", | ||
@@ -34,0 +33,0 @@ "rimraf": "^2.2.8", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
548
60412
21
- Removedpromise-map-series@^0.2.1
- Removedpromise-map-series@0.2.3(transitive)
Updatedbroccoli-slow-trees@^1.0.0
Updatedcommander@^2.5.0
Updatedconnect@^3.3.3