Skip to content

Instantly share code, notes, and snippets.

@tinganho
Created June 12, 2015 08:37
Show Gist options
  • Save tinganho/34dd5afc0543326e1f4e to your computer and use it in GitHub Desktop.
Save tinganho/34dd5afc0543326e1f4e to your computer and use it in GitHub Desktop.
Generate Diagnostics file
function() {
var json = require('./errors/errors.json');
var errorText = 'export default {\n';
var length = Object.keys(json).length;
var index = 0;
for (var error in json) {
errorText += ' ' +
error.replace(/\s+/g, '_')
.replace(/['"\.]/g, '')
.replace(/{(\d)}/g, '$1');
errorText += ': {\n';
errorText += ' message: \'' + error + '\',\n';
errorText += ' code: ' + json[error].code + '\n';
errorText += ' }\n';
if (index < length - 1) {
errorText += ',';
}
index++;
}
errorText += '}';
fs.writeFileSync(path.join(__dirname, 'errors/errors.ts'), errorText);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment