Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created May 7, 2014 20:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasboyt/9a8f0da4b518d6737912 to your computer and use it in GitHub Desktop.
Save thomasboyt/9a8f0da4b518d6737912 to your computer and use it in GitHub Desktop.
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