docs v2
This commit is contained in:
163
autogen/xmlgen.js
Normal file
163
autogen/xmlgen.js
Normal file
@@ -0,0 +1,163 @@
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { XMLBuilder, XMLParser } = require("fast-xml-parser");
|
||||
|
||||
const xmlAPIPath = path.join(__dirname, "../", "xml", "types")
|
||||
const xmlEnumPath = path.join(__dirname, "../", "xml", "enums")
|
||||
|
||||
if (!fs.existsSync(xmlAPIPath)) {
|
||||
fs.mkdirSync(xmlAPIPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(xmlEnumPath)) {
|
||||
fs.mkdirSync(xmlEnumPath, { recursive: true })
|
||||
}
|
||||
|
||||
const data = JSON.parse(fs.readFileSync("def.json", "utf-8"))
|
||||
|
||||
const parser = new XMLParser();
|
||||
const builder = new XMLBuilder({
|
||||
format: true
|
||||
});
|
||||
|
||||
// Process Classes
|
||||
for (const c of data.Classes) {
|
||||
let xmlPath = path.join(xmlAPIPath, c.Name + ".xml")
|
||||
|
||||
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(xmlPath)) {
|
||||
const existingXml = fs.readFileSync(xmlPath, "utf-8");
|
||||
const existingData = parser.parse(existingXml);
|
||||
|
||||
if (existingData.ClassDef) {
|
||||
// Preserve existing class description
|
||||
if (existingData.ClassDef.Description) {
|
||||
existingClassDescription = existingData.ClassDef.Description;
|
||||
}
|
||||
|
||||
// Build lookup maps for existing descriptions
|
||||
if (existingData.ClassDef.Properties) {
|
||||
const props = Array.isArray(existingData.ClassDef.Properties)
|
||||
? existingData.ClassDef.Properties
|
||||
: [existingData.ClassDef.Properties];
|
||||
props.forEach(p => {
|
||||
if (p.Name) existingDescriptions.Properties[p.Name] = p.Description || "";
|
||||
});
|
||||
}
|
||||
|
||||
if (existingData.ClassDef.Methods) {
|
||||
const methods = Array.isArray(existingData.ClassDef.Methods)
|
||||
? existingData.ClassDef.Methods
|
||||
: [existingData.ClassDef.Methods];
|
||||
methods.forEach(m => {
|
||||
if (m.Name) existingDescriptions.Methods[m.Name] = m.Description || "";
|
||||
});
|
||||
}
|
||||
|
||||
if (existingData.ClassDef.Events) {
|
||||
const events = Array.isArray(existingData.ClassDef.Events)
|
||||
? existingData.ClassDef.Events
|
||||
: [existingData.ClassDef.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) {
|
||||
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] || ""
|
||||
})
|
||||
}
|
||||
|
||||
const xmlContent = builder.build({
|
||||
"?xml": "",
|
||||
ClassDef: obj
|
||||
});
|
||||
fs.writeFileSync(xmlPath, xmlContent)
|
||||
}
|
||||
|
||||
// Process Enums
|
||||
for (const e of data.Enums) {
|
||||
let xmlPath = path.join(xmlEnumPath, e.Name + ".xml")
|
||||
|
||||
let obj = {
|
||||
...e,
|
||||
Options: []
|
||||
}
|
||||
|
||||
let existingDescriptions = {};
|
||||
let existingEnumDescription = "";
|
||||
if (fs.existsSync(xmlPath)) {
|
||||
const existingXml = fs.readFileSync(xmlPath, "utf-8");
|
||||
const existingData = parser.parse(existingXml);
|
||||
|
||||
if (existingData.EnumDef) {
|
||||
existingEnumDescription = existingData.EnumDef.Description || "";
|
||||
|
||||
if (existingData.EnumDef.Options) {
|
||||
const options = Array.isArray(existingData.EnumDef.Options)
|
||||
? existingData.EnumDef.Options
|
||||
: [existingData.EnumDef.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] || ""
|
||||
})
|
||||
}
|
||||
|
||||
const xmlContent = builder.build({
|
||||
"?xml": "",
|
||||
EnumDef: obj
|
||||
});
|
||||
fs.writeFileSync(xmlPath, xmlContent)
|
||||
}
|
||||
Reference in New Issue
Block a user