First commit

This commit is contained in:
2025-12-16 03:43:54 +01:00
parent 962582e906
commit 28d51ec760
11 changed files with 1576 additions and 0 deletions

53
modules/loader.js Normal file
View File

@@ -0,0 +1,53 @@
const fs = require("node:fs")
const path = require("node:path")
function getRecursiveFiles(dir) {
let results = []
if (!fs.existsSync(dir)) {
return results
}
const list = fs.readdirSync(dir)
for (const file of list) {
const fullPath = path.join(dir, file)
const stat = fs.statSync(fullPath)
if (stat && stat.isDirectory()) {
results = results.concat(getRecursiveFiles(fullPath))
} else {
if (fullPath.endsWith(".js")) {
results.push(fullPath)
}
}
}
return results
}
function computeRoutePath(baseDir, filePath) {
const relativePath = path.relative(baseDir, filePath)
const normalizedPath = relativePath.replace(/\\/g, "/")
let route = "/" + normalizedPath
if (route.endsWith("index.js")) {
route = route.replace("index.js", "")
} else {
route = route.replace(".js", "")
}
route = route.replace(/\/{2,}/g, "/")
if (route.length > 1 && route.endsWith('/')) {
route = route.slice(0, -1)
}
return route
}
module.exports = {
getRecursiveFiles,
computeRoutePath
}