Files
aura-keep/scripts/clear-directory.ts
2025-03-10 16:29:47 +08:00

35 lines
859 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()