add: base module

This commit is contained in:
2025-03-10 16:29:47 +08:00
parent 8b59a8e21a
commit 3a583a3619
40 changed files with 2698 additions and 218 deletions

View File

@@ -0,0 +1,35 @@
import path from 'path';
import fs from 'fs';
const root = process.cwd();
const buildPath = path.join(root, 'build');
export const main = () => {
//列出buildPath目录下的所有文件夹并删除
const files = fs.readdirSync(buildPath);
files.forEach((file) => {
const filePath = path.join(buildPath, file);
if (fs.statSync(filePath).isDirectory()) {
fs.rmdirSync(filePath, { recursive: true });
}
});
// 获取目录下的所有文件生成一个文件列表生成一个index.html包函下载列表相对路径
const _files = fs.readdirSync(buildPath);
let html = `
<html>
<body>
<ul>
`;
_files.forEach((file) => {
html += `<li><a href="./${file}">${file}</a></li>`;
});
html += `
</ul>
</body>
</html>
`;
fs.writeFileSync(path.join(buildPath, 'index.html'), html);
};
main()