fix list --source listing non-main sources

This commit is contained in:
David DeSandro
2013-03-02 10:31:48 -05:00
parent 81a80c68fe
commit deb4855598
4 changed files with 20 additions and 14 deletions

View File

@@ -53,27 +53,33 @@ var generatePath = function (name, main) {
}
};
var mainTypes = ['main', 'scripts', 'styles', 'templates', 'images'];
var buildSource = function (pkg, shallow) {
var result = {};
if (pkg) {
['main', 'scripts', 'styles', 'templates', 'images'].forEach(function (type) {
mainTypes.forEach(function (type) {
if (pkg.json[type]) result[type] = generatePath(pkg.name, pkg.json[type]);
});
}
if (shallow) {
result.main = result.main ? result.main
: result.scripts ? result.scripts
: result.styles ? result.styles
: result.templates ? result.templates
: result.images ? result.images
: generatePath(pkg.name, '');
result.main = getMain(result) || generatePath(pkg.name, '');
}
return result;
};
var getMain = function (source) {
for (var i = 0, len = mainTypes.length; i < len; i += 1) {
var type = mainTypes[i];
if (source[type]) {
return source[type];
}
}
};
var shallowTree = function (packages, tree) {
var result = {};
@@ -127,7 +133,7 @@ var getDependencySrcs = function (list) {
var dependency, main;
for (var name in list) {
dependency = list[name];
main = dependency.source && dependency.source.main;
main = dependency.source && getMain(dependency.source);
if (dependency.dependencies) {
var depSrcs = getDependencySrcs(dependency.dependencies);

View File

@@ -1,7 +1,7 @@
{
"name": "a1",
"version": "0.0.1",
"main": [
"scripts": [
"a1.js"
],
"dependencies": {

View File

@@ -1,7 +1,7 @@
{
"name": "c",
"version": "0.0.1",
"main": "c.js",
"styles": "c.css",
"dependencies": {
}
}

View File

@@ -78,7 +78,7 @@ describe('list', function () {
],
b: ['components/b/b.js', 'components/b/b.html'],
b1: ['components/b1/b1.js', 'components/b1/b1.css'],
c: 'components/c/c.js'
c: 'components/c/c.css'
});
next();
@@ -141,13 +141,13 @@ describe('list', function () {
'components/a2/a2.js',
'components/a/a.js',
'components/b1/b1.js',
'components/b/b.js',
'components/c/c.js'
'components/b/b.js'
],
'.css': [
'components/a2/a2.css',
'components/a/a.css',
'components/b1/b1.css'
'components/b1/b1.css',
'components/c/c.css'
],
'.html': [ 'components/a2/a2.html', 'components/b/b.html' ]
});