perform a switch to yaml
This commit is contained in:
147
autogen/yamlgen.js
Normal file
147
autogen/yamlgen.js
Normal file
@@ -0,0 +1,147 @@
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const yaml = require("yaml")
|
||||
|
||||
const yamlAPIPath = path.join(__dirname, "../", "yaml", "types")
|
||||
const yamlEnumPath = path.join(__dirname, "../", "yaml", "enums")
|
||||
|
||||
if (!fs.existsSync(yamlAPIPath)) {
|
||||
fs.mkdirSync(yamlAPIPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(yamlEnumPath)) {
|
||||
fs.mkdirSync(yamlEnumPath, { recursive: true })
|
||||
}
|
||||
|
||||
const data = JSON.parse(fs.readFileSync("def.json", "utf-8"))
|
||||
|
||||
// Process Classes
|
||||
for (const c of data.Classes) {
|
||||
let yamlPath = path.join(yamlAPIPath, c.Name + ".yaml")
|
||||
|
||||
let obj = {
|
||||
...c,
|
||||
Properties: [],
|
||||
Methods: [],
|
||||
Events: [],
|
||||
}
|
||||
|
||||
// Load existing data if file exists
|
||||
let existingDescriptions = { Properties: {}, Methods: {}, Events: {} };
|
||||
let existingArguments = { Events: {} };
|
||||
let existingClassDescription = "Missing Documentation";
|
||||
|
||||
if (fs.existsSync(yamlPath)) {
|
||||
const existingXml = fs.readFileSync(yamlPath, "utf-8");
|
||||
const existingData = yaml.parse(existingXml);
|
||||
|
||||
// Preserve existing class description
|
||||
if (existingData.Description) {
|
||||
existingClassDescription = existingData.Description;
|
||||
}
|
||||
|
||||
// Build lookup maps for existing descriptions
|
||||
if (existingData.Properties) {
|
||||
const props = Array.isArray(existingData.Properties)
|
||||
? existingData.Properties
|
||||
: [existingData.Properties];
|
||||
props.forEach(p => {
|
||||
if (p.Name) existingDescriptions.Properties[p.Name] = p.Description || "";
|
||||
});
|
||||
}
|
||||
|
||||
if (existingData.Methods) {
|
||||
const methods = Array.isArray(existingData.Methods)
|
||||
? existingData.Methods
|
||||
: [existingData.Methods];
|
||||
methods.forEach(m => {
|
||||
if (m.Name) existingDescriptions.Methods[m.Name] = m.Description || "";
|
||||
});
|
||||
}
|
||||
|
||||
if (existingData.Events) {
|
||||
const events = Array.isArray(existingData.Events)
|
||||
? existingData.Events
|
||||
: [existingData.Events];
|
||||
events.forEach(e => {
|
||||
if (e.Name) {
|
||||
existingDescriptions.Events[e.Name] = e.Description || "";
|
||||
existingArguments.Events[e.Name] = e.Arguments || "";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add class description
|
||||
obj.Description = existingClassDescription;
|
||||
|
||||
// Add properties
|
||||
for (const prop of c.Properties) {
|
||||
if (prop.IsObsolete) continue
|
||||
obj.Properties.push({
|
||||
...prop,
|
||||
Description: existingDescriptions.Properties[prop.Name] || "Missing Documentation"
|
||||
})
|
||||
}
|
||||
|
||||
// Add methods
|
||||
for (const m of c.Methods) {
|
||||
if (m.IsObsolete) continue
|
||||
obj.Methods.push({
|
||||
...m,
|
||||
Description: existingDescriptions.Methods[m.Name] || "Missing Documentation"
|
||||
})
|
||||
}
|
||||
|
||||
// Add events
|
||||
for (const e of c.Events) {
|
||||
obj.Events.push({
|
||||
...e,
|
||||
Description: existingDescriptions.Events[e.Name] || "Missing Documentation",
|
||||
Arguments: existingArguments.Events[e.Name] || ""
|
||||
})
|
||||
}
|
||||
|
||||
fs.writeFileSync(yamlPath, yaml.stringify(obj))
|
||||
}
|
||||
|
||||
// Process Enums
|
||||
for (const e of data.Enums) {
|
||||
let yamlPath = path.join(yamlEnumPath, e.Name + ".yaml")
|
||||
|
||||
let obj = {
|
||||
...e,
|
||||
Options: []
|
||||
}
|
||||
|
||||
let existingDescriptions = {};
|
||||
let existingEnumDescription = "";
|
||||
if (fs.existsSync(yamlPath)) {
|
||||
const existingXml = fs.readFileSync(yamlPath, "utf-8");
|
||||
const existingData = yaml.parse(existingXml);
|
||||
|
||||
existingEnumDescription = existingData.Description || "";
|
||||
|
||||
if (existingData.Options) {
|
||||
const options = Array.isArray(existingData.Options)
|
||||
? existingData.Options
|
||||
: [existingData.Options];
|
||||
options.forEach(o => {
|
||||
if (o.Name) existingDescriptions[o.Name] = o.Description || "";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add enum description
|
||||
obj.Description = existingEnumDescription || "Missing Documentation";
|
||||
|
||||
// Add options
|
||||
for (const option of e.Options) {
|
||||
obj.Options.push({
|
||||
Name: option,
|
||||
Description: existingDescriptions[option] || ""
|
||||
})
|
||||
}
|
||||
|
||||
fs.writeFileSync(yamlPath, yaml.stringify(obj))
|
||||
}
|
||||
Reference in New Issue
Block a user