Created
May 11, 2020 06:14
-
-
Save csauve/b45294b4b358fb3f7a8266a14938878b to your computer and use it in GitHub Desktop.
BREAK GLASS IF NEW C20 YAML FILES NEEDED
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
function buildYamlFiles(invaderStructDefs, basicTags) { | |
const describeStruct = (invaderStructName, name) => { | |
const struct = invaderStructDefs[invaderStructName]; | |
if (!struct) { | |
return { | |
...(name && {name}), | |
md: "...", | |
}; | |
} else if (struct.type == "enum") { | |
return { | |
...(name && {name}), | |
md: "...", | |
options: struct.options.map(name => ({name, md: "..."})) | |
}; | |
} else if (struct.type == "bitfield") { | |
return { | |
...(name && {name}), | |
md: "...", | |
fields: struct.fields.map(field => ({name: field, md: "..."})) | |
}; | |
} if (struct.type == "struct") { | |
const namedFields = struct.fields.filter(it => it.name); | |
return { | |
...(name && {name}), | |
md: "...", | |
fields: namedFields.map(field => ({ | |
...(field.type && describeStruct(field.type, field.name)), | |
...(field.type == "TagReflexive" && describeStruct(field.struct, field.name)), | |
})) | |
}; | |
} else { | |
throw new Error(`Unhandled type: ${struct.type}`); | |
} | |
}; | |
for (let tag of basicTags) { | |
try { | |
const tagOut = { | |
name: tag.name, | |
id: tag.id, | |
...(tag.parent && { | |
parent: tag.parent.name | |
}), | |
...(tag.invaderStructName && { | |
invaderStructName: tag.invaderStructName | |
}), | |
...(tag.invaderStructName && { | |
comments: describeStruct(tag.invaderStructName) | |
}) | |
}; | |
fs.writeFileSync( | |
`./tags/${tag.name}.yml`, | |
yaml.safeDump(tagOut), | |
"utf8" | |
); | |
} catch (e) { | |
console.error(tag.name); | |
console.error(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment