一、代码:
// 该文件名是:outFileUrl.js
const fs = require("fs");
const path = require("path");
const rootDir = path.resolve(__dirname);
const createDirTree = (dir, skip) => {
const recur = (curDir) => {
fs.readdirSync(curDir, { withFileTypes: true }).forEach((value) => {
if (skip.includes(value.name)) return;
const childPath = path.join(curDir, value.name);
const depths = childPath.replace(rootDir, '').split(path.sep).filter(Boolean).length;
const isDirectory = value.isDirectory();
const prefix = `${'│ '.repeat(depths - 1)}${isDirectory ? '├──' : '├──'}── `;
console.log(`${prefix}${value.name}`);
if (isDirectory) {
recur(path.join(curDir, value.name));
}
});
}
recur(dir);
}
createDirTree(rootDir, ["node_modules", ".vscode", ".git", ".next", "_next"])
二、文件存放:
三、运行命令:
node ./outFileUrl
四、运行结果:
五、git源码仓库:
https://github.com/linjyuan/webpack_code