@into-cps-association/libms 0.5.0 → 0.5.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.
Files changed (80) hide show
  1. package/README.md +1 -0
  2. package/config/http.json +1 -0
  3. package/dist/src/app.module.js +5 -6
  4. package/dist/src/app.module.js.map +1 -1
  5. package/dist/src/bootstrap.js +11 -21
  6. package/dist/src/bootstrap.js.map +1 -1
  7. package/dist/src/config/config.interface.d.ts +14 -0
  8. package/dist/src/config/config.interface.js +2 -0
  9. package/dist/src/config/config.interface.js.map +1 -0
  10. package/dist/src/config/config.model.d.ts +14 -0
  11. package/dist/src/config/config.model.js +2 -0
  12. package/dist/src/config/config.model.js.map +1 -0
  13. package/dist/src/config/config.module.d.ts +2 -0
  14. package/dist/src/config/config.module.js +33 -0
  15. package/dist/src/config/config.module.js.map +1 -0
  16. package/dist/src/config/config.service.d.ts +17 -0
  17. package/dist/src/config/config.service.js +61 -0
  18. package/dist/src/config/config.service.js.map +1 -0
  19. package/dist/src/config/util.d.ts +1 -0
  20. package/dist/src/config/util.js +5 -0
  21. package/dist/src/config/util.js.map +1 -0
  22. package/dist/src/files/files-service.factory.d.ts +2 -2
  23. package/dist/src/files/files-service.factory.js +4 -1
  24. package/dist/src/files/files-service.factory.js.map +1 -1
  25. package/dist/src/files/files.module.js +2 -2
  26. package/dist/src/files/files.module.js.map +1 -1
  27. package/dist/src/files/git/git-files.service.d.ts +4 -2
  28. package/dist/src/files/git/git-files.service.js +31 -20
  29. package/dist/src/files/git/git-files.service.js.map +1 -1
  30. package/dist/src/files/interfaces/files.service.interface.d.ts +1 -0
  31. package/dist/src/files/local/local-files.service.d.ts +3 -2
  32. package/dist/src/files/local/local-files.service.js +12 -4
  33. package/dist/src/files/local/local-files.service.js.map +1 -1
  34. package/dist/src/main.d.ts +4 -1
  35. package/dist/test/cloudcmd/cloudcmd.spec.js +3 -3
  36. package/dist/test/cloudcmd/cloudcmd.spec.js.map +1 -1
  37. package/dist/test/e2e/app.e2e.spec.js +18 -12
  38. package/dist/test/e2e/app.e2e.spec.js.map +1 -1
  39. package/dist/test/integration/files.service.integration.spec.js +6 -6
  40. package/dist/test/integration/files.service.integration.spec.js.map +1 -1
  41. package/dist/test/testUtil.d.ts +7 -1
  42. package/dist/test/testUtil.js +20 -17
  43. package/dist/test/testUtil.js.map +1 -1
  44. package/dist/test/unit/files-service.factory.unit.spec.js +20 -8
  45. package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -1
  46. package/dist/test/unit/files.resolver.unit.spec.js +1 -0
  47. package/dist/test/unit/files.resolver.unit.spec.js.map +1 -1
  48. package/dist/test/unit/git-files.service.unit.spec.js +6 -5
  49. package/dist/test/unit/git-files.service.unit.spec.js.map +1 -1
  50. package/dist/test/unit/local-files.service.unit.spec.js +36 -21
  51. package/dist/test/unit/local-files.service.unit.spec.js.map +1 -1
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/eslint.config.js +5 -0
  54. package/libms.yaml.sample +12 -0
  55. package/package.json +9 -7
  56. package/src/app.module.ts +6 -7
  57. package/src/bootstrap.ts +14 -21
  58. package/src/config/config.interface.ts +14 -0
  59. package/src/config/config.model.ts +13 -0
  60. package/src/config/config.module.ts +23 -0
  61. package/src/config/config.service.ts +54 -0
  62. package/src/config/util.ts +5 -0
  63. package/src/files/files-service.factory.ts +5 -3
  64. package/src/files/files.module.ts +3 -3
  65. package/src/files/git/git-files.service.ts +28 -21
  66. package/src/files/interfaces/files.service.interface.ts +1 -0
  67. package/src/files/local/local-files.service.ts +13 -4
  68. package/src/main.ts +1 -1
  69. package/test/cloudcmd/cloudcmd.spec.ts +4 -4
  70. package/test/data/user2/tools/large_file.md +1 -0
  71. package/test/e2e/app.e2e.spec.ts +23 -13
  72. package/test/integration/files.service.integration.spec.ts +9 -10
  73. package/test/jest-e2e.json +3 -0
  74. package/test/libms.test.yaml +6 -0
  75. package/test/testUtil.ts +23 -19
  76. package/test/unit/files-service.factory.unit.spec.ts +22 -11
  77. package/test/unit/files.resolver.unit.spec.ts +1 -0
  78. package/test/unit/git-files.service.unit.spec.ts +6 -5
  79. package/test/unit/local-files.service.unit.spec.ts +41 -25
  80. package/test/update-config.js +25 -0
