Comparing version 0.0.1 to 0.1.0
0.1.0 / 2015-10-18 | ||
================== | ||
* adding file helpers for working with tree | ||
* adding tree.isSource check | ||
* updating travis npm config | ||
* adding badges | ||
* adding note about file.contents | ||
0.0.1 / 2015-10-18 | ||
@@ -3,0 +12,0 @@ ================== |
@@ -9,7 +9,32 @@ | ||
class File { | ||
constructor(location) { | ||
debug('initialize %s', this.path); | ||
constructor(location, tree) { | ||
debug('initialize %s', location); | ||
this.type = extension(location); | ||
this.path = location; | ||
this.tree = tree; | ||
} | ||
isSource() { | ||
return this.tree.isSource(this.path); | ||
} | ||
hasDependency(child) { | ||
return this.tree.hasDependency(this.path, child); | ||
} | ||
addDependency(child) { | ||
return this.tree.addDependency(this.path, child); | ||
} | ||
removeDependency(child) { | ||
return this.tree.removeDependency(this.path, child); | ||
} | ||
dependencies(recursive) { | ||
return this.tree.dependenciesOf(this.path, recursive); | ||
} | ||
dependants(recursive) { | ||
return this.tree.dependantsOf(this.path, recursive); | ||
} | ||
} | ||
@@ -16,0 +41,0 @@ |
@@ -21,3 +21,3 @@ | ||
debug('adding node: %s', location); | ||
let file = new File(location); | ||
let file = new File(location, this); | ||
this.graph.ensureVertex(location, file); | ||
@@ -36,4 +36,10 @@ return this.getFile(location); | ||
isSource(location) { | ||
return this.graph.inDegree(location) === 0; | ||
} | ||
getSources() { | ||
debug('listing sources'); | ||
return Array.from(this.graph.sources()).map(function (vertex) { | ||
debug('found source %s', vertex[0]); | ||
return vertex[0]; | ||
@@ -59,3 +65,3 @@ }); | ||
// if nothing else depends on this node, let's remove it | ||
if (this.dependantsOf(child).length === 0) { | ||
if (this.graph.inDegree(child) === 0) { | ||
debug('node %s no longer depended on, removing from tree', child); | ||
@@ -62,0 +68,0 @@ this.removeFile(child); |
{ | ||
"name": "mako-tree", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "The build tree structure used internally by mako", | ||
@@ -5,0 +5,0 @@ "repository": "makojs/tree", |
@@ -5,2 +5,5 @@ # mako-tree | ||
[![npm version](https://img.shields.io/npm/v/mako-tree.svg)](https://www.npmjs.com/package/mako-tree) | ||
[![build status](https://img.shields.io/travis/makojs/tree.svg)](https://travis-ci.org/makojs/tree) | ||
## Overview | ||
@@ -126,1 +129,6 @@ | ||
CoffeeScript plugin would switch from `"coffee"` to `"js"`. | ||
### File#contents | ||
This holds the current contents of the file. When first read, this property should be set, and | ||
subsequent changes to the source code should apply to this property. |
@@ -6,2 +6,3 @@ | ||
let File = require('../lib/file'); | ||
let Tree = require('../lib/tree'); | ||
@@ -23,2 +24,98 @@ describe('File()', function () { | ||
}); | ||
describe('#isSource()', function () { | ||
// a -> b | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
let b = tree.addFile('b'); | ||
tree.addDependency('a', 'b'); | ||
it('should return true if the file is a source', function () { | ||
assert.isTrue(a.isSource()); | ||
}); | ||
it('should return false if the file is not a source', function () { | ||
assert.isFalse(b.isSource()); | ||
}); | ||
}); | ||
describe('#hasDependency(child)', function () { | ||
// a -> b | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
tree.addFile('b'); | ||
tree.addDependency('a', 'b'); | ||
it('should return true file has the given child dependency', function () { | ||
assert.isTrue(a.hasDependency('b')); | ||
}); | ||
it('should return false if the file does not have the given child dependency', function () { | ||
assert.isFalse(a.hasDependency('c')); | ||
}); | ||
}); | ||
describe('#addDependency(child)', function () { | ||
it('should add the child as a new dependency', function () { | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
a.addDependency('b'); | ||
assert.isTrue(tree.hasFile('b')); | ||
}); | ||
it('should return the newly added dependency file', function () { | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
let b = a.addDependency('b'); | ||
assert.strictEqual(b, tree.getFile('b')); | ||
}); | ||
}); | ||
describe('#removeDependency(child)', function () { | ||
it('should remove the child as a dependency', function () { | ||
// a -> b | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
a.addDependency('b'); | ||
a.removeDependency('b'); | ||
assert.isFalse(tree.hasDependency('a', 'b')); | ||
}); | ||
}); | ||
describe('#dependencies(recursive)', function () { | ||
// a -> b -> c -> d | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
let b = a.addDependency('b'); | ||
let c = b.addDependency('c'); | ||
c.addDependency('d'); | ||
it('should return the direct descendents', function () { | ||
assert.deepEqual(b.dependencies(), [ 'c' ]); | ||
}); | ||
it('should return the entire dependency chain', function () { | ||
assert.deepEqual(b.dependencies(true), [ 'c', 'd' ]); | ||
}); | ||
}); | ||
describe('#dependants(recursive)', function () { | ||
// a -> b -> c -> d | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
let b = a.addDependency('b'); | ||
let c = b.addDependency('c'); | ||
c.addDependency('d'); | ||
it('should return the direct descendents', function () { | ||
assert.deepEqual(c.dependants(), [ 'b' ]); | ||
}); | ||
it('should return the entire dependency chain', function () { | ||
assert.deepEqual(c.dependants(true), [ 'b', 'a' ]); | ||
}); | ||
}); | ||
}); |
@@ -73,2 +73,3 @@ | ||
it('should fail if there are still dependencies defined', function () { | ||
// a -> b | ||
let tree = new Tree(); | ||
@@ -123,3 +124,20 @@ tree.addFile('a'); | ||
describe('#isSource(location)', function () { | ||
// a -> b | ||
let tree = new Tree(); | ||
tree.addFile('a'); | ||
tree.addFile('b'); | ||
tree.addDependency('a', 'b'); | ||
it('should return true when the file has no dependants', function () { | ||
assert.isTrue(tree.isSource('a')); | ||
}); | ||
it('should return false when the file is depended upon', function () { | ||
assert.isFalse(tree.isSource('b')); | ||
}); | ||
}); | ||
describe('#hasDependency(parent, child)', function () { | ||
// a -> b | ||
let tree = new Tree(); | ||
@@ -126,0 +144,0 @@ tree.addFile('a'); |
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
24000
465
133