Skip to content

Instantly share code, notes, and snippets.

@sgoumaz
Last active December 24, 2015 11:39
Show Gist options
  • Save sgoumaz/6792873 to your computer and use it in GitHub Desktop.
Save sgoumaz/6792873 to your computer and use it in GitHub Desktop.
sintaxi/terraform: Alternatively accept `_data.js` for metadata instead of plain JSON
// simplest example
module.exports = {
"some-page": {
"title": "This uses data from an external JSON file",
"sourceData": require("./some.json")
}
};
try{
var possibleNames = ["_data.json", "_data.js"]
var dataPath
for(var i = 0; i < possibleNames.length; i++){
dataPath = path.resolve(dirPath, possibleNames[i])
if(fs.existsSync(dataPath)){
// ensure reload
delete require.cache[dataPath]
obj.data = require(dataPath)
break
}
}
}catch(e){
// removed check for non-existing case, this is explicitly taken care of above
e.source = "Data"
e.dest = "Globals"
e.lineno = -1
e.filename = dataPath
//e.stack = fileData.toString()
throw new TerraformError(e)
//console.log(e.code)
}
@sgoumaz
Copy link
Author

sgoumaz commented Oct 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment