contensis-cli 1.0.0-beta.10 → 1.0.0-beta.100

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 (125) hide show
  1. package/README.md +1146 -78
  2. package/cli.js +3 -0
  3. package/dist/commands/connect.js +3 -3
  4. package/dist/commands/connect.js.map +2 -2
  5. package/dist/commands/create.js +45 -10
  6. package/dist/commands/create.js.map +2 -2
  7. package/dist/commands/dev.js +71 -0
  8. package/dist/commands/dev.js.map +7 -0
  9. package/dist/commands/diff.js +57 -0
  10. package/dist/commands/diff.js.map +7 -0
  11. package/dist/commands/execute.js +103 -0
  12. package/dist/commands/execute.js.map +7 -0
  13. package/dist/commands/get.js +169 -32
  14. package/dist/commands/get.js.map +3 -3
  15. package/dist/commands/globalOptions.js +37 -12
  16. package/dist/commands/globalOptions.js.map +2 -2
  17. package/dist/commands/import.js +65 -12
  18. package/dist/commands/import.js.map +2 -2
  19. package/dist/commands/index.js +22 -2
  20. package/dist/commands/index.js.map +2 -2
  21. package/dist/commands/list.js +53 -10
  22. package/dist/commands/list.js.map +2 -2
  23. package/dist/commands/login.js +2 -2
  24. package/dist/commands/login.js.map +2 -2
  25. package/dist/commands/push.js +17 -13
  26. package/dist/commands/push.js.map +2 -2
  27. package/dist/commands/remove.js +51 -8
  28. package/dist/commands/remove.js.map +2 -2
  29. package/dist/commands/set.js +139 -12
  30. package/dist/commands/set.js.map +2 -2
  31. package/dist/index.js +1 -1
  32. package/dist/index.js.map +2 -2
  33. package/dist/localisation/en-GB.js +297 -49
  34. package/dist/localisation/en-GB.js.map +2 -2
  35. package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js +56 -0
  36. package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js.map +7 -0
  37. package/dist/mappers/DevInit-to-CIWorkflow.js +374 -0
  38. package/dist/mappers/DevInit-to-CIWorkflow.js.map +7 -0
  39. package/dist/mappers/DevInit-to-RolePermissions.js +56 -0
  40. package/dist/mappers/DevInit-to-RolePermissions.js.map +7 -0
  41. package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +56 -0
  42. package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +7 -0
  43. package/dist/models/CliService.d.js +17 -0
  44. package/dist/models/CliService.d.js.map +7 -0
  45. package/dist/models/DevService.d.js +17 -0
  46. package/dist/models/DevService.d.js.map +7 -0
  47. package/dist/providers/CredentialProvider.js +46 -14
  48. package/dist/providers/CredentialProvider.js.map +3 -3
  49. package/dist/providers/SessionCacheProvider.js +21 -1
  50. package/dist/providers/SessionCacheProvider.js.map +2 -2
  51. package/dist/providers/file-provider.js +12 -6
  52. package/dist/providers/file-provider.js.map +3 -3
  53. package/dist/services/ContensisCliService.js +1211 -420
  54. package/dist/services/ContensisCliService.js.map +3 -3
  55. package/dist/services/ContensisDevService.js +368 -0
  56. package/dist/services/ContensisDevService.js.map +7 -0
  57. package/dist/services/ContensisRoleService.js +114 -0
  58. package/dist/services/ContensisRoleService.js.map +7 -0
  59. package/dist/shell.js +58 -18
  60. package/dist/shell.js.map +3 -3
  61. package/dist/util/console.printer.js +171 -55
  62. package/dist/util/console.printer.js.map +2 -2
  63. package/dist/util/diff.js +116 -0
  64. package/dist/util/diff.js.map +7 -0
  65. package/dist/util/dotenv.js +57 -0
  66. package/dist/util/dotenv.js.map +7 -0
  67. package/dist/util/find.js +31 -0
  68. package/dist/util/find.js.map +7 -0
  69. package/dist/util/git.js +128 -0
  70. package/dist/util/git.js.map +7 -0
  71. package/dist/util/index.js +8 -2
  72. package/dist/util/index.js.map +3 -3
  73. package/dist/util/logger.js +90 -29
  74. package/dist/util/logger.js.map +3 -3
  75. package/dist/util/os.js +42 -0
  76. package/dist/util/os.js.map +7 -0
  77. package/dist/util/timers.js +49 -0
  78. package/dist/util/timers.js.map +7 -0
  79. package/dist/util/yaml.js +45 -0
  80. package/dist/util/yaml.js.map +7 -0
  81. package/dist/version.js +1 -1
  82. package/dist/version.js.map +1 -1
  83. package/esbuild.config.js +3 -1
  84. package/package.json +14 -3
  85. package/src/commands/connect.ts +3 -2
  86. package/src/commands/create.ts +61 -8
  87. package/src/commands/dev.ts +69 -0
  88. package/src/commands/diff.ts +41 -0
  89. package/src/commands/execute.ts +117 -0
  90. package/src/commands/get.ts +242 -28
  91. package/src/commands/globalOptions.ts +42 -12
  92. package/src/commands/import.ts +83 -8
  93. package/src/commands/index.ts +22 -1
  94. package/src/commands/list.ts +85 -11
  95. package/src/commands/login.ts +2 -1
  96. package/src/commands/push.ts +18 -11
  97. package/src/commands/remove.ts +66 -4
  98. package/src/commands/set.ts +189 -9
  99. package/src/index.ts +1 -4
  100. package/src/localisation/en-GB.ts +428 -66
  101. package/src/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.ts +44 -0
  102. package/src/mappers/DevInit-to-CIWorkflow.ts +526 -0
  103. package/src/mappers/DevInit-to-RolePermissions.ts +32 -0
  104. package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +44 -0
  105. package/src/models/CliService.d.ts +36 -0
  106. package/src/models/DevService.d.ts +40 -0
  107. package/src/models/JsModules.d.ts +2 -0
  108. package/src/providers/CredentialProvider.ts +51 -18
  109. package/src/providers/SessionCacheProvider.ts +29 -2
  110. package/src/providers/file-provider.ts +17 -6
  111. package/src/services/ContensisCliService.ts +1532 -508
  112. package/src/services/ContensisDevService.ts +434 -0
  113. package/src/services/ContensisRoleService.ts +108 -0
  114. package/src/shell.ts +68 -18
  115. package/src/util/console.printer.ts +240 -78
  116. package/src/util/diff.ts +124 -0
  117. package/src/util/dotenv.ts +37 -0
  118. package/src/util/find.ts +8 -0
  119. package/src/util/git.ts +131 -0
  120. package/src/util/index.ts +16 -7
  121. package/src/util/logger.ts +145 -31
  122. package/src/util/os.ts +12 -0
  123. package/src/util/timers.ts +24 -0
  124. package/src/util/yaml.ts +13 -0
  125. package/src/version.ts +1 -1
