-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtreeToDependencies.js
33 lines (23 loc) · 944 Bytes
/
treeToDependencies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var archy = require('archy')
module.exports = treeToDependencies
function treeToDependencies( tree ) {
return archy(treeToArchyTree(tree), '', {'unicode': false})
}
function treeToArchyTree(tree) {
var newTree = {}
function recurssiveArchyFormat(tree, newTree) {
var label = tree.parent == null ? tree.url.replace(/^.*\//,'') : tree.label
newTree.label = "<a href ='"+tree.url+"'>"+label+"</a>"
newTree.label += "<button class='btn clipboard' data-clipboard-text='+["+label+"]("+tree.url+")'>"
newTree.label += " <img class='clippy' src='images/clippy.svg' alt='Copy to clipboard' width='13'>"
newTree.label += "</button>"
newTree.nodes = []
tree.children.forEach( function(childTree, index) {
newTree.nodes[index] = {}
newTree.nodes[index] = recurssiveArchyFormat(childTree, newTree.nodes[index])
})
return newTree
}
recurssiveArchyFormat(tree, newTree)
return newTree
}