Skip to content

Commit

Permalink
[INTERNAL] Adapt to new ui5-project graph API
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Apr 23, 2022
1 parent b767199 commit 8092727
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 49 deletions.
17 changes: 16 additions & 1 deletion lib/cli/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const cli = require("yargs");
cli.usage("Usage: ui5 <command> [options]")
.demandCommand(1, "Command required! Please have a look at the help documentation above.")
.option("config", {
describe: "Path to configuration file",
describe: "Path to project configuration file in YAML format",
type: "string"
})
.option("dependency-definition", {
describe: "Path to a YAML file containing the project's dependency tree. " +
"This option will disable resolution of node package dependencies.",
type: "string"
})
.option("translator", {
Expand All @@ -22,6 +27,16 @@ 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: false,
type: "boolean"
})
.option("x-perf", {
describe: "Outputs performance measurements",
default: false,
type: "boolean"
})
.showHelpOnFail(true)
.strict(true)
.alias("help", "h")
Expand Down
52 changes: 30 additions & 22 deletions lib/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ build.builder = function(cli) {
default: false,
type: "boolean"
})
.option("x-graph-mode", {
describe: "Uses an experimental project graph instead of a dependency tree",
default: false,
type: "boolean"
})
.example("ui5 build", "Preload build for project without dependencies")
.example("ui5 build self-contained --all", "Self-contained build for project including dependencies")
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
Expand All @@ -129,35 +124,48 @@ build.builder = function(cli) {
};

async function handleBuild(argv) {
const normalizer = require("@ui5/project").normalizer;
const builder = require("@ui5/builder").builder;
const logger = require("@ui5/logger");

const command = argv._[argv._.length - 1];
logger.setShowProgress(true);

const normalizerOptions = {
translatorName: argv.translator,
configPath: argv.config
};

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

let tree;
let graph;
let buildSettings;
if (argv.xGraphMode) {
graph = await normalizer.generateProjectGraph(normalizerOptions);
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
if (argv.dependencyDefinition) {
graph = await generateProjectGraph.usingStaticFile({
filePath: argv.dependencyDefinition,
versionOverride: argv.frameworkVersion
});
} else {
graph = await generateProjectGraph.usingNodePackageDependencies({
rootConfigPath: argv.config,
versionOverride: argv.frameworkVersion
});
}
buildSettings = graph.getRoot().getBuilderSettings() || {};
} else {
const normalizerOptions = {
translatorName: argv.translator,
configPath: argv.config
};

if (argv.frameworkVersion) {
normalizerOptions.frameworkOptions = {
versionOverride: argv.frameworkVersion
};
}
const normalizer = require("@ui5/project").normalizer;
tree = await normalizer.generateProjectTree(normalizerOptions);
buildSettings = (tree.builder && tree.builder.settings) || {};
}
const buildSettings = (tree.builder && tree.builder.settings) || {};

const {includedDependencies, excludedDependencies} = buildHelper.createDependencyLists({
tree: tree,
tree,
graph,
includeDependency: argv["include-dependency"],
includeDependencyRegExp: argv["include-dependency-regexp"],
includeDependencyTree: argv["include-dependency-tree"],
Expand All @@ -171,8 +179,8 @@ async function handleBuild(argv) {
const buildAll = buildHelper.alignWithBuilderApi(argv.all, includedDependencies, excludedDependencies);

await builder.build({
tree: tree,
graph: graph,
tree,
graph,
destPath: argv.dest,
cleanDest: argv["clean-dest"],
buildDependencies: buildAll,
Expand Down
55 changes: 29 additions & 26 deletions lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ tree.builder = function(cli) {
"Overrides the framework version defined by the project. Only supported in combination with --full",
type: "string"
})
.option("x-graph-mode", {
describe: "Uses an experimental project graph instead of a dependency tree",
default: false,
type: "boolean"
})
.option("x-perf", {
describe: "Outputs performance measurements",
default: false,
type: "boolean"
})
.check((argv) => {
if (argv.frameworkVersion && !argv.full) {
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
Expand All @@ -55,27 +45,25 @@ tree.handler = async function(argv) {
const treeify = require("treeify");
const chalk = require("chalk");

const options = {
translatorName: argv.translator,
translatorOptions: {
includeDeduped: !argv.dedupe
},
configPath: argv.config
};

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

let startTime;
let elapsedTime;
if (argv.xPerf) {
startTime = process.hrtime();
}
if (argv.xGraphMode) {
const graph = await normalizer.generateProjectGraph(options);
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);
Expand Down Expand Up @@ -131,6 +119,20 @@ tree.handler = async function(argv) {
console.log(chalk.italic(`None`));
}
} else {
const options = {
translatorName: argv.translator,
translatorOptions: {
includeDeduped: !argv.dedupe
},
configPath: argv.config
};

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

let projectTree;
if (argv.full) {
projectTree = await normalizer.generateProjectTree(options);
Expand All @@ -148,7 +150,8 @@ tree.handler = async function(argv) {

if (argv.xPerf) {
console.log("");
console.log(chalk.blue(`Normalizer took ${chalk.bold(elapsedTime)}`));
console.log(chalk.blue(
`Dependency ${argv.xGraphMode ? "graph" : "tree"} generation took ${chalk.bold(elapsedTime)}`));
}
};

Expand Down

0 comments on commit 8092727

Please sign in to comment.