Skip to content

Commit 48ea928

Browse files
RandomBytematz3
andauthored
[cli][BREAKING] Adapt to Project Graph APIs (SAP/ui5-cli#413)
Adapt to new ui5-project Project Graph and builder APIs: SAP/ui5-project#457 BREAKING CHANGES: * Removed CLI option `--translator`. Use new option `--dependency-definition` to provide a file with static dependency information * Removed `ui5 build dev` command * Refactored `ui5 tree`: Removed `--full`, `--json` and `--dedupe` options Co-authored-by: Matthias Osswald <[email protected]>
1 parent 5875b84 commit 48ea928

File tree

26 files changed

+2196
-2587
lines changed

26 files changed

+2196
-2587
lines changed

packages/cli/lib/cli/commands/add.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ addCommand.handler = async function(argv) {
4141
throw new Error("Options 'development' and 'optional' cannot be combined");
4242
}
4343

44-
const normalizerOptions = {
45-
translatorName: argv.translator,
46-
configPath: argv.config
44+
const projectGraphOptions = {
45+
dependencyDefinition: argv.dependencyDefinition,
46+
config: argv.config
4747
};
4848

4949
const libraries = libraryNames.map((name) => {
@@ -57,7 +57,7 @@ addCommand.handler = async function(argv) {
5757
});
5858

5959
const {yamlUpdated} = await require("../../framework/add")({
60-
normalizerOptions,
60+
projectGraphOptions,
6161
libraries
6262
});
6363

packages/cli/lib/cli/commands/base.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +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",
77
type: "string"
88
})
9-
.option("translator", {
10-
describe: "Translator to use. Including optional colon separated translator parameters.",
11-
alias: "t8r",
12-
default: "npm",
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.",
1312
type: "string"
1413
})
1514
.option("verbose", {
@@ -22,6 +21,11 @@ cli.usage("Usage: ui5 <command> [options]")
2221
default: "info",
2322
type: "string"
2423
})
24+
.option("x-perf", {
25+
describe: "Outputs performance measurements",
26+
default: false,
27+
type: "boolean"
28+
})
2529
.showHelpOnFail(true)
2630
.strict(true)
2731
.alias("help", "h")

packages/cli/lib/cli/commands/build.js

Lines changed: 50 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Build
22

33
const baseMiddleware = require("../middlewares/base.js");
4-
const buildHelper = require("../../utils/buildHelper");
54

65
const build = {
76
command: "build",
@@ -12,11 +11,6 @@ const build = {
1211

1312
build.builder = function(cli) {
1413
return cli
15-
.command("dev", "Dev build: Skips non-essential and time-intensive tasks during build", {
16-
handler: handleBuild,
17-
builder: noop,
18-
middlewares: [baseMiddleware]
19-
})
2014
.command("jsdoc", "Build JSDoc resources", {
2115
handler: handleBuild,
2216
builder: noop,
@@ -29,46 +23,46 @@ build.builder = function(cli) {
2923
})
3024
.command("self-contained",
3125
"Build project and create self-contained bundle. " +
32-
"Recommended to be used in conjunction with --all", {
26+
"Recommended to be used in conjunction with --include-dependencies", {
3327
handler: handleBuild,
3428
builder: noop,
3529
middlewares: [baseMiddleware]
3630
})
37-
.option("all", {
38-
describe: "Include all project dependencies into build process",
39-
alias: "a",
31+
.option("include-all-dependencies", {
32+
describe: "Include all dependencies in the build result",
33+
alias: ["all", "a"],
4034
default: false,
4135
type: "boolean"
4236
})
4337
.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" +
38+
describe: "A list of dependencies to be included in the build result. You can use the asterisk '*' as" +
39+
" an alias for including all dependencies in the build result. The listed dependencies cannot be" +
4640
" overruled by dependencies defined in 'exclude-dependency'.",
4741
type: "array"
4842
})
4943
.option("include-dependency-regexp", {
50-
describe: "A list of regular expressions defining dependencies to be included into the build process." +
44+
describe: "A list of regular expressions defining dependencies to be included in the build result." +
5145
" This list is prioritized like 'include-dependency'.",
5246
type: "array"
5347
})
5448
.option("include-dependency-tree", {
55-
describe: "A list of dependencies to be included into the build process. Transitive dependencies are" +
49+
describe: "A list of dependencies to be included in the build result. Transitive dependencies are" +
5650
" implicitly included and do not need to be part of this list. These dependencies overrule" +
5751
" the selection of 'exclude-dependency-tree' but can be overruled by 'exclude-dependency'.",
5852
type: "array"
5953
})
6054
.option("exclude-dependency", {
61-
describe: "A list of dependencies to be excluded from the build process. The listed dependencies can" +
55+
describe: "A list of dependencies to be excluded from the build result. The listed dependencies can" +
6256
" be overruled by dependencies defined in 'include-dependency'.",
6357
type: "array"
6458
})
6559
.option("exclude-dependency-regexp", {
66-
describe: "A list of regular expressions defining dependencies to be excluded from the build process." +
60+
describe: "A list of regular expressions defining dependencies to be excluded from the build result." +
6761
" This list is prioritized like 'exclude-dependency'.",
6862
type: "array"
6963
})
7064
.option("exclude-dependency-tree", {
71-
describe: "A list of dependencies to be excluded from the build process. Transitive dependencies are" +
65+
describe: "A list of dependencies to be excluded from the build result. Transitive dependencies are" +
7266
" implicitly included and do not need to be part of this list.",
7367
type: "array"
7468
})
@@ -82,18 +76,19 @@ build.builder = function(cli) {
8276
default: false,
8377
type: "boolean"
8478
})
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"
79+
.option("create-build-manifest", {
80+
describe: "Store build metadata in a '.ui5' directory in the build destination, " +
81+
"allowing reuse of the build result in other builds",
82+
default: false,
83+
type: "boolean"
9084
})
9185
.option("include-task", {
92-
describe: "A list of specific tasks to be included to the default/dev set",
86+
describe: "A list of tasks to be added to the default execution set. " +
87+
"This option takes precedence over any excludes.",
9388
type: "array"
9489
})
9590
.option("exclude-task", {
96-
describe: "A list of specific tasks to be excluded from default/dev set",
91+
describe: "A list of tasks to be excluded from the default task execution set",
9792
type: "array"
9893
})
9994
.option("framework-version", {
@@ -108,6 +103,8 @@ build.builder = function(cli) {
108103
type: "boolean"
109104
})
110105
.example("ui5 build", "Preload build for project without dependencies")
106+
107+
// TODO 3.0: Update examples
111108
.example("ui5 build self-contained --all", "Self-contained build for project including dependencies")
112109
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
113110
"Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks")
@@ -120,56 +117,49 @@ build.builder = function(cli) {
120117
.example("ui5 build dev",
121118
"Build project and dependencies in dev mode. Only a set of essential tasks is executed.")
122119
.example("ui5 build --experimental-css-variables",
123-
"Preload build for project without dependencies but with CSS variable artefacts");
120+
"Preload build for project without dependencies but with CSS variable artifacts");
124121
};
125122

126123
async function handleBuild(argv) {
127-
const normalizer = require("@ui5/project").normalizer;
128-
const builder = require("@ui5/builder").builder;
129124
const logger = require("@ui5/logger");
125+
const {generateProjectGraph, builder} = require("@ui5/project");
130126

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

134-
const normalizerOptions = {
135-
translatorName: argv.translator,
136-
configPath: argv.config
137-
};
138-
139-
if (argv.frameworkVersion) {
140-
normalizerOptions.frameworkOptions = {
130+
let graph;
131+
if (argv.dependencyDefinition) {
132+
graph = await generateProjectGraph.usingStaticFile({
133+
filePath: argv.dependencyDefinition,
134+
rootConfigPath: argv.config,
141135
versionOverride: argv.frameworkVersion
142-
};
136+
});
137+
} else {
138+
graph = await generateProjectGraph.usingNodePackageDependencies({
139+
rootConfigPath: argv.config,
140+
versionOverride: argv.frameworkVersion
141+
});
143142
}
144-
145-
const tree = await normalizer.generateProjectTree(normalizerOptions);
146-
const buildSettings = (tree.builder && tree.builder.settings) || {};
147-
148-
const {includedDependencies, excludedDependencies} = buildHelper.createDependencyLists({
149-
tree: tree,
150-
includeDependency: argv["include-dependency"],
151-
includeDependencyRegExp: argv["include-dependency-regexp"],
152-
includeDependencyTree: argv["include-dependency-tree"],
153-
excludeDependency: argv["exclude-dependency"],
154-
excludeDependencyRegExp: argv["exclude-dependency-regexp"],
155-
excludeDependencyTree: argv["exclude-dependency-tree"],
156-
defaultIncludeDependency: buildSettings.includeDependency,
157-
defaultIncludeDependencyRegExp: buildSettings.includeDependencyRegExp,
158-
defaultIncludeDependencyTree: buildSettings.includeDependencyTree
159-
});
160-
const buildAll = buildHelper.alignWithBuilderApi(argv.all, includedDependencies, excludedDependencies);
161-
162-
await builder.build({
163-
tree: tree,
143+
const buildSettings = graph.getRoot().getBuilderSettings() || {};
144+
await builder({
145+
graph,
164146
destPath: argv.dest,
165147
cleanDest: argv["clean-dest"],
166-
buildDependencies: buildAll,
167-
includedDependencies: includedDependencies,
168-
excludedDependencies: excludedDependencies,
169-
dev: command === "dev",
148+
createBuildManifest: argv["create-build-manifest"],
149+
complexDependencyIncludes: {
150+
includeAllDependencies: argv["include-all-dependencies"],
151+
includeDependency: argv["include-dependency"],
152+
includeDependencyRegExp: argv["include-dependency-regexp"],
153+
includeDependencyTree: argv["include-dependency-tree"],
154+
excludeDependency: argv["exclude-dependency"],
155+
excludeDependencyRegExp: argv["exclude-dependency-regexp"],
156+
excludeDependencyTree: argv["exclude-dependency-tree"],
157+
defaultIncludeDependency: buildSettings.includeDependency,
158+
defaultIncludeDependencyRegExp: buildSettings.includeDependencyRegExp,
159+
defaultIncludeDependencyTree: buildSettings.includeDependencyTree
160+
},
170161
selfContained: command === "self-contained",
171162
jsdoc: command === "jsdoc",
172-
devExcludeProject: argv["dev-exclude-project"],
173163
includedTasks: argv["include-task"],
174164
excludedTasks: argv["exclude-task"],
175165
cssVariables: argv["experimental-css-variables"]

packages/cli/lib/cli/commands/remove.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ removeCommand.handler = async function(argv) {
2727
return libraryNames.indexOf(libraryName) === index;
2828
});
2929

30-
const normalizerOptions = {
31-
translatorName: argv.translator,
32-
configPath: argv.config
30+
const projectGraphOptions = {
31+
dependencyDefinition: argv.dependencyDefinition,
32+
config: argv.config
3333
};
3434

3535
const libraries = libraryNames.map((name) => {
@@ -38,7 +38,7 @@ removeCommand.handler = async function(argv) {
3838
});
3939

4040
const {yamlUpdated} = await require("../../framework/remove")({
41-
normalizerOptions,
41+
projectGraphOptions,
4242
libraries
4343
});
4444

packages/cli/lib/cli/commands/serve.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,32 @@ serve.builder = function(cli) {
7373
};
7474

7575
serve.handler = async function(argv) {
76-
const normalizer = require("@ui5/project").normalizer;
76+
const {generateProjectGraph} = require("@ui5/project");
7777
const ui5Server = require("@ui5/server");
7878
const server = ui5Server.server;
7979

80-
const normalizerOptions = {
81-
translatorName: argv.translator,
82-
configPath: argv.config
83-
};
84-
85-
if (argv.frameworkVersion) {
86-
normalizerOptions.frameworkOptions = {
80+
let graph;
81+
if (argv.dependencyDefinition) {
82+
graph = await generateProjectGraph.usingStaticFile({
83+
filePath: argv.dependencyDefinition,
84+
versionOverride: argv.frameworkVersion
85+
});
86+
} else {
87+
graph = await generateProjectGraph.usingNodePackageDependencies({
88+
rootConfigPath: argv.config,
8789
versionOverride: argv.frameworkVersion
88-
};
90+
});
8991
}
9092

91-
const tree = await normalizer.generateProjectTree(normalizerOptions);
9293
let port = argv.port;
9394
let changePortIfInUse = false;
9495

95-
if (!port && tree.server && tree.server.settings) {
96+
if (!port && graph.getRoot().getServerSettings()) {
97+
const serverSettings = graph.getRoot().getServerSettings();
9698
if (argv.h2) {
97-
port = tree.server.settings.httpsPort;
99+
port = serverSettings.httpsPort;
98100
} else {
99-
port = tree.server.settings.httpPort;
101+
port = serverSettings.httpPort;
100102
}
101103
}
102104

@@ -127,7 +129,7 @@ serve.handler = async function(argv) {
127129
serverConfig.cert = cert;
128130
}
129131

130-
const {h2, port: actualPort} = await server.serve(tree, serverConfig);
132+
const {h2, port: actualPort} = await server.serve(graph, serverConfig);
131133

132134
const protocol = h2 ? "https" : "http";
133135
let browserUrl = protocol + "://localhost:" + actualPort;

0 commit comments

Comments
 (0)