@@ -17,14 +17,11 @@ import {
17
17
  expectedFileContentResponse,
18
18
  expectedListDirectoryResponse,
19
19
  } from '../testUtil';
20
+ import { CONFIG_SERVICE, IConfig } from 'src/config/config.interface';
21
+ import Config from 'src/config/config.service';
20
22
 
21
- const client = new ApolloClient({
22
- link: new HttpLink({
23
- uri: `http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}`,
24
- fetch,
25
- }),
26
- cache: new InMemoryCache({ addTypename: false }),
27
- });
23
+ let client;
24
+ let configService: IConfig;
28
25
 
29
26
  describe('End to End test for the application', () => {
30
27
  let app: INestApplication;
@@ -33,13 +30,24 @@ describe('End to End test for the application', () => {
33
30
  const moduleFixture: TestingModule = await Test.createTestingModule({
34
31
  imports: [AppModule],
35
32
  }).compile();
33
+ configService = moduleFixture.get<Config>(CONFIG_SERVICE);
36
34
  app = moduleFixture.createNestApplication();
35
+ client = new ApolloClient({
36
+ link: new HttpLink({
37
+ uri: `http://localhost:${configService.getPort()}${configService.getApolloPath()}`,
38
+ fetch,
39
+ }),
40
+ cache: new InMemoryCache({ addTypename: false }),
41
+ });
37
42
  await app.init(); // Initialize the application
38
- await app.listen(process.env.PORT);
43
+ await app.listen(configService.getPort());
39
44
 
40
- // eslint-disable-next-line no-promise-executor-return
41
- await new Promise((resolve) => setTimeout(resolve, 4000));
42
- }, 10000);
45
+ // Check if the port is available
46
+
47
+ while (!app.getHttpServer().listening) {
48
+ await new Promise((resolve) => setTimeout(resolve, 100));
49
+ }
50
+ }, 15000);
43
51
 
