Skip to content

Commit

Permalink
Fixes yui#61 - Added try/catch to readdirSync
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Sep 17, 2012
1 parent 61207b6 commit 199c29e
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,46 +233,50 @@ var getProjectData = function(dir) {
if (!dir) {
dir = process.cwd();
}
var dirs = fs.readdirSync(dir);
dirs.forEach(function(d) {
var p = path.join(dir, d);
if (d.indexOf('.') === 0) {
return;
}
if (d === 'node_modules') {
Y.log('Skipping node_modules directory while scanning for yuidoc.json', 'warn', 'yuidoc');
return;
}
if (projectData) {
return;
}
if (Y.Files.isFile(p)) {
if (d === 'yuidoc.json') {
Y.log('Loading project data from: ' + p, 'info', 'yuidoc');
try {
projectData = Y.Files.getJSON(p);
} catch (e) {
var err = 'Failed to parse yuidoc.json file, please make sure it is valid JSON';
Y.log(err, 'error', 'yuidoc');
throw(e+'');
}
try {
var dirs = fs.readdirSync(dir);
dirs.forEach(function(d) {
var p = path.join(dir, d);
if (d.indexOf('.') === 0) {
return;
}
if (d === 'node_modules') {
Y.log('Skipping node_modules directory while scanning for yuidoc.json', 'warn', 'yuidoc');
return;
}
if (projectData) {
return;
}
if (d === 'package.json') {
Y.log('Loading project data from: ' + p, 'info', 'yuidoc');
try {
packageData = Y.Files.getJSON(p);
} catch (e) {
var err = 'Failed to parse package.json file, please make sure it is valid JSON';
Y.log(err, 'error', 'yuidoc');
throw(e+'');
if (Y.Files.isFile(p)) {
if (d === 'yuidoc.json') {
Y.log('Loading project data from: ' + p, 'info', 'yuidoc');
try {
projectData = Y.Files.getJSON(p);
} catch (e) {
var err = 'Failed to parse yuidoc.json file, please make sure it is valid JSON';
Y.log(err, 'error', 'yuidoc');
throw(e+'');
}
}
if (d === 'package.json') {
Y.log('Loading project data from: ' + p, 'info', 'yuidoc');
try {
packageData = Y.Files.getJSON(p);
} catch (e) {
var err = 'Failed to parse package.json file, please make sure it is valid JSON';
Y.log(err, 'error', 'yuidoc');
throw(e+'');
}
}
}
}
if (!projectData && Y.Files.isDirectory(p)) {
dirCount++
projectData = getProjectData(p);
}
});
if (!projectData && Y.Files.isDirectory(p)) {
dirCount++
projectData = getProjectData(p);
}
});
} catch (dirPerm) {
Y.log('Accessing dir (' + dir + ') threw an error', 'warn', 'yuidoc');
}
if (packageData && projectData || (packageData && packageData.yuidoc)) {
projectData = mergeData(packageData, projectData);
}
Expand Down

0 comments on commit 199c29e

Please sign in to comment.