@scaleway/configuration-loader 1.0.12 → 2.2.0

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.
@@ -1,23 +1,19 @@
1
1
 
2
- > @scaleway/configuration-loader@1.0.11 build /home/runner/work/scaleway-sdk-js/scaleway-sdk-js/packages/configuration-loader
2
+ > @scaleway/configuration-loader@2.1.0 build /home/runner/work/scaleway-sdk-js/scaleway-sdk-js/packages/configuration-loader
3
3
  > vite build --config ../../vite.config.ts && pnpm run type:generate
4
4
 
5
- vite v6.4.1 building SSR bundle for production...
6
- transforming...
7
- ✓ 5 modules transformed.
5
+ vite v8.0.0-beta.16 building ssr environment for production...
6
+ 
8
7
  rendering chunks...
9
- dist/index.js 0.27 kB
10
- dist/env.js 0.62 kB
11
- dist/path-resolver.js 0.75 kB
12
- dist/yml-loader.js 1.26 kB
13
- dist/config-loader.js 1.93 kB
14
- dist/index.cjs 0.42 kB
15
- dist/env.cjs 0.72 kB
16
- dist/yml-loader.cjs 1.40 kB
17
- dist/path-resolver.cjs 1.47 kB
18
- dist/config-loader.cjs 2.20 kB
19
- ✓ built in 121ms
8
+ computing gzip size...
9
+ dist/index.js 0.26 kB │ gzip: 0.12 kB
10
+ dist/path-resolver.js 0.89 kB │ gzip: 0.38 kB
11
+ dist/env.js 0.90 kB │ gzip: 0.38 kB
12
+ dist/yml-loader.js 1.40 kB │ gzip: 0.64 kB
13
+ dist/config-loader.js 2.56 kB │ gzip: 0.81 kB
20
14
 
21
- > @scaleway/configuration-loader@1.0.11 type:generate /home/runner/work/scaleway-sdk-js/scaleway-sdk-js/packages/configuration-loader
15
+ ✓ built in 28ms
16
+
17
+ > @scaleway/configuration-loader@2.1.0 type:generate /home/runner/work/scaleway-sdk-js/scaleway-sdk-js/packages/configuration-loader
22
18
  > tsc --declaration -p tsconfig.build.json
23
19
 
