function createNodeLicenseEntry()

in tasks/generate-license-data.js [146:197]


    function createNodeLicenseEntry(queue, licenses, errors, rootPath, name, dependencyType, dependencyScope, metadata) {
        var path = nodeTreeWalkUp(rootPath, name); 
        // some dependencies are declared but not used within child projects
        if (path === undefined) {
            var optionalDependencies = findAttribute(rootPath + '/package.json', 'optionalDependencies');
            // optional dependencies might not be loaded
            if (optionalDependencies != null && optionalDependencies[name] != null) {
                grunt.verbose.writeln('Node dependency ' + name + ' was declared optional but not found'  + ' when in ' + rootPath);
            } else {
                errors.push('WARNING: Node dependency declared but not used: ' + name + ' when in ' + rootPath);
            }
            return;
        }

        var version = findNodeAttribute(name, path, 'version');
        if (version == null || version.length === 0) {
            errors.push('WARNING: Could not find version of ' + name + ' in ' + path);
            version = '0.0.0';
        }

        var existingNode = _(licenses).find(function(element){
            return element.name == name;
        });

        if (existingNode != null) {
            // ignore the node if it is a duplicate or an older version
            if (existingNode.version.localeCompare(version) >= 0) {
                return;
            }
            // update the existing node if it is newer than this one
            existingNode.version = version;
            existingNode.url = findNodeHomepage(name, path, errors, metadata);
            existingNode.license = findNodeLicense(name, path, errors, metadata);
        } else {
            licenses.push({
                name: name,
                version: version,
                url: findNodeHomepage(name, path, errors, metadata),
                license: findNodeLicense(name, path, errors, metadata),
                type: dependencyType,
                scope: dependencyScope
            });

        }

        // add child to the queue
        queue.push({ path: path + '/node_modules/' + name,
                     dependencyName: name,
                     dependencyScope: DEPENDENCY_SCOPE.TRANSITIVE, // all child dependencies are by definition transitive
                     dependencyType: dependencyType,
                   });
    }