Skip to content

Commit a54c2e0

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

File tree

2 files changed

+60
-115
lines changed

2 files changed

+60
-115
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: 60 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -9,145 +9,95 @@ 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-
})
1712
.option("json", {
1813
describe: "Output tree as formatted JSON string",
1914
default: false,
2015
type: "boolean"
2116
})
22-
.option("dedupe", {
23-
describe: "Remove duplicate projects from project tree",
24-
default: false,
25-
type: "boolean"
26-
})
2717
.option("framework-version", {
2818
describe:
29-
"Overrides the framework version defined by the project. Only supported in combination with --full",
19+
"Overrides the framework version defined by the project",
3020
type: "string"
3121
})
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-
})
3922
.example("ui5 tree > tree.txt", "Pipes the dependency tree into a new file \"tree.txt\"")
4023
.example("ui5 tree --json > tree.json", "Pipes the dependency tree into a new file \"tree.json\"");
4124
};
4225

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

4829
let startTime;
4930
let elapsedTime;
5031
if (argv.xPerf) {
5132
startTime = process.hrtime();
5233
}
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-
};
34+
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
35+
let graph;
36+
if (argv.dependencyDefinition) {
37+
graph = await generateProjectGraph.usingStaticFile({
38+
filePath: argv.dependencyDefinition,
39+
versionOverride: argv.frameworkVersion
40+
});
41+
} else {
42+
graph = await generateProjectGraph.usingNodePackageDependencies({
43+
rootConfigPath: argv.config,
44+
versionOverride: argv.frameworkVersion
10245
});
46+
}
10347

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("");
48+
if (argv.xPerf) {
49+
elapsedTime = getElapsedTime(startTime);
50+
}
10851

109-
const extensions = graph.getAllExtensions();
110-
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
111-
if (extensions.length) {
112-
extensions.forEach((extension) => {
52+
const projects = {};
53+
const indentWidth = 4;
54+
await graph.traverseBreadthFirst(async ({project, getDependencies}) => {
55+
const deps = getDependencies().map((dep) => {
56+
return dep.getName();
57+
});
58+
projects[project.getName()] = {
59+
render: function(indentation, connectorIndices, lastChild) {
60+
let baseString = " ".repeat(indentation * indentWidth);
61+
connectorIndices.forEach((idx) => {
62+
baseString = `${baseString.slice(0, idx)}${baseString.slice(idx + 1)}`;
63+
});
64+
const connectorString = lastChild ? "╰─" : "├─";
11365
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-
};
66+
`${baseString}${connectorString} ${chalk.bold(project.getName())} ` +
67+
`${project.getNamespace ? chalk.inverse(project.getNamespace()) + " " : ""}` +
68+
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
69+
chalk.dim.italic(`${project.getPath()}`)
70+
);
12971

130-
if (argv.frameworkVersion ) {
131-
options.frameworkOptions = {
132-
versionOverride: argv.frameworkVersion
133-
};
134-
}
135-
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-
}
72+
const lastIdx = deps.length -1;
73+
const newConnectorIndices = [...connectorIndices];
74+
if (!lastChild) {
75+
newConnectorIndices.push(indentation * indentWidth);
76+
}
77+
deps.forEach((dep, i) => {
78+
projects[dep].render(indentation + 1, newConnectorIndices, i === lastIdx);
79+
});
80+
}
81+
};
82+
});
14583

84+
const projectKeys = Object.keys(projects);
85+
console.log(chalk.bold.underline(`Dependencies (${projectKeys.length}):`));
86+
projects[projectKeys[0]].render(0, [], true);
87+
console.log("");
14688

147-
const output = argv.json ? JSON.stringify(projectTree, null, 4) : treeify.asTree(projectTree, true);
148-
console.log(output);
89+
const extensions = graph.getAllExtensions();
90+
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
91+
if (extensions.length) {
92+
extensions.forEach((extension) => {
93+
console.log(
94+
`${" ".repeat(indentWidth)} ├─ ${extension.getName()}` +
95+
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
96+
chalk.dim.italic(`${extension.getPath()}`));
97+
});
98+
} else {
99+
console.log(chalk.italic(`None`));
149100
}
150-
151101
if (argv.xPerf) {
152102
console.log("");
153103
console.log(chalk.blue(

0 commit comments

Comments
 (0)