Skip to content

Commit e66c82d

Browse files
committed
[INTERNAL] Enhance tree and build commands with project graph options
Depends on SAP/ui5-project#394
1 parent 0ee2c7b commit e66c82d

File tree

2 files changed

+108
-8
lines changed

2 files changed

+108
-8
lines changed

lib/cli/commands/build.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ build.builder = function(cli) {
6565
describe: "Overrides the framework version defined by the project",
6666
type: "string"
6767
})
68+
.option("x-graph-mode", {
69+
describe: "Uses an experimental project graph instead of a dependency tree",
70+
default: false,
71+
type: "boolean"
72+
})
6873
.example("ui5 build --all", "Preload build for project and dependencies to \"./dist\"")
6974
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
7075
"Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks")
@@ -97,9 +102,16 @@ async function handleBuild(argv) {
97102
};
98103
}
99104

100-
const tree = await normalizer.generateProjectTree(normalizerOptions);
105+
let tree;
106+
let graph;
107+
if (argv.xGraphMode) {
108+
graph = await normalizer.generateProjectGraph(normalizerOptions);
109+
} else {
110+
tree = await normalizer.generateProjectTree(normalizerOptions);
111+
}
101112
await builder.build({
102113
tree: tree,
114+
graph: graph,
103115
destPath: argv.dest,
104116
cleanDest: argv["clean-dest"],
105117
buildDependencies: argv.all,

lib/cli/commands/tree.js

Lines changed: 95 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ tree.builder = function(cli) {
2828
describe:
2929
"Overrides the framework version defined by the project. Only supported in combination with --full",
3030
type: "string"
31-
}).check((argv) => {
31+
})
32+
.option("x-graph-mode", {
33+
describe: "Uses an experimental project graph instead of a dependency tree",
34+
default: false,
35+
type: "boolean"
36+
})
37+
.option("x-perf", {
38+
describe: "Outputs performance measurements",
39+
default: false,
40+
type: "boolean"
41+
})
42+
.check((argv) => {
3243
if (argv.frameworkVersion && !argv.full) {
3344
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
3445
} else {
@@ -42,6 +53,7 @@ tree.builder = function(cli) {
4253
tree.handler = async function(argv) {
4354
const normalizer = require("@ui5/project").normalizer;
4455
const treeify = require("treeify");
56+
const chalk = require("chalk");
4557

4658
const options = {
4759
translatorName: argv.translator,
@@ -57,15 +69,91 @@ tree.handler = async function(argv) {
5769
};
5870
}
5971

60-
let projectTree;
61-
if (argv.full) {
62-
projectTree = await normalizer.generateProjectTree(options);
72+
let startTime;
73+
let elapsedTime;
74+
if (argv.xPerf) {
75+
startTime = process.hrtime();
76+
}
77+
if (argv.xGraphMode) {
78+
const graph = await normalizer.generateProjectGraph(options);
79+
80+
if (argv.xPerf) {
81+
elapsedTime = getElapsedTime(startTime);
82+
}
83+
84+
const projects = {};
85+
const indentWidth = 4;
86+
await graph.traverseBreadthFirst(async ({project, getDependencies}) => {
87+
const deps = getDependencies().map((dep) => {
88+
return dep.getName();
89+
});
90+
projects[project.getName()] = {
91+
render: function(indentation, connectorIndices, lastChild) {
92+
let baseString = " ".repeat(indentation * indentWidth);
93+
connectorIndices.forEach((idx) => {
94+
baseString = `${baseString.slice(0, idx)}${baseString.slice(idx + 1)}`;
95+
});
96+
const connectorString = lastChild ? "╰─" : "├─";
97+
console.log(
98+
`${baseString}${connectorString} ${chalk.bold(project.getName())} ` +
99+
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
100+
chalk.dim.italic(`${project.getPath()}`)
101+
);
102+
103+
const lastIdx = deps.length -1;
104+
const newConnectorIndices = [...connectorIndices];
105+
if (!lastChild) {
106+
newConnectorIndices.push(indentation * indentWidth);
107+
}
108+
deps.forEach((dep, i) => {
109+
projects[dep].render(indentation + 1, newConnectorIndices, i === lastIdx);
110+
});
111+
}
112+
};
113+
});
114+
115+
const projectKeys = Object.keys(projects);
116+
console.log(chalk.bold.underline(`Dependencies (${projectKeys.length}):`));
117+
projects[projectKeys[0]].render(0, [], true);
118+
console.log("");
119+
120+
const extensions = Object.entries(graph.getAllExtensions());
121+
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
122+
if (extensions.length) {
123+
extensions.forEach((extension) => {
124+
console.log(
125+
`${" ".repeat(indentWidth)} ├─ ${extension.getName()}` +
126+
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
127+
chalk.dim.italic(`${extension.getPath()}`));
128+
});
129+
} else {
130+
console.log(chalk.italic(`None`));
131+
}
63132
} else {
64-
projectTree = await normalizer.generateDependencyTree(options);
133+
let projectTree;
134+
if (argv.full) {
135+
projectTree = await normalizer.generateProjectTree(options);
136+
} else {
137+
projectTree = await normalizer.generateDependencyTree(options);
138+
}
139+
if (argv.xPerf) {
140+
elapsedTime = getElapsedTime(startTime);
141+
}
142+
143+
144+
const output = argv.json ? JSON.stringify(projectTree, null, 4) : treeify.asTree(projectTree, true);
145+
console.log(output);
65146
}
66147

67-
const output = argv.json ? JSON.stringify(projectTree, null, 4) : treeify.asTree(projectTree, true);
68-
console.log(output);
148+
if (argv.xPerf) {
149+
console.log("");
150+
console.log(chalk.blue(`Normalizer took ${chalk.bold(elapsedTime)}`));
151+
}
69152
};
70153

154+
function getElapsedTime(startTime) {
155+
const timeDiff = process.hrtime(startTime);
156+
const prettyHrtime = require("pretty-hrtime");
157+
return prettyHrtime(timeDiff);
158+
}
71159
module.exports = tree;

0 commit comments

Comments
 (0)