Skip to content

Instantly share code, notes, and snippets.

@csauve
Created May 11, 2020 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csauve/b45294b4b358fb3f7a8266a14938878b to your computer and use it in GitHub Desktop.
Save csauve/b45294b4b358fb3f7a8266a14938878b to your computer and use it in GitHub Desktop.
BREAK GLASS IF NEW C20 YAML FILES NEEDED
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