44
52
  afterAll(async () => {
45
53
  await app.close();
@@ -49,8 +57,10 @@ describe('End to End test for the application', () => {
49
57
  query: string,
50
58
  expectedResponse: unknown,
51
59
  ): Promise<void> {
52
- const response = await request(`http://localhost:${process.env.PORT}`)
53
- .post(process.env.APOLLO_PATH)
60
+ const response = await request(
61
+ `http://localhost:${configService.getPort()}`,
62
+ )
63
+ .post(configService.getApolloPath())
54
64
  .send({ query });
55
65
  expect(response.body).toEqual(expectedResponse);
56
66
  }
@@ -1,43 +1,44 @@
1
1
  import { describe, it, expect, jest } from '@jest/globals';
2
2
  import { Test, TestingModule } from '@nestjs/testing';
3
- import { ConfigService } from '@nestjs/config';
4
3
  import FilesResolver from '../../src/files/files.resolver';
5
4
  import LocalFilesService from '../../src/files/local/local-files.service';
6
5
  import {
6
+ jestMockConfigService,
7
7
  pathToTestDirectory,
8
8
  pathToTestFileContent,
9
9
  testDirectory,
10
10
  testFileContent,
11
- MockConfigService,
12
11
  } from '../testUtil';
13
12
  import GitFilesService from '../../src/files/git/git-files.service';
14
13
  import { FILE_SERVICE } from '../../src/files/interfaces/files.service.interface';
15
14
  import FilesServiceFactory from '../../src/files/files-service.factory';
15
+ import { CONFIG_SERVICE, IConfig } from 'src/config/config.interface';
16
16
 
17
17
  describe('Integration tests for FilesResolver', () => {
18
18
  let filesResolver: FilesResolver;
19
- let mockConfigService: MockConfigService;
19
+ let mockConfigService: IConfig;
20
20
 
21
21
  beforeEach(async () => {
22
- mockConfigService = new MockConfigService();
22
+ mockConfigService = jestMockConfigService();
23
+
23
24
  const module: TestingModule = await Test.createTestingModule({
24
25
  providers: [
25
26
  FilesResolver,
26
27
  {
27
28
  provide: FILE_SERVICE,
28
29
  useFactory: (
29
- configService: ConfigService,
30
+ configService: IConfig,
30
31
  localFilesService: LocalFilesService,
31
32
  gitFilesService: GitFilesService,
32
33
  ) => {
33
34
  const fileServices = [localFilesService, gitFilesService];
34
35
  return FilesServiceFactory.create(configService, fileServices);
35
36
  },
36
- inject: [ConfigService, LocalFilesService, GitFilesService],
37
+ inject: [CONFIG_SERVICE, LocalFilesService, GitFilesService],
37
38
  },
38
39
  LocalFilesService,
39
40
  GitFilesService,
40
- { provide: ConfigService, useClass: MockConfigService },
41
+ { provide: CONFIG_SERVICE, useValue: mockConfigService },
41
42
  ],
42
43
  }).compile();
43
44
 
@@ -50,12 +51,10 @@ describe('Integration tests for FilesResolver', () => {
50
51
 
51
52
  const modes = ['local'];
52
53
 
53
- // eslint-disable-next-line no-restricted-syntax
54
54
  for (const mode of modes) {
55
- // eslint-disable-next-line no-loop-func
56
55
  describe(`when MODE is ${mode}`, () => {
57
56
  beforeEach(() => {
58
- jest.spyOn(mockConfigService, 'get').mockReturnValue(mode);
57
+ jest.spyOn(mockConfigService, 'getMode').mockImplementation(() => mode);
59
58
  });
60
59
 
61
60
  it('should be defined', () => {
@@ -5,5 +5,8 @@
5
5
  "testRegex": ".e2e.spec.ts$",
6
6
  "transform": {
7
7
  "^.+\\.(t|j)s$": "ts-jest"
8
+ },
9
+ "moduleNameMapper": {
10
+ "^(\\.\\.?\\/.+)\\.jsx?$": "$1"
8
11
  }
9
12
  }
@@ -0,0 +1,6 @@
1
+ port: '4001'
2
+ local-path: 'test/data'
3
+ mode: 'local'
4
+ log-level: 'debug'
5
+ apollo-path: '/lib'
6
+ graphql-playground: 'true'
package/test/testUtil.ts CHANGED
@@ -1,7 +1,8 @@
1
- import * as dotenv from 'dotenv';
1
+ import { IConfig } from 'src/config/config.interface';
2
2
  import { setTimeout } from 'timers/promises';
3
-
4
- dotenv.config({ path: '.env' });
3
+ import { jest } from '@jest/globals';
4
+ import { GitRepo } from 'src/config/config.model';
5
+ import { CONFIG_MODE } from 'src/enums/config-mode.enum';
5
6
 
6
7
  // actual data for integration and e2e tests
7
8
  export const readFileActualContent = ['content123'];
@@ -26,7 +27,10 @@ export const testDirectory = {
26
27
  };
27
28
  export const testFileName = 'README.md';
28
29
  export const fstestFileContent = 'content123';
30
+ export const largeTestFileName = 'large_file.md';
31
+ export const largeFstestFileContent = 'a'.repeat(500 * 1000);
29
32
  export const pathToTestFileContent = 'user2/tools/README.md';
33
+ export const pathToLargeTestFileContent = 'user2/tools/large_file.md';
30
34
  export const testFileArray = [
31
35
  'data',
32
36
  'digital_twins',
@@ -54,26 +58,26 @@ export function sleep(ms) {
54
58
  }
55
59
 
56
60
  export class MockConfigService {
57
- // eslint-disable-next-line class-methods-use-this
58
- get(key: string): string {
59
- switch (key) {
60
- case 'LOCAL_PATH':
61
- return process.env.LOCAL_PATH;
62
- case 'MODE':
63
- if (process.env.MODE === 'local') {
64
- return 'local';
65
- }
66
- if (process.env.MODE === 'git') {
67
- return 'git';
68
- }
69
- return 'unknown';
61
+ getMode(): string {
62
+ return '';
63
+ }
70
64
 
71
- default:
72
- return undefined;
73
- }
65
+ getLocalPath(): string {
66
+ return 'test/data';
74
67
  }
75
68
  }
76
69
 
70
+ export const jestMockConfigService = (): IConfig => ({
71
+ getMode: jest.fn<() => string>().mockReturnValue(CONFIG_MODE.LOCAL),
72
+ getLocalPath: jest.fn<() => string>().mockReturnValue('test/data'),
73
+ getApolloPath: jest.fn<() => string>(),
74
+ getGitRepos: jest.fn<() => { [key: string]: GitRepo }[]>(),
75
+ getGraphqlPlayground: jest.fn<() => string>(),
76
+ getLogLevel: jest.fn<() => string>(),
77
+ getPort: jest.fn<() => number>(),
78
+ loadConfig: jest.fn<() => Promise<void>>(),
79
+ });
80
+
77
81
  export const mockReadFileResponseData = {
78
82
  project: {
79
83
  __typename: 'Project',
@@ -1,51 +1,62 @@
1
1
  // files-service.factory.spec.ts
2
2
  import { describe, it, expect, jest } from '@jest/globals';
3
3
  import { Test, TestingModule } from '@nestjs/testing';
4
- import { ConfigService } from '@nestjs/config';
5
4
  import FilesServiceFactory from '../../src/files/files-service.factory';
6
5
  import LocalFilesService from '../../src/files/local/local-files.service';
7
6
  import { IFilesService } from '../../src/files/interfaces/files.service.interface';
8
7
  import GitFilesService from '../../src/files/git/git-files.service';
8
+ import { CONFIG_SERVICE, IConfig } from 'src/config/config.interface';
9
+ import { jestMockConfigService } from 'test/testUtil';
10
+ import { CONFIG_MODE } from 'src/enums/config-mode.enum';
9
11
 
10
12
  describe('FilesServiceFactory', () => {
11
- let configService: ConfigService;
13
+ let configService: IConfig;
12
14
  let localFilesService: IFilesService;
13
15
  let gitFilesService: IFilesService;
14
16
  let fileServices: IFilesService[];
15
17
 
16
18
  beforeEach(async () => {
19
+ configService = jestMockConfigService();
20
+ gitFilesService = {
21
+ getMode: jest.fn<() => CONFIG_MODE>().mockReturnValue(CONFIG_MODE.GIT),
22
+ init: jest.fn<() => Promise<void>>(),
23
+ } as unknown as IFilesService;
24
+
17
25
  const module: TestingModule = await Test.createTestingModule({
18
26
  providers: [
19
- GitFilesService,
20
- { provide: ConfigService, useValue: { get: jest.fn() } },
27
+ { provide: GitFilesService, useValue: gitFilesService },
28
+ {
29
+ provide: CONFIG_SERVICE,
30
+ useValue: configService,
31
+ },
21
32
  LocalFilesService,
22
33
  ],
23
34
  }).compile();
24
35
 
25
- configService = module.get<ConfigService>(ConfigService);
26
36
  localFilesService = module.get<LocalFilesService>(LocalFilesService);
27
37
  gitFilesService = module.get<GitFilesService>(GitFilesService);
28
38
  fileServices = [gitFilesService, localFilesService];
29
39
  });
30
40
 
31
41
  it('should create a local files service when MODE is local', () => {
32
- jest.spyOn(configService, 'get').mockReturnValue('local');
42
+ jest.spyOn(configService, 'getMode').mockReturnValue('local');
33
43
  expect(FilesServiceFactory.create(configService, fileServices)).toBe(
34
44
  localFilesService,
35
45
  );
36
46
  });
37
47
 
38
48
  it('should create a git files service when MODE is git', () => {
39
- jest.spyOn(configService, 'get').mockReturnValue('git');
49
+ jest.spyOn(configService, 'getMode').mockReturnValue(CONFIG_MODE.GIT);
40
50
  expect(FilesServiceFactory.create(configService, fileServices)).toBe(
41
51
  gitFilesService,
42
52
  );
43
53
  });
44
54
 
45
55
  it('should throw an error when MODE is invalid', () => {
46
- jest.spyOn(configService, 'get').mockReturnValue('invalid');
47
- expect(() =>
48
- FilesServiceFactory.create(configService, fileServices),
49
- ).toThrow(`Invalid MODE: invalid`);
56
+ const invalidMode = 'invalid';
57
+ jest.spyOn(configService, 'getMode').mockReturnValue(invalidMode);
58
+ expect(() => {
59
+ FilesServiceFactory.create(configService, fileServices);
60
+ }).toThrow(`Invalid MODE: ${invalidMode}`);
50
61
  });
51
62
  });
@@ -27,6 +27,7 @@ describe('Unit tests for FilesResolver', () => {
27
27
  .fn<() => Promise<Project>>()
28
28
  .mockImplementation(() => Promise.resolve(testFileContent)),
29
29
  getMode: jest.fn<() => CONFIG_MODE>().mockReturnValue(CONFIG_MODE.LOCAL),
30
+ init: jest.fn<() => Promise<void>>(),
30
31
  };
31
32
 
32
33
  const module: TestingModule = await Test.createTestingModule({
@@ -1,16 +1,16 @@
1
1
  import { describe, it, expect, jest } from '@jest/globals';
2
2
  import { Test, TestingModule } from '@nestjs/testing';
3
- import { ConfigService } from '@nestjs/config';
4
3
  import LocalFileService from 'src/files/local/local-files.service';
5
4
  import { Project } from 'src/types';
6
5
  import {
7
- MockConfigService,
6
+ jestMockConfigService,
8
7
  testDirectory,
9
8
  testFileContent,
10
9
  } from 'test/testUtil';
11
10
  import GitFilesService from 'src/files/git/git-files.service';
12
11
  import { CONFIG_MODE } from 'src/enums/config-mode.enum';
13
12
  import { IFilesService } from 'src/files/interfaces/files.service.interface';
13
+ import { CONFIG_SERVICE } from 'src/config/config.interface';
14
14
 
15
15
  jest.mock('fs', () => ({
16
16
  promises: {
@@ -22,7 +22,7 @@ jest.mock('fs', () => ({
22
22
 
23
23
  describe('GitFilesService', () => {
24
24
  let service: GitFilesService;
25
- const mockConfigService = new MockConfigService();
25
+ const mockConfigService = jestMockConfigService();
26
26
  const mockLocalFilesService: IFilesService = {
27
27
  listDirectory: jest
28
28
  .fn<() => Promise<Project>>()
@@ -31,13 +31,14 @@ describe('GitFilesService', () => {
31
31
  .fn<() => Promise<Project>>()
32
32
  .mockImplementation(() => Promise.resolve(testFileContent)),
33
33
  getMode: jest.fn<() => CONFIG_MODE>().mockReturnValue(CONFIG_MODE.LOCAL),
34
+ init: jest.fn<() => Promise<void>>(),
34
35
  };
35
36
 
36
37
  beforeEach(async () => {
37
38
  const module: TestingModule = await Test.createTestingModule({
38
39
  providers: [
39
40
  GitFilesService,
40
- { provide: ConfigService, useValue: mockConfigService },
41
+ { provide: CONFIG_SERVICE, useValue: mockConfigService },
41
42
  { provide: LocalFileService, useValue: mockLocalFilesService },
42
43
  ],
43
44
  }).compile();
@@ -76,6 +77,6 @@ describe('GitFilesService', () => {
76
77
  await service.readFile('/some/path/file.txt');
77
78
 
78
79
  // Assert
79
- expect(mockReadFile).toBeCalledTimes(1);
80
+ expect(mockReadFile).toHaveBeenCalledTimes(1);
80
81
  });
81
82
  });
@@ -1,6 +1,5 @@
1
1
  import { describe, it, expect, jest } from '@jest/globals';
2
2
  import { Test, TestingModule } from '@nestjs/testing';
3
- import { ConfigService } from '@nestjs/config';
4
3
  import * as fs from 'fs';
5
4
  import { join } from 'path';
6
5
  import LocalFilesService from '../../src/files/local/local-files.service';
@@ -8,11 +7,15 @@ import {
8
7
  fstestFileContent,
9
8
  pathToTestDirectory,
10
9
  pathToTestFileContent,
11
- testFileArray,
12
- MockConfigService,
13
10
  testFileName,
11
+ pathToLargeTestFileContent,
12
+ largeFstestFileContent,
13
+ largeTestFileName,
14
+ jestMockConfigService,
15
+ testFileArray,
14
16
  } from '../testUtil';
15
17
  import { Dirent } from 'fs';
18
+ import { CONFIG_SERVICE } from 'src/config/config.interface';
16
19
 
17
20
  jest.mock('fs', () => ({
18
21
  promises: {
@@ -24,13 +27,14 @@ jest.mock('fs', () => ({
24
27
 
25
28
  describe('LocalFilesService', () => {
26
29
  let service: LocalFilesService;
27
- const mockConfigService = new MockConfigService();
30
+ let mockConfigService;
28
31
 
29
32
  beforeEach(async () => {
33
+ mockConfigService = jestMockConfigService();
30
34
  const module: TestingModule = await Test.createTestingModule({
31
35
  providers: [
32
36
  LocalFilesService,
33
- { provide: ConfigService, useValue: mockConfigService },
37
+ { provide: CONFIG_SERVICE, useValue: mockConfigService },
34
38
  ],
35
39
  }).compile();
36
40
 
@@ -47,7 +51,7 @@ describe('LocalFilesService', () => {
47
51
 
48
52
  it('should list directory', async () => {
49
53
  const fullPath = join(
50
- mockConfigService.get('LOCAL_PATH'),
54
+ mockConfigService.getLocalPath(),
51
55
  pathToTestDirectory,
52
56
  );
53
57
 
@@ -83,28 +87,40 @@ describe('LocalFilesService', () => {
83
87
  expect(fs.promises.lstat).toHaveBeenCalledTimes(testFileArray.length);
84
88
  });
85
89
 
86
- it('should read file', async () => {
87
- const fullPath = join(
88
- mockConfigService.get('LOCAL_PATH'),
89
- pathToTestFileContent,
90
- );
90
+ const readTestFile = [
91
+ {
92
+ name: largeTestFileName,
93
+ filePath: pathToLargeTestFileContent,
94
+ expectedContent: largeFstestFileContent,
95
+ },
96
+ {
97
+ name: testFileName,
98
+ filePath: pathToTestFileContent,
99
+ expectedContent: fstestFileContent,
100
+ },
101
+ ];
91
102
 
92
- jest.spyOn(fs.promises, 'readFile').mockResolvedValue(fstestFileContent);
103
+ readTestFile.forEach(({ name, filePath, expectedContent }) => {
104
+ it(`should read file ${name}`, async () => {
105
+ const fullPath = join(mockConfigService.getLocalPath(), filePath);
93
106
 
94
- const result = await service.readFile(pathToTestFileContent);
95
- expect(result).toEqual({
96
- repository: {
97
- blobs: {
98
- nodes: [
99
- {
100
- name: testFileName,
101
- rawBlob: fstestFileContent,
102
- rawTextBlob: fstestFileContent,
103
- },
104
- ],
107
+ jest.spyOn(fs.promises, 'readFile').mockResolvedValue(expectedContent);
108
+
109
+ const result = await service.readFile(filePath);
110
+ expect(result).toEqual({
111
+ repository: {
112
+ blobs: {
113
+ nodes: [
114
+ {
115
+ name: name,
116
+ rawBlob: expectedContent,
117
+ rawTextBlob: expectedContent,
118
+ },
119
+ ],
120
+ },
105
121
  },
106
- },
122
+ });
123
+ expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
107
124
  });
108
- expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
109
125
  });
110
126
  });
@@ -0,0 +1,25 @@
1
+ import * as fs from 'fs';
2
+ import * as yaml from 'js-yaml';
3
+ import * as path from 'path';
4
+
5
+ // Load environment variables
6
+ const env = process.env;
7
+
8
+ const yamlFilePath = path.join(process.env.LIBMS_CONFIG_PATH || 'test/libms.test.yaml');
9
+ const fileContents = fs.readFileSync(yamlFilePath, 'utf8');
10
+ const config = yaml.load(fileContents);
11
+
12
+ if (env.LIBMS_LOCAL_PATH) {
13
+ console.log('Updating local-path to '+ env.LIBMS_LOCAL_PATH);
14
+ config['local-path'] = env.LIBMS_LOCAL_PATH;
15
+ }
16
+
17
+ if (env.LIBMS_PORT) {
18
+ console.log('Updating PORT to '+ env.LIBMS_PORT);
19
+ config['port'] = env.LIBMS_PORT;
20
+ }
21
+
22
+ const updatedYaml = yaml.dump(config);
23
+ fs.writeFileSync(yamlFilePath, updatedYaml, 'utf8');
24
+
25
+ console.log( yamlFilePath + ' updated successfully.');