'use strict';

var fs = require('fs'),
    handlebars = require('handlebars'),
    bower = require('bower'),
    registry = require('./initRegistry');


var getRegistryList = function (request, result) {
    var templateFile = fs.readFileSync('viewRegistryList.hbs', 'utf-8');
    var hbTemplate = handlebars.compile(templateFile);

    var temp = [];
    for (var name in registry.packages) {
        //getDetailedPackageInfo(name);
        temp.push({
            name: name,
            url: registry.packages[name]
        });
    }
    var mustacheData = {
        bowerPackages : temp
    };

    result.send(hbTemplate(mustacheData));
};

var getDetailedPackageInfo = function (request, result) {
    console.log(request.params.name);
    bower.commands.info(request.params.name)
        .on('end', function (packageInfo) {
            console.log('Loaded details for : ' + request.params.name);
            console.log('pkgName: ' + packageInfo.name);
            console.log('versions: ' + packageInfo.versions);
            console.log('latestVersion: ' + packageInfo.versions[0]);
            console.log('dependencies: ' + packageInfo.latest.dependencies);
            console.log('devDependencies: ' + packageInfo.latest.devDependencies);
            result.send(packageInfo);
        });
};


exports.getRegistryList = getRegistryList;
exports.getDetailedPackageInfo = getDetailedPackageInfo;

@@ -1089,83 +1089,555 @@
 %5D);%0A
-            console.log('dependencies: ' + packageInfo.latest.dependencies)
+%0A            var flatDependencies = %5B%5D;%0A            for (var dep in packageInfo.latest.dependencies) %7B%0A                flatDependencies.push(dep);%0A            %7D%0A            packageInfo.latest.dependencies = flatDependencies;%0A            console.log('dependencies: ' + packageInfo.latest.dependencies);%0A%0A%0A            var flatDevDependencies = %5B%5D;%0A            for (var devDep in packageInfo.latest.devDependencies) %7B%0A                flatDevDependencies.push(devDep);%0A            %7D%0A            packageInfo.latest.devDependencies = flatDevDependencies
 ;%0A  
@@ -1713,24 +1713,25 @@
 endencies);%0A
+%0A
             

Package info now shows the dependencies and devDepencies