MCPcopy Create free account
hub / github.com/eryajf/vdoing-template / readFileList

Function readFileList

utils/modules/readFileList.js:8–41  ·  view source on GitHub ↗
(dir = docsRoot, filesList = [])

Source from the content-addressed store, hash-verified

6const docsRoot = path.join(__dirname, '..', '..', 'docs'); // docs文件路径
7
8function readFileList(dir = docsRoot, filesList = []) {
9 const files = fs.readdirSync(dir);
10 files.forEach( (item, index) => {
11 let filePath = path.join(dir, item);
12 const stat = fs.statSync(filePath);
13 if (stat.isDirectory() && item !== '.vuepress') {
14 readFileList(path.join(dir, item), filesList); //递归读取文件
15 } else {
16 if(path.basename(dir) !== 'docs'){ // 过滤docs目录级下的文件
17
18 const fileNameArr = path.basename(filePath).split('.')
19 let name = null, type = null;
20 if (fileNameArr.length === 2) { // 没有序号的文件
21 name = fileNameArr[0]
22 type = fileNameArr[1]
23 } else if (fileNameArr.length === 3) { // 有序号的文件
24 name = fileNameArr[1]
25 type = fileNameArr[2]
26 } else { // 超过两个‘.’的
27 log(chalk.yellow(`warning: 该文件 "${filePath}" 没有按照约定命名,将忽略生成相应数据。`))
28 return
29 }
30 if(type === 'md'){ // 过滤非md文件
31 filesList.push({
32 name,
33 filePath
34 });
35 }
36
37 }
38 }
39 });
40 return filesList;
41}
42
43module.exports = readFileList;

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected