forked from inkeep/inkeep-milvus.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
walkFile.js
77 lines (74 loc) · 2.54 KB
/
walkFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs');
const path = require('path');
/**
* @param dirPath the root dir
* @returns {'master':{version: '0.4.0',released: 'yes/no'}}
*/
function walkFiles(dirPath, fileObj = {}) {
let filesList = fs.readdirSync(dirPath);
for (let i = 0; i < filesList.length; i++) {
//拼接当前文件的路径(上一层路径+当前file的名字)
let filePath = path.join(dirPath, filesList[i]);
//根据文件路径获取文件信息,返回一个fs.Stats对象
let stats = fs.statSync(filePath);
if (stats.isDirectory()) {
//递归调用
walkFiles(filePath, fileObj);
} else {
switch (filesList[i]) {
// extract doc version
case 'version.json':
handleCfgFile(fileObj, { dirPath, filePath });
break;
// extract api versions
case 'Variables.json':
handleCfgFile(fileObj, { dirPath, filePath, isVariables: true });
break;
default:
break;
}
}
}
return fileObj;
}
/**
* read directory and generate versions result
* @param {obejct} fileObj versions result from file name:
* {'v1.1.0': { pymilvus: 'v1.1.0', version: 'v1.1.0', released: 'yes' },
* master: { version: 'v2.0.0', released: 'no' }}
* @param {object} param1 { dirPath, filePath, isVariables }
*/
const handleCfgFile = (fileObj, { dirPath, filePath, isVariables }) => {
const paths = dirPath.split('/');
const parent = paths[paths.length - 1];
const doc = fs.readFileSync(filePath);
const content = JSON.parse(doc.toString());
let result = content;
if (isVariables) {
const pymilvus =
content?.milvus_python_sdk_version &&
`v${content?.milvus_python_sdk_version}`;
const go =
content?.milvus_go_sdk_version && `v${content?.milvus_go_sdk_version}`;
const java =
content?.milvus_java_sdk_version &&
`v${content?.milvus_java_sdk_version}`;
const node =
content?.milvus_node_sdk_version &&
content?.milvus_node_sdk_version >= '1.0.14' &&
`v${content?.milvus_node_sdk_version}`;
const restful =
content?.milvus_restful_sdk_version &&
content?.milvus_restful_sdk_version >= '1.0.14' &&
`v${content?.milvus_restful_sdk_version}`;
const csharp =
content?.milvus_csharp_sdk_version &&
content?.milvus_csharp_sdk_version >= '1.0.14' &&
`v${content?.milvus_csharp_sdk_version}`;
result = { pymilvus, go, java, node, restful, csharp };
}
fileObj[parent] = fileObj[parent]
? { ...fileObj[parent], ...result }
: result;
};
module.exports = walkFiles;