Skip to content

Commit ae7932b

Browse files
matz3RandomByte
andauthored
[FEATURE] Add --framework-version option (#306)
Co-authored-by: Merlin Beutlberger <[email protected]>
1 parent e4d93db commit ae7932b

File tree

6 files changed

+107
-4
lines changed

6 files changed

+107
-4
lines changed

lib/cli/commands/build.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ build.builder = function(cli) {
5959
describe: "A list of specific tasks to be excluded from default/dev set",
6060
type: "array"
6161
})
62+
.option("framework-version", {
63+
describe: "Overrides the framework version defined by the project",
64+
type: "string"
65+
})
6266
.example("ui5 build --all", "Preload build for project and dependencies to \"./dist\"")
6367
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
6468
"Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks")
@@ -78,10 +82,18 @@ async function handleBuild(argv) {
7882
const command = argv._[argv._.length - 1];
7983
logger.setShowProgress(true);
8084

81-
const tree = await normalizer.generateProjectTree({
85+
const normalizerOptions = {
8286
translatorName: argv.translator,
8387
configPath: argv.config
84-
});
88+
};
89+
90+
if (argv.frameworkVersion) {
91+
normalizerOptions.frameworkOptions = {
92+
versionOverride: argv.frameworkVersion
93+
};
94+
}
95+
96+
const tree = await normalizer.generateProjectTree(normalizerOptions);
8597
await builder.build({
8698
tree: tree,
8799
destPath: argv.dest,

lib/cli/commands/serve.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ serve.builder = function(cli) {
5050
default: false,
5151
type: "boolean"
5252
})
53+
.option("framework-version", {
54+
describe: "Overrides the framework version defined by the project",
55+
type: "string"
56+
})
5357
.example("ui5 serve", "Start a web server for the current project")
5458
.example("ui5 serve --h2", "Enable the HTTP/2 protocol for the web server (requires SSL certificate)")
5559
.example("ui5 serve --config /path/to/ui5.yaml", "Use the project configuration from a custom path")
@@ -64,10 +68,18 @@ serve.handler = async function(argv) {
6468
const ui5Server = require("@ui5/server");
6569
const server = ui5Server.server;
6670

67-
const tree = await normalizer.generateProjectTree({
71+
const normalizerOptions = {
6872
translatorName: argv.translator,
6973
configPath: argv.config
70-
});
74+
};
75+
76+
if (argv.frameworkVersion) {
77+
normalizerOptions.frameworkOptions = {
78+
versionOverride: argv.frameworkVersion
79+
};
80+
}
81+
82+
const tree = await normalizer.generateProjectTree(normalizerOptions);
7183
let port = argv.port;
7284
let changePortIfInUse = false;
7385

lib/cli/commands/tree.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ tree.builder = function(cli) {
2222
default: false,
2323
type: "boolean"
2424
})
25+
.option("framework-version", {
26+
describe: "Overrides the framework version defined by the project. Only supported in combination with --full",
27+
type: "string"
28+
}).check((argv) => {
29+
if (argv.frameworkVersion && !argv.full) {
30+
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
31+
} else {
32+
return true;
33+
}
34+
})
2535
.example("ui5 tree > tree.txt", "Pipes the dependency tree into a new file \"tree.txt\"")
2636
.example("ui5 tree --json > tree.json", "Pipes the dependency tree into a new file \"tree.json\"");
2737
};
@@ -37,6 +47,13 @@ tree.handler = async function(argv) {
3747
},
3848
configPath: argv.config
3949
};
50+
51+
if (argv.frameworkVersion ) {
52+
options.frameworkOptions = {
53+
versionOverride: argv.frameworkVersion
54+
};
55+
}
56+
4057
let projectTree;
4158
if (argv.full) {
4259
projectTree = await normalizer.generateProjectTree(options);

test/lib/cli/commands/build.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,26 @@ test.serial("ui5 build jsdoc", async (t) => {
100100
"JSDoc build called with expected arguments"
101101
);
102102
});
103+
104+
test.serial("ui5 build --framework-version 1.99", async (t) => {
105+
normalizerStub.resolves({
106+
metadata:
107+
{
108+
name: "Sample"
109+
}
110+
});
111+
112+
args._ = ["build"];
113+
args.frameworkVersion = "1.99.0";
114+
await build.handler(args);
115+
t.deepEqual(
116+
normalizerStub.getCall(0).args[0],
117+
{
118+
configPath: undefined,
119+
translatorName: "npm",
120+
frameworkOptions: {
121+
versionOverride: "1.99.0"
122+
}
123+
}, "generateProjectTree got called with expected arguments"
124+
);
125+
});

test/lib/cli/commands/serve.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,26 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting and port CLI argument", a
320320
t.deepEqual(injectedServerConfig.port, 5555, "https port setting from CLI argument was used");
321321
t.deepEqual(injectedServerConfig.changePortIfInUse, false, "changePortIfInUse is set to false");
322322
});
323+
324+
test.serial("ui5 serve: --framework-version", async (t) => {
325+
normalizerStub.resolves(projectTree);
326+
serverStub.resolves({h2: false, port: 8080});
327+
328+
// loads project tree
329+
const pPrepareServerConfig = await serve.handler(
330+
Object.assign({}, defaultInitialHandlerArgs, {frameworkVersion: "1.2.3"})
331+
);
332+
// preprocess project config, skipping cert load
333+
const pServeServer = await pPrepareServerConfig;
334+
// serve server using config
335+
await pServeServer;
336+
337+
t.is(normalizerStub.called, true);
338+
t.deepEqual(normalizerStub.getCall(0).args, [{
339+
configPath: undefined,
340+
translatorName: "npm",
341+
frameworkOptions: {
342+
versionOverride: "1.2.3"
343+
}
344+
}]);
345+
});

test/lib/cli/commands/tree.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ test.serial("ui5 tree --dedupe=true", async (t) => {
7474
}), true, "includeDeduped passed as expected");
7575
});
7676

77+
test.serial("ui5 tree --full --framework-version", async (t) => {
78+
normalizer.generateProjectTree.resolves({});
79+
await tree.handler({full: true, frameworkVersion: "1.2.3"});
80+
t.is(normalizer.generateProjectTree.called, true, "project tree output");
81+
t.deepEqual(normalizer.generateProjectTree.getCall(0).args, [{
82+
configPath: undefined,
83+
translatorName: undefined,
84+
translatorOptions: {
85+
includeDeduped: true
86+
},
87+
frameworkOptions: {
88+
versionOverride: "1.2.3"
89+
}
90+
}]);
91+
});
92+
7793
// test.serial("Error: throws on error during processing", async (t) => {
7894
// normalizer.generateDependencyTree.rejects(new Error("Some error happened ..."));
7995
// const processExitStub = sinon.stub(process, "exit");

0 commit comments

Comments
 (0)