Created
May 7, 2014 20:46
-
-
Save thomasboyt/9a8f0da4b518d6737912 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var fs = require('fs'); | |
var globSync = require('glob').sync; | |
var yaml = require('js-yaml'); | |
module.exports = function(folder) { | |
var files = globSync(path.join(folder, '**/*.yaml')); | |
var data = {}; | |
files.forEach(function(filename) { | |
var dataKey = path.basename(filename, path.extname(filename)); | |
if ( data[dataKey] ) { | |
throw new Error('Attempted to add key ' + dataKey + ' to data hash, but that key already exists.'); | |
} | |
var content = fs.readFileSync(filename, {encoding: 'utf8'}); | |
data[dataKey] = yaml.safeLoad(content); | |
}); | |
return data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment