perform a switch to yaml
This commit is contained in:
@@ -1,43 +1,38 @@
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { XMLParser } = require("fast-xml-parser");
|
||||
const yaml = require("yaml")
|
||||
|
||||
const xmlAPIPath = path.join(__dirname, "../", "xml", "types")
|
||||
const yamlAPIPath = path.join(__dirname, "../", "yaml", "types")
|
||||
const mdAPIPath = path.join(__dirname, "../", "docs/api", "types")
|
||||
const iconDataPath = path.join(__dirname, "../", "docs/theme/.icons", "polytoria")
|
||||
const xmlEnumPath = path.join(__dirname, "../", "xml", "enums")
|
||||
const yamlEnumPath = path.join(__dirname, "../", "yaml", "enums")
|
||||
const mdEnumPath = path.join(__dirname, "../", "docs/api", "enums")
|
||||
|
||||
if (!fs.existsSync(mdAPIPath)) {
|
||||
fs.mkdirSync(mdAPIPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(xmlAPIPath)) {
|
||||
fs.mkdirSync(xmlAPIPath, { recursive: true })
|
||||
if (!fs.existsSync(yamlAPIPath)) {
|
||||
fs.mkdirSync(yamlAPIPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(mdEnumPath)) {
|
||||
fs.mkdirSync(mdEnumPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(xmlEnumPath)) {
|
||||
fs.mkdirSync(xmlEnumPath, { recursive: true })
|
||||
if (!fs.existsSync(yamlEnumPath)) {
|
||||
fs.mkdirSync(yamlEnumPath, { recursive: true })
|
||||
}
|
||||
|
||||
const parser = new XMLParser();
|
||||
|
||||
// Process API Classes
|
||||
const xmlFiles = fs.readdirSync(xmlAPIPath).filter(file => file.endsWith('.xml'));
|
||||
const yamlFiles = fs.readdirSync(yamlAPIPath).filter(file => file.endsWith('.yaml'));
|
||||
|
||||
for (const xmlFile of xmlFiles) {
|
||||
const xmlPath = path.join(xmlAPIPath, xmlFile)
|
||||
const xmlContent = fs.readFileSync(xmlPath, "utf-8")
|
||||
const data = parser.parse(xmlContent)
|
||||
for (const yamlFile of yamlFiles) {
|
||||
const yamlPath = path.join(yamlAPIPath, yamlFile)
|
||||
const yamlContent = fs.readFileSync(yamlPath, "utf-8")
|
||||
|
||||
if (!data.ClassDef) continue;
|
||||
|
||||
const c = data.ClassDef;
|
||||
const className = path.basename(xmlFile, '.xml')
|
||||
const c = yaml.parse(yamlContent);
|
||||
const className = path.basename(yamlFile, '.yaml')
|
||||
let mdPath = path.join(mdAPIPath, className + ".md")
|
||||
let mk = ""
|
||||
const iconPath = path.join(iconDataPath, c.Name + ".svg")
|
||||
@@ -149,20 +144,17 @@ for (const xmlFile of xmlFiles) {
|
||||
fs.writeFileSync(mdPath, mk)
|
||||
}
|
||||
|
||||
console.log(`Converted ${xmlFiles.length} XML files to Markdown`)
|
||||
console.log(`Converted ${yamlFiles.length} XML files to Markdown`)
|
||||
|
||||
// Process Enums
|
||||
const xmlEnumFiles = fs.readdirSync(xmlEnumPath).filter(file => file.endsWith('.xml'));
|
||||
const yamlEnumFiles = fs.readdirSync(yamlEnumPath).filter(file => file.endsWith('.yaml'));
|
||||
|
||||
for (const xmlFile of xmlEnumFiles) {
|
||||
const xmlPath = path.join(xmlEnumPath, xmlFile);
|
||||
const xmlContent = fs.readFileSync(xmlPath, "utf-8");
|
||||
const data = parser.parse(xmlContent);
|
||||
for (const yamlFile of yamlEnumFiles) {
|
||||
const yamlPath = path.join(yamlEnumPath, yamlFile);
|
||||
const yamlContent = fs.readFileSync(yamlPath, "utf-8");
|
||||
|
||||
if (!data.EnumDef) continue;
|
||||
|
||||
const e = data.EnumDef;
|
||||
const enumName = path.basename(xmlFile, '.xml');
|
||||
const e = yaml.parse(yamlContent);
|
||||
const enumName = path.basename(yamlFile, '.yaml');
|
||||
let mdPath = path.join(mdEnumPath, enumName + ".md")
|
||||
let mk = ""
|
||||
|
||||
@@ -198,4 +190,4 @@ for (const xmlFile of xmlEnumFiles) {
|
||||
fs.writeFileSync(mdPath, mk)
|
||||
}
|
||||
|
||||
console.log(`Converted ${xmlEnumFiles.length} enum XML files to Markdown`)
|
||||
console.log(`Converted ${yamlEnumFiles.length} enum XML files to Markdown`)
|
||||
18
autogen/package-lock.json
generated
18
autogen/package-lock.json
generated
@@ -5,7 +5,8 @@
|
||||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"fast-xml-parser": "^5.3.3"
|
||||
"fast-xml-parser": "^5.3.3",
|
||||
"yaml": "^2.8.2"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-xml-parser": {
|
||||
@@ -37,6 +38,21 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/yaml": {
|
||||
"version": "2.8.2",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz",
|
||||
"integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==",
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"yaml": "bin.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/eemeli"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"fast-xml-parser": "^5.3.3"
|
||||
"fast-xml-parser": "^5.3.3",
|
||||
"yaml": "^2.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
const fs = require("fs")
|
||||
const yaml = require("yaml")
|
||||
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")
|
||||
const yamlAPIPath = path.join(__dirname, "../", "yaml", "types")
|
||||
const yamlEnumPath = path.join(__dirname, "../", "yaml", "enums")
|
||||
|
||||
if (!fs.existsSync(xmlAPIPath)) {
|
||||
fs.mkdirSync(xmlAPIPath, { recursive: true })
|
||||
@@ -13,16 +16,22 @@ if (!fs.existsSync(xmlEnumPath)) {
|
||||
fs.mkdirSync(xmlEnumPath, { recursive: true })
|
||||
}
|
||||
|
||||
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"))
|
||||
|
||||
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 yamlPath = path.join(yamlAPIPath, c.Name + ".yaml")
|
||||
|
||||
let obj = {
|
||||
...c,
|
||||
@@ -80,7 +89,7 @@ for (const c of data.Classes) {
|
||||
}
|
||||
|
||||
// Add class description
|
||||
obj.Description = existingClassDescription;
|
||||
obj.Description = existingClassDescription ?? "";
|
||||
|
||||
// Add properties
|
||||
for (const prop of c.Properties) {
|
||||
@@ -109,16 +118,13 @@ for (const c of data.Classes) {
|
||||
})
|
||||
}
|
||||
|
||||
const xmlContent = builder.build({
|
||||
"?xml": "",
|
||||
ClassDef: obj
|
||||
});
|
||||
fs.writeFileSync(xmlPath, xmlContent)
|
||||
fs.writeFileSync(yamlPath, yaml.stringify(obj))
|
||||
}
|
||||
|
||||
// Process Enums
|
||||
for (const e of data.Enums) {
|
||||
let xmlPath = path.join(xmlEnumPath, e.Name + ".xml")
|
||||
let yamlPath = path.join(yamlEnumPath, e.Name + ".yaml")
|
||||
|
||||
let obj = {
|
||||
...e,
|
||||
@@ -156,9 +162,5 @@ for (const e of data.Enums) {
|
||||
})
|
||||
}
|
||||
|
||||
const xmlContent = builder.build({
|
||||
"?xml": "",
|
||||
EnumDef: obj
|
||||
});
|
||||
fs.writeFileSync(xmlPath, xmlContent)
|
||||
fs.writeFileSync(yamlPath, yaml.stringify(obj))
|
||||
}
|
||||
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