Skip to content

Commit

Permalink
[INTERNAL] tree: Remove legacy dependency tree implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed May 23, 2022
1 parent 5ca3f20 commit a54c2e0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 115 deletions.
5 changes: 0 additions & 5 deletions lib/cli/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ cli.usage("Usage: ui5 <command> [options]")
default: "info",
type: "string"
})
.option("x-graph-mode", {
describe: "Uses an experimental project graph instead of a dependency tree",
default: true,
type: "boolean"
})
.option("x-perf", {
describe: "Outputs performance measurements",
default: false,
Expand Down
170 changes: 60 additions & 110 deletions lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,145 +9,95 @@ const tree = {

tree.builder = function(cli) {
return cli
.option("full", {
describe: "Include more information (currently the project configuration)",
default: false,
type: "boolean"
})
.option("json", {
describe: "Output tree as formatted JSON string",
default: false,
type: "boolean"
})
.option("dedupe", {
describe: "Remove duplicate projects from project tree",
default: false,
type: "boolean"
})
.option("framework-version", {
describe:
"Overrides the framework version defined by the project. Only supported in combination with --full",
"Overrides the framework version defined by the project",
type: "string"
})
.check((argv) => {
if (argv.frameworkVersion && !argv.full) {
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
} else {
return true;
}
})
.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 = async function(argv) {
const normalizer = require("@ui5/project").normalizer;
const treeify = require("treeify");
const chalk = require("chalk");

let startTime;
let elapsedTime;
if (argv.xPerf) {
startTime = process.hrtime();
}
if (argv.xGraphMode) {
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
let graph;
if (argv.dependencyDefinition) {
graph = await generateProjectGraph.usingStaticFile({
filePath: argv.dependencyDefinition,
versionOverride: argv.frameworkVersion
});
} else {
graph = await generateProjectGraph.usingNodePackageDependencies({
rootConfigPath: argv.config,
versionOverride: argv.frameworkVersion
});
}

if (argv.xPerf) {
elapsedTime = getElapsedTime(startTime);
}

const projects = {};
const indentWidth = 4;
await graph.traverseBreadthFirst(async ({project, getDependencies}) => {
const deps = getDependencies().map((dep) => {
return dep.getName();
});
projects[project.getName()] = {
render: function(indentation, connectorIndices, lastChild) {
let baseString = " ".repeat(indentation * indentWidth);
connectorIndices.forEach((idx) => {
baseString = `${baseString.slice(0, idx)}${baseString.slice(idx + 1)}`;
});
const connectorString = lastChild ? "╰─" : "├─";
console.log(
`${baseString}${connectorString} ${chalk.bold(project.getName())} ` +
`${project.getNamespace ? chalk.inverse(project.getNamespace()) + " " : ""}` +
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
chalk.dim.italic(`${project.getPath()}`)
);

const lastIdx = deps.length -1;
const newConnectorIndices = [...connectorIndices];
if (!lastChild) {
newConnectorIndices.push(indentation * indentWidth);
}
deps.forEach((dep, i) => {
projects[dep].render(indentation + 1, newConnectorIndices, i === lastIdx);
});
}
};
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
let graph;
if (argv.dependencyDefinition) {
graph = await generateProjectGraph.usingStaticFile({
filePath: argv.dependencyDefinition,
versionOverride: argv.frameworkVersion
});
} else {
graph = await generateProjectGraph.usingNodePackageDependencies({
rootConfigPath: argv.config,
versionOverride: argv.frameworkVersion
});
}

const projectKeys = Object.keys(projects);
console.log(chalk.bold.underline(`Dependencies (${projectKeys.length}):`));
projects[projectKeys[0]].render(0, [], true);
console.log("");
if (argv.xPerf) {
elapsedTime = getElapsedTime(startTime);
}

const extensions = graph.getAllExtensions();
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
if (extensions.length) {
extensions.forEach((extension) => {
const projects = {};
const indentWidth = 4;
await graph.traverseBreadthFirst(async ({project, getDependencies}) => {
const deps = getDependencies().map((dep) => {
return dep.getName();
});
projects[project.getName()] = {
render: function(indentation, connectorIndices, lastChild) {
let baseString = " ".repeat(indentation * indentWidth);
connectorIndices.forEach((idx) => {
baseString = `${baseString.slice(0, idx)}${baseString.slice(idx + 1)}`;
});
const connectorString = lastChild ? "╰─" : "├─";
console.log(
`${" ".repeat(indentWidth)} ├─ ${extension.getName()}` +
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
chalk.dim.italic(`${extension.getPath()}`));
});
} else {
console.log(chalk.italic(`None`));
}
} else {
const options = {
translatorName: argv.translator,
translatorOptions: {
includeDeduped: !argv.dedupe
},
configPath: argv.config
};
`${baseString}${connectorString} ${chalk.bold(project.getName())} ` +
`${project.getNamespace ? chalk.inverse(project.getNamespace()) + " " : ""}` +
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
chalk.dim.italic(`${project.getPath()}`)
);

if (argv.frameworkVersion ) {
options.frameworkOptions = {
versionOverride: argv.frameworkVersion
};
}

let projectTree;
if (argv.full) {
projectTree = await normalizer.generateProjectTree(options);
} else {
projectTree = await normalizer.generateDependencyTree(options);
}
if (argv.xPerf) {
elapsedTime = getElapsedTime(startTime);
}
const lastIdx = deps.length -1;
const newConnectorIndices = [...connectorIndices];
if (!lastChild) {
newConnectorIndices.push(indentation * indentWidth);
}
deps.forEach((dep, i) => {
projects[dep].render(indentation + 1, newConnectorIndices, i === lastIdx);
});
}
};
});

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

const output = argv.json ? JSON.stringify(projectTree, null, 4) : treeify.asTree(projectTree, true);
console.log(output);
const extensions = graph.getAllExtensions();
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
if (extensions.length) {
extensions.forEach((extension) => {
console.log(
`${" ".repeat(indentWidth)} ├─ ${extension.getName()}` +
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
chalk.dim.italic(`${extension.getPath()}`));
});
} else {
console.log(chalk.italic(`None`));
}

if (argv.xPerf) {
console.log("");
console.log(chalk.blue(
Expand Down

0 comments on commit a54c2e0

Please sign in to comment.