Skip to content

Commit

Permalink
[FEATURE] Add option to redefine output directory structure (#665)
Browse files Browse the repository at this point in the history
New CLI `build` option `--output-style`. Whether to omit the
/resources/\<namespace\> directory structure in the build output.

Resolves SAP/ui5-tooling#507
Depends on: SAP/ui5-project#624
  • Loading branch information
d3xter666 authored Dec 12, 2023
1 parent 6c1390d commit 388dc79
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lib/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ build.builder = function(cli) {
default: false,
type: "boolean"
})
.option("output-style", {
describe:
"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"],
})
.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")
.example("ui5 build --exclude-task=* --include-task=minify generateComponentPreload",
Expand Down Expand Up @@ -176,7 +192,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"],
outputStyle: argv["output-style"],
});
}

Expand Down
24 changes: 24 additions & 0 deletions test/lib/cli/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
16 changes: 15 additions & 1 deletion test/lib/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function getDefaultArgv() {
"experimentalCssVariables": false,
"cache-mode": "Default",
"cacheMode": "Default",
"output-style": "Default",
"$0": "ui5"
};
}
Expand All @@ -50,7 +51,8 @@ function getDefaultBuilderArgs() {
jsdoc: false,
includedTasks: undefined,
excludedTasks: undefined,
cssVariables: false
cssVariables: false,
outputStyle: "Default"
};
}

Expand Down Expand Up @@ -364,3 +366,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 --output-style", async (t) => {
const {build, argv, builder, expectedBuilderArgs} = t.context;

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");
});

0 comments on commit 388dc79

Please sign in to comment.