diff --git a/packages/file-graph/fileNode.js b/packages/file-graph/fileNode.js index d7d4e01..cf8f089 100644 --- a/packages/file-graph/fileNode.js +++ b/packages/file-graph/fileNode.js @@ -80,6 +80,9 @@ export default class FileNode extends File { // If this is the same node, merge the children if (fileNode.path === this.path) { + // Update the state of this node + this.discovered = this.discovered || fileNode.discovered + fileNode.children.forEach((child) => { const existingChild = this.children.find((c) => c.path === child.path) if (existingChild) { @@ -116,12 +119,15 @@ export default class FileNode extends File { } } - toString() { - const indent = ' '.repeat(this.path.split('/').length - 1) - const suffix = this.isDirectory() ? '/' : '' + toString(level = 0) { + let { name } = this + const indent = ' '.repeat(level) + name = `${indent}${name}` + if (this.isDirectory()) name += '/' + if (!this.discovered) name += `*` const childrenString = this.children - .map((child) => child.toString()) + .map((child) => child.toString(level + 1)) .join('') - return `${indent}${this.name}${suffix}\n${childrenString}` + return `${name}\n${childrenString}` } } diff --git a/packages/file-graph/fileNode.test.js b/packages/file-graph/fileNode.test.js index 4621baf..3413dc5 100644 --- a/packages/file-graph/fileNode.test.js +++ b/packages/file-graph/fileNode.test.js @@ -193,6 +193,35 @@ describe('FileNode', () => { mergeTest(files1, files2, expected) }) + test('merge-hidden', () => { + const root = { + path: '/', + type: 'folder', + } + const files1 = [ + root, + { path: '/a', type: 'file', discovered: true }, + { path: '/.b', type: 'file', discovered: false }, + { path: '/c', type: 'folder', discovered: true }, + { path: '/c/.d', type: 'file', discovered: false }, + ] + + const files2 = [ + { path: '/c', type: 'folder', discovered: true }, + { path: '/c/.d', type: 'file', discovered: true }, + ] + + const expected = [ + root, + { path: '/a', type: 'file', discovered: true }, + { path: '/.b', type: 'file', discovered: false }, + { path: '/c', type: 'folder', discovered: true }, + { path: '/c/.d', type: 'file', discovered: true }, + ] + + mergeTest(files1, files2, expected) + }) + test('remove-child', () => { const root = { path: '/',