@aneuhold/be-ts-lib 1.0.1 → 1.0.3
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/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/services/ConfigService/ConfigDefinition.d.ts +11 -0
- package/lib/services/ConfigService/ConfigDefinition.d.ts.map +1 -0
- package/lib/services/ConfigService/ConfigDefinition.js +2 -0
- package/lib/services/ConfigService/ConfigService.d.ts +18 -3
- package/lib/services/ConfigService/ConfigService.d.ts.map +1 -1
- package/lib/services/ConfigService/ConfigService.js +25 -4
- package/lib/services/ConfigService/ConfigService.spec.js +1 -8
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import OSFileSystemService from './services/applications/OSFileSystemService';
|
|
|
6
6
|
import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
|
|
7
7
|
import ITermService from './services/applications/ITermService';
|
|
8
8
|
import ConfigService from './services/ConfigService/ConfigService';
|
|
9
|
+
import Config from './services/ConfigService/ConfigDefinition';
|
|
9
10
|
export { CLIService, CurrentEnv, ChromeService, DockerService, OSFileSystemService, sleep, OperatingSystemType, ShellType, TerminalType, ITermService, ConfigService };
|
|
10
|
-
export type {};
|
|
11
|
+
export type { Config };
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,MAAM,MAAM,2CAA2C,CAAC;AAG/D,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,CAAC;AAGF,YAAY,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment configuration that is pulled in for the current environment
|
|
3
|
+
* from the GitHub repository.
|
|
4
|
+
*/
|
|
5
|
+
export default interface Config {
|
|
6
|
+
someKey: string;
|
|
7
|
+
mongoRootUsername: string;
|
|
8
|
+
mongoRootPassword: string;
|
|
9
|
+
mongoUrl: string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ConfigDefinition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigDefinition.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigDefinition.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,MAAM;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
+
import Config from './ConfigDefinition';
|
|
2
3
|
export type ConfigEnv = 'local' | 'dev' | 'prod';
|
|
3
4
|
/**
|
|
4
|
-
* A class which can be used to load configuration into the
|
|
5
|
-
* from a pre-defined location.
|
|
5
|
+
* A class which can be used to load configuration into the ConfigService
|
|
6
|
+
* from a pre-defined location. This requries that a `.env` file exists in the
|
|
7
|
+
* root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
|
|
6
8
|
*/
|
|
7
9
|
export default class ConfigService {
|
|
10
|
+
static env: ConfigEnv | null;
|
|
8
11
|
private static gitHub;
|
|
9
|
-
static
|
|
12
|
+
private static configObject;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the configuration object that has been loaded in for the current
|
|
15
|
+
* environment.
|
|
16
|
+
*/
|
|
17
|
+
static get config(): Config;
|
|
18
|
+
static get isInitialized(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Loads configuration from the GitHub repository into the ConfigService.
|
|
21
|
+
*/
|
|
22
|
+
static useConfig(env: ConfigEnv): Promise<void>;
|
|
10
23
|
/**
|
|
11
24
|
* Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
|
|
12
25
|
* local environment or .env file.
|
|
@@ -14,6 +27,8 @@ export default class ConfigService {
|
|
|
14
27
|
private static getGitHubClient;
|
|
15
28
|
/**
|
|
16
29
|
* Inserts the provided configuration into the local environment.
|
|
30
|
+
*
|
|
31
|
+
* This may not actually need to happen.
|
|
17
32
|
*/
|
|
18
33
|
private static insertPropertiesIntoEnv;
|
|
19
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAEvB,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAQ;IAEpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwB;IAE7C,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuB;IAElD;;;OAGG;IACH,MAAM,KAAK,MAAM,IAAI,MAAM,CAO1B;IAED,MAAM,KAAK,aAAa,IAAI,OAAO,CAElC;IAED;;OAEG;WACU,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBrD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAUtC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAG9B;CACH"}
|
|
@@ -4,12 +4,32 @@ const octokit_1 = require("octokit");
|
|
|
4
4
|
require("dotenv/config");
|
|
5
5
|
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
6
6
|
/**
|
|
7
|
-
* A class which can be used to load configuration into the
|
|
8
|
-
* from a pre-defined location.
|
|
7
|
+
* A class which can be used to load configuration into the ConfigService
|
|
8
|
+
* from a pre-defined location. This requries that a `.env` file exists in the
|
|
9
|
+
* root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
|
|
9
10
|
*/
|
|
10
11
|
class ConfigService {
|
|
12
|
+
static env = null;
|
|
11
13
|
static gitHub = null;
|
|
14
|
+
static configObject = null;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the configuration object that has been loaded in for the current
|
|
17
|
+
* environment.
|
|
18
|
+
*/
|
|
19
|
+
static get config() {
|
|
20
|
+
if (!ConfigService.configObject) {
|
|
21
|
+
throw new Error('ConfigService has not been initialized yet. Use ConfigService.useConfig() to initialize it.');
|
|
22
|
+
}
|
|
23
|
+
return ConfigService.configObject;
|
|
24
|
+
}
|
|
25
|
+
static get isInitialized() {
|
|
26
|
+
return !!ConfigService.configObject;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Loads configuration from the GitHub repository into the ConfigService.
|
|
30
|
+
*/
|
|
12
31
|
static async useConfig(env) {
|
|
32
|
+
ConfigService.env = env;
|
|
13
33
|
if (!ConfigService.gitHub) {
|
|
14
34
|
ConfigService.gitHub = ConfigService.getGitHubClient();
|
|
15
35
|
}
|
|
@@ -23,8 +43,7 @@ class ConfigService {
|
|
|
23
43
|
path: `${env}.jsonc`
|
|
24
44
|
});
|
|
25
45
|
const strippedJson = ConfigService.stripJsonComments(result.data);
|
|
26
|
-
|
|
27
|
-
ConfigService.insertPropertiesIntoEnv(config);
|
|
46
|
+
ConfigService.configObject = JSON.parse(strippedJson);
|
|
28
47
|
}
|
|
29
48
|
catch (error) {
|
|
30
49
|
core_ts_lib_1.Logger.error(`Failed to load ${env}.json, error: ${error}`);
|
|
@@ -46,6 +65,8 @@ class ConfigService {
|
|
|
46
65
|
}
|
|
47
66
|
/**
|
|
48
67
|
* Inserts the provided configuration into the local environment.
|
|
68
|
+
*
|
|
69
|
+
* This may not actually need to happen.
|
|
49
70
|
*/
|
|
50
71
|
static insertPropertiesIntoEnv(config) {
|
|
51
72
|
Object.entries(config).forEach(([key, value]) => {
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const console_1 = require("console");
|
|
7
|
-
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
8
7
|
const ConfigService_1 = __importDefault(require("./ConfigService"));
|
|
9
8
|
describe('ConfigService', () => {
|
|
10
9
|
describe('useConfig', () => {
|
|
@@ -16,13 +15,7 @@ describe('ConfigService', () => {
|
|
|
16
15
|
it('should load configuration from GitHub', async () => {
|
|
17
16
|
const env = 'local';
|
|
18
17
|
await ConfigService_1.default.useConfig(env);
|
|
19
|
-
(0, console_1.assert)(
|
|
20
|
-
});
|
|
21
|
-
it('should throw an error when loading configuration fails', async () => {
|
|
22
|
-
const env = 'invalid_env';
|
|
23
|
-
core_ts_lib_1.TestUtils.suppressConsole();
|
|
24
|
-
await expect(ConfigService_1.default.useConfig(env)).rejects.toThrow();
|
|
25
|
-
core_ts_lib_1.TestUtils.restoreConsole();
|
|
18
|
+
(0, console_1.assert)(ConfigService_1.default.config.someKey === 'SOME_VALUE');
|
|
26
19
|
});
|
|
27
20
|
});
|
|
28
21
|
});
|
package/package.json
CHANGED