Skip to content

Commit abc2a91

Browse files
committed
[INTERNAL] tree: Remove legacy dependency tree implementation
1 parent 5ca3f20 commit abc2a91

File tree

2 files changed

+61
-123
lines changed

2 files changed

+61
-123
lines changed

lib/cli/commands/base.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ cli.usage("Usage: ui5 <command> [options]")
2727
default: "info",
2828
type: "string"
2929
})
30-
.option("x-graph-mode", {
31-
describe: "Uses an experimental project graph instead of a dependency tree",
32-
default: true,
33-
type: "boolean"
34-
})
3530
.option("x-perf", {
3631
describe: "Outputs performance measurements",
3732
default: false,

lib/cli/commands/tree.js

Lines changed: 61 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -9,145 +9,88 @@ const tree = {
99

1010
tree.builder = function(cli) {
1111
return cli
12-
.option("full", {
13-
describe: "Include more information (currently the project configuration)",
14-
default: false,
15-
type: "boolean"
16-
})
17-
.option("json", {
18-
describe: "Output tree as formatted JSON string",
19-
default: false,
20-
type: "boolean"
21-
})
22-
.option("dedupe", {
23-
describe: "Remove duplicate projects from project tree",
24-
default: false,
25-
type: "boolean"
26-
})
2712
.option("framework-version", {
2813
describe:
29-
"Overrides the framework version defined by the project. Only supported in combination with --full",
14+
"Overrides the framework version defined by the project",
3015
type: "string"
31-
})
32-
.check((argv) => {
33-
if (argv.frameworkVersion && !argv.full) {
34-
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
35-
} else {
36-
return true;
37-
}
38-
})
39-
.example("ui5 tree > tree.txt", "Pipes the dependency tree into a new file \"tree.txt\"")
40-
.example("ui5 tree --json > tree.json", "Pipes the dependency tree into a new file \"tree.json\"");
16+
});
4117
};
4218

4319
tree.handler = async function(argv) {
44-
const normalizer = require("@ui5/project").normalizer;
45-
const treeify = require("treeify");
4620
const chalk = require("chalk");
4721

4822
let startTime;
4923
let elapsedTime;
5024
if (argv.xPerf) {
5125
startTime = process.hrtime();
5226
}
53-
if (argv.xGraphMode) {
54-
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
55-
let graph;
56-
if (argv.dependencyDefinition) {
57-
graph = await generateProjectGraph.usingStaticFile({
58-
filePath: argv.dependencyDefinition,
59-
versionOverride: argv.frameworkVersion
60-
});
61-
} else {
62-
graph = await generateProjectGraph.usingNodePackageDependencies({
63-
rootConfigPath: argv.config,
64-
versionOverride: argv.frameworkVersion
65-
});
66-
}
67-
68-
if (argv.xPerf) {
69-
elapsedTime = getElapsedTime(startTime);
70-
}
71-
72-
const projects = {};
73-
const indentWidth = 4;
74-
await graph.traverseBreadthFirst(async ({project, getDependencies}) => {
75-
const deps = getDependencies().map((dep) => {
76-
return dep.getName();
77-
});
78-
projects[project.getName()] = {
79-
render: function(indentation, connectorIndices, lastChild) {
80-
let baseString = " ".repeat(indentation * indentWidth);
81-
connectorIndices.forEach((idx) => {
82-
baseString = `${baseString.slice(0, idx)}${baseString.slice(idx + 1)}`;
83-
});
84-
const connectorString = lastChild ? "╰─" : "├─";
85-
console.log(
86-
`${baseString}${connectorString} ${chalk.bold(project.getName())} ` +
87-
`${project.getNamespace ? chalk.inverse(project.getNamespace()) + " " : ""}` +
88-
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
89-
chalk.dim.italic(`${project.getPath()}`)
90-
);
91-
92-
const lastIdx = deps.length -1;
93-
const newConnectorIndices = [...connectorIndices];
94-
if (!lastChild) {
95-
newConnectorIndices.push(indentation * indentWidth);
96-
}
97-
deps.forEach((dep, i) => {
98-
projects[dep].render(indentation + 1, newConnectorIndices, i === lastIdx);
99-
});
100-
}
101-
};
27+
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
28+
let graph;
29+
if (argv.dependencyDefinition) {
30+
graph = await generateProjectGraph.usingStaticFile({
31+
filePath: argv.dependencyDefinition,
32+
versionOverride: argv.frameworkVersion
10233
});
34+
} else {
35+
graph = await generateProjectGraph.usingNodePackageDependencies({
36+
rootConfigPath: argv.config,
37+
versionOverride: argv.frameworkVersion
38+
});
39+
}
10340

104-
const projectKeys = Object.keys(projects);
105-
console.log(chalk.bold.underline(`Dependencies (${projectKeys.length}):`));
106-
projects[projectKeys[0]].render(0, [], true);
107-
console.log("");
41+
if (argv.xPerf) {
42+
elapsedTime = getElapsedTime(startTime);
43+
}
10844

109-
const extensions = graph.getAllExtensions();
110-
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
111-
if (extensions.length) {
112-
extensions.forEach((extension) => {
45+
const projects = {};
46+
const indentWidth = 4;
47+
await graph.traverseBreadthFirst(async ({project, getDependencies}) => {
48+
const deps = getDependencies().map((dep) => {
49+
return dep.getName();
50+
});
51+
projects[project.getName()] = {
52+
render: function(indentation, connectorIndices, lastChild) {
53+
let baseString = " ".repeat(indentation * indentWidth);
54+
connectorIndices.forEach((idx) => {
55+
baseString = `${baseString.slice(0, idx)}${baseString.slice(idx + 1)}`;
56+
});
57+
const connectorString = lastChild ? "╰─" : "├─";
11358
console.log(
114-
`${" ".repeat(indentWidth)} ├─ ${extension.getName()}` +
115-
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
116-
chalk.dim.italic(`${extension.getPath()}`));
117-
});
118-
} else {
119-
console.log(chalk.italic(`None`));
120-
}
121-
} else {
122-
const options = {
123-
translatorName: argv.translator,
124-
translatorOptions: {
125-
includeDeduped: !argv.dedupe
126-
},
127-
configPath: argv.config
128-
};
129-
130-
if (argv.frameworkVersion ) {
131-
options.frameworkOptions = {
132-
versionOverride: argv.frameworkVersion
133-
};
134-
}
59+
`${baseString}${connectorString} ${chalk.bold(project.getName())} ` +
60+
`${project.getNamespace ? chalk.inverse(project.getNamespace()) + " " : ""}` +
61+
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
62+
chalk.dim.italic(`${project.getPath()}`)
63+
);
13564

136-
let projectTree;
137-
if (argv.full) {
138-
projectTree = await normalizer.generateProjectTree(options);
139-
} else {
140-
projectTree = await normalizer.generateDependencyTree(options);
141-
}
142-
if (argv.xPerf) {
143-
elapsedTime = getElapsedTime(startTime);
144-
}
65+
const lastIdx = deps.length -1;
66+
const newConnectorIndices = [...connectorIndices];
67+
if (!lastChild) {
68+
newConnectorIndices.push(indentation * indentWidth);
69+
}
70+
deps.forEach((dep, i) => {
71+
projects[dep].render(indentation + 1, newConnectorIndices, i === lastIdx);
72+
});
73+
}
74+
};
75+
});
14576

77+
const projectKeys = Object.keys(projects);
78+
console.log(chalk.bold.underline(`Dependencies (${projectKeys.length}):`));
79+
projects[projectKeys[0]].render(0, [], true);
80+
console.log("");
14681

147-
const output = argv.json ? JSON.stringify(projectTree, null, 4) : treeify.asTree(projectTree, true);
148-
console.log(output);
82+
const extensions = graph.getAllExtensions();
83+
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
84+
if (extensions.length) {
85+
extensions.forEach((extension) => {
86+
console.log(
87+
`${" ".repeat(indentWidth)} ├─ ${extension.getName()}` +
88+
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
89+
chalk.dim.italic(`${extension.getPath()}`));
90+
});
91+
} else {
92+
console.log(chalk.italic(`None`));
14993
}
150-
15194
if (argv.xPerf) {
15295
console.log("");
15396
console.log(chalk.blue(

0 commit comments

Comments
 (0)