package/CHANGELOG.md CHANGED
@@ -3,6 +3,32 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 2.2.0 (2026-03-05)
7
+
8
+ ### Features
9
+
10
+ - **sdk-react:** add react sdk ([#2794](https://github.com/scaleway/scaleway-sdk-js/issues/2794)) ([7dfbf6b](https://github.com/scaleway/scaleway-sdk-js/commit/7dfbf6b4d4eae5f95cd05ff7433e30c522619475))
11
+
12
+ # 2.1.0 (2025-12-19)
13
+
14
+ ### Bug Fixes
15
+
16
+ - exclude generated config files from biome formatting ([#2661](https://github.com/scaleway/scaleway-sdk-js/issues/2661)) ([e6b1391](https://github.com/scaleway/scaleway-sdk-js/commit/e6b1391483b1ff41d3fcbcb40a89a7f46e934663))
17
+
18
+ ### Features
19
+
20
+ - publish packages as ESM only ([#2624](https://github.com/scaleway/scaleway-sdk-js/issues/2624)) ([8ab940d](https://github.com/scaleway/scaleway-sdk-js/commit/8ab940deadfbc8fc0d540148c51868dae63a74af))
21
+
22
+ ## 2.0.0 (2025-01-XX)
23
+
24
+ ### âš  BREAKING CHANGES
25
+
26
+ - packages are ESM only
27
+
28
+ ### :gear: Features
29
+
30
+ - publish packages as ESM only
31
+
6
32
  ## 1.0.12 (2025-10-29)
7
33
 
8
34
  **Note:** Version bump only for package @scaleway/configuration-loader
package/biome.jsonc ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "../../node_modules/@biomejs/biome/configuration_schema.json",
3
+ "assist": {
4
+ "actions": {
5
+ "source": {
6
+ "organizeImports": "on"
7
+ }
8
+ },
9
+ "enabled": true
10
+ },
11
+ "extends": "//",
12
+ "root": false
13
+ }
@@ -1,52 +1,68 @@
1
- import { env } from "process";
2
1
  import { EnvironmentKey } from "./env.js";
3
2
  import { resolveConfigurationFilePath } from "./path-resolver.js";
4
3
  import { loadConfigurationFromFile } from "./yml-loader.js";
5
- const convertFileConfigToSDK = (obj) => ({
6
- accessKey: obj.access_key,
7
- apiURL: obj.api_url,
8
- defaultOrganizationId: obj.default_organization_id,
9
- defaultProjectId: obj.default_project_id,
10
- defaultRegion: obj.default_region,
11
- defaultZone: obj.default_zone,
12
- secretKey: obj.secret_key
4
+ import { env } from "node:process";
5
+ var convertFileConfigToSDK = (obj) => ({
6
+ accessKey: obj.access_key,
7
+ apiURL: obj.api_url,
8
+ defaultOrganizationId: obj.default_organization_id,
9
+ defaultProjectId: obj.default_project_id,
10
+ defaultRegion: obj.default_region,
11
+ defaultZone: obj.default_zone,
12
+ secretKey: obj.secret_key
13
13
  });
14
+ /**
15
+ * Loads profile from environment values.
16
+ *
17
+ * @returns The profile filled with values found in the environment
18
+ *
19
+ * @public
20
+ */
14
21
  const loadProfileFromEnvironmentValues = () => ({
15
- accessKey: env[EnvironmentKey.ScwAccessKey],
16
- apiURL: env[EnvironmentKey.ScwAPIURL],
17
- defaultOrganizationId: env[EnvironmentKey.ScwDefaultOrganizationId],
18
- defaultProjectId: env[EnvironmentKey.ScwDefaultProjectId],
19
- defaultRegion: env[EnvironmentKey.ScwDefaultRegion],
20
- defaultZone: env[EnvironmentKey.ScwDefaultZone],
21
- secretKey: env[EnvironmentKey.ScwSecretKey]
22
+ accessKey: env[EnvironmentKey.ScwAccessKey],
23
+ apiURL: env[EnvironmentKey.ScwAPIURL],
24
+ defaultOrganizationId: env[EnvironmentKey.ScwDefaultOrganizationId],
25
+ defaultProjectId: env[EnvironmentKey.ScwDefaultProjectId],
26
+ defaultRegion: env[EnvironmentKey.ScwDefaultRegion],
27
+ defaultZone: env[EnvironmentKey.ScwDefaultZone],
28
+ secretKey: env[EnvironmentKey.ScwSecretKey]
22
29
  });
30
+ /**
31
+ * Loads all the profiles from configuration file.
32
+ *
33
+ * @param params - The parameters to load the profile
34
+ * @returns The profiles filled with values found in the configuration profile
35
+ *
36
+ * @throws Error
37
+ * Thrown if the configuration file couldn't be found.
38
+ *
39
+ * @public
40
+ */
23
41
  const loadAllProfilesFromConfigurationFile = (params) => {
24
- const filePath = params?.filepath ?? resolveConfigurationFilePath();
25
- if (typeof filePath !== "string" || filePath.length === 0) {
26
- throw new Error("Could not find the path to the configuration file.");
27
- }
28
- const configs = loadConfigurationFromFile(filePath);
29
- return Object.keys(configs).reduce(
30
- (prev, pKey) => ({
31
- ...prev,
32
- [pKey]: convertFileConfigToSDK(configs[pKey])
33
- }),
34
- {}
35
- );
42
+ const filePath = params?.filepath ?? resolveConfigurationFilePath();
43
+ if (typeof filePath !== "string" || filePath.length === 0) throw new Error("Could not find the path to the configuration file.");
44
+ const configs = loadConfigurationFromFile(filePath);
45
+ const result = {};
46
+ for (const pKey of Object.keys(configs)) result[pKey] = convertFileConfigToSDK(configs[pKey]);
47
+ return result;
36
48
  };
49
+ /**
50
+ * Loads profile from configuration file.
51
+ *
52
+ * @param params - The parameters to load the profile
53
+ * @returns The profile filled with values found in the configuration profile
54
+ *
55
+ * @throws Error
56
+ * Thrown if the configuration file couldn't be found,
57
+ * or if the specified profile can't be found.
58
+ *
59
+ * @public
60
+ */
37
61
  const loadProfileFromConfigurationFile = (params) => {
38
- const configs = loadAllProfilesFromConfigurationFile(params);
39
- const profileName = params?.profileName ?? "default";
40
- const profileMap = configs[profileName];
41
- if (typeof profileMap !== "object") {
42
- throw new Error(
43
- `Could not find the desired profile '${profileName}' in the configuration file.`
44
- );
45
- }
46
- return profileMap;
47
- };
48
- export {
49
- loadAllProfilesFromConfigurationFile,
50
- loadProfileFromConfigurationFile,
51
- loadProfileFromEnvironmentValues
62
+ const configs = loadAllProfilesFromConfigurationFile(params);
63
+ const profileName = params?.profileName ?? "default";
64
+ const profileMap = configs[profileName];
65
+ if (typeof profileMap !== "object") throw new Error(`Could not find the desired profile '${profileName}' in the configuration file.`);
66
+ return profileMap;
52
67
  };
68
+ export { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
package/dist/env.js CHANGED
@@ -1,14 +1,26 @@
1
- var EnvironmentKey = /* @__PURE__ */ ((EnvironmentKey2) => {
2
- EnvironmentKey2["ScwConfigPath"] = "SCW_CONFIG_PATH";
3
- EnvironmentKey2["ScwAccessKey"] = "SCW_ACCESS_KEY";
4
- EnvironmentKey2["ScwSecretKey"] = "SCW_SECRET_KEY";
5
- EnvironmentKey2["ScwAPIURL"] = "SCW_API_URL";
6
- EnvironmentKey2["ScwDefaultOrganizationId"] = "SCW_DEFAULT_ORGANIZATION_ID";
7
- EnvironmentKey2["ScwDefaultProjectId"] = "SCW_DEFAULT_PROJECT_ID";
8
- EnvironmentKey2["ScwDefaultRegion"] = "SCW_DEFAULT_REGION";
9
- EnvironmentKey2["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
10
- return EnvironmentKey2;
11
- })(EnvironmentKey || {});
12
- export {
13
- EnvironmentKey
14
- };
1
+ /**
2
+ * Environment Key.
3
+ */
4
+ let EnvironmentKey = /* @__PURE__ */ function(EnvironmentKey) {
5
+ /** Path to the Scaleway configuration file */
6
+ EnvironmentKey["ScwConfigPath"] = "SCW_CONFIG_PATH";
7
+ /** Scaleway access key */
8
+ EnvironmentKey["ScwAccessKey"] = "SCW_ACCESS_KEY";
9
+ /**
10
+ * Scaleway secret key
11
+ * @remarks #nosec G101
12
+ */
13
+ EnvironmentKey["ScwSecretKey"] = "SCW_SECRET_KEY";
14
+ /** Scaleway API URL */
15
+ EnvironmentKey["ScwAPIURL"] = "SCW_API_URL";
16
+ /** Scaleway default organization ID */
17
+ EnvironmentKey["ScwDefaultOrganizationId"] = "SCW_DEFAULT_ORGANIZATION_ID";
18
+ /** Scaleway default project ID */
19
+ EnvironmentKey["ScwDefaultProjectId"] = "SCW_DEFAULT_PROJECT_ID";
20
+ /** Scaleway default region */
21
+ EnvironmentKey["ScwDefaultRegion"] = "SCW_DEFAULT_REGION";
22
+ /** Scaleway default zone */
23
+ EnvironmentKey["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
24
+ return EnvironmentKey;
25
+ }({});
26
+ export { EnvironmentKey };
package/dist/index.js CHANGED
@@ -1,6 +1,2 @@
1
1
  import { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues } from "./config-loader.js";
2
- export {
3
- loadAllProfilesFromConfigurationFile,
4
- loadProfileFromConfigurationFile,
5
- loadProfileFromEnvironmentValues
6
- };
2
+ export { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
@@ -1,22 +1,29 @@
1
+ import { EnvironmentKey } from "./env.js";
2
+ import { env } from "node:process";
1
3
  import { homedir } from "node:os";
2
4
  import * as path from "node:path";
3
- import { env } from "node:process";
4
- import { EnvironmentKey } from "./env.js";
5
+ /**
6
+ * Gets the Scaleway directory.
7
+ *
8
+ * @returns The path to the Scaleway diretory
9
+ *
10
+ * @internal
11
+ */
5
12
  const getScwConfigurationDirectory = () => {
6
- const xdgConfigPath = env.XDG_CONFIG_HOME;
7
- if (typeof xdgConfigPath === "string" && xdgConfigPath.length > 0) {
8
- return path.join(xdgConfigPath, "scw");
9
- }
10
- return path.join(homedir(), ".config", "scw");
13
+ const xdgConfigPath = env.XDG_CONFIG_HOME;
14
+ if (typeof xdgConfigPath === "string" && xdgConfigPath.length > 0) return path.join(xdgConfigPath, "scw");
15
+ return path.join(homedir(), ".config", "scw");
11
16
  };
17
+ /**
18
+ * Gets the configuration file path.
19
+ *
20
+ * @returns The path to the configuration file
21
+ *
22
+ * @internal
23
+ */
12
24
  const resolveConfigurationFilePath = () => {
13
- const envFilePath = env[EnvironmentKey.ScwConfigPath];
14
- if (typeof envFilePath === "string" && envFilePath.length > 0) {
15
- return envFilePath;
16
- }
17
- return path.join(getScwConfigurationDirectory(), "config.yaml");
18
- };
19
- export {
20
- getScwConfigurationDirectory,
21
- resolveConfigurationFilePath
25
+ const envFilePath = env[EnvironmentKey.ScwConfigPath];
26
+ if (typeof envFilePath === "string" && envFilePath.length > 0) return envFilePath;
27
+ return path.join(getScwConfigurationDirectory(), "config.yaml");
22
28
  };
29
+ export { resolveConfigurationFilePath };
@@ -1,41 +1,49 @@
1
- import { readFileSync } from "fs";
2
- const STRIP_COMMENT_REGEX = /(^|\s)[;#]/;
3
- const DETECT_SECTION_REGEX = /^\s*([^]+):\s*$/;
4
- const DETECT_ITEM_REGEX = /^\s*(.+?)\s*:\s*(.+?)\s*$/;
1
+ import { readFileSync } from "node:fs";
2
+ var STRIP_COMMENT_REGEX = /(^|\s)[;#]/;
3
+ var DETECT_SECTION_REGEX = /^\s*([\s\S]+?):\s*$/;
4
+ var DETECT_ITEM_REGEX = /^\s*(.+?)\s*:\s*(.+?)\s*$/;
5
+ /**
6
+ * Converts YAML to configuration map.
7
+ *
8
+ * @param input - YAML string
9
+ * @returns The configuration map
10
+ *
11
+ * @internal
12
+ */
5
13
  const convertYamlToConfiguration = (input) => {
6
- let foundProfilesKey = false;
7
- let currentSection = "default";
8
- const map = {};
9
- if (typeof input !== "string") {
10
- return map;
11
- }
12
- input.split(/\r?\n/).forEach((rawLine) => {
13
- const line = rawLine.split(STRIP_COMMENT_REGEX)[0];
14
- const newSection = DETECT_SECTION_REGEX.exec(line);
15
- if (newSection) {
16
- currentSection = void 0;
17
- if (newSection[1] === "profiles") {
18
- foundProfilesKey = true;
19
- } else if (foundProfilesKey) {
20
- [, currentSection] = newSection;
21
- }
22
- } else if (currentSection) {
23
- const item = DETECT_ITEM_REGEX.exec(line);
24
- if (item) {
25
- if (typeof map[currentSection] !== "object") {
26
- map[currentSection] = {};
27
- }
28
- [, , map[currentSection][item[1]]] = item;
29
- }
30
- }
31
- });
32
- return map;
14
+ let foundProfilesKey = false;
15
+ let currentSection = "default";
16
+ const map = {};
17
+ if (typeof input !== "string") return map;
18
+ input.split(/\r?\n/).forEach((rawLine) => {
19
+ const line = rawLine.split(STRIP_COMMENT_REGEX)[0];
20
+ const newSection = DETECT_SECTION_REGEX.exec(line);
21
+ if (newSection) {
22
+ currentSection = void 0;
23
+ if (newSection[1] === "profiles") foundProfilesKey = true;
24
+ else if (foundProfilesKey) [, currentSection] = newSection;
25
+ } else if (currentSection) {
26
+ const item = DETECT_ITEM_REGEX.exec(line);
27
+ if (item) {
28
+ if (typeof map[currentSection] !== "object") map[currentSection] = {};
29
+ [, , map[currentSection][item[1]]] = item;
30
+ }
31
+ }
32
+ });
33
+ return map;
33
34
  };
35
+ /**
36
+ * Loads configuration from a file.
37
+ *
38
+ * @param filePath - Path to the configuration file
39
+ * @returns The configuration
40
+ *
41
+ * @throws Error
42
+ * Thrown if the file doesn't exist.
43
+ *
44
+ * @internal
45
+ */
34
46
  const loadConfigurationFromFile = (filePath) => {
35
- const fileContent = readFileSync(filePath, "utf-8");
36
- return convertYamlToConfiguration(fileContent);
37
- };
38
- export {
39
- convertYamlToConfiguration,
40
- loadConfigurationFromFile
47
+ return convertYamlToConfiguration(readFileSync(filePath, "utf-8"));
41
48
  };
49
+ export { loadConfigurationFromFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleway/configuration-loader",
3
- "version": "1.0.12",
3
+ "version": "2.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Load configuration via file or environment for NodeJS.",
6
6
  "publishConfig": {
@@ -12,19 +12,17 @@
12
12
  "directory": "packages/configuration-loader"
13
13
  },
14
14
  "engines": {
15
- "node": ">=20.19.4"
15
+ "node": ">=20.19.6"
16
16
  },
17
17
  "type": "module",
18
18
  "exports": {
19
19
  ".": {
20
20
  "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js",
22
- "require": "./dist/index.cjs",
23
21
  "default": "./dist/index.js"
24
22
  }
25
23
  },
26
24
  "devDependencies": {
27
- "@types/node": "18.11.18"
25
+ "@types/node": "20.19.35"
28
26
  },
29
27
  "scripts": {
30
28
  "typecheck": "tsc --noEmit",
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const process = require("process");
4
- const env = require("./env.cjs");
5
- const pathResolver = require("./path-resolver.cjs");
6
- const ymlLoader = require("./yml-loader.cjs");
7
- const convertFileConfigToSDK = (obj) => ({
8
- accessKey: obj.access_key,
9
- apiURL: obj.api_url,
10
- defaultOrganizationId: obj.default_organization_id,
11
- defaultProjectId: obj.default_project_id,
12
- defaultRegion: obj.default_region,
13
- defaultZone: obj.default_zone,
14
- secretKey: obj.secret_key
15
- });
16
- const loadProfileFromEnvironmentValues = () => ({
17
- accessKey: process.env[env.EnvironmentKey.ScwAccessKey],
18
- apiURL: process.env[env.EnvironmentKey.ScwAPIURL],
19
- defaultOrganizationId: process.env[env.EnvironmentKey.ScwDefaultOrganizationId],
20
- defaultProjectId: process.env[env.EnvironmentKey.ScwDefaultProjectId],
21
- defaultRegion: process.env[env.EnvironmentKey.ScwDefaultRegion],
22
- defaultZone: process.env[env.EnvironmentKey.ScwDefaultZone],
23
- secretKey: process.env[env.EnvironmentKey.ScwSecretKey]
24
- });
25
- const loadAllProfilesFromConfigurationFile = (params) => {
26
- const filePath = params?.filepath ?? pathResolver.resolveConfigurationFilePath();
27
- if (typeof filePath !== "string" || filePath.length === 0) {
28
- throw new Error("Could not find the path to the configuration file.");
29
- }
30
- const configs = ymlLoader.loadConfigurationFromFile(filePath);
31
- return Object.keys(configs).reduce(
32
- (prev, pKey) => ({
33
- ...prev,
34
- [pKey]: convertFileConfigToSDK(configs[pKey])
35
- }),
36
- {}
37
- );
38
- };
39
- const loadProfileFromConfigurationFile = (params) => {
40
- const configs = loadAllProfilesFromConfigurationFile(params);
41
- const profileName = params?.profileName ?? "default";
42
- const profileMap = configs[profileName];
43
- if (typeof profileMap !== "object") {
44
- throw new Error(
45
- `Could not find the desired profile '${profileName}' in the configuration file.`
46
- );
47
- }
48
- return profileMap;
49
- };
50
- exports.loadAllProfilesFromConfigurationFile = loadAllProfilesFromConfigurationFile;
51
- exports.loadProfileFromConfigurationFile = loadProfileFromConfigurationFile;
52
- exports.loadProfileFromEnvironmentValues = loadProfileFromEnvironmentValues;
package/dist/env.cjs DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- var EnvironmentKey = /* @__PURE__ */ ((EnvironmentKey2) => {
4
- EnvironmentKey2["ScwConfigPath"] = "SCW_CONFIG_PATH";
5
- EnvironmentKey2["ScwAccessKey"] = "SCW_ACCESS_KEY";
6
- EnvironmentKey2["ScwSecretKey"] = "SCW_SECRET_KEY";
7
- EnvironmentKey2["ScwAPIURL"] = "SCW_API_URL";
8
- EnvironmentKey2["ScwDefaultOrganizationId"] = "SCW_DEFAULT_ORGANIZATION_ID";
9
- EnvironmentKey2["ScwDefaultProjectId"] = "SCW_DEFAULT_PROJECT_ID";
10
- EnvironmentKey2["ScwDefaultRegion"] = "SCW_DEFAULT_REGION";
11
- EnvironmentKey2["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
12
- return EnvironmentKey2;
13
- })(EnvironmentKey || {});
14
- exports.EnvironmentKey = EnvironmentKey;
package/dist/index.cjs DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const configLoader = require("./config-loader.cjs");
4
- exports.loadAllProfilesFromConfigurationFile = configLoader.loadAllProfilesFromConfigurationFile;
5
- exports.loadProfileFromConfigurationFile = configLoader.loadProfileFromConfigurationFile;
6
- exports.loadProfileFromEnvironmentValues = configLoader.loadProfileFromEnvironmentValues;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_os = require("node:os");
4
- const path = require("node:path");
5
- const node_process = require("node:process");
6
- const env = require("./env.cjs");
7
- function _interopNamespaceDefault(e) {
8
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
- if (e) {
10
- for (const k in e) {
11
- if (k !== "default") {
12
- const d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: () => e[k]
16
- });
17
- }
18
- }
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
- const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
24
- const getScwConfigurationDirectory = () => {
25
- const xdgConfigPath = node_process.env.XDG_CONFIG_HOME;
26
- if (typeof xdgConfigPath === "string" && xdgConfigPath.length > 0) {
27
- return path__namespace.join(xdgConfigPath, "scw");
28
- }
29
- return path__namespace.join(node_os.homedir(), ".config", "scw");
30
- };
31
- const resolveConfigurationFilePath = () => {
32
- const envFilePath = node_process.env[env.EnvironmentKey.ScwConfigPath];
33
- if (typeof envFilePath === "string" && envFilePath.length > 0) {
34
- return envFilePath;
35
- }
36
- return path__namespace.join(getScwConfigurationDirectory(), "config.yaml");
37
- };
38
- exports.getScwConfigurationDirectory = getScwConfigurationDirectory;
39
- exports.resolveConfigurationFilePath = resolveConfigurationFilePath;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("fs");
4
- const STRIP_COMMENT_REGEX = /(^|\s)[;#]/;
5
- const DETECT_SECTION_REGEX = /^\s*([^]+):\s*$/;
6
- const DETECT_ITEM_REGEX = /^\s*(.+?)\s*:\s*(.+?)\s*$/;
7
- const convertYamlToConfiguration = (input) => {
8
- let foundProfilesKey = false;
9
- let currentSection = "default";
10
- const map = {};
11
- if (typeof input !== "string") {
12
- return map;
13
- }
14
- input.split(/\r?\n/).forEach((rawLine) => {
15
- const line = rawLine.split(STRIP_COMMENT_REGEX)[0];
16
- const newSection = DETECT_SECTION_REGEX.exec(line);
17
- if (newSection) {
18
- currentSection = void 0;
19
- if (newSection[1] === "profiles") {
20
- foundProfilesKey = true;
21
- } else if (foundProfilesKey) {
22
- [, currentSection] = newSection;
23
- }
24
- } else if (currentSection) {
25
- const item = DETECT_ITEM_REGEX.exec(line);
26
- if (item) {
27
- if (typeof map[currentSection] !== "object") {
28
- map[currentSection] = {};
29
- }
30
- [, , map[currentSection][item[1]]] = item;
31
- }
32
- }
33
- });
34
- return map;
35
- };
36
- const loadConfigurationFromFile = (filePath) => {
37
- const fileContent = fs.readFileSync(filePath, "utf-8");
38
- return convertYamlToConfiguration(fileContent);
39
- };
40
- exports.convertYamlToConfiguration = convertYamlToConfiguration;
41
- exports.loadConfigurationFromFile = loadConfigurationFromFile;