forked from CodecrumbsIO/codecrumbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (51 loc) · 1.52 KB
/
Copy pathindex.js
File metadata and controls
56 lines (51 loc) · 1.52 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
const { getCrumbs } = require('./codecrumbs/');
const { getImports, getDependencies } = require('./dependencies/');
const file = require('../utils/file');
const parseFile = (
itemPath,
projectDir,
{ parseCodeCrumbs, parseImports, parseDependencies, attachCode } = {}
) =>
Promise.all([
parseDependencies && getDependencies(itemPath, projectDir),
file.read(itemPath, 'utf8')
]).then(([dependencies, code]) => {
const item = {
path: itemPath,
dependencies: parseDependencies && dependencies,
fileCode: attachCode && code
};
if (parseCodeCrumbs) {
const codecrumbsList = 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 = getImports(code, itemPath);
if (importedDependencies.length) {
item.importedDependencies = importedDependencies;
item.hasDependenciesImports = true;
} else {
item.importedDependencies = undefined;
item.hasDependenciesImports = false;
}
}
return item;
});
module.exports = {
parseFile
};