@@ -10,6 +10,7 @@ interface Remarks {
10
10
 
11
11
  class CredentialProvider {
12
12
  private serviceId: string;
13
+ private keytar!: typeof keytar;
13
14
  private userId: string = '';
14
15
  private passwordFallback?: string;
15
16
 
@@ -29,36 +30,61 @@ class CredentialProvider {
29
30
  this.passwordFallback = passwordFallback;
30
31
  }
31
32
 
33
+ Import = async () => {
34
+ try {
35
+ this.keytar = (await import('keytar')).default;
36
+ } catch (ex) {
37
+ this.keytar = {
38
+ findCredentials: async () => {
39
+ throw ex;
40
+ },
41
+ getPassword: async () => {
42
+ throw ex;
43
+ },
44
+ findPassword: async () => {
45
+ throw ex;
46
+ },
47
+ setPassword: async () => {
48
+ throw ex;
49
+ },
50
+ deletePassword: async () => {
51
+ throw ex;
52
+ },
53
+ };
54
+ }
55
+ };
56
+
32
57
  Init = async (): Promise<[Error, CredentialProvider]> => {
58
+ await this.Import();
59
+
33
60
  const [err, stored] = (await to(
34
- keytar.findCredentials(this.serviceId)
35
- )) as [
36
- Error,
37
- {
38
- account: string;
39
- password: string;
40
- }[]
41
- ];
61
+ this.keytar.getPassword(this.serviceId, this.userId)
62
+ )) as [Error, string];
63
+
42
64
  if (err && this.passwordFallback) {
43
- this.current = { account: this.userId, password: this.passwordFallback };
44
- // this.remarks = { secure: false };
65
+ this.current = {
66
+ account: this.userId,
67
+ password: this.passwordFallback,
68
+ };
45
69
  }
46
70
  if (!err) {
47
71
  this.remarks = { secure: true };
48
- this.current =
49
- stored?.find(
50
- u => u?.account?.toLowerCase() === this.userId.toLowerCase()
51
- ) || null;
72
+ if (stored) this.current = { account: this.userId, password: stored };
73
+
74
+ if (!this.current && this.passwordFallback) {
75
+ await this.Save(this.passwordFallback);
76
+ return await this.Init();
77
+ }
52
78
  }
53
79
  return [err, this];
54
80
  };
55
81
 
56
82
  Save = async (password: string) => {
57
83
  const [err] = await to(
58
- keytar.setPassword(this.serviceId, this.userId, password)
84
+ this.keytar.setPassword(this.serviceId, this.userId, password)
59
85
  );
60
86
 
61
- if (!err) Logger.info(`${this.serviceId} - credentials saved`);
87
+ // if (!err) Logger.info(`${this.serviceId} - credentials saved`);
62
88
  return err && !this.passwordFallback ? err : true;
63
89
  };
64
90
 
