Skip to content

Commit

Permalink
[INTERNAL] SETTINGS -> OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Aug 17, 2023
1 parent 9b15b33 commit 2317826
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions lib/config/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "node:path";
import os from "node:os";

/**
* Provides basic configuration settings for @ui5/project/ui5Framework/* resolvers.
* Provides basic configuration for @ui5/project.
* Reads/writes configuration from/to ~/.ui5rc
*
* @public
Expand All @@ -11,32 +11,33 @@ import os from "node:os";
*/
class Configuration {
/**
* A list of all configuration settings.
* A list of all configuration options.
*
* @public
* @static
*/
static SETTINGS = [
static OPTIONS = [
"mavenSnapshotEndpointUrl",
"ui5DataDir"
];

#settings = new Map();
#options = new Map();

/**
* @param {object} configuration
* @param {string} [configuration.mavenSnapshotEndpointUrl]
* @param {string} [configuration.ui5DataDir]
*/
constructor(configuration) {
// Initialize map with undefined values for every setting
Configuration.SETTINGS.forEach((key) => this.#settings.set(key, undefined));
// Initialize map with undefined values for every option so that they are
// returned via toJson()
Configuration.OPTIONS.forEach((key) => this.#options.set(key, undefined));

Object.entries(configuration).forEach(([key, value]) => {
if (!Configuration.SETTINGS.includes(key)) {
throw new Error(`Unknown configuration setting '${key}'`);
if (!Configuration.OPTIONS.includes(key)) {
throw new Error(`Unknown configuration option '${key}'`);
}
this.#settings.set(key, value);
this.#options.set(key, value);
});
}

Expand All @@ -48,7 +49,7 @@ class Configuration {
* @returns {string}
*/
getMavenSnapshotEndpointUrl() {
return this.#settings.get("mavenSnapshotEndpointUrl");
return this.#options.get("mavenSnapshotEndpointUrl");
}

/**
Expand All @@ -58,15 +59,15 @@ class Configuration {
* @returns {string}
*/
getUi5DataDir() {
return this.#settings.get("ui5DataDir");
return this.#options.get("ui5DataDir");
}

/**
* @public
* @returns {object} The configuration in a JSON format
*/
toJson() {
return Object.fromEntries(this.#settings);
return Object.fromEntries(this.#options);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/lib/config/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ test.afterEach.always((t) => {
esmock.purge(t.context.Configuration);
});

test.serial("Available configuration settings", (t) => {
test.serial("Configuration options", (t) => {
const {Configuration} = t.context;
t.deepEqual(Configuration.SETTINGS, [
t.deepEqual(Configuration.OPTIONS, [
"mavenSnapshotEndpointUrl",
"ui5DataDir"
]);
Expand Down

0 comments on commit 2317826

Please sign in to comment.