mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
745 B
30 lines
745 B
'use strict'
|
|
var validate = require('aproba')
|
|
var moduleName = require('../utils/module-name.js')
|
|
|
|
module.exports = function (tree) {
|
|
validate('O', arguments)
|
|
var seen = {}
|
|
var flat = {}
|
|
var todo = [[tree, '/']]
|
|
while (todo.length) {
|
|
var next = todo.shift()
|
|
var pkg = next[0]
|
|
seen[pkg.path] = true
|
|
var path = next[1]
|
|
flat[path] = pkg
|
|
if (path !== '/') path += '/'
|
|
for (var ii = 0; ii < pkg.children.length; ++ii) {
|
|
var child = pkg.children[ii]
|
|
if (!seen[child.path]) {
|
|
todo.push([child, flatName(path, child)])
|
|
}
|
|
}
|
|
}
|
|
return flat
|
|
}
|
|
|
|
var flatName = module.exports.flatName = function (path, child) {
|
|
validate('SO', arguments)
|
|
return path + (moduleName(child) || 'TOP')
|
|
}
|
|
|