@@ -68,10 +94,17 @@ class CredentialProvider {
68
94
  return true;
69
95
  } else {
70
96
  const [err] = await to(
71
- keytar.deletePassword(this.serviceId, this.userId)
97
+ this.keytar.deletePassword(this.serviceId, this.userId)
72
98
  );
73
99
 
74
- Logger.warning(`${this.serviceId} - invalid credentials removed`);
100
+ if (err)
101
+ Logger.warning(
102
+ `${this.serviceId} - could not remove invalid credentials for ${this.userId}`
103
+ );
104
+ else
105
+ Logger.warning(
106
+ `${this.serviceId} - invalid credentials removed for ${this.userId}`
107
+ );
75
108
  return err || true;
76
109
  }
77
110
  };
@@ -3,7 +3,8 @@ import path from 'path';
3
3
  import clone from 'lodash/cloneDeep';
4
4
  import mergeWith from 'lodash/mergeWith';
5
5
  import unionBy from 'lodash/unionBy';
6
- import { isJson, tryParse, tryStringify } from '~/util';
6
+ import { appRootDir } from './file-provider';
7
+ import { isJson, tryParse } from '~/util';
7
8
  import { Logger } from '~/util/logger';
8
9
 
9
10
  class SessionCacheProvider {
@@ -11,7 +12,7 @@ class SessionCacheProvider {
11
12
  private cache = {} as SessionCache;
12
13
 
13
14
  constructor() {
14
- this.localFilePath = path.join(__dirname, '../../environments.json');
15
+ this.localFilePath = path.join(appRootDir, 'environments.json');
15
16
  this.cache = {
16
17
  currentTimestamp: new Date().toISOString(),
17
18
  environments: {},
@@ -69,6 +70,32 @@ class SessionCacheProvider {
69
70
  }
70
71
  return this.Get();
71
72
  };
73
+
74
+ UpdateEnv = (
75
+ updateContent: Partial<EnvironmentCache>,
76
+ env = this.cache.currentEnvironment,
77
+ setCurrentEnv = true
78
+ ) => {
79
+ try {
80
+ const environment = this.cache.environments[env || ''];
81
+
82
+ this.cache.environments[env || ''] = {
83
+ ...environment,
84
+ ...updateContent,
85
+ };
86
+ this.Update({
87
+ currentEnvironment: setCurrentEnv ? env : this.cache.currentEnvironment,
88
+ environments: this.cache.environments,
89
+ });
90
+ } catch (ex: any) {
91
+ // Problem merging cache data for update
92
+ Logger.error(
93
+ `Problem updating environment "${env}" in environments.json`
94
+ );
95
+ Logger.error(ex);
96
+ }
97
+ return this.Get();
98
+ };
72
99
  }
73
100
 
74
101
  export default SessionCacheProvider;
@@ -1,8 +1,15 @@
1
1
  import fs from 'fs';
2
+ import { homedir } from 'os';
2
3
  import path from 'path';
3
- import { path as appRoot } from 'app-root-path';
4
4
  import { tryParse } from '~/util';
5
5
 
6
+ const userHomeDir = homedir();
7
+
8
+ export const appRootDir =
9
+ process.env.CONTAINER_CONTEXT === 'true'
10
+ ? process.cwd()
11
+ : path.join(userHomeDir, '.contensis/');
12
+
6
13
  export const readJsonFile = <T>(filePath: string) => {
7
14
  const file = readFile(filePath);
8
15
  if (file) return tryParse(file) as T | string;
@@ -18,14 +25,17 @@ export const readFile = (filePath: string) => {
18
25
  }
19
26
  };
20
27
 
21
- export const readFiles = (directory: string) => {
28
+ export const readFiles = (directory: string, createDirectory = true) => {
22
29
  const directoryPath = localPath(directory);
23
30
  if (fs.existsSync(directoryPath)) {
24
31
  const files = fs.readdirSync(directoryPath);
25
32
  return files;
26
- } else {
33
+ } else if (createDirectory) {
27
34
  fs.mkdirSync(directoryPath, { recursive: true });
28
35
  return [];
36
+ } else {
37
+ throw new Error(`ENOENT: Directory does not exist ${directoryPath}`);
38
+ // return undefined;
29
39
  }
30
40
  };
31
41
 
@@ -42,8 +52,8 @@ export const removeFile = (filePath: string) => {
42
52
  };
43
53
 
44
54
  export const moveFile = (file: string, fromPath: string, toPath: string) => {
45
- const from = path.join(appRoot, `${fromPath}${file}`);
46
- const to = path.join(appRoot, `${toPath}${file}`);
55
+ const from = path.join(appRootDir, `${fromPath}${file}`);
56
+ const to = path.join(appRootDir, `${toPath}${file}`);
47
57
  if (fs.existsSync(from)) {
48
58
  checkDir(toPath);
49
59
  // if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });
@@ -69,4 +79,5 @@ export const checkDir = (filePath: string) => {
69
79
  fs.mkdirSync(directoryPath, { recursive: true });
70
80
  };
71
81
 
72
- export const localPath = (filePath: string) => path.join(appRoot, filePath);
82
+ export const localPath = (filePath: string) =>
83
+ path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);