Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (52 loc) · 1.61 KB
/
Copy pathindex.js
File metadata and controls
58 lines (52 loc) · 1.61 KB
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
const file = require('../utils/file');
const { getLanguageParsers } = require('./language');
const parseFile = (
itemPath,
projectDir,
{ parseCodeCrumbs, parseImports, parseDependencies, attachCode, language } = {}
) => {
const { codecrumbsParser, dependenciesParser } = getLanguageParsers(language);
return Promise.all([
parseDependencies && dependenciesParser.getDependencies(itemPath, projectDir),
file.read(itemPath, 'utf8')
]).then(([dependencies, code]) => {
const item = {
path: itemPath,
dependencies: parseDependencies && dependencies,
fileCode: attachCode && code
};
if (parseCodeCrumbs) {
const codecrumbsList = codecrumbsParser.getCrumbs(code, itemPath);
if (codecrumbsList.length) {
item.fileCode = code;
item.children = codecrumbsList;
item.hasCodecrumbs = true;
item.flows = codecrumbsList
.filter(cc => cc.params.flow)
.map(cc => cc.params)
.reduce((acc, { flow }) => {
acc[flow] = true;
return acc;
}, {});
} else {
item.children = undefined;
item.hasCodecrumbs = false;
item.flows = undefined;
}
}
if (parseImports) {
const importedDependencies = dependenciesParser.getImports(code, itemPath);
if (importedDependencies.length) {
item.importedDependencies = importedDependencies;
item.hasDependenciesImports = true;
} else {
item.importedDependencies = undefined;
item.hasDependenciesImports = false;
}
}
return item;
});
};
module.exports = {
parseFile
};