contensis-cli 1.0.0-beta.5 → 1.0.0-beta.51
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/README.md +669 -74
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +30 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/get.js +61 -12
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +22 -17
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +36 -10
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +9 -1
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +19 -8
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +8 -4
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/release.js +47 -0
- package/dist/commands/release.js.map +7 -0
- package/dist/commands/remove.js +10 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +53 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/localisation/en-GB.js +97 -47
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/providers/CredentialProvider.js +36 -7
- package/dist/providers/CredentialProvider.js.map +3 -3
- package/dist/providers/SessionCacheProvider.js +21 -1
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/providers/file-provider.js +8 -4
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +600 -336
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +27 -10
- package/dist/shell.js.map +3 -3
- package/dist/util/console.printer.js +170 -47
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/index.js +5 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +45 -13
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +37 -8
- package/src/commands/diff.ts +41 -0
- package/src/commands/get.ts +80 -5
- package/src/commands/globalOptions.ts +18 -17
- package/src/commands/import.ts +43 -4
- package/src/commands/index.ts +9 -1
- package/src/commands/list.ts +35 -9
- package/src/commands/login.ts +3 -2
- package/src/commands/push.ts +9 -2
- package/src/commands/release.ts +32 -0
- package/src/commands/remove.ts +12 -4
- package/src/commands/set.ts +65 -9
- package/src/localisation/en-GB.ts +142 -64
- package/src/providers/CredentialProvider.ts +39 -6
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +8 -4
- package/src/services/ContensisCliService.ts +742 -387
- package/src/shell.ts +31 -11
- package/src/util/console.printer.ts +234 -66
- package/src/util/index.ts +12 -6
- package/src/util/logger.ts +84 -15
- package/src/version.ts +1 -1
package/src/commands/remove.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
3
|
import { shell } from '~/shell';
|
|
4
|
-
import { commit, mapContensisOpts } from './globalOptions';
|
|
4
|
+
import { commit, mapContensisOpts, zenql } from './globalOptions';
|
|
5
5
|
|
|
6
6
|
export const makeRemoveCommand = () => {
|
|
7
7
|
const remove = new Command()
|
|
8
8
|
.command('remove')
|
|
9
|
+
.description('remove command')
|
|
10
|
+
.addHelpText('after', `\n`)
|
|
9
11
|
.showHelpAfterError(true)
|
|
10
12
|
.exitOverride();
|
|
11
13
|
|
|
12
14
|
remove
|
|
13
15
|
.command('project')
|
|
16
|
+
.description('remove an entire project')
|
|
14
17
|
.argument('<projectId>', 'the project id to delete')
|
|
15
18
|
.usage('<projectId>')
|
|
19
|
+
.addHelpText('after', `\n`)
|
|
16
20
|
.action(async (projectId, opts) => {
|
|
17
21
|
const project = await cliCommand(
|
|
18
22
|
['remove', 'project', projectId],
|
|
19
23
|
opts
|
|
20
24
|
).SetProject(projectId);
|
|
21
|
-
if (project) await shell().
|
|
25
|
+
if (project) await shell().restart();
|
|
22
26
|
});
|
|
27
|
+
|
|
23
28
|
remove
|
|
24
29
|
.command('key')
|
|
30
|
+
.description('remove api key')
|
|
25
31
|
.argument('<id>', 'the id of the API key to delete')
|
|
26
32
|
.usage('<id>')
|
|
27
33
|
.addHelpText(
|
|
@@ -37,6 +43,7 @@ Example call:
|
|
|
37
43
|
|
|
38
44
|
remove
|
|
39
45
|
.command('components')
|
|
46
|
+
.description('delete components')
|
|
40
47
|
.argument('<id...>', 'the id(s) of the components to delete')
|
|
41
48
|
.addOption(commit)
|
|
42
49
|
.usage('<id> [--commit]')
|
|
@@ -49,13 +56,14 @@ Example call:
|
|
|
49
56
|
)
|
|
50
57
|
.action(async (id: string[], opts) => {
|
|
51
58
|
await cliCommand(
|
|
52
|
-
['remove', 'components', id.join('
|
|
59
|
+
['remove', 'components', id.join(' ')],
|
|
53
60
|
opts
|
|
54
61
|
).RemoveComponents(id, opts.commit);
|
|
55
62
|
});
|
|
56
63
|
|
|
57
64
|
remove
|
|
58
65
|
.command('contenttypes')
|
|
66
|
+
.description('delete content types')
|
|
59
67
|
.argument('<id...>', 'the id(s) of the content types to delete')
|
|
60
68
|
.addOption(commit)
|
|
61
69
|
.usage('<id> [--commit]')
|
|
@@ -68,7 +76,7 @@ Example call:
|
|
|
68
76
|
)
|
|
69
77
|
.action(async (id: string[], opts) => {
|
|
70
78
|
await cliCommand(
|
|
71
|
-
['remove', 'contenttypes', id.join('
|
|
79
|
+
['remove', 'contenttypes', id.join(' ')],
|
|
72
80
|
opts
|
|
73
81
|
).RemoveContentTypes(id, opts.commit);
|
|
74
82
|
});
|
package/src/commands/set.ts
CHANGED
|
@@ -5,35 +5,91 @@ import { shell } from '~/shell';
|
|
|
5
5
|
export const makeSetCommand = () => {
|
|
6
6
|
const set = new Command()
|
|
7
7
|
.command('set')
|
|
8
|
+
.description('set command')
|
|
9
|
+
.addHelpText('after', `\n`)
|
|
8
10
|
.showHelpAfterError(true)
|
|
9
11
|
.exitOverride();
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
const project = set
|
|
11
14
|
.command('project')
|
|
15
|
+
.description('set current working project')
|
|
12
16
|
.argument('<projectId>', 'the project id to work with')
|
|
13
17
|
.usage('<projectId>')
|
|
18
|
+
.addHelpText(
|
|
19
|
+
'after',
|
|
20
|
+
`
|
|
21
|
+
Example call:
|
|
22
|
+
> set project website\n`
|
|
23
|
+
)
|
|
14
24
|
.action(async projectId => {
|
|
15
|
-
const
|
|
25
|
+
const nextProjectId = cliCommand([
|
|
16
26
|
'set',
|
|
17
27
|
'project',
|
|
18
28
|
projectId,
|
|
19
29
|
]).SetProject(projectId);
|
|
20
|
-
if (
|
|
30
|
+
if (nextProjectId) await shell().restart();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
project
|
|
34
|
+
.command('name')
|
|
35
|
+
.description('update project name')
|
|
36
|
+
.argument('<"Project name">', 'update the current project name')
|
|
37
|
+
.usage('<"Project name">')
|
|
38
|
+
.addHelpText(
|
|
39
|
+
'after',
|
|
40
|
+
`
|
|
41
|
+
Example call:
|
|
42
|
+
> set project name "Project name"\n`
|
|
43
|
+
)
|
|
44
|
+
.action(async (name: string, opts) => {
|
|
45
|
+
const success = await cliCommand(
|
|
46
|
+
['set', 'project', 'name'],
|
|
47
|
+
opts
|
|
48
|
+
).UpdateProject({
|
|
49
|
+
name,
|
|
50
|
+
});
|
|
51
|
+
if (success) await shell().restart();
|
|
21
52
|
});
|
|
53
|
+
|
|
54
|
+
project
|
|
55
|
+
.command('description')
|
|
56
|
+
.description('update project description')
|
|
57
|
+
.argument(
|
|
58
|
+
'<"Project description">',
|
|
59
|
+
'update the current project description'
|
|
60
|
+
)
|
|
61
|
+
.usage('<"Project description">')
|
|
62
|
+
.addHelpText(
|
|
63
|
+
'after',
|
|
64
|
+
`
|
|
65
|
+
Example call:
|
|
66
|
+
> set project description "Description of project"\n`
|
|
67
|
+
)
|
|
68
|
+
.action(async (description: string, opts) => {
|
|
69
|
+
const success = await cliCommand(
|
|
70
|
+
['set', 'project', 'description'],
|
|
71
|
+
opts
|
|
72
|
+
).UpdateProject({
|
|
73
|
+
description,
|
|
74
|
+
});
|
|
75
|
+
if (success) await shell().restart();
|
|
76
|
+
});
|
|
77
|
+
|
|
22
78
|
set
|
|
23
79
|
.command('version')
|
|
80
|
+
.description('set content version')
|
|
24
81
|
.addArgument(
|
|
25
82
|
new Argument('<versionStatus>', 'content version status')
|
|
26
83
|
.choices(['latest', 'published'])
|
|
27
84
|
.default('latest')
|
|
28
85
|
)
|
|
29
86
|
.usage('<latest/published>')
|
|
87
|
+
.addHelpText('after', `\n`)
|
|
30
88
|
.action(async versionStatus => {
|
|
31
|
-
const success =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]).SetVersion(versionStatus);
|
|
36
|
-
if (success) await shell().start();
|
|
89
|
+
const success = cliCommand(['set', 'version', versionStatus]).SetVersion(
|
|
90
|
+
versionStatus
|
|
91
|
+
);
|
|
92
|
+
if (success) await shell().restart();
|
|
37
93
|
});
|
|
38
94
|
|
|
39
95
|
return set;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BlockRunningStatus,
|
|
3
|
+
MigrateModelsResult,
|
|
4
|
+
MigrateStatus,
|
|
5
|
+
} from 'migratortron';
|
|
2
6
|
import { Logger } from '~/util/logger';
|
|
3
7
|
|
|
4
8
|
export const LogMessages = {
|
|
5
9
|
app: {
|
|
6
10
|
contensis: () => 'Contensis',
|
|
7
11
|
quit: () => `Goodbye 👋\n`,
|
|
8
|
-
startup: () =>
|
|
9
|
-
|
|
12
|
+
startup: (version: string) =>
|
|
13
|
+
`v${version} © 2001-${new Date().getFullYear()} Zengenti 🇬🇧. \n - Creators of Contensis and purveyors of other fine software\n\n👋 Welcome to the contensis-cli\n`,
|
|
10
14
|
help: () =>
|
|
11
15
|
'Press [CTRL]+[C] or type "quit" to return to your system shell\nPress [TAB] for suggestions\n',
|
|
12
16
|
suggestions: () =>
|
|
@@ -73,8 +77,10 @@ export const LogMessages = {
|
|
|
73
77
|
'the shared secret to use when logging in with a client id',
|
|
74
78
|
},
|
|
75
79
|
},
|
|
76
|
-
passwordPrompt: (env
|
|
77
|
-
|
|
80
|
+
passwordPrompt: (env?: string, userId?: string) =>
|
|
81
|
+
userId
|
|
82
|
+
? `Enter password for ${userId}@${env}:`
|
|
83
|
+
: `Please enter a password`,
|
|
78
84
|
failed: (env: string, userId: string) =>
|
|
79
85
|
`Unable to login to ${env} as ${userId}`,
|
|
80
86
|
success: (env: string, userId: string) =>
|
|
@@ -87,49 +93,38 @@ export const LogMessages = {
|
|
|
87
93
|
projects: {
|
|
88
94
|
list: () => `Available projects:`,
|
|
89
95
|
noList: () => `Cannot retrieve projects list`,
|
|
90
|
-
set: (projectId: string) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`[${env}] ${commit ? `Deleted` : `Will delete`} content type "${id}"`,
|
|
105
|
-
failedRemove: (env: string, id: string) =>
|
|
106
|
-
`[${env}] Unable to delete content type "${id}"`,
|
|
107
|
-
},
|
|
108
|
-
components: {
|
|
109
|
-
list: (projectId: string) => `Components in "${projectId}":`,
|
|
110
|
-
noList: (projectId: string) =>
|
|
111
|
-
`[${projectId}] Cannot retrieve components list`,
|
|
112
|
-
get: (projectId: string, componentId: string) =>
|
|
113
|
-
`[${projectId}] Component "${componentId}"`,
|
|
114
|
-
failedGet: (projectId: string, componentId: string) =>
|
|
115
|
-
`[${projectId}] Unable to get component "${componentId}"`,
|
|
116
|
-
created: (projectId: string, componentId: string, status?: string) =>
|
|
117
|
-
`[${projectId}] Component ${status}d "${componentId}"`,
|
|
118
|
-
removed: (env: string, id: string, commit: boolean) =>
|
|
119
|
-
`[${env}] ${commit ? `Deleted` : `Will delete`} component "${id}"`,
|
|
120
|
-
failedRemove: (env: string, id: string) =>
|
|
121
|
-
`[${env}] Unable to delete component "${id}"`,
|
|
122
|
-
},
|
|
123
|
-
version: {
|
|
124
|
-
set: (env: string, versionStatus: string) =>
|
|
125
|
-
`[${env}] Content version status set to "${versionStatus}"`,
|
|
126
|
-
invalid: (versionStatus: string) =>
|
|
127
|
-
`Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
|
|
128
|
-
noEnv: () =>
|
|
129
|
-
`No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
|
|
96
|
+
set: (projectId: string) =>
|
|
97
|
+
`Current project is set to ${Logger.highlightText(projectId)}`,
|
|
98
|
+
failedSet: (projectId: string) =>
|
|
99
|
+
`Project ${Logger.highlightText(projectId)} not found`,
|
|
100
|
+
tip: () =>
|
|
101
|
+
`You need to set your current working project with "set project {projectId}"`,
|
|
102
|
+
created: (env: string, id: string) =>
|
|
103
|
+
`[${env}] Created project ${Logger.highlightText(id)}`,
|
|
104
|
+
failedCreate: (env: string, id: string) =>
|
|
105
|
+
`[${env}] Unable to create project ${Logger.highlightText(id)}`,
|
|
106
|
+
updated: (env: string, id: string) =>
|
|
107
|
+
`[${env}] Updated project ${Logger.highlightText(id)}`,
|
|
108
|
+
failedUpdate: (env: string, id: string) =>
|
|
109
|
+
`[${env}] Unable to update project ${Logger.highlightText(id)}`,
|
|
130
110
|
},
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
migrate: {
|
|
112
|
+
models: {
|
|
113
|
+
result: (
|
|
114
|
+
status: keyof MigrateModelsResult['project']['contentTypes']
|
|
115
|
+
) => {
|
|
116
|
+
switch (status) {
|
|
117
|
+
case 'created':
|
|
118
|
+
case 'updated':
|
|
119
|
+
return Logger.successText;
|
|
120
|
+
case 'errors':
|
|
121
|
+
return Logger.errorText;
|
|
122
|
+
default:
|
|
123
|
+
return Logger.infoText;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
status: (status: MigrateStatus) => {
|
|
133
128
|
switch (status) {
|
|
134
129
|
case 'no change':
|
|
135
130
|
return Logger.successText;
|
|
@@ -145,23 +140,75 @@ export const LogMessages = {
|
|
|
145
140
|
return Logger.infoText;
|
|
146
141
|
}
|
|
147
142
|
},
|
|
143
|
+
},
|
|
144
|
+
models: {
|
|
145
|
+
list: (projectId: string) =>
|
|
146
|
+
`Content models in ${Logger.highlightText(projectId)}:`,
|
|
147
|
+
noList: (projectId: string) =>
|
|
148
|
+
`[${projectId}] Cannot retrieve content models`,
|
|
149
|
+
get: (projectId: string, id: string) =>
|
|
150
|
+
`[${projectId}] Content models ${Logger.infoText(`[ ${id} ]`)}`,
|
|
151
|
+
failedGet: (projectId: string, id: string) =>
|
|
152
|
+
`[${projectId}] Unable to get content models ${Logger.highlightText(id)}`,
|
|
153
|
+
},
|
|
154
|
+
contenttypes: {
|
|
155
|
+
list: (projectId: string) =>
|
|
156
|
+
`Content types in ${Logger.highlightText(projectId)}:`,
|
|
157
|
+
get: (projectId: string, id: string) =>
|
|
158
|
+
`[${projectId}] Content type ${Logger.highlightText(id)}`,
|
|
159
|
+
failedGet: (projectId: string, id: string) =>
|
|
160
|
+
`[${projectId}] Unable to get content type ${Logger.highlightText(id)}`,
|
|
161
|
+
created: (projectId: string, id: string, status?: string) =>
|
|
162
|
+
`[${projectId}] Content type ${status}d ${Logger.highlightText(id)}`,
|
|
163
|
+
removed: (env: string, id: string, commit: boolean) =>
|
|
164
|
+
`[${env}] ${
|
|
165
|
+
commit ? `Deleted` : `Will delete`
|
|
166
|
+
} content type ${Logger.highlightText(id)}`,
|
|
167
|
+
failedRemove: (env: string, id: string) =>
|
|
168
|
+
`[${env}] Unable to delete content type ${Logger.highlightText(id)}`,
|
|
169
|
+
},
|
|
170
|
+
components: {
|
|
171
|
+
list: (projectId: string) =>
|
|
172
|
+
`Components in ${Logger.highlightText(projectId)}:`,
|
|
173
|
+
get: (projectId: string, id: string) =>
|
|
174
|
+
`[${projectId}] Component ${Logger.highlightText(id)}`,
|
|
175
|
+
failedGet: (projectId: string, id: string) =>
|
|
176
|
+
`[${projectId}] Unable to get component ${Logger.highlightText(id)}`,
|
|
177
|
+
created: (projectId: string, id: string, status?: string) =>
|
|
178
|
+
`[${projectId}] Component ${status}d ${Logger.highlightText(id)}`,
|
|
148
179
|
removed: (env: string, id: string, commit: boolean) =>
|
|
149
|
-
`[${env}] ${
|
|
180
|
+
`[${env}] ${
|
|
181
|
+
commit ? `Deleted` : `Will delete`
|
|
182
|
+
} component ${Logger.highlightText(id)}`,
|
|
150
183
|
failedRemove: (env: string, id: string) =>
|
|
151
|
-
`[${env}] Unable to delete
|
|
152
|
-
|
|
184
|
+
`[${env}] Unable to delete component ${Logger.highlightText(id)}`,
|
|
185
|
+
},
|
|
186
|
+
version: {
|
|
187
|
+
set: (env: string, versionStatus: string) =>
|
|
188
|
+
`[${env}] Content version status set to "${versionStatus}"`,
|
|
189
|
+
invalid: (versionStatus: string) =>
|
|
190
|
+
`Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
|
|
191
|
+
noEnv: () =>
|
|
192
|
+
`No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
|
|
193
|
+
},
|
|
194
|
+
entries: {
|
|
195
|
+
removed: (env: string, commit: boolean) =>
|
|
196
|
+
`[${env}] ${commit ? `Deleted` : `Will delete`} entries`,
|
|
197
|
+
failedRemove: (env: string) => `[${env}] Unable to delete entries`,
|
|
198
|
+
notFound: (env: string) => `[${env}] Entries were not found`,
|
|
153
199
|
commitTip: () => ` Add --commit flag to commit the previewed changes`,
|
|
154
200
|
},
|
|
155
201
|
keys: {
|
|
156
202
|
list: (env: string) => `[${env}] API keys:`,
|
|
157
203
|
noList: (env: string) => `[${env}] Cannot retrieve API`,
|
|
158
204
|
created: (env: string, name: string) =>
|
|
159
|
-
`[${env}] Created API key
|
|
205
|
+
`[${env}] Created API key ${Logger.highlightText(name)}`,
|
|
160
206
|
failedCreate: (env: string, name: string) =>
|
|
161
|
-
`[${env}] Unable to create API key
|
|
162
|
-
removed: (env: string, id: string) =>
|
|
207
|
+
`[${env}] Unable to create API key ${Logger.highlightText(name)}`,
|
|
208
|
+
removed: (env: string, id: string) =>
|
|
209
|
+
`[${env}] Deleted API key ${Logger.highlightText(id)}`,
|
|
163
210
|
failedRemove: (env: string, id: string) =>
|
|
164
|
-
`[${env}] Unable to delete API key
|
|
211
|
+
`[${env}] Unable to delete API key ${Logger.highlightText(id)}`,
|
|
165
212
|
},
|
|
166
213
|
blocks: {
|
|
167
214
|
runningStatus: (status: BlockRunningStatus | 'broken') => {
|
|
@@ -180,32 +227,63 @@ export const LogMessages = {
|
|
|
180
227
|
return Logger.infoText(status);
|
|
181
228
|
}
|
|
182
229
|
},
|
|
183
|
-
get: (env: string) =>
|
|
230
|
+
get: (id: string, env: string, projectId?: string) =>
|
|
231
|
+
`[${env}] Block ${id} in project ${projectId}:`,
|
|
184
232
|
list: (env: string, projectId?: string) =>
|
|
185
233
|
`[${env}] Blocks in project ${projectId}:`,
|
|
186
234
|
noList: (env: string, projectId?: string) =>
|
|
187
235
|
`[${env}] Cannot retrieve blocks in project ${projectId}`,
|
|
236
|
+
getLogs: (id: string, branch: string, env: string, projectId?: string) =>
|
|
237
|
+
`[${env}] Requesting logs from block ${Logger.highlightText(
|
|
238
|
+
id
|
|
239
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
240
|
+
failedGetLogs: (id: string, env: string, projectId?: string) =>
|
|
241
|
+
`[${env}] Unable to fetch block logs for ${Logger.highlightText(
|
|
242
|
+
id
|
|
243
|
+
)} in project ${projectId}`,
|
|
188
244
|
tryPush: (id: string, branch: string, env: string, projectId?: string) =>
|
|
189
|
-
`[${env}] Request to push block
|
|
245
|
+
`[${env}] Request to push block ${Logger.highlightText(
|
|
246
|
+
id
|
|
247
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
190
248
|
pushed: (id: string, branch: string, env: string, projectId?: string) =>
|
|
191
|
-
`[${env}] Pushed block
|
|
249
|
+
`[${env}] Pushed block ${Logger.highlightText(
|
|
250
|
+
id
|
|
251
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
192
252
|
failedPush: (id: string, env: string, projectId?: string) =>
|
|
193
|
-
`[${env}] Unable to push block
|
|
253
|
+
`[${env}] Unable to push block ${Logger.highlightText(
|
|
254
|
+
id
|
|
255
|
+
)} in project ${projectId}`,
|
|
256
|
+
released: (id: string, env: string, projectId?: string) =>
|
|
257
|
+
`[${env}] Released block ${Logger.highlightText(
|
|
258
|
+
id
|
|
259
|
+
)} in project ${projectId}`,
|
|
260
|
+
failedRelease: (id: string, env: string, projectId?: string) =>
|
|
261
|
+
`[${env}] Unable to release block ${Logger.highlightText(
|
|
262
|
+
id
|
|
263
|
+
)} in project ${projectId}`,
|
|
194
264
|
deleted: (id: string, env: string, projectId?: string) =>
|
|
195
|
-
`[${env}] Deleted block
|
|
265
|
+
`[${env}] Deleted block ${Logger.highlightText(
|
|
266
|
+
id
|
|
267
|
+
)} in project ${projectId}`,
|
|
196
268
|
failedDelete: (id: string, env: string, projectId?: string) =>
|
|
197
|
-
`[${env}] Unable to delete block
|
|
269
|
+
`[${env}] Unable to delete block ${Logger.highlightText(
|
|
270
|
+
id
|
|
271
|
+
)} in project ${projectId}`,
|
|
198
272
|
},
|
|
199
273
|
webhooks: {
|
|
200
274
|
list: (env: string) => `[${env}] Webhook subscriptions:`,
|
|
201
275
|
noList: (env: string) => `[${env}] Cannot retrieve webhook subscriptions`,
|
|
202
276
|
created: (env: string, name: string) =>
|
|
203
|
-
`[${env}] Created Webhook subscription
|
|
277
|
+
`[${env}] Created Webhook subscription ${Logger.highlightText(name)}`,
|
|
204
278
|
failedCreate: (env: string, name: string) =>
|
|
205
|
-
`[${env}] Unable to create Webhook subscription
|
|
279
|
+
`[${env}] Unable to create Webhook subscription ${Logger.highlightText(
|
|
280
|
+
name
|
|
281
|
+
)}`,
|
|
206
282
|
deleted: (env: string, id: string) =>
|
|
207
|
-
`[${env}] Deleted Webhook subscription
|
|
283
|
+
`[${env}] Deleted Webhook subscription ${Logger.highlightText(id)}`,
|
|
208
284
|
failedDelete: (env: string, id: string) =>
|
|
209
|
-
`[${env}] Unable to delete Webhook subscription
|
|
285
|
+
`[${env}] Unable to delete Webhook subscription ${Logger.highlightText(
|
|
286
|
+
id
|
|
287
|
+
)}`,
|
|
210
288
|
},
|
|
211
289
|
};
|
|
@@ -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,9 +30,34 @@ 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();
|
|
33
59
|
const [err, stored] = (await to(
|
|
34
|
-
keytar.findCredentials(this.serviceId)
|
|
60
|
+
this.keytar.findCredentials(this.serviceId)
|
|
35
61
|
)) as [
|
|
36
62
|
Error,
|
|
37
63
|
{
|
|
@@ -40,8 +66,10 @@ class CredentialProvider {
|
|
|
40
66
|
}[]
|
|
41
67
|
];
|
|
42
68
|
if (err && this.passwordFallback) {
|
|
43
|
-
this.current = {
|
|
44
|
-
|
|
69
|
+
this.current = {
|
|
70
|
+
account: this.userId,
|
|
71
|
+
password: this.passwordFallback,
|
|
72
|
+
};
|
|
45
73
|
}
|
|
46
74
|
if (!err) {
|
|
47
75
|
this.remarks = { secure: true };
|
|
@@ -49,16 +77,21 @@ class CredentialProvider {
|
|
|
49
77
|
stored?.find(
|
|
50
78
|
u => u?.account?.toLowerCase() === this.userId.toLowerCase()
|
|
51
79
|
) || null;
|
|
80
|
+
|
|
81
|
+
if (!this.current && this.passwordFallback) {
|
|
82
|
+
await this.Save(this.passwordFallback);
|
|
83
|
+
return await this.Init();
|
|
84
|
+
}
|
|
52
85
|
}
|
|
53
86
|
return [err, this];
|
|
54
87
|
};
|
|
55
88
|
|
|
56
89
|
Save = async (password: string) => {
|
|
57
90
|
const [err] = await to(
|
|
58
|
-
keytar.setPassword(this.serviceId, this.userId, password)
|
|
91
|
+
this.keytar.setPassword(this.serviceId, this.userId, password)
|
|
59
92
|
);
|
|
60
93
|
|
|
61
|
-
if (!err) Logger.info(`${this.serviceId} - credentials saved`);
|
|
94
|
+
// if (!err) Logger.info(`${this.serviceId} - credentials saved`);
|
|
62
95
|
return err && !this.passwordFallback ? err : true;
|
|
63
96
|
};
|
|
64
97
|
|
|
@@ -68,7 +101,7 @@ class CredentialProvider {
|
|
|
68
101
|
return true;
|
|
69
102
|
} else {
|
|
70
103
|
const [err] = await to(
|
|
71
|
-
keytar.deletePassword(this.serviceId, this.userId)
|
|
104
|
+
this.keytar.deletePassword(this.serviceId, this.userId)
|
|
72
105
|
);
|
|
73
106
|
|
|
74
107
|
Logger.warning(`${this.serviceId} - invalid credentials removed`);
|
|
@@ -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 {
|
|
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(
|
|
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,11 @@
|
|
|
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
|
+
export const appRootDir = path.join(userHomeDir, '.contensis/');
|
|
8
|
+
|
|
6
9
|
export const readJsonFile = <T>(filePath: string) => {
|
|
7
10
|
const file = readFile(filePath);
|
|
8
11
|
if (file) return tryParse(file) as T | string;
|
|
@@ -42,8 +45,8 @@ export const removeFile = (filePath: string) => {
|
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
export const moveFile = (file: string, fromPath: string, toPath: string) => {
|
|
45
|
-
const from = path.join(
|
|
46
|
-
const to = path.join(
|
|
48
|
+
const from = path.join(appRootDir, `${fromPath}${file}`);
|
|
49
|
+
const to = path.join(appRootDir, `${toPath}${file}`);
|
|
47
50
|
if (fs.existsSync(from)) {
|
|
48
51
|
checkDir(toPath);
|
|
49
52
|
// if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });
|
|
@@ -69,4 +72,5 @@ export const checkDir = (filePath: string) => {
|
|
|
69
72
|
fs.mkdirSync(directoryPath, { recursive: true });
|
|
70
73
|
};
|
|
71
74
|
|
|
72
|
-
export const localPath = (filePath: string) =>
|
|
75
|
+
export const localPath = (filePath: string) =>
|
|
76
|
+
path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);
|