File size: 3,270 Bytes
4c0b9f8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | require("../../../configs")
let SH = require("../../../configs")
/**
* Copyright © 2025 [ balxzzy ]
*
* All rights reserved. This source code is the property of [ Shiina Team ].
* Unauthorized copying, distribution, modification, or use of this file,
* via any medium, is strictly prohibited without prior written permission.
*
* This software is protected under international copyright laws.
*
* Contact: [ pa424013@gmail.com ]
* GitHub: https://github.com/balxz
*/
function generateApiDocs(dir) {
const apiDocs = {
"name": SH.name,
"version": SH.version,
"description": SH.description,
"bannerImage": SH.banner,
"header": {
"status": SH.status
},
"apiSettings": {
"creator": SH.creator
},
"categories": []
}
const categoriesMap = new Map()
function readRoutes(currentDir) {
const files = fs.readdirSync(currentDir)
for (const file of files) {
const filePath = path.join(currentDir, file)
const stat = fs.statSync(filePath)
if (stat.isDirectory()) {
readRoutes(filePath)
} else if (file.endsWith(".js")) {
delete require.cache[require.resolve(filePath)]
const route = require(filePath)
if (!route.name
|| !route.path
|| !route.description
|| !route.tags
|| route.hidden) {
if (!route.hidden)
continue
}
const categoryName = route.tags
const codeString = route.code.toString()
const paramMatch = codeString.match(/req\.query\.(\w+)/)
const paramName = paramMatch ? paramMatch[1] : "text"
const routeItem = {
name: route.name,
desc: route.description,
path: route.path,
status: route.isDisable ? "Offline" : SH.status,
example: route.example || "No example provided",
/*params: {
[paramName]: `Parameter ${paramName} dibutuhkan`
}*/
params: route.params || {}
}
if (!categoriesMap.has(categoryName)) {
categoriesMap.set(categoryName, {
name: categoryName,
items: []
})
}
categoriesMap.get(categoryName).items.push(routeItem)
}
}
}
readRoutes(dir)
apiDocs.categories = Array.from(categoriesMap.values())
return apiDocs
}
function generateJson(directory, outputPath) {
const apiDocsObject = generateApiDocs(directory)
fs.writeFileSync(outputPath, JSON.stringify(apiDocsObject, null, 2))
}
module.exports = { generateJson }
let file = require.resolve(__filename)
fs.watchFile(file, () => {
fs.unwatchFile(file)
delete require.cache[file]
})
|