import express from "express" import template from "express-art-template" import fs from "node:fs/promises" import lodash from "lodash" /* * npm run app web-debug开启Bot后 * 可另外通过 npm run web 开启浏览器调试 * 访问 http://localhost:8000/ 即可看到对应页面 * 页面内的资源需使用 {{_res_path}}来作为resources目录的根目录 * 可编辑模板与页面查看效果 * todo: 预览页面的热更 * * */ let app = express() let _path = process.cwd() app.engine("html", template) app.set("views", _path + "/resources/") app.set("view engine", "art") app.use(express.static(_path + "/resources")) app.use("/plugins", express.static("plugins")) app.get("/", async function (req, res) { let pluginList = await fs.readdir(_path + "/temp/ViewData/") || [] let html = [ "在npm run web-dev模式下触发截图消息后,可在下方选择页面进行调试", "如果页面内资源路径不正确请使用{{_res_path}}作为根路径,对应之前的../../../../", "可直接修改模板html或css刷新查看效果" ] let li = {} for (let pIdx in pluginList) { const plugin = pluginList[pIdx] let fileList = await fs.readdir(_path + `/temp/ViewData/${plugin}/`) || [] for (let idx in fileList) { let ret = /(.+)\.json$/.exec(fileList[idx]) if (ret && ret[1]) { let text = [plugin, ...ret[1].split("_")] li[text.join("")] = (`