@ui5/cli 3.0.7 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,25 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
4
 
5
- A list of unreleased changes can be found [here](https://github.com/SAP/ui5-cli/compare/v3.0.7...HEAD).
5
+ A list of unreleased changes can be found [here](https://github.com/SAP/ui5-cli/compare/v3.1.1...HEAD).
6
+
7
+ <a name="v3.1.1"></a>
8
+ ## [v3.1.1] - 2023-04-27
9
+ ### Dependency Updates
10
+ - Bump [@ui5](https://github.com/ui5)/project from 3.2.1 to 3.2.2 [`defb631`](https://github.com/SAP/ui5-cli/commit/defb6313fc651826876dd9713ee67fba72ced51c)
11
+
12
+
13
+ <a name="v3.1.0"></a>
14
+ ## [v3.1.0] - 2023-04-26
15
+ ### Dependency Updates
16
+ - Bump [@ui5](https://github.com/ui5)/project from 3.2.0 to 3.2.1 [`922fb09`](https://github.com/SAP/ui5-cli/commit/922fb09c9cb6b8f317b8bba55a9a13f152532c73)
17
+ - Bump [@ui5](https://github.com/ui5)/project from 3.1.1 to 3.2.0 [`4619e2f`](https://github.com/SAP/ui5-cli/commit/4619e2fc555987613920a4a30808534cbd70ab79)
18
+ - Bump [@ui5](https://github.com/ui5)/builder from 3.0.2 to 3.0.3 [`b5fbf4a`](https://github.com/SAP/ui5-cli/commit/b5fbf4adb094ab534d893d0f1e1f45226c52149b)
19
+ - Bump [@ui5](https://github.com/ui5)/fs from 3.0.2 to 3.0.3 [`c6fd1f8`](https://github.com/SAP/ui5-cli/commit/c6fd1f8c6c4c0d1419cb5820d6d37e173f528d1d)
20
+
21
+ ### Features
22
+ - Add config command ([#618](https://github.com/SAP/ui5-cli/issues/618)) [`9910e30`](https://github.com/SAP/ui5-cli/commit/9910e304b80ca262587e99ab9a6118a4db15c584)
23
+
6
24
 
7
25
  <a name="v3.0.7"></a>
8
26
  ## [v3.0.7] - 2023-04-12
@@ -1007,6 +1025,8 @@ Only Node.js v10 or higher is supported.
1007
1025
 
1008
1026
  <a name="v0.0.1"></a>
1009
1027
  ## v0.0.1 - 2018-06-06
1028
+ [v3.1.1]: https://github.com/SAP/ui5-cli/compare/v3.1.0...v3.1.1
1029
+ [v3.1.0]: https://github.com/SAP/ui5-cli/compare/v3.0.7...v3.1.0
1010
1030
  [v3.0.7]: https://github.com/SAP/ui5-cli/compare/v3.0.6...v3.0.7
1011
1031
  [v3.0.6]: https://github.com/SAP/ui5-cli/compare/v3.0.5...v3.0.6
1012
1032
  [v3.0.5]: https://github.com/SAP/ui5-cli/compare/v3.0.4...v3.0.5
package/lib/cli/base.js CHANGED
@@ -4,7 +4,7 @@ import ConsoleWriter from "@ui5/logger/writers/Console";
4
4
 
5
5
  export default function(cli) {
6
6
  cli.usage("Usage: ui5 <command> [options]")
7
- .demandCommand(1, "Command required! Please have a look at the help documentation above.")
7
+ .demandCommand(1, "Command required")
8
8
  .option("config", {
9
9
  alias: "c",
10
10
  describe: "Path to project configuration file in YAML format",
@@ -121,7 +121,7 @@ export default function(cli) {
121
121
  console.log(chalk.bold.yellow("Command Failed:"));
122
122
  console.log(`${msg}`);
123
123
  console.log("");
124
- console.log(chalk.dim(`See 'ui5 --help' or 'ui5 build --help' for help`));
124
+ console.log(chalk.dim(`See 'ui5 --help'`));
125
125
  }
126
126
  process.exit(1);
127
127
  });
@@ -0,0 +1,88 @@
1
+ import chalk from "chalk";
2
+ import process from "node:process";
3
+ import baseMiddleware from "../middlewares/base.js";
4
+
5
+ const configCommand = {
6
+ command: "config",
7
+ describe: "Get and set UI5 Tooling configuration options",
8
+ middlewares: [baseMiddleware],
9
+ handler: handleConfig
10
+ };
11
+
12
+ configCommand.builder = function(cli) {
13
+ return cli
14
+ .demandCommand(1, "Command required. Available commands are 'set', 'get', and 'list'")
15
+ .command("set <key> [value]", "Set the value for a given configuration key. " +
16
+ "Clear an existing configuration by omitting the value", {
17
+ handler: handleConfig,
18
+ builder: noop,
19
+ middlewares: [baseMiddleware],
20
+ })
21
+ .command("get <key>", "Get the value for a given configuration key", {
22
+ handler: handleConfig,
23
+ builder: noop,
24
+ middlewares: [baseMiddleware],
25
+ })
26
+ .command("list", "Display the current configuration", {
27
+ handler: handleConfig,
28
+ builder: noop,
29
+ middlewares: [baseMiddleware],
30
+ })
31
+ .example("$0 set mavenSnapshotEndpointUrl http://example.com/snapshots/",
32
+ "Set a value for the mavenSnapshotEndpointUrl configuration")
33
+ .example("$0 set mavenSnapshotEndpointUrl",
34
+ "Unset the current value of the mavenSnapshotEndpointUrl configuration");
35
+ };
36
+
37
+ function noop() {}
38
+
39
+ async function handleConfig(argv) {
40
+ const {_: commandArgs, key, value} = argv;
41
+ const command = commandArgs[commandArgs.length - 1];
42
+
43
+ const {default: Configuration} = await import( "@ui5/project/config/Configuration");
44
+ const allowedKeys = ["mavenSnapshotEndpointUrl"];
45
+
46
+ if (["set", "get"].includes(command) && !allowedKeys.includes(key)) {
47
+ throw new Error(
48
+ `The provided key is not a valid configuration option. Valid options are: ${allowedKeys.join(", ")}`);
49
+ }
50
+
51
+ const config = await Configuration.fromFile();
52
+ if (command === "list") {
53
+ // Print all configuration values to stdout
54
+ process.stdout.write(formatJsonForOutput(config.toJson()));
55
+ } else if (command === "get") {
56
+ // Get a single configuration value and print to stdout
57
+ let configValue = config.toJson()[key];
58
+ if (configValue === undefined) {
59
+ configValue = "";
60
+ }
61
+ process.stdout.write(`${configValue}\n`);
62
+ } else if (command === "set") {
63
+ const jsonConfig = config.toJson();
64
+ if (value === undefined || value === "") {
65
+ delete jsonConfig[key];
66
+ process.stderr.write(`Configuration option ${chalk.bold(key)} has been unset\n`);
67
+ } else {
68
+ jsonConfig[key] = value;
69
+ process.stderr.write(`Configuration option ${chalk.bold(key)} has been updated:
70
+ ${formatJsonForOutput(jsonConfig, key)}`);
71
+ }
72
+
73
+ await Configuration.toFile(new Configuration(jsonConfig));
74
+ } else {
75
+ throw new Error(`Unknown 'ui5 config' command '${command}'`);
76
+ }
77
+ }
78
+
79
+ function formatJsonForOutput(config, filterKey) {
80
+ return Object.keys(config)
81
+ .filter((key) => !filterKey || filterKey === key)
82
+ .filter((key) => config[key] !== undefined) // Don't print undefined config values
83
+ .map((key) => {
84
+ return ` ${key} = ${config[key]}\n`;
85
+ }).join("");
86
+ }
87
+
88
+ export default configCommand;
@@ -17,24 +17,27 @@ export default async function({projectGraphOptions, libraries}) {
17
17
  );
18
18
  }
19
19
 
20
- if (!project.getFrameworkName()) {
20
+ const frameworkName = project.getFrameworkName();
21
+ const frameworkVersion = project.getFrameworkVersion();
22
+
23
+ if (!frameworkName) {
21
24
  throw new Error(
22
25
  `Project ${project.getName()} is missing a framework configuration. ` +
23
26
  `Please use "ui5 use" to configure a framework and version.`
24
27
  );
25
28
  }
26
- if (!project.getFrameworkVersion()) {
29
+ if (!frameworkVersion) {
27
30
  throw new Error(
28
31
  `Project ${project.getName()} does not define a framework version configuration. ` +
29
32
  `Please use "ui5 use" to configure a version.`
30
33
  );
31
34
  }
32
35
 
33
- const Resolver = getFrameworkResolver(project.getFrameworkName());
36
+ const Resolver = await getFrameworkResolver(frameworkName, frameworkVersion);
34
37
 
35
38
  const resolver = new Resolver({
36
39
  cwd: project.getRootPath(),
37
- version: project.getFrameworkVersion()
40
+ version: frameworkVersion
38
41
  });
39
42
 
40
43
  // Get metadata of all libraries to verify that they can be installed
@@ -42,7 +45,7 @@ export default async function({projectGraphOptions, libraries}) {
42
45
  try {
43
46
  await resolver.getLibraryMetadata(name);
44
47
  } catch (err) {
45
- throw new Error(`Failed to find ${project.getFrameworkName()} framework library ${name}: ` + err.message);
48
+ throw new Error(`Failed to find ${frameworkName} framework library ${name}: ` + err.message);
46
49
  }
47
50
  }));
48
51
 
@@ -1,7 +1,8 @@
1
1
  import {getRootProjectConfiguration, getFrameworkResolver} from "./utils.js";
2
2
 
3
3
  async function resolveVersion({frameworkName, frameworkVersion}, resolverOptions) {
4
- return await getFrameworkResolver(frameworkName).resolveVersion(frameworkVersion, resolverOptions);
4
+ const Resolver = await getFrameworkResolver(frameworkName, frameworkVersion);
5
+ return Resolver.resolveVersion(frameworkVersion, resolverOptions);
5
6
  }
6
7
 
7
8
  function getEffectiveFrameworkName({project, frameworkOptions}) {
@@ -1,6 +1,4 @@
1
1
  import {graphFromStaticFile, graphFromPackageDependencies} from "@ui5/project/graph";
2
- import Sapui5Resolver from "@ui5/project/ui5Framework/Sapui5Resolver";
3
- import Openui5Resolver from "@ui5/project/ui5Framework/Openui5Resolver";
4
2
 
5
3
  export async function getRootProjectConfiguration(projectGraphOptions) {
6
4
  let graph;
@@ -19,11 +17,14 @@ export async function getRootProjectConfiguration(projectGraphOptions) {
19
17
  return graph.getRoot();
20
18
  }
21
19
 
22
- export function getFrameworkResolver(frameworkName) {
23
- if (frameworkName === "SAPUI5") {
24
- return Sapui5Resolver;
20
+ export async function getFrameworkResolver(frameworkName, frameworkVersion) {
21
+ if (frameworkVersion.toLowerCase().endsWith("-snapshot")) {
22
+ // Framework version could be for example: "latest-snapshot" or "1.112.0-SNAPSHOT"
23
+ return (await import("@ui5/project/ui5Framework/Sapui5MavenSnapshotResolver")).default;
25
24
  } else if (frameworkName === "OpenUI5") {
26
- return Openui5Resolver;
25
+ return (await import("@ui5/project/ui5Framework/Openui5Resolver")).default;
26
+ } else if (frameworkName === "SAPUI5") {
27
+ return (await import("@ui5/project/ui5Framework/Sapui5Resolver")).default;
27
28
  } else {
28
29
  throw new Error("Invalid framework.name: " + frameworkName);
29
30
  }