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`)
|
||||
Reference in New Issue
Block a user