Comparing version 0.12.3 to 0.13.0
0.13.0 / 2016-06-13 | ||
=================== | ||
* support a global tree root (fixes #15) | ||
0.12.3 / 2016-06-11 | ||
@@ -3,0 +8,0 @@ =================== |
@@ -23,5 +23,8 @@ | ||
* Creates a new instance, particularly creating the Graph instance. | ||
* | ||
* @param {String} [root] The project root. (default: pwd) | ||
*/ | ||
constructor() { | ||
constructor(root) { | ||
debug('initialize'); | ||
this.root = root; | ||
this.graph = new Graph(); | ||
@@ -48,2 +51,8 @@ } | ||
addFile(params) { | ||
if (typeof params === 'string') { | ||
params = { base: this.root, path: params }; | ||
} else { | ||
params.base = this.root; | ||
} | ||
let file = new File(params, this); | ||
@@ -50,0 +59,0 @@ debug('adding file: %s', relative(file.path)); |
{ | ||
"name": "mako-tree", | ||
"version": "0.12.3", | ||
"version": "0.13.0", | ||
"main": "./lib/tree", | ||
@@ -5,0 +5,0 @@ "description": "The build tree structure used internally by mako", |
@@ -21,3 +21,3 @@ # mako-tree | ||
### Tree() *(constructor)* | ||
### Tree([root]) *(constructor)* | ||
@@ -27,2 +27,6 @@ Each instance represents a build tree. Internally, a graph is used to manage the relationships | ||
The `root` is a project root that will determine all `file.base` properties. Only 1 root is | ||
supported per tree. Also, this value will override any `base` parameter you specify in when | ||
adding files. | ||
### Tree#hasFile(file) | ||
@@ -29,0 +33,0 @@ |
@@ -327,2 +327,9 @@ | ||
describe('#toString()', function () { | ||
it('should return a string', function () { | ||
let a = new File('a'); | ||
assert.isString(a.toString()); | ||
}); | ||
}); | ||
describe('.fromObject(input, tree)', function () { | ||
@@ -329,0 +336,0 @@ it('should parse a JSON string into a file instance', function () { |
@@ -6,5 +6,7 @@ | ||
let bufferEqual = require('buffer-equal'); | ||
let File = require('../lib/file'); | ||
let Tree = require('../lib/tree'); | ||
describe('Tree()', function () { | ||
describe('Tree([root])', function () { | ||
it('should be a constructor function', function () { | ||
@@ -14,2 +16,7 @@ assert.instanceOf(new Tree(), Tree); | ||
it('should add the root property', function () { | ||
let tree = new Tree('a'); | ||
assert.strictEqual(tree.root, 'a'); | ||
}); | ||
it('should be empty by default', function () { | ||
@@ -43,2 +50,34 @@ let tree = new Tree(); | ||
}); | ||
it('should return the new file', function () { | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
assert.instanceOf(a, File); | ||
}); | ||
it('should set the path of the new file', function () { | ||
let tree = new Tree(); | ||
let a = tree.addFile('a'); | ||
assert.strictEqual(a.path, 'a'); | ||
}); | ||
it('should support objects', function () { | ||
let tree = new Tree(); | ||
let a = tree.addFile({ path: 'a' }); | ||
assert.strictEqual(a.path, 'a'); | ||
}); | ||
context('with root', function () { | ||
it('should impose tree.root as file.base', function () { | ||
let tree = new Tree('a'); | ||
let file = tree.addFile('z'); | ||
assert.strictEqual(file.base, 'a'); | ||
}); | ||
it('should override any specified base with tree.root', function () { | ||
let tree = new Tree('a'); | ||
let file = tree.addFile({ base: 'b', path: 'z' }); | ||
assert.strictEqual(file.base, 'a'); | ||
}); | ||
}); | ||
}); | ||
@@ -45,0 +84,0 @@ |
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
61411
1413
222