-
Notifications
You must be signed in to change notification settings - Fork 21
/
tree.js
53 lines (48 loc) · 1.33 KB
/
tree.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
// Tree
const tree = {
command: "tree",
describe: "Outputs the dependency tree of the current project to stdout. It takes all relevant parameters of ui5 build into account.",
middlewares: [require("../middlewares/base.js")]
};
tree.builder = function(cli) {
return cli
.option("full", {
describe: "Include more information (currently the project configuration)",
type: "boolean"
})
.option("json", {
describe: "Output tree as formatted JSON string",
type: "boolean"
})
.example("ui5 tree > tree.txt", "Pipes the dependency tree into a new file \"tree.txt\"")
.example("ui5 tree --json > tree.json", "Pipes the dependency tree into a new file \"tree.json\"");
};
tree.handler = function(argv) {
const normalizer = require("@ui5/project").normalizer;
const treeify = require("treeify");
let p;
if (argv.full) {
p = normalizer.generateProjectTree({
translator: argv.translator,
configPath: argv.config
});
} else {
p = normalizer.generateDependencyTree({
translator: argv.translator,
configPath: argv.config
});
}
p.then(function(tree) {
if (argv.json) {
// Formatted JSON
console.log(JSON.stringify(tree, null, 4));
} else {
// Formatted tree
console.log(treeify.asTree(tree, true));
}
}).catch(function(err) {
console.error(err);
process.exit(1);
});
};
module.exports = tree;