Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
load package main from bower.json if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Feb 19, 2015
1 parent b79f3c2 commit c054a90
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,53 @@ GithubLocation.prototype = {
return false;
});
});
},

// check if the main entry point exists. If not, try the bower.json main.
build: function(pjson, dir) {
var main = pjson.main || '';

if (main.indexOf('!') != -1)
return;

function checkMain(main) {
if (!main)
return Promise.resolve(false);

return new Promise(function(resolve, reject) {
fs.exists(path.resolve(dir, main), function(exists) {
resolve(exists);
});
});
}

return checkMain(main, dir)
.then(function(hasMain) {
if (hasMain)
return;

return asp(fs.readFile)(path.resolve(dir, 'bower.json'))
.then(function(bowerJson) {
try {
bowerJson = JSON.parse(bowerJson);
}
catch(e) {
return;
}

main = bowerJson.main || '';
if (main instanceof Array)
main = main[0];

return checkMain(main, dir);
})
.then(function(hasBowerMain) {
if (!hasBowerMain)
return;

pjson.main = main;
});
});
}

};
Expand Down

0 comments on commit c054a90

Please sign in to comment.