From 838ec29b05314ed86c1b1e80b07551b99838fe5c Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Mon, 9 Mar 2020 16:47:34 +0100 Subject: [PATCH 1/2] [FEATURE] Add --framework-version option --- lib/cli/commands/build.js | 16 ++++++++++++++-- lib/cli/commands/serve.js | 16 ++++++++++++++-- lib/cli/commands/tree.js | 17 +++++++++++++++++ test/lib/cli/commands/build.js | 6 ++++++ test/lib/cli/commands/serve.js | 23 +++++++++++++++++++++++ test/lib/cli/commands/tree.js | 16 ++++++++++++++++ 6 files changed, 90 insertions(+), 4 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index 8d0f2467..f2cd8649 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -59,6 +59,10 @@ build.builder = function(cli) { describe: "A list of specific tasks to be excluded from default/dev set", type: "array" }) + .option("framework-version", { + describe: "Overrides the framework version defined by the project", + type: "string" + }) .example("ui5 build --all", "Preload build for project and dependencies to \"./dist\"") .example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload", "Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks") @@ -78,10 +82,18 @@ async function handleBuild(argv) { const command = argv._[argv._.length - 1]; logger.setShowProgress(true); - const tree = await normalizer.generateProjectTree({ + const normalizerOptions = { translatorName: argv.translator, configPath: argv.config - }); + }; + + if (argv.frameworkVersion) { + normalizerOptions.frameworkOptions = { + versionOverride: argv.frameworkVersion + }; + } + + const tree = await normalizer.generateProjectTree(normalizerOptions); await builder.build({ tree: tree, destPath: argv.dest, diff --git a/lib/cli/commands/serve.js b/lib/cli/commands/serve.js index 91effd24..0ee730b8 100644 --- a/lib/cli/commands/serve.js +++ b/lib/cli/commands/serve.js @@ -50,6 +50,10 @@ serve.builder = function(cli) { default: false, type: "boolean" }) + .option("framework-version", { + describe: "Overrides the framework version defined by the project", + type: "string" + }) .example("ui5 serve", "Start a web server for the current project") .example("ui5 serve --h2", "Enable the HTTP/2 protocol for the web server (requires SSL certificate)") .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) { const ui5Server = require("@ui5/server"); const server = ui5Server.server; - const tree = await normalizer.generateProjectTree({ + const normalizerOptions = { translatorName: argv.translator, configPath: argv.config - }); + }; + + if (argv.frameworkVersion) { + normalizerOptions.frameworkOptions = { + versionOverride: argv.frameworkVersion + }; + } + + const tree = await normalizer.generateProjectTree(normalizerOptions); let port = argv.port; let changePortIfInUse = false; diff --git a/lib/cli/commands/tree.js b/lib/cli/commands/tree.js index a909bd45..4ee8030b 100644 --- a/lib/cli/commands/tree.js +++ b/lib/cli/commands/tree.js @@ -22,6 +22,16 @@ tree.builder = function(cli) { default: false, type: "boolean" }) + .option("framework-version", { + describe: "Overrides the framework version defined by the project. Only supported in combination with --full", + type: "string" + }).check((argv) => { + if (argv.frameworkVersion && !argv.full) { + throw new Error(`"framework-version" can only be used in combination with option "--full"`); + } else { + return true; + } + }) .example("ui5 tree > tree.txt", "Pipes the dependency tree into a new file \"tree.txt\"") .example("ui5 tree --json > tree.json", "Pipes the dependency tree into a new file \"tree.json\""); }; @@ -37,6 +47,13 @@ tree.handler = async function(argv) { }, configPath: argv.config }; + + if (argv.frameworkVersion ) { + options.frameworkOptions = { + versionOverride: argv.frameworkVersion + }; + } + let projectTree; if (argv.full) { projectTree = await normalizer.generateProjectTree(options); diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index fe0bfb92..a42aa503 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -100,3 +100,9 @@ test.serial("ui5 build jsdoc", async (t) => { "JSDoc build called with expected arguments" ); }); + +test.todo("ui5 build --framework-version"); +test.todo("ui5 build preload --framework-version"); +test.todo("ui5 build self-contained --framework-version"); +test.todo("ui5 build dev --framework-version"); +test.todo("ui5 build jsdoc --framework-version"); diff --git a/test/lib/cli/commands/serve.js b/test/lib/cli/commands/serve.js index 577110e2..dd891a8b 100644 --- a/test/lib/cli/commands/serve.js +++ b/test/lib/cli/commands/serve.js @@ -320,3 +320,26 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting and port CLI argument", a t.deepEqual(injectedServerConfig.port, 5555, "https port setting from CLI argument was used"); t.deepEqual(injectedServerConfig.changePortIfInUse, false, "changePortIfInUse is set to false"); }); + +test.serial("ui5 serve: --framework-version", async (t) => { + normalizerStub.resolves(projectTree); + serverStub.resolves({h2: false, port: 8080}); + + // loads project tree + const pPrepareServerConfig = await serve.handler( + Object.assign({}, defaultInitialHandlerArgs, {frameworkVersion: "1.2.3"}) + ); + // preprocess project config, skipping cert load + const pServeServer = await pPrepareServerConfig; + // serve server using config + await pServeServer; + + t.is(normalizerStub.called, true); + t.deepEqual(normalizerStub.getCall(0).args, [{ + configPath: undefined, + translatorName: "npm", + frameworkOptions: { + versionOverride: "1.2.3" + } + }]); +}); diff --git a/test/lib/cli/commands/tree.js b/test/lib/cli/commands/tree.js index a798303a..8ea7b216 100644 --- a/test/lib/cli/commands/tree.js +++ b/test/lib/cli/commands/tree.js @@ -74,6 +74,22 @@ test.serial("ui5 tree --dedupe=true", async (t) => { }), true, "includeDeduped passed as expected"); }); +test.serial("ui5 tree --full --framework-version", async (t) => { + normalizer.generateProjectTree.resolves({}); + await tree.handler({full: true, frameworkVersion: "1.2.3"}); + t.is(normalizer.generateProjectTree.called, true, "project tree output"); + t.deepEqual(normalizer.generateProjectTree.getCall(0).args, [{ + configPath: undefined, + translatorName: undefined, + translatorOptions: { + includeDeduped: true + }, + frameworkOptions: { + versionOverride: "1.2.3" + } + }]); +}); + // test.serial("Error: throws on error during processing", async (t) => { // normalizer.generateDependencyTree.rejects(new Error("Some error happened ...")); // const processExitStub = sinon.stub(process, "exit"); From 472013128591c5e023a554173953b2e016762b90 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Tue, 10 Mar 2020 18:22:50 +0100 Subject: [PATCH 2/2] [INTERNAL] Framework version parameter: Add build test --- test/lib/cli/commands/build.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index a42aa503..2b4fffb9 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -101,8 +101,25 @@ test.serial("ui5 build jsdoc", async (t) => { ); }); -test.todo("ui5 build --framework-version"); -test.todo("ui5 build preload --framework-version"); -test.todo("ui5 build self-contained --framework-version"); -test.todo("ui5 build dev --framework-version"); -test.todo("ui5 build jsdoc --framework-version"); +test.serial("ui5 build --framework-version 1.99", async (t) => { + normalizerStub.resolves({ + metadata: + { + name: "Sample" + } + }); + + args._ = ["build"]; + args.frameworkVersion = "1.99.0"; + await build.handler(args); + t.deepEqual( + normalizerStub.getCall(0).args[0], + { + configPath: undefined, + translatorName: "npm", + frameworkOptions: { + versionOverride: "1.99.0" + } + }, "generateProjectTree got called with expected arguments" + ); +});