Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
# Logs
logs
*.log
Expand Down
35 changes: 19 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,28 @@ var readFirstFile = function readFirstFile(uri, filenames, css, cb, examinedFile
var filename = filenames.shift();
examinedFiles = examinedFiles || [];
examinedFiles.push(filename);
fs.readFile(filename, function(err, data) {
if (err) {
if (filenames.length) {
readFirstFile(uri, filenames, css, cb, examinedFiles);
}
else {
cb(new Error('Could not import `' + uri + '` from any of the following locations:\n ' + examinedFiles.join('\n ')));
}
try {
var data = fs.readFileSync(filename);
} catch (e) {
var err = e;
}
if (err) {
if (filenames.length) {
readFirstFile(uri, filenames, css, cb, examinedFiles);
}
else {
if ([ '.js', '.json', '.yml', '.yaml' ].indexOf(path.extname(filename)) !== -1) {
data = parseJSON(data, filename);
}
cb(null, {
'contents': data.toString(),
'file': filename
});
cb(new Error('Could not import `' + uri + '` from any of the following locations:\n ' + examinedFiles.join('\n ')));
}
});
}
else {
if ([ '.js', '.json', '.yml', '.yaml' ].indexOf(path.extname(filename)) !== -1) {
data = parseJSON(data, filename);
}
cb(null, {
'contents': data.toString(),
'file': filename
});
}
};

// This is a bootstrap function for calling readFirstFile.
Expand Down