Skip to content

Commit 8092727

Browse files
committed
[INTERNAL] Adapt to new ui5-project graph API
1 parent b767199 commit 8092727

File tree

3 files changed

+75
-49
lines changed

3 files changed

+75
-49
lines changed

lib/cli/commands/base.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ const cli = require("yargs");
33
cli.usage("Usage: ui5 <command> [options]")
44
.demandCommand(1, "Command required! Please have a look at the help documentation above.")
55
.option("config", {
6-
describe: "Path to configuration file",
6+
describe: "Path to project configuration file in YAML format",
7+
type: "string"
8+
})
9+
.option("dependency-definition", {
10+
describe: "Path to a YAML file containing the project's dependency tree. " +
11+
"This option will disable resolution of node package dependencies.",
712
type: "string"
813
})
914
.option("translator", {
@@ -22,6 +27,16 @@ cli.usage("Usage: ui5 <command> [options]")
2227
default: "info",
2328
type: "string"
2429
})
30+
.option("x-graph-mode", {
31+
describe: "Uses an experimental project graph instead of a dependency tree",
32+
default: false,
33+
type: "boolean"
34+
})
35+
.option("x-perf", {
36+
describe: "Outputs performance measurements",
37+
default: false,
38+
type: "boolean"
39+
})
2540
.showHelpOnFail(true)
2641
.strict(true)
2742
.alias("help", "h")

lib/cli/commands/build.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ build.builder = function(cli) {
107107
default: false,
108108
type: "boolean"
109109
})
110-
.option("x-graph-mode", {
111-
describe: "Uses an experimental project graph instead of a dependency tree",
112-
default: false,
113-
type: "boolean"
114-
})
115110
.example("ui5 build", "Preload build for project without dependencies")
116111
.example("ui5 build self-contained --all", "Self-contained build for project including dependencies")
117112
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
@@ -129,35 +124,48 @@ build.builder = function(cli) {
129124
};
130125

131126
async function handleBuild(argv) {
132-
const normalizer = require("@ui5/project").normalizer;
133127
const builder = require("@ui5/builder").builder;
134128
const logger = require("@ui5/logger");
135129

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

139-
const normalizerOptions = {
140-
translatorName: argv.translator,
141-
configPath: argv.config
142-
};
143-
144-
if (argv.frameworkVersion) {
145-
normalizerOptions.frameworkOptions = {
146-
versionOverride: argv.frameworkVersion
147-
};
148-
}
149-
150133
let tree;
151134
let graph;
135+
let buildSettings;
152136
if (argv.xGraphMode) {
153-
graph = await normalizer.generateProjectGraph(normalizerOptions);
137+
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
138+
if (argv.dependencyDefinition) {
139+
graph = await generateProjectGraph.usingStaticFile({
140+
filePath: argv.dependencyDefinition,
141+
versionOverride: argv.frameworkVersion
142+
});
143+
} else {
144+
graph = await generateProjectGraph.usingNodePackageDependencies({
145+
rootConfigPath: argv.config,
146+
versionOverride: argv.frameworkVersion
147+
});
148+
}
149+
buildSettings = graph.getRoot().getBuilderSettings() || {};
154150
} else {
151+
const normalizerOptions = {
152+
translatorName: argv.translator,
153+
configPath: argv.config
154+
};
155+
156+
if (argv.frameworkVersion) {
157+
normalizerOptions.frameworkOptions = {
158+
versionOverride: argv.frameworkVersion
159+
};
160+
}
161+
const normalizer = require("@ui5/project").normalizer;
155162
tree = await normalizer.generateProjectTree(normalizerOptions);
163+
buildSettings = (tree.builder && tree.builder.settings) || {};
156164
}
157-
const buildSettings = (tree.builder && tree.builder.settings) || {};
158165

159166
const {includedDependencies, excludedDependencies} = buildHelper.createDependencyLists({
160-
tree: tree,
167+
tree,
168+
graph,
161169
includeDependency: argv["include-dependency"],
162170
includeDependencyRegExp: argv["include-dependency-regexp"],
163171
includeDependencyTree: argv["include-dependency-tree"],
@@ -171,8 +179,8 @@ async function handleBuild(argv) {
171179
const buildAll = buildHelper.alignWithBuilderApi(argv.all, includedDependencies, excludedDependencies);
172180

173181
await builder.build({
174-
tree: tree,
175-
graph: graph,
182+
tree,
183+
graph,
176184
destPath: argv.dest,
177185
cleanDest: argv["clean-dest"],
178186
buildDependencies: buildAll,

lib/cli/commands/tree.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ tree.builder = function(cli) {
2929
"Overrides the framework version defined by the project. Only supported in combination with --full",
3030
type: "string"
3131
})
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-
})
4232
.check((argv) => {
4333
if (argv.frameworkVersion && !argv.full) {
4434
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
@@ -55,27 +45,25 @@ tree.handler = async function(argv) {
5545
const treeify = require("treeify");
5646
const chalk = require("chalk");
5747

58-
const options = {
59-
translatorName: argv.translator,
60-
translatorOptions: {
61-
includeDeduped: !argv.dedupe
62-
},
63-
configPath: argv.config
64-
};
65-
66-
if (argv.frameworkVersion ) {
67-
options.frameworkOptions = {
68-
versionOverride: argv.frameworkVersion
69-
};
70-
}
71-
7248
let startTime;
7349
let elapsedTime;
7450
if (argv.xPerf) {
7551
startTime = process.hrtime();
7652
}
7753
if (argv.xGraphMode) {
78-
const graph = await normalizer.generateProjectGraph(options);
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+
}
7967

8068
if (argv.xPerf) {
8169
elapsedTime = getElapsedTime(startTime);
@@ -131,6 +119,20 @@ tree.handler = async function(argv) {
131119
console.log(chalk.italic(`None`));
132120
}
133121
} 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+
}
135+
134136
let projectTree;
135137
if (argv.full) {
136138
projectTree = await normalizer.generateProjectTree(options);
@@ -148,7 +150,8 @@ tree.handler = async function(argv) {
148150

149151
if (argv.xPerf) {
150152
console.log("");
151-
console.log(chalk.blue(`Normalizer took ${chalk.bold(elapsedTime)}`));
153+
console.log(chalk.blue(
154+
`Dependency ${argv.xGraphMode ? "graph" : "tree"} generation took ${chalk.bold(elapsedTime)}`));
152155
}
153156
};
154157

0 commit comments

Comments
 (0)