contensis-cli 1.0.0-beta.52 → 1.0.0-beta.53

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 (99) hide show
  1. package/.vscode/launch.json +15 -15
  2. package/README.md +1226 -1226
  3. package/dist/commands/connect.js +44 -0
  4. package/dist/commands/connect.js.map +7 -0
  5. package/dist/commands/create.js +75 -0
  6. package/dist/commands/create.js.map +7 -0
  7. package/dist/commands/diff.js +57 -0
  8. package/dist/commands/diff.js.map +7 -0
  9. package/dist/commands/get.js +170 -0
  10. package/dist/commands/get.js.map +7 -0
  11. package/dist/commands/globalOptions.js +144 -0
  12. package/dist/commands/globalOptions.js.map +7 -0
  13. package/dist/commands/import.js +121 -0
  14. package/dist/commands/import.js.map +7 -0
  15. package/dist/commands/index.js +89 -0
  16. package/dist/commands/index.js.map +7 -0
  17. package/dist/commands/list.js +99 -0
  18. package/dist/commands/list.js.map +7 -0
  19. package/dist/commands/login.js +56 -0
  20. package/dist/commands/login.js.map +7 -0
  21. package/dist/commands/push.js +137 -0
  22. package/dist/commands/push.js.map +7 -0
  23. package/dist/commands/release.js +47 -0
  24. package/dist/commands/release.js.map +7 -0
  25. package/dist/commands/remove.js +79 -0
  26. package/dist/commands/remove.js.map +7 -0
  27. package/dist/commands/set.js +96 -0
  28. package/dist/commands/set.js.map +7 -0
  29. package/dist/index.js +32 -0
  30. package/dist/index.js.map +7 -0
  31. package/dist/localisation/en-GB.js +253 -0
  32. package/dist/localisation/en-GB.js.map +7 -0
  33. package/dist/models/AppError.d.js +2 -0
  34. package/dist/models/AppError.d.js.map +7 -0
  35. package/dist/models/Cache.d.js +2 -0
  36. package/dist/models/Cache.d.js.map +7 -0
  37. package/dist/models/JsModules.d.js +2 -0
  38. package/dist/models/JsModules.d.js.map +7 -0
  39. package/dist/providers/CredentialProvider.js +116 -0
  40. package/dist/providers/CredentialProvider.js.map +7 -0
  41. package/dist/providers/SessionCacheProvider.js +111 -0
  42. package/dist/providers/SessionCacheProvider.js.map +7 -0
  43. package/dist/providers/file-provider.js +117 -0
  44. package/dist/providers/file-provider.js.map +7 -0
  45. package/dist/services/ContensisAuthService.js +75 -0
  46. package/dist/services/ContensisAuthService.js.map +7 -0
  47. package/dist/services/ContensisCliService.js +1374 -0
  48. package/dist/services/ContensisCliService.js.map +7 -0
  49. package/dist/shell.js +278 -0
  50. package/dist/shell.js.map +7 -0
  51. package/dist/util/console.printer.js +317 -0
  52. package/dist/util/console.printer.js.map +7 -0
  53. package/dist/util/csv.formatter.js +50 -0
  54. package/dist/util/csv.formatter.js.map +7 -0
  55. package/dist/util/index.js +97 -0
  56. package/dist/util/index.js.map +7 -0
  57. package/dist/util/json.formatter.js +29 -0
  58. package/dist/util/json.formatter.js.map +7 -0
  59. package/dist/util/logger.js +216 -0
  60. package/dist/util/logger.js.map +7 -0
  61. package/dist/util/xml.formatter.js +51 -0
  62. package/dist/util/xml.formatter.js.map +7 -0
  63. package/dist/version.js +29 -0
  64. package/dist/version.js.map +7 -0
  65. package/esbuild.config.js +49 -49
  66. package/headless-setup.sh +6 -6
  67. package/package.json +59 -59
  68. package/src/commands/connect.ts +24 -24
  69. package/src/commands/create.ts +70 -70
  70. package/src/commands/diff.ts +41 -41
  71. package/src/commands/get.ts +214 -214
  72. package/src/commands/globalOptions.ts +127 -127
  73. package/src/commands/import.ts +128 -128
  74. package/src/commands/index.ts +80 -80
  75. package/src/commands/list.ts +116 -116
  76. package/src/commands/login.ts +34 -34
  77. package/src/commands/push.ts +127 -127
  78. package/src/commands/release.ts +32 -32
  79. package/src/commands/remove.ts +85 -85
  80. package/src/commands/set.ts +96 -96
  81. package/src/index.ts +19 -19
  82. package/src/localisation/en-GB.ts +289 -289
  83. package/src/models/AppError.d.ts +40 -40
  84. package/src/models/Cache.d.ts +25 -25
  85. package/src/models/JsModules.d.ts +1 -1
  86. package/src/providers/CredentialProvider.ts +121 -121
  87. package/src/providers/SessionCacheProvider.ts +101 -101
  88. package/src/providers/file-provider.ts +76 -76
  89. package/src/services/ContensisAuthService.ts +70 -70
  90. package/src/services/ContensisCliService.ts +1745 -1745
  91. package/src/shell.ts +270 -270
  92. package/src/util/console.printer.ts +371 -371
  93. package/src/util/csv.formatter.ts +21 -21
  94. package/src/util/index.ts +73 -73
  95. package/src/util/json.formatter.ts +1 -1
  96. package/src/util/logger.ts +234 -234
  97. package/src/util/xml.formatter.ts +20 -20
  98. package/src/version.ts +1 -1
  99. package/tsconfig.json +22 -22
