mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Finished switching to bower.json
This commit is contained in:
32
lib/util/fallback.js
Normal file
32
lib/util/fallback.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// ==========================================
|
||||
// BOWER: fallback
|
||||
// ==========================================
|
||||
// Copyright 2012 Twitter, Inc
|
||||
// Licensed under The MIT License
|
||||
// http://opensource.org/licenses/MIT
|
||||
// ==========================================
|
||||
// A function that takes a list of files and returns the first one that exists
|
||||
// If none exists, return null
|
||||
|
||||
var fileExists = require('./file-exists');
|
||||
var path = require('path');
|
||||
|
||||
var fallback = function (baseDir, files, callback) {
|
||||
if (!Array.isArray(files) || files.length === 0) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
var file = files.shift();
|
||||
|
||||
fileExists(path.join(baseDir, file), function (exists) {
|
||||
if (!exists) {
|
||||
return fallback(baseDir, files, callback);
|
||||
} else {
|
||||
return callback(file);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = fallback;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user