From fa5f18d768da9ff796d2fd2977a196240d181a55 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 28 Nov 2023 15:16:10 +0200 Subject: [PATCH 01/12] Enable --flat-output build option --- lib/cli/commands/build.js | 12 +++++++++++- test/lib/cli/commands/build.js | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index b34c51db..64c682d3 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -121,6 +121,15 @@ build.builder = function(cli) { default: false, type: "boolean" }) + .option("flat-output", { + describe: + "Write the build results into a flat directory structure, omitting the project" + + "namespace and the \"resources\" directory." + + "This is currently only supported for projects of type 'library'." + + "No other dependencies can be included in the build result." + + "Projects of type 'application' always result in flat output.", + type: "boolean" + }) .example("ui5 build", "Preload build for project without dependencies") .example("ui5 build self-contained", "Self-contained build for project") .example("ui5 build --exclude-task=* --include-task=minify generateComponentPreload", @@ -176,7 +185,8 @@ async function handleBuild(argv) { jsdoc: command === "jsdoc", includedTasks: argv["include-task"], excludedTasks: argv["exclude-task"], - cssVariables: argv["experimental-css-variables"] + cssVariables: argv["experimental-css-variables"], + flatOutput: argv["flat-output"], }); } diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index 3e0e0ca3..3950b6f4 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -364,3 +364,15 @@ test.serial("ui5 build --experimental-css-variables", async (t) => { t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, "Build with activated CSS Variables is called with expected arguments"); }); + +test.serial("ui5 build --flat-output", async (t) => { + const {build, argv, builder, expectedBuilderArgs} = t.context; + + argv["flat-output"] = true; + + await build.handler(argv); + + expectedBuilderArgs.flatOutput = true; + t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, + "Build with activated flatOutput is called with expected arguments"); +}); From 11c5fe46e7cea2f9e84c3b9525cd2f9da9a0584d Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 28 Nov 2023 15:18:38 +0200 Subject: [PATCH 02/12] Fix tests --- test/lib/cli/commands/build.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index 3950b6f4..751a0097 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -50,7 +50,8 @@ function getDefaultBuilderArgs() { jsdoc: false, includedTasks: undefined, excludedTasks: undefined, - cssVariables: false + cssVariables: false, + flatOutput: undefined }; } From 567160cb3795777e75d7fc509d272c5aea53b2c1 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 30 Nov 2023 10:34:41 +0200 Subject: [PATCH 03/12] Adjust docs --- lib/cli/commands/build.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index 64c682d3..8a4cd4ad 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -125,9 +125,11 @@ build.builder = function(cli) { describe: "Write the build results into a flat directory structure, omitting the project" + "namespace and the \"resources\" directory." + - "This is currently only supported for projects of type 'library'." + - "No other dependencies can be included in the build result." + - "Projects of type 'application' always result in flat output.", + "This is currently only supported for projects of type 'library' and projects of " + + "type 'application' always result in flat output." + + "No other dependencies can be included in the build result.", + // We need to explicitly check wether the falsy value is explicit or not for project type "application" + // default: false, type: "boolean" }) .example("ui5 build", "Preload build for project without dependencies") From 1dd7a9ed88ec89e60041a0046c255830d2b9b420 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 30 Nov 2023 13:43:15 +0200 Subject: [PATCH 04/12] Migrate from boolean flag to enum --- lib/cli/commands/build.js | 18 +++++++++--------- test/lib/cli/commands/build.js | 9 +++++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index 8a4cd4ad..b5c98fa5 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -121,16 +121,16 @@ build.builder = function(cli) { default: false, type: "boolean" }) - .option("flat-output", { + .option("output-style", { describe: - "Write the build results into a flat directory structure, omitting the project" + - "namespace and the \"resources\" directory." + - "This is currently only supported for projects of type 'library' and projects of " + - "type 'application' always result in flat output." + + "The way build results into a specific directory structure. " + + "\"Flat\" omits the project namespace and the \"resources\" directory. This is" + + " currently only supported for projects of type 'library'. Projects of " + + "type 'application' always have a default result as a flat output." + "No other dependencies can be included in the build result.", - // We need to explicitly check wether the falsy value is explicit or not for project type "application" - // default: false, - type: "boolean" + type: "string", + default: "Default", + choices: ["Default", "Flat", "Namespace"], }) .example("ui5 build", "Preload build for project without dependencies") .example("ui5 build self-contained", "Self-contained build for project") @@ -188,7 +188,7 @@ async function handleBuild(argv) { includedTasks: argv["include-task"], excludedTasks: argv["exclude-task"], cssVariables: argv["experimental-css-variables"], - flatOutput: argv["flat-output"], + outputStyle: argv["output-style"], }); } diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index 751a0097..068bae81 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -25,6 +25,7 @@ function getDefaultArgv() { "experimentalCssVariables": false, "cache-mode": "Default", "cacheMode": "Default", + "output-style": "Default", "$0": "ui5" }; } @@ -51,7 +52,7 @@ function getDefaultBuilderArgs() { includedTasks: undefined, excludedTasks: undefined, cssVariables: false, - flatOutput: undefined + outputStyle: "Default" }; } @@ -366,14 +367,14 @@ test.serial("ui5 build --experimental-css-variables", async (t) => { "Build with activated CSS Variables is called with expected arguments"); }); -test.serial("ui5 build --flat-output", async (t) => { +test.serial("ui5 build --output-style", async (t) => { const {build, argv, builder, expectedBuilderArgs} = t.context; - argv["flat-output"] = true; + argv["output-style"] = "Flat"; await build.handler(argv); - expectedBuilderArgs.flatOutput = true; + expectedBuilderArgs.outputStyle = "Flat"; t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, "Build with activated flatOutput is called with expected arguments"); }); From 5d316e39c757f68acb36c0375c1747a60eb4af27 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 30 Nov 2023 13:45:59 +0200 Subject: [PATCH 05/12] Rewrite description --- lib/cli/commands/build.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index b5c98fa5..8c02eafb 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -123,10 +123,10 @@ build.builder = function(cli) { }) .option("output-style", { describe: - "The way build results into a specific directory structure. " + + "Processes build results into a specific directory structure. " + "\"Flat\" omits the project namespace and the \"resources\" directory. This is" + " currently only supported for projects of type 'library'. Projects of " + - "type 'application' always have a default result as a flat output." + + "type 'application' always result in a flat output." + "No other dependencies can be included in the build result.", type: "string", default: "Default", From 2777fa16e94cc5567e59e161a2918a8e22684ea4 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 30 Nov 2023 14:15:06 +0200 Subject: [PATCH 06/12] Update test description --- test/lib/cli/commands/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index 068bae81..ac36226c 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -376,5 +376,5 @@ test.serial("ui5 build --output-style", async (t) => { expectedBuilderArgs.outputStyle = "Flat"; t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, - "Build with activated flatOutput is called with expected arguments"); + "Build with activated outputStyle='Flat' is called with expected arguments"); }); From dcbcbcbcaefa6b9072f75fc8e104bacc76fb2057 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 5 Dec 2023 14:23:30 +0200 Subject: [PATCH 07/12] Choices for --output-style in small caps --- lib/cli/commands/build.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index 8c02eafb..deefe0c9 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -129,8 +129,8 @@ build.builder = function(cli) { "type 'application' always result in a flat output." + "No other dependencies can be included in the build result.", type: "string", - default: "Default", - choices: ["Default", "Flat", "Namespace"], + default: "default", + choices: ["default", "flat", "namespace"], }) .example("ui5 build", "Preload build for project without dependencies") .example("ui5 build self-contained", "Self-contained build for project") @@ -188,7 +188,7 @@ async function handleBuild(argv) { includedTasks: argv["include-task"], excludedTasks: argv["exclude-task"], cssVariables: argv["experimental-css-variables"], - outputStyle: argv["output-style"], + outputStyle: (argv["output-style"].charAt(0).toUpperCase() + argv["output-style"].slice(1)), }); } From 1374846894c74ab66e3186633ad8e4a901740a0d Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 5 Dec 2023 14:25:28 +0200 Subject: [PATCH 08/12] Fix tests --- test/lib/cli/commands/build.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index ac36226c..3b711f85 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -25,7 +25,7 @@ function getDefaultArgv() { "experimentalCssVariables": false, "cache-mode": "Default", "cacheMode": "Default", - "output-style": "Default", + "output-style": "default", "$0": "ui5" }; } @@ -370,11 +370,11 @@ test.serial("ui5 build --experimental-css-variables", async (t) => { test.serial("ui5 build --output-style", async (t) => { const {build, argv, builder, expectedBuilderArgs} = t.context; - argv["output-style"] = "Flat"; + argv["output-style"] = "flat"; await build.handler(argv); - expectedBuilderArgs.outputStyle = "Flat"; + expectedBuilderArgs.outputStyle = "flat"; t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, - "Build with activated outputStyle='Flat' is called with expected arguments"); + "Build with activated outputStyle='flat' is called with expected arguments"); }); From 187e0d078b0ba71ee79570399d84a95e108e808e Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 5 Dec 2023 14:28:57 +0200 Subject: [PATCH 09/12] Fix tests --- test/lib/cli/commands/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index 3b711f85..a31102ff 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -374,7 +374,7 @@ test.serial("ui5 build --output-style", async (t) => { await build.handler(argv); - expectedBuilderArgs.outputStyle = "flat"; + expectedBuilderArgs.outputStyle = "Flat"; t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, "Build with activated outputStyle='flat' is called with expected arguments"); }); From b677c954dc2734c0eb2a5feac548c396919eb8a9 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Wed, 6 Dec 2023 14:52:02 +0200 Subject: [PATCH 10/12] Ignore case for output-style CLI params --- lib/cli/commands/build.js | 9 ++++++--- test/lib/cli/commands/build.js | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index deefe0c9..ac9c1e66 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -129,8 +129,11 @@ build.builder = function(cli) { "type 'application' always result in a flat output." + "No other dependencies can be included in the build result.", type: "string", - default: "default", - choices: ["default", "flat", "namespace"], + default: "Default", + choices: ["Default", "Flat", "Namespace"], + }) + .coerce("output-style", (opt) => { + return opt.charAt(0).toUpperCase() + opt.slice(1).toLowerCase(); }) .example("ui5 build", "Preload build for project without dependencies") .example("ui5 build self-contained", "Self-contained build for project") @@ -188,7 +191,7 @@ async function handleBuild(argv) { includedTasks: argv["include-task"], excludedTasks: argv["exclude-task"], cssVariables: argv["experimental-css-variables"], - outputStyle: (argv["output-style"].charAt(0).toUpperCase() + argv["output-style"].slice(1)), + outputStyle: argv["output-style"], }); } diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index a31102ff..ac36226c 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -25,7 +25,7 @@ function getDefaultArgv() { "experimentalCssVariables": false, "cache-mode": "Default", "cacheMode": "Default", - "output-style": "default", + "output-style": "Default", "$0": "ui5" }; } @@ -370,11 +370,11 @@ test.serial("ui5 build --experimental-css-variables", async (t) => { test.serial("ui5 build --output-style", async (t) => { const {build, argv, builder, expectedBuilderArgs} = t.context; - argv["output-style"] = "flat"; + argv["output-style"] = "Flat"; await build.handler(argv); expectedBuilderArgs.outputStyle = "Flat"; t.deepEqual(builder.getCall(0).args[0], expectedBuilderArgs, - "Build with activated outputStyle='flat' is called with expected arguments"); + "Build with activated outputStyle='Flat' is called with expected arguments"); }); From 318b2a78242e83d5a1347a54b65c380848921403 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 12 Dec 2023 11:28:45 +0200 Subject: [PATCH 11/12] Adjust CLI description for the output style --- lib/cli/commands/build.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index ac9c1e66..3dec442d 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -123,11 +123,13 @@ build.builder = function(cli) { }) .option("output-style", { describe: - "Processes build results into a specific directory structure. " + - "\"Flat\" omits the project namespace and the \"resources\" directory. This is" + - " currently only supported for projects of type 'library'. Projects of " + - "type 'application' always result in a flat output." + - "No other dependencies can be included in the build result.", + "Processes build results into a specific directory structure. \r\n\r\n" + + "- Flat: Omits the project namespace and the \"resources\" directory.\r\n" + + "- Namespace: Respects the project namespace and the \"resources\" directory, " + + "maintaining the original structure.\r\n" + + "- Default: The default directory structure for every project type. For applications, " + + "this is identical to \"Flat\", and for libraries, it is \"Namespace\". Other types have a " + + "more distinct default output style.", type: "string", default: "Default", choices: ["Default", "Flat", "Namespace"], From eb45644b14203f4b9a2faa272cded4584a80e669 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 12 Dec 2023 14:07:12 +0200 Subject: [PATCH 12/12] Add tests for output-style coercion --- test/lib/cli/base.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/lib/cli/base.js b/test/lib/cli/base.js index ae0d0650..9f924adc 100644 --- a/test/lib/cli/base.js +++ b/test/lib/cli/base.js @@ -281,3 +281,27 @@ test.serial("ui5 --no-update-notifier", async (t) => { t.regex(stdout, /@ui5\/cli:/, "Output includes version information"); t.false(failed, "Command should not fail"); }); + +test.serial("ui5 --output-style", async (t) => { + await t.throwsAsync(ui5(["build", "--output-style", "nonExistent"]), { + message: /Argument: output-style, Given: "Nonexistent", Choices: "Default", "Flat", "Namespace"/s + }, "Coercion correctly capitalizes the first letter and makes the rest lowercase"); + + + // "--output-style" uses a coerce to transform the input into the correct letter case. + // It is hard/unmaintainable to spy on internal implementation, so we check the output. + // The coerce goes before the real ui5 build, so we just need to check whether + // an invalid "--output-style" choice exception is not thrown. + // Of course, the build would throw another exception, because there's nothing actually to build. + await t.throwsAsync(ui5(["build", "--output-style", "flat"]), { + message: /^((?!Argument: output-style, Given: "Flat).)*$/s + }, "Does not throw an exception because of the --output-style input"); + + await t.throwsAsync(ui5(["build", "--output-style", "nAmEsPaCe"]), { + message: /^((?!Argument: output-style, Given: "Namespace).)*$/s + }, "Does not throw an exception because of the --output-style input"); + + await t.throwsAsync(ui5(["build", "--output-style", "Default"]), { + message: /^((?!Argument: output-style, Given: "Default).)*$/s + }, "Does not throw an exception because of the --output-style input"); +});