Skip to content

Commit acd8135

Browse files
committed
[INTERNAL] Adapt to new ui5-project graph API
1 parent 6b52efc commit acd8135

File tree

3 files changed

+97
-89
lines changed

3 files changed

+97
-89
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: true,
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: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const build = {
1212

1313
build.builder = function(cli) {
1414
return cli
15-
.command("dev", "Dev build: Skips non-essential and time-intensive tasks during build", {
15+
.command("archive", "Archive build: Creates a reusable build archive of the project", {
1616
handler: handleBuild,
1717
builder: noop,
1818
middlewares: [baseMiddleware]
@@ -29,7 +29,7 @@ build.builder = function(cli) {
2929
})
3030
.command("self-contained",
3131
"Build project and create self-contained bundle. " +
32-
"Recommended to be used in conjunction with --all", {
32+
"Recommended to be used in conjunction with --include-dependencies", {
3333
handler: handleBuild,
3434
builder: noop,
3535
middlewares: [baseMiddleware]
@@ -40,35 +40,42 @@ build.builder = function(cli) {
4040
default: false,
4141
type: "boolean"
4242
})
43+
.deprecateOption("all", "Use --include-dependencies")
44+
.option("include-all-dependencies", {
45+
describe: "Include all dependencies in the build result",
46+
alias: ["d", "deps"],
47+
default: false,
48+
type: "boolean"
49+
})
4350
.option("include-dependency", {
44-
describe: "A list of dependencies to be included into the build process. You can use the asterisk '*' as" +
45-
" an alias for including all dependencies into the build process. The listed dependencies cannot be" +
51+
describe: "A list of dependencies to be included in the build result. You can use the asterisk '*' as" +
52+
" an alias for including all dependencies in the build result. The listed dependencies cannot be" +
4653
" overruled by dependencies defined in 'exclude-dependency'.",
4754
type: "array"
4855
})
4956
.option("include-dependency-regexp", {
50-
describe: "A list of regular expressions defining dependencies to be included into the build process." +
57+
describe: "A list of regular expressions defining dependencies to be included in the build result." +
5158
" This list is prioritized like 'include-dependency'.",
5259
type: "array"
5360
})
5461
.option("include-dependency-tree", {
55-
describe: "A list of dependencies to be included into the build process. Transitive dependencies are" +
62+
describe: "A list of dependencies to be included in the build result. Transitive dependencies are" +
5663
" implicitly included and do not need to be part of this list. These dependencies overrule" +
5764
" the selection of 'exclude-dependency-tree' but can be overruled by 'exclude-dependency'.",
5865
type: "array"
5966
})
6067
.option("exclude-dependency", {
61-
describe: "A list of dependencies to be excluded from the build process. The listed dependencies can" +
68+
describe: "A list of dependencies to be excluded from the build result. The listed dependencies can" +
6269
" be overruled by dependencies defined in 'include-dependency'.",
6370
type: "array"
6471
})
6572
.option("exclude-dependency-regexp", {
66-
describe: "A list of regular expressions defining dependencies to be excluded from the build process." +
73+
describe: "A list of regular expressions defining dependencies to be excluded from the build result." +
6774
" This list is prioritized like 'exclude-dependency'.",
6875
type: "array"
6976
})
7077
.option("exclude-dependency-tree", {
71-
describe: "A list of dependencies to be excluded from the build process. Transitive dependencies are" +
78+
describe: "A list of dependencies to be excluded from the build result. Transitive dependencies are" +
7279
" implicitly included and do not need to be part of this list.",
7380
type: "array"
7481
})
@@ -82,18 +89,13 @@ build.builder = function(cli) {
8289
default: false,
8390
type: "boolean"
8491
})
85-
.option("dev-exclude-project", {
86-
describe:
87-
"A list of specific projects to be excluded from dev mode " +
88-
"(dev mode must be active for this to be effective)",
89-
type: "array"
90-
})
9192
.option("include-task", {
92-
describe: "A list of specific tasks to be included to the default/dev set",
93+
describe: "A list of tasks to be added to the default execution set. " +
94+
"This option takes precedence over any excludes.",
9395
type: "array"
9496
})
9597
.option("exclude-task", {
96-
describe: "A list of specific tasks to be excluded from default/dev set",
98+
describe: "A list of tasks to be excluded from the default task execution set",
9799
type: "array"
98100
})
99101
.option("framework-version", {
@@ -107,12 +109,9 @@ build.builder = function(cli) {
107109
default: false,
108110
type: "boolean"
109111
})
110-
.option("x-graph-mode", {
111-
describe: "Uses an experimental project graph instead of a dependency tree",
112-
default: false,
113-
type: "boolean"
114-
})
115112
.example("ui5 build", "Preload build for project without dependencies")
113+
114+
// TODO 3.0: Update examples
116115
.example("ui5 build self-contained --all", "Self-contained build for project including dependencies")
117116
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
118117
"Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks")
@@ -125,60 +124,51 @@ build.builder = function(cli) {
125124
.example("ui5 build dev",
126125
"Build project and dependencies in dev mode. Only a set of essential tasks is executed.")
127126
.example("ui5 build --experimental-css-variables",
128-
"Preload build for project without dependencies but with CSS variable artefacts");
127+
"Preload build for project without dependencies but with CSS variable artifacts");
129128
};
130129

131130
async function handleBuild(argv) {
132-
const normalizer = require("@ui5/project").normalizer;
133-
const builder = require("@ui5/builder").builder;
134131
const logger = require("@ui5/logger");
132+
const {generateProjectGraph, builder} = require("@ui5/project");
135133

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

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-
};
137+
if (argv.all) {
138+
logger.warn(
139+
"CLI option --all is deprecated. Dependencies are now built automatically in case they are required");
148140
}
149141

150-
let tree;
151142
let graph;
152-
if (argv.xGraphMode) {
153-
graph = await normalizer.generateProjectGraph(normalizerOptions);
143+
if (argv.dependencyDefinition) {
144+
graph = await generateProjectGraph.usingStaticFile({
145+
filePath: argv.dependencyDefinition,
146+
versionOverride: argv.frameworkVersion
147+
});
154148
} else {
155-
tree = await normalizer.generateProjectTree(normalizerOptions);
149+
graph = await generateProjectGraph.usingNodePackageDependencies({
150+
rootConfigPath: argv.config,
151+
versionOverride: argv.frameworkVersion
152+
});
156153
}
157-
const buildSettings = (tree.builder && tree.builder.settings) || {};
158-
159-
const {includedDependencies, excludedDependencies} = buildHelper.createDependencyLists({
160-
tree: tree,
161-
includeDependency: argv["include-dependency"],
162-
includeDependencyRegExp: argv["include-dependency-regexp"],
163-
includeDependencyTree: argv["include-dependency-tree"],
164-
excludeDependency: argv["exclude-dependency"],
165-
excludeDependencyRegExp: argv["exclude-dependency-regexp"],
166-
excludeDependencyTree: argv["exclude-dependency-tree"],
167-
defaultIncludeDependency: buildSettings.includeDependency,
168-
defaultIncludeDependencyRegExp: buildSettings.includeDependencyRegExp,
169-
defaultIncludeDependencyTree: buildSettings.includeDependencyTree
170-
});
171-
const buildAll = buildHelper.alignWithBuilderApi(argv.all, includedDependencies, excludedDependencies);
172-
173-
await builder.build({
174-
tree: tree,
175-
graph: graph,
154+
const buildSettings = graph.getRoot().getBuilderSettings() || {};
155+
await builder({
156+
graph,
176157
destPath: argv.dest,
177158
cleanDest: argv["clean-dest"],
178-
buildDependencies: buildAll,
179-
includedDependencies: includedDependencies,
180-
excludedDependencies: excludedDependencies,
181-
dev: command === "dev",
159+
composeProjectList: {
160+
includeAllDependencies: argv["include-all-dependencies"],
161+
includeDependency: argv["include-dependency"],
162+
includeDependencyRegExp: argv["include-dependency-regexp"],
163+
includeDependencyTree: argv["include-dependency-tree"],
164+
excludeDependency: argv["exclude-dependency"],
165+
excludeDependencyRegExp: argv["exclude-dependency-regexp"],
166+
excludeDependencyTree: argv["exclude-dependency-tree"],
167+
defaultIncludeDependency: buildSettings.includeDependency,
168+
defaultIncludeDependencyRegExp: buildSettings.includeDependencyRegExp,
169+
defaultIncludeDependencyTree: buildSettings.includeDependencyTree
170+
},
171+
archive: command === "archive",
182172
selfContained: command === "self-contained",
183173
jsdoc: command === "jsdoc",
184174
devExcludeProject: argv["dev-exclude-project"],

lib/cli/commands/tree.js

Lines changed: 30 additions & 27 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);
@@ -118,7 +106,7 @@ tree.handler = async function(argv) {
118106
projects[projectKeys[0]].render(0, [], true);
119107
console.log("");
120108

121-
const extensions = Object.entries(graph.getAllExtensions());
109+
const extensions = graph.getAllExtensions();
122110
console.log(chalk.bold.underline(`Extensions (${extensions.length}):`));
123111
if (extensions.length) {
124112
extensions.forEach((extension) => {
@@ -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)