@@ -1,25 +1,25 @@
1
- type SessionCache = {
2
- currentEnvironment?: string;
3
- currentTimestamp: string;
4
- environments: {
5
- [alias: string]: EnvironmentCache;
6
- };
7
- history: string[];
8
- };
9
-
10
- type EnvironmentCache = {
11
- lastUserId: string;
12
- passwordFallback?: string;
13
- authToken?: string;
14
- currentProject?: string;
15
- projects: string[];
16
- history: CliCommand[];
17
- versionStatus: 'latest' | 'published';
18
- };
19
-
20
- type CliCommand = {
21
- createdDate: string;
22
- createdUserId: string;
23
- commandText: string;
24
- result?: any;
25
- };
1
+ type SessionCache = {
2
+ currentEnvironment?: string;
3
+ currentTimestamp: string;
4
+ environments: {
5
+ [alias: string]: EnvironmentCache;
6
+ };
7
+ history: string[];
8
+ };
9
+
10
+ type EnvironmentCache = {
11
+ lastUserId: string;
12
+ passwordFallback?: string;
13
+ authToken?: string;
14
+ currentProject?: string;
15
+ projects: string[];
16
+ history: CliCommand[];
17
+ versionStatus: 'latest' | 'published';
18
+ };
19
+
20
+ type CliCommand = {
21
+ createdDate: string;
22
+ createdUserId: string;
23
+ commandText: string;
24
+ result?: any;
25
+ };
@@ -1 +1 @@
1
- declare module 'inquirer-command-prompt';
1
+ declare module 'inquirer-command-prompt';
@@ -1,121 +1,121 @@
1
- import keytar from 'keytar';
2
- import to from 'await-to-js';
3
- import { Logger } from '~/util/logger';
4
-
5
- const SERVICE_NAME = 'contensis-cli';
6
-
7
- interface Remarks {
8
- secure: boolean;
9
- }
10
-
11
- class CredentialProvider {
12
- private serviceId: string;
13
- private keytar!: typeof keytar;
14
- private userId: string = '';
15
- private passwordFallback?: string;
16
-
17
- current: {
18
- account: string;
19
- password: string;
20
- } | null = null;
21
- remarks: Remarks = { secure: false };
22
-
23
- constructor(
24
- { userId, alias }: { userId: string; alias?: string },
25
- passwordFallback?: string
26
- ) {
27
- this.serviceId =
28
- typeof alias !== 'undefined' ? `${SERVICE_NAME}_${alias}` : SERVICE_NAME;
29
- this.userId = userId;
30
- this.passwordFallback = passwordFallback;
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
-
57
- Init = async (): Promise<[Error, CredentialProvider]> => {
58
- await this.Import();
59
- const [err, stored] = (await to(
60
- this.keytar.findCredentials(this.serviceId)
61
- )) as [
62
- Error,
63
- {
64
- account: string;
65
- password: string;
66
- }[]
67
- ];
68
- if (err && this.passwordFallback) {
69
- this.current = {
70
- account: this.userId,
71
- password: this.passwordFallback,
72
- };
73
- }
74
- if (!err) {
75
- this.remarks = { secure: true };
76
- this.current =
77
- stored?.find(
78
- u => u?.account?.toLowerCase() === this.userId.toLowerCase()
79
- ) || null;
80
-
81
- if (!this.current && this.passwordFallback) {
82
- await this.Save(this.passwordFallback);
83
- return await this.Init();
84
- }
85
- }
86
- return [err, this];
87
- };
88
-
89
- Save = async (password: string) => {
90
- const [err] = await to(
91
- this.keytar.setPassword(this.serviceId, this.userId, password)
92
- );
93
-
94
- // if (!err) Logger.info(`${this.serviceId} - credentials saved`);
95
- return err && !this.passwordFallback ? err : true;
96
- };
97
-
98
- Delete = async () => {
99
- if (this.passwordFallback) {
100
- this.passwordFallback = undefined;
101
- return true;
102
- } else {
103
- const [err] = await to(
104
- this.keytar.deletePassword(this.serviceId, this.userId)
105
- );
106
-
107
- Logger.warning(`${this.serviceId} - invalid credentials removed`);
108
- return err || true;
109
- }
110
- };
111
-
112
- // GetPassword = async () => {
113
- // const [err, password] = await to(
114
- // keytar.getPassword(this.serviceId, this.userId)
115
- // );
116
-
117
- // return err || password;
118
- // };
119
- }
120
-
121
- export default CredentialProvider;
1
+ import keytar from 'keytar';
2
+ import to from 'await-to-js';
3
+ import { Logger } from '~/util/logger';
4
+
5
+ const SERVICE_NAME = 'contensis-cli';
6
+
7
+ interface Remarks {
8
+ secure: boolean;
9
+ }
10
+
11
+ class CredentialProvider {
12
+ private serviceId: string;
13
+ private keytar!: typeof keytar;
14
+ private userId: string = '';
15
+ private passwordFallback?: string;
16
+
17
+ current: {
18
+ account: string;
19
+ password: string;
20
+ } | null = null;
21
+ remarks: Remarks = { secure: false };
22
+
23
+ constructor(
24
+ { userId, alias }: { userId: string; alias?: string },
25
+ passwordFallback?: string
26
+ ) {
27
+ this.serviceId =
28
+ typeof alias !== 'undefined' ? `${SERVICE_NAME}_${alias}` : SERVICE_NAME;
29
+ this.userId = userId;
30
+ this.passwordFallback = passwordFallback;
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
+
57
+ Init = async (): Promise<[Error, CredentialProvider]> => {
58
+ await this.Import();
59
+ const [err, stored] = (await to(
60
+ this.keytar.findCredentials(this.serviceId)
61
+ )) as [
62
+ Error,
63
+ {
64
+ account: string;
65
+ password: string;
66
+ }[]
67
+ ];
68
+ if (err && this.passwordFallback) {
69
+ this.current = {
70
+ account: this.userId,
71
+ password: this.passwordFallback,
72
+ };
73
+ }
74
+ if (!err) {
75
+ this.remarks = { secure: true };
76
+ this.current =
77
+ stored?.find(
78
+ u => u?.account?.toLowerCase() === this.userId.toLowerCase()
79
+ ) || null;
80
+
81
+ if (!this.current && this.passwordFallback) {
82
+ await this.Save(this.passwordFallback);
83
+ return await this.Init();
84
+ }
85
+ }
86
+ return [err, this];
87
+ };
88
+
89
+ Save = async (password: string) => {
90
+ const [err] = await to(
91
+ this.keytar.setPassword(this.serviceId, this.userId, password)
92
+ );
93
+
94
+ // if (!err) Logger.info(`${this.serviceId} - credentials saved`);
95
+ return err && !this.passwordFallback ? err : true;
96
+ };
97
+
98
+ Delete = async () => {
99
+ if (this.passwordFallback) {
100
+ this.passwordFallback = undefined;
101
+ return true;
102
+ } else {
103
+ const [err] = await to(
104
+ this.keytar.deletePassword(this.serviceId, this.userId)
105
+ );
106
+
107
+ Logger.warning(`${this.serviceId} - invalid credentials removed`);
108
+ return err || true;
109
+ }
110
+ };
111
+
112
+ // GetPassword = async () => {
113
+ // const [err, password] = await to(
114
+ // keytar.getPassword(this.serviceId, this.userId)
115
+ // );
116
+
117
+ // return err || password;
118
+ // };
119
+ }
120
+
121
+ export default CredentialProvider;
@@ -1,101 +1,101 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import clone from 'lodash/cloneDeep';
4
- import mergeWith from 'lodash/mergeWith';
5
- import unionBy from 'lodash/unionBy';
6
- import { appRootDir } from './file-provider';
7
- import { isJson, tryParse } from '~/util';
8
- import { Logger } from '~/util/logger';
9
-
10
- class SessionCacheProvider {
11
- private localFilePath: string;
12
- private cache = {} as SessionCache;
13
-
14
- constructor() {
15
- this.localFilePath = path.join(appRootDir, 'environments.json');
16
- this.cache = {
17
- currentTimestamp: new Date().toISOString(),
18
- environments: {},
19
- history: [],
20
- };
21
- this.ReadCacheFromDisk();
22
- }
23
-
24
- private ReadCacheFromDisk = () => {
25
- try {
26
- if (fs.existsSync(this.localFilePath)) {
27
- const raw = fs.readFileSync(this.localFilePath, 'utf-8');
28
- if (isJson(raw)) this.cache = tryParse(raw);
29
- } else {
30
- this.WriteCacheToDisk();
31
- }
32
- } catch (ex) {
33
- // Problem reading or parsing cache file
34
- }
35
- };
36
-
37
- private WriteCacheToDisk = () => {
38
- try {
39
- fs.writeFileSync(this.localFilePath, JSON.stringify(this.cache, null, 2));
40
- } catch (ex) {
41
- // Problem writing session cache to file
42
- }
43
- };
44
-
45
- Get = () => clone(this.cache);
46
-
47
- Update = (updateContent: Partial<SessionCache>) => {
48
- try {
49
- this.cache = mergeWith(this.cache, updateContent, (val, src, key) => {
50
- if (
51
- key === 'history' &&
52
- ((src?.[0] &&
53
- typeof src[0] === 'object' &&
54
- 'createdDate' in src[0]) ||
55
- (val?.[0] && typeof val[0] === 'object' && 'createdDate' in val[0]))
56
- ) {
57
- return unionBy(val, src, 'createdDate');
58
- }
59
- if (key === 'projects')
60
- return Array.isArray(val) ? [...new Set([...val, ...src])] : src;
61
-
62
- if (Array.isArray(val)) return val.concat(src);
63
- });
64
- this.cache.currentTimestamp = new Date().toISOString();
65
- this.WriteCacheToDisk();
66
- } catch (ex: any) {
67
- // Problem merging cache data for update
68
- Logger.error(`Problem updating environments.json`);
69
- Logger.error(ex);
70
- }
71
- return this.Get();
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
- };
99
- }
100
-
101
- export default SessionCacheProvider;
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import clone from 'lodash/cloneDeep';
4
+ import mergeWith from 'lodash/mergeWith';
5
+ import unionBy from 'lodash/unionBy';
6
+ import { appRootDir } from './file-provider';
7
+ import { isJson, tryParse } from '~/util';
8
+ import { Logger } from '~/util/logger';
9
+
10
+ class SessionCacheProvider {
11
+ private localFilePath: string;
12
+ private cache = {} as SessionCache;
13
+
14
+ constructor() {
15
+ this.localFilePath = path.join(appRootDir, 'environments.json');
16
+ this.cache = {
17
+ currentTimestamp: new Date().toISOString(),
18
+ environments: {},
19
+ history: [],
20
+ };
21
+ this.ReadCacheFromDisk();
22
+ }
23
+
24
+ private ReadCacheFromDisk = () => {
25
+ try {
26
+ if (fs.existsSync(this.localFilePath)) {
27
+ const raw = fs.readFileSync(this.localFilePath, 'utf-8');
28
+ if (isJson(raw)) this.cache = tryParse(raw);
29
+ } else {
30
+ this.WriteCacheToDisk();
31
+ }
32
+ } catch (ex) {
33
+ // Problem reading or parsing cache file
34
+ }
35
+ };
36
+
37
+ private WriteCacheToDisk = () => {
38
+ try {
39
+ fs.writeFileSync(this.localFilePath, JSON.stringify(this.cache, null, 2));
40
+ } catch (ex) {
41
+ // Problem writing session cache to file
42
+ }
43
+ };
44
+
45
+ Get = () => clone(this.cache);
46
+
47
+ Update = (updateContent: Partial<SessionCache>) => {
48
+ try {
49
+ this.cache = mergeWith(this.cache, updateContent, (val, src, key) => {
50
+ if (
51
+ key === 'history' &&
52
+ ((src?.[0] &&
53
+ typeof src[0] === 'object' &&
54
+ 'createdDate' in src[0]) ||
55
+ (val?.[0] && typeof val[0] === 'object' && 'createdDate' in val[0]))
56
+ ) {
57
+ return unionBy(val, src, 'createdDate');
58
+ }
59
+ if (key === 'projects')
60
+ return Array.isArray(val) ? [...new Set([...val, ...src])] : src;
61
+
62
+ if (Array.isArray(val)) return val.concat(src);
63
+ });
64
+ this.cache.currentTimestamp = new Date().toISOString();
65
+ this.WriteCacheToDisk();
66
+ } catch (ex: any) {
67
+ // Problem merging cache data for update
68
+ Logger.error(`Problem updating environments.json`);
69
+ Logger.error(ex);
70
+ }
71
+ return this.Get();
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
+ };
99
+ }
100
+
101
+ export default SessionCacheProvider;
@@ -1,76 +1,76 @@
1
- import fs from 'fs';
2
- import { homedir } from 'os';
3
- import path from 'path';
4
- import { tryParse } from '~/util';
5
-
6
- const userHomeDir = homedir();
7
- export const appRootDir = path.join(userHomeDir, '.contensis/');
8
-
9
- export const readJsonFile = <T>(filePath: string) => {
10
- const file = readFile(filePath);
11
- if (file) return tryParse(file) as T | string;
12
- return undefined;
13
- };
14
- export const readFile = (filePath: string) => {
15
- const directoryPath = localPath(filePath);
16
- if (fs.existsSync(directoryPath)) {
17
- const file = fs.readFileSync(directoryPath, 'utf8');
18
- return file;
19
- } else {
20
- return undefined;
21
- }
22
- };
23
-
24
- export const readFiles = (directory: string) => {
25
- const directoryPath = localPath(directory);
26
- if (fs.existsSync(directoryPath)) {
27
- const files = fs.readdirSync(directoryPath);
28
- return files;
29
- } else {
30
- fs.mkdirSync(directoryPath, { recursive: true });
31
- return [];
32
- }
33
- };
34
-
35
- export const writeFile = (filePath: string, content: string) => {
36
- const directoryPath = localPath(filePath);
37
- fs.writeFileSync(directoryPath, content, { encoding: 'utf-8' });
38
- };
39
-
40
- export const removeFile = (filePath: string) => {
41
- const directoryPath = localPath(filePath);
42
- if (fs.existsSync(directoryPath)) {
43
- fs.rmSync(directoryPath);
44
- }
45
- };
46
-
47
- export const moveFile = (file: string, fromPath: string, toPath: string) => {
48
- const from = path.join(appRootDir, `${fromPath}${file}`);
49
- const to = path.join(appRootDir, `${toPath}${file}`);
50
- if (fs.existsSync(from)) {
51
- checkDir(toPath);
52
- // if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });
53
-
54
- fs.rename(from, to, err => {
55
- if (err)
56
- console.error(
57
- `Could not rename file "${file}" from: ${fromPath} to: ${toPath}`,
58
- err
59
- );
60
- console.info(`Renamed file "${file}" from: ${fromPath} to: ${toPath}`);
61
- });
62
- } else {
63
- console.error(
64
- `Could not rename file "${file}" from: ${fromPath} to: ${toPath}\nFile does not exist!`
65
- );
66
- }
67
- };
68
-
69
- export const checkDir = (filePath: string) => {
70
- const directoryPath = path.dirname(localPath(filePath));
71
- if (!fs.existsSync(directoryPath))
72
- fs.mkdirSync(directoryPath, { recursive: true });
73
- };
74
-
75
- export const localPath = (filePath: string) =>
76
- path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);
1
+ import fs from 'fs';
2
+ import { homedir } from 'os';
3
+ import path from 'path';
4
+ import { tryParse } from '~/util';
5
+
6
+ const userHomeDir = homedir();
7
+ export const appRootDir = path.join(userHomeDir, '.contensis/');
8
+
9
+ export const readJsonFile = <T>(filePath: string) => {
10
+ const file = readFile(filePath);
11
+ if (file) return tryParse(file) as T | string;
12
+ return undefined;
13
+ };
14
+ export const readFile = (filePath: string) => {
15
+ const directoryPath = localPath(filePath);
16
+ if (fs.existsSync(directoryPath)) {
17
+ const file = fs.readFileSync(directoryPath, 'utf8');
18
+ return file;
19
+ } else {
20
+ return undefined;
21
+ }
22
+ };
23
+
24
+ export const readFiles = (directory: string) => {
25
+ const directoryPath = localPath(directory);
26
+ if (fs.existsSync(directoryPath)) {
27
+ const files = fs.readdirSync(directoryPath);
28
+ return files;
29
+ } else {
30
+ fs.mkdirSync(directoryPath, { recursive: true });
31
+ return [];
32
+ }
33
+ };
34
+
35
+ export const writeFile = (filePath: string, content: string) => {
36
+ const directoryPath = localPath(filePath);
37
+ fs.writeFileSync(directoryPath, content, { encoding: 'utf-8' });
38
+ };
39
+
40
+ export const removeFile = (filePath: string) => {
41
+ const directoryPath = localPath(filePath);
42
+ if (fs.existsSync(directoryPath)) {
43
+ fs.rmSync(directoryPath);
44
+ }
45
+ };
46
+
47
+ export const moveFile = (file: string, fromPath: string, toPath: string) => {
48
+ const from = path.join(appRootDir, `${fromPath}${file}`);
49
+ const to = path.join(appRootDir, `${toPath}${file}`);
50
+ if (fs.existsSync(from)) {
51
+ checkDir(toPath);
52
+ // if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });
53
+
54
+ fs.rename(from, to, err => {
55
+ if (err)
56
+ console.error(
57
+ `Could not rename file "${file}" from: ${fromPath} to: ${toPath}`,
58
+ err
59
+ );
60
+ console.info(`Renamed file "${file}" from: ${fromPath} to: ${toPath}`);
61
+ });
62
+ } else {
63
+ console.error(
64
+ `Could not rename file "${file}" from: ${fromPath} to: ${toPath}\nFile does not exist!`
65
+ );
66
+ }
67
+ };
68
+
69
+ export const checkDir = (filePath: string) => {
70
+ const directoryPath = path.dirname(localPath(filePath));
71
+ if (!fs.existsSync(directoryPath))
72
+ fs.mkdirSync(directoryPath, { recursive: true });
73
+ };
74
+
75
+ export const localPath = (filePath: string) =>
76
+ path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);