Last active
December 24, 2015 11:39
-
-
Save sgoumaz/6792873 to your computer and use it in GitHub Desktop.
sintaxi/terraform: Alternatively accept `_data.js` for metadata instead of plain JSON
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
// simplest example | |
module.exports = { | |
"some-page": { | |
"title": "This uses data from an external JSON file", | |
"sourceData": require("./some.json") | |
} | |
}; |
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
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This applies to https://github.com/sintaxi/terraform/blob/master/lib/helpers/raw.js#L222
See sintaxi/harp#103 for original context.