contensis-cli 1.0.0-beta.9 → 1.0.0-beta.90

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 +75 -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 +47 -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 +259 -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 +127 -0
  38. package/dist/mappers/DevInit-to-CIWorkflow.js.map +7 -0
  39. package/dist/mappers/DevInit-to-RolePermissions.js +54 -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 +1148 -421
  54. package/dist/services/ContensisCliService.js.map +3 -3
  55. package/dist/services/ContensisDevService.js +309 -0
  56. package/dist/services/ContensisDevService.js.map +7 -0
  57. package/dist/services/ContensisRoleService.js +87 -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 +102 -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 +126 -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 +39 -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 +12 -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 +58 -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 +374 -66
  101. package/src/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.ts +44 -0
  102. package/src/mappers/DevInit-to-CIWorkflow.ts +150 -0
  103. package/src/mappers/DevInit-to-RolePermissions.ts +33 -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 +5 -0
  107. package/src/models/JsModules.d.ts +1 -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 +1458 -518
  112. package/src/services/ContensisDevService.ts +365 -0
  113. package/src/services/ContensisRoleService.ts +76 -0
  114. package/src/shell.ts +68 -18
  115. package/src/util/console.printer.ts +240 -78
  116. package/src/util/diff.ts +113 -0
  117. package/src/util/dotenv.ts +37 -0
  118. package/src/util/find.ts +8 -0
  119. package/src/util/git.ts +130 -0
  120. package/src/util/index.ts +16 -7
  121. package/src/util/logger.ts +145 -31
  122. package/src/util/os.ts +7 -0
  123. package/src/util/timers.ts +24 -0
  124. package/src/util/yaml.ts +13 -0
  125. package/src/version.ts +1 -1
@@ -1,12 +1,19 @@
1
- import { BlockRunningStatus, MigrateStatus } from 'migratortron';
1
+ import {
2
+ BlockActionType,
3
+ BlockRunningStatus,
4
+ MigrateModelsResult,
5
+ MigrateStatus,
6
+ } from 'migratortron';
7
+ import { GitHelper } from '~/util/git';
2
8
  import { Logger } from '~/util/logger';
9
+ import { winSlash } from '~/util/os';
3
10
 
4
11
  export const LogMessages = {
5
12
  app: {
6
13
  contensis: () => 'Contensis',
7
14
  quit: () => `Goodbye 👋\n`,
8
- startup: () =>
9
- 2001-${new Date().getFullYear()} Zengenti 🇬🇧. \n - Creators of Contensis and purveyors of other fine software\n\n👋 Welcome to the contensis-cli\n`,
15
+ startup: (version: string) =>
16
+ `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
17
  help: () =>
11
18
  'Press [CTRL]+[C] or type "quit" to return to your system shell\nPress [TAB] for suggestions\n',
12
19
  suggestions: () =>
@@ -73,8 +80,10 @@ export const LogMessages = {
73
80
  'the shared secret to use when logging in with a client id',
74
81
  },
75
82
  },
76
- passwordPrompt: (env: string, userId: string) =>
77
- `Enter password for ${userId}@${env}:`,
83
+ passwordPrompt: (env?: string, userId?: string) =>
84
+ userId
85
+ ? `Enter password for ${userId}@${env}:`
86
+ : `Please enter a password`,
78
87
  failed: (env: string, userId: string) =>
79
88
  `Unable to login to ${env} as ${userId}`,
80
89
  success: (env: string, userId: string) =>
@@ -87,49 +96,38 @@ export const LogMessages = {
87
96
  projects: {
88
97
  list: () => `Available projects:`,
89
98
  noList: () => `Cannot retrieve projects list`,
90
- set: (projectId: string) => `Current project is set to "${projectId}"`,
91
- failedSet: (projectId: string) => `Project "${projectId}" not found`,
92
- },
93
- contenttypes: {
94
- list: (projectId: string) => `Content types in "${projectId}":`,
95
- noList: (projectId: string) =>
96
- `[${projectId}] Cannot retrieve content types list`,
97
- get: (projectId: string, contentTypeId: string) =>
98
- `[${projectId}] Content type "${contentTypeId}"`,
99
- failedGet: (projectId: string, contentTypeId: string) =>
100
- `[${projectId}] Unable to get content type "${contentTypeId}"`,
101
- created: (projectId: string, componentId: string, status?: string) =>
102
- `[${projectId}] Content type ${status}d "${componentId}"`,
103
- removed: (env: string, id: string, commit: boolean) =>
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}"`,
99
+ set: (projectId: string) =>
100
+ `Current project is set to ${Logger.highlightText(projectId)}`,
101
+ failedSet: (projectId: string) =>
102
+ `Project ${Logger.highlightText(projectId)} not found`,
103
+ tip: () =>
104
+ `You need to set your current working project with "set project {projectId}"`,
105
+ created: (env: string, id: string) =>
106
+ `[${env}] Created project ${Logger.highlightText(id)}`,
107
+ failedCreate: (env: string, id: string) =>
108
+ `[${env}] Unable to create project ${Logger.highlightText(id)}`,
109
+ updated: (env: string, id: string) =>
110
+ `[${env}] Updated project ${Logger.highlightText(id)}`,
111
+ failedUpdate: (env: string, id: string) =>
112
+ `[${env}] Unable to update project ${Logger.highlightText(id)}`,
130
113
  },
131
- entries: {
132
- migrateStatus: (status: MigrateStatus) => {
114
+ migrate: {
115
+ models: {
116
+ result: (
117
+ status: keyof MigrateModelsResult['project']['contentTypes']
118
+ ) => {
119
+ switch (status) {
120
+ case 'created':
121
+ case 'updated':
122
+ return Logger.successText;
123
+ case 'errors':
124
+ return Logger.errorText;
125
+ default:
126
+ return Logger.infoText;
127
+ }
128
+ },
129
+ },
130
+ status: (status: MigrateStatus) => {
133
131
  switch (status) {
134
132
  case 'no change':
135
133
  return Logger.successText;
@@ -145,23 +143,177 @@ export const LogMessages = {
145
143
  return Logger.infoText;
146
144
  }
147
145
  },
146
+ },
147
+ models: {
148
+ list: (projectId: string) =>
149
+ `Content models in ${Logger.highlightText(projectId)}:`,
150
+ noList: (projectId: string) =>
151
+ `[${projectId}] Cannot retrieve content models`,
152
+ get: (projectId: string, id: string) =>
153
+ `[${projectId}] Content models ${Logger.infoText(`[ ${id} ]`)}`,
154
+ failedGet: (projectId: string, id: string) =>
155
+ `[${projectId}] Unable to get content models ${Logger.highlightText(id)}`,
156
+ },
157
+ nodes: {
158
+ failedGet: (projectId: string) =>
159
+ `[${projectId}] Cannot retrieve nodes from Site view`,
160
+ get: (projectId: string, root: string, depth: number) =>
161
+ `[${projectId}] Site view nodes at: ${Logger.highlightText(root)}${
162
+ depth ? ` to a depth of ${depth}` : ``
163
+ }\n`,
164
+ },
165
+ contenttypes: {
166
+ list: (projectId: string) =>
167
+ `Content types in ${Logger.highlightText(projectId)}:`,
168
+ get: (projectId: string, id: string) =>
169
+ `[${projectId}] Content type ${Logger.highlightText(id)}`,
170
+ failedGet: (projectId: string, id: string) =>
171
+ `[${projectId}] Unable to get content type ${Logger.highlightText(id)}`,
172
+ created: (projectId: string, id: string, status?: string) =>
173
+ `[${projectId}] Content type ${status}d ${Logger.highlightText(id)}`,
174
+ removed: (env: string, id: string, commit: boolean) =>
175
+ `[${env}] ${
176
+ commit ? `Deleted` : `Will delete`
177
+ } content type ${Logger.highlightText(id)}`,
178
+ failedRemove: (env: string, id: string) =>
179
+ `[${env}] Unable to delete content type ${Logger.highlightText(id)}`,
180
+ },
181
+ components: {
182
+ list: (projectId: string) =>
183
+ `Components in ${Logger.highlightText(projectId)}:`,
184
+ get: (projectId: string, id: string) =>
185
+ `[${projectId}] Component ${Logger.highlightText(id)}`,
186
+ failedGet: (projectId: string, id: string) =>
187
+ `[${projectId}] Unable to get component ${Logger.highlightText(id)}`,
188
+ created: (projectId: string, id: string, status?: string) =>
189
+ `[${projectId}] Component ${status}d ${Logger.highlightText(id)}`,
148
190
  removed: (env: string, id: string, commit: boolean) =>
149
- `[${env}] ${commit ? `Deleted` : `Will delete`} entry "${id}"`,
191
+ `[${env}] ${
192
+ commit ? `Deleted` : `Will delete`
193
+ } component ${Logger.highlightText(id)}`,
150
194
  failedRemove: (env: string, id: string) =>
151
- `[${env}] Unable to delete entry "${id}"`,
152
- notFound: (id: string) => `Entry "${id}" not found`,
153
- commitTip: () => ` Add --commit flag to commit the previewed changes`,
195
+ `[${env}] Unable to delete component ${Logger.highlightText(id)}`,
196
+ },
197
+ version: {
198
+ set: (env: string, versionStatus: string) =>
199
+ `[${env}] Content version status set to "${versionStatus}"`,
200
+ invalid: (versionStatus: string) =>
201
+ `Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
202
+ noEnv: () =>
203
+ `No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
204
+ },
205
+ entries: {
206
+ imported: (env: string, commit: boolean, count: number) =>
207
+ `[${env}] ${commit ? `Imported` : `Will import`} ${count} entries`,
208
+ failedImport: (env: string) => `[${env}] Unable to import entries`,
209
+ removed: (env: string, commit: boolean) =>
210
+ `[${env}] ${commit ? `Deleted` : `Will delete`} entries`,
211
+ failedRemove: (env: string) => `[${env}] Unable to delete entries`,
212
+ notFound: (env: string) => `[${env}] Entries were not found`,
213
+ commitTip: () => `Add --commit flag to commit the previewed changes`,
154
214
  },
155
215
  keys: {
156
216
  list: (env: string) => `[${env}] API keys:`,
157
- noList: (env: string) => `[${env}] Cannot retrieve API`,
217
+ noList: (env: string) => `[${env}] Cannot retrieve API keys`,
158
218
  created: (env: string, name: string) =>
159
- `[${env}] Created API key "${name}"`,
219
+ `[${env}] Created API key ${Logger.highlightText(name)}`,
220
+ tip: () =>
221
+ `Assign your new key to a role with "set role assignments", or create a new role with "create role"`,
160
222
  failedCreate: (env: string, name: string) =>
161
- `[${env}] Unable to create API key "${name}"`,
162
- removed: (env: string, id: string) => `[${env}] Deleted API key "${id}"`,
223
+ `[${env}] Unable to create API key ${Logger.highlightText(name)}`,
224
+ failedUpdate: (env: string, name: string) =>
225
+ `[${env}] Unable to update API key ${Logger.highlightText(name)}`,
226
+ removed: (env: string, id: string) =>
227
+ `[${env}] Deleted API key ${Logger.highlightText(id)}`,
228
+ failedRemove: (env: string, id: string) =>
229
+ `[${env}] Unable to delete API key ${Logger.highlightText(id)}`,
230
+ },
231
+ proxies: {
232
+ list: (env: string, projectId: string | undefined) =>
233
+ `[${env}] Retrieved proxies in project ${projectId}:`,
234
+ noList: (env: string, projectId: string | undefined) =>
235
+ `[${env}] Cannot retrieve proxies in project ${projectId}`,
236
+ // noneExist: () => `Create a role with "create renderer"`,
237
+ failedGet: (env: string, name: string, projectId: string) =>
238
+ `[${env}] Unable to find proxy ${Logger.highlightText(
239
+ name
240
+ )} in project ${projectId}`,
241
+ created: (env: string, name: string, projectId: string) =>
242
+ `[${env}] Created proxy ${Logger.highlightText(
243
+ name
244
+ )} in project ${projectId}\n`,
245
+ failedCreate: (env: string, name: string, projectId: string) =>
246
+ `[${env}] Unable to create proxy ${Logger.highlightText(
247
+ name
248
+ )} in project ${projectId}`,
249
+ setPayload: () => `Updating proxy with details\n`,
250
+ set: () => `Succesfully updated proxy\n`,
251
+ failedSet: (env: string, name: string, projectId: string) =>
252
+ `[${env}] Unable to update proxy ${Logger.highlightText(
253
+ name
254
+ )} in project ${projectId}`,
255
+ removed: (env: string, id: string, projectId: string) =>
256
+ `[${env}] Deleted proxy ${Logger.highlightText(
257
+ id
258
+ )} in project ${projectId}\n`,
259
+ failedRemove: (env: string, id: string, projectId: string) =>
260
+ `[${env}] Unable to delete proxy ${Logger.highlightText(
261
+ id
262
+ )} in project ${projectId}`,
263
+ },
264
+ renderers: {
265
+ list: (env: string, projectId: string | undefined) =>
266
+ `[${env}] Retrieved renderers in project ${projectId}:`,
267
+ noList: (env: string, projectId: string | undefined) =>
268
+ `[${env}] Cannot retrieve renderers in project ${projectId}`,
269
+ // noneExist: () => `Create a role with "create renderer"`,
270
+ failedGet: (env: string, name: string, projectId: string) =>
271
+ `[${env}] Unable to find renderer ${Logger.highlightText(
272
+ name
273
+ )} in project ${projectId}`,
274
+ created: (env: string, name: string, projectId: string) =>
275
+ `[${env}] Created renderer ${Logger.highlightText(
276
+ name
277
+ )} in project ${projectId}\n`,
278
+ failedCreate: (env: string, name: string, projectId: string) =>
279
+ `[${env}] Unable to create renderer ${Logger.highlightText(
280
+ name
281
+ )} in project ${projectId}`,
282
+ setPayload: () => `Updating renderer with details\n`,
283
+ set: () => `Succesfully updated renderer\n`,
284
+ failedSet: (env: string, name: string, projectId: string) =>
285
+ `[${env}] Unable to update renderer ${Logger.highlightText(
286
+ name
287
+ )} in project ${projectId}`,
288
+ removed: (env: string, id: string, projectId: string) =>
289
+ `[${env}] Deleted renderer ${Logger.highlightText(
290
+ id
291
+ )} in project ${projectId}\n`,
292
+ failedRemove: (env: string, id: string, projectId: string) =>
293
+ `[${env}] Unable to delete renderer ${Logger.highlightText(
294
+ id
295
+ )} in project ${projectId}`,
296
+ },
297
+ roles: {
298
+ list: (env: string) => `[${env}] Retrieved roles`,
299
+ noList: (env: string) => `[${env}] Cannot retrieve roles`,
300
+ noneExist: () => `Create a role with "create role"`,
301
+ failedGet: (env: string, name: string) =>
302
+ `[${env}] Unable to find role ${Logger.highlightText(name)}`,
303
+ created: (env: string, name: string) =>
304
+ `[${env}] Created role ${Logger.highlightText(name)}\n`,
305
+ tip: () =>
306
+ `Give access to your role with "set role assignments", allow your role to do things with "set role permissions"`,
307
+ failedCreate: (env: string, name?: string) =>
308
+ `[${env}] Unable to create role ${Logger.highlightText(name)}`,
309
+ setPayload: () => `Updating role with details\n`,
310
+ set: () => `Succesfully updated role\n`,
311
+ failedSet: (env: string, name?: string) =>
312
+ `[${env}] Unable to update role ${Logger.highlightText(name)}`,
313
+ removed: (env: string, id: string) =>
314
+ `[${env}] Deleted role ${Logger.highlightText(id)}\n`,
163
315
  failedRemove: (env: string, id: string) =>
164
- `[${env}] Unable to delete API key "${id}"`,
316
+ `[${env}] Unable to delete role ${Logger.highlightText(id)}`,
165
317
  },
166
318
  blocks: {
167
319
  runningStatus: (status: BlockRunningStatus | 'broken') => {
@@ -180,32 +332,188 @@ export const LogMessages = {
180
332
  return Logger.infoText(status);
181
333
  }
182
334
  },
183
- get: (env: string) => `[${env}] Block versions:`,
335
+ get: (id: string, env: string, projectId?: string) =>
336
+ `[${env}] Block ${id} in project ${projectId}:`,
184
337
  list: (env: string, projectId?: string) =>
185
338
  `[${env}] Blocks in project ${projectId}:`,
186
339
  noList: (env: string, projectId?: string) =>
187
340
  `[${env}] Cannot retrieve blocks in project ${projectId}`,
341
+ getLogs: (id: string, branch: string, env: string, projectId?: string) =>
342
+ `[${env}] Requesting logs from block ${Logger.highlightText(
343
+ id
344
+ )} in branch ${branch} in project ${projectId}`,
345
+ failedGetLogs: (id: string, env: string, projectId?: string) =>
346
+ `[${env}] Unable to fetch block logs for ${Logger.highlightText(
347
+ id
348
+ )} in project ${projectId}`,
188
349
  tryPush: (id: string, branch: string, env: string, projectId?: string) =>
189
- `[${env}] Request to push block "${id}" in branch ${branch} in project ${projectId}`,
350
+ `[${env}] Request to push block ${Logger.highlightText(
351
+ id
352
+ )} in branch ${branch} in project ${projectId}`,
190
353
  pushed: (id: string, branch: string, env: string, projectId?: string) =>
191
- `[${env}] Pushed block "${id}" in branch ${branch} in project ${projectId}`,
354
+ `[${env}] Pushed block ${Logger.highlightText(
355
+ id
356
+ )} in branch ${branch} in project ${projectId}`,
192
357
  failedPush: (id: string, env: string, projectId?: string) =>
193
- `[${env}] Unable to push block "${id}" in project ${projectId}`,
358
+ `[${env}] Unable to push block ${Logger.highlightText(
359
+ id
360
+ )} in project ${projectId}`,
361
+ latestVersion: (
362
+ version: string,
363
+ id: string,
364
+ env: string,
365
+ projectId?: string
366
+ ) =>
367
+ `[${env}] Found latest block version ${Logger.highlightText(
368
+ id
369
+ )} in project ${projectId} ${Logger.highlightText(version)}`,
370
+ failedParsingVersion: () =>
371
+ `Did not find a "version.versionNo" in response`,
372
+ actionComplete: (
373
+ action: BlockActionType,
374
+ id: string,
375
+ env: string,
376
+ projectId?: string
377
+ ) =>
378
+ `[${env}] Action ${Logger.highlightText(
379
+ action
380
+ )} on ${Logger.highlightText(
381
+ id
382
+ )} in project ${projectId} requested successfully`,
383
+ actionFailed: (
384
+ action: BlockActionType,
385
+ id: string,
386
+ env: string,
387
+ projectId?: string
388
+ ) =>
389
+ `[${env}] Problem executing ${action} on block ${Logger.highlightText(
390
+ id
391
+ )} in project ${projectId}`,
194
392
  deleted: (id: string, env: string, projectId?: string) =>
195
- `[${env}] Deleted block "${id}" in project ${projectId}`,
393
+ `[${env}] Deleted block ${Logger.highlightText(
394
+ id
395
+ )} in project ${projectId}`,
196
396
  failedDelete: (id: string, env: string, projectId?: string) =>
197
- `[${env}] Unable to delete block "${id}" in project ${projectId}`,
397
+ `[${env}] Unable to delete block ${Logger.highlightText(
398
+ id
399
+ )} in project ${projectId}`,
400
+ stopFollow: (id: string, env: string, projectId?: string) =>
401
+ `[${env}]\n\n 👌 stop fetching new ${Logger.highlightText(
402
+ id
403
+ )} logs in project ${projectId}`,
404
+ timeoutFollow: (id: string, env: string, projectId?: string) =>
405
+ `[${env}]\n\n 🤏 pausing fetching new ${Logger.highlightText(
406
+ id
407
+ )} logs in project ${projectId} due to too many requests`,
198
408
  },
199
409
  webhooks: {
200
410
  list: (env: string) => `[${env}] Webhook subscriptions:`,
201
411
  noList: (env: string) => `[${env}] Cannot retrieve webhook subscriptions`,
412
+ noneExist: () => `No webhook subscriptions exist`,
202
413
  created: (env: string, name: string) =>
203
- `[${env}] Created Webhook subscription "${name}"`,
414
+ `[${env}] Created Webhook subscription ${Logger.highlightText(name)}`,
204
415
  failedCreate: (env: string, name: string) =>
205
- `[${env}] Unable to create Webhook subscription "${name}"`,
416
+ `[${env}] Unable to create Webhook subscription ${Logger.highlightText(
417
+ name
418
+ )}`,
206
419
  deleted: (env: string, id: string) =>
207
- `[${env}] Deleted Webhook subscription "${id}"`,
420
+ `[${env}] Deleted Webhook subscription ${Logger.highlightText(id)}`,
208
421
  failedDelete: (env: string, id: string) =>
209
- `[${env}] Unable to delete Webhook subscription "${id}"`,
422
+ `[${env}] Unable to delete Webhook subscription ${Logger.highlightText(
423
+ id
424
+ )}`,
425
+ },
426
+ devinit: {
427
+ intro: () => `Contensis developer environment initialisation`,
428
+ //`This will initialise your local working directory to develop with the current connected Contensis project`,
429
+ projectDetails: (
430
+ name: string,
431
+ env: string,
432
+ projectId: string,
433
+ git: GitHelper
434
+ ) =>
435
+ `Project: ${Logger.highlightText(name)} set arg --name to override
436
+ - Home: ${Logger.standardText(process.cwd())}
437
+ - Repository: ${git.home}
438
+
439
+ Connect to Contensis instance: ${Logger.standardText(env)}
440
+ - Project id: ${Logger.standardText(projectId)}`,
441
+ developmentKey: (name: string, existing: boolean) =>
442
+ ` - ${
443
+ !existing ? 'Create development API key' : 'Development API key found'
444
+ }: ${Logger[!existing ? 'highlightText' : 'standardText'](name)}`,
445
+ deploymentKey: (name: string, existing: boolean) =>
446
+ ` - ${
447
+ !existing ? 'Create deployment API key' : 'Deployment API key found'
448
+ }: ${Logger[!existing ? 'highlightText' : 'standardText'](name)}`,
449
+ ciIntro: (git: GitHelper) =>
450
+ `We will create API keys with permissions to use this project with Contensis, and add a job to your CI that will deploy a container build.
451
+
452
+ We will ask you to add secrets/variables to your git repository to give your workflow permission to push a Block to Contensis. ${Logger.infoText(
453
+ `You could visit ${git.secretsUri} to check that you can see repository settings, a page not found generally indicates you need to ask the repo owner for permission to add repository secrets, or ask the repo owner to add these secrets for you.`
454
+ )}`,
455
+ ciDetails: (filename: string) =>
456
+ `Add push-block job to CI file: ${Logger.highlightText(filename)}\n`,
457
+ ciMultipleChoices: () =>
458
+ `Multiple GitHub workflow files found\n${Logger.infoText(
459
+ `Tell us which GitHub workflow builds the container image after each push:`
460
+ )}`,
461
+ confirm: () =>
462
+ `Confirm these details are correct so we can make changes to your project`,
463
+ accessTokenPrompt: () =>
464
+ `Please supply the access token for the Delivery API (optional)`,
465
+ createDevKey: (keyName: string, existing: boolean) =>
466
+ `${
467
+ !existing ? 'Created' : 'Checked permissions for'
468
+ } development API key ${Logger.standardText(keyName)}`,
469
+ createDeployKey: (keyName: string, existing: boolean) =>
470
+ `${
471
+ !existing ? 'Created' : 'Checked permissions for'
472
+ } deployment API key ${Logger.standardText(keyName)}`,
473
+ createKeyFail: (keyName: string, existing: boolean) =>
474
+ `Failed to ${
475
+ !existing ? 'create' : 'update'
476
+ } API key ${Logger.highlightText(keyName)}`,
477
+ writeEnvFile: () => `Written .env file to project home directory`,
478
+ useEnvFileTip: () =>
479
+ `You should alter existing project code that connects a Contensis client to use the variables from this file`,
480
+ writeCiFile: (ciFilePath: string) =>
481
+ `Updated CI file ${Logger.standardText(winSlash(ciFilePath))}`,
482
+ ciBlockTip: (blockId: string, env: string, projectId: string) =>
483
+ `A job is included to deploy your built container image to ${Logger.standardText(
484
+ projectId
485
+ )} at ${Logger.standardText(env)} in a block called ${Logger.standardText(
486
+ blockId
487
+ )}`,
488
+ addGitSecretsIntro: () =>
489
+ `We have created an API key that allows you to deploy your app image to a Contensis Block but we need you to add these details to your GitLab repository.`,
490
+ addGitSecretsHelp: (git: GitHelper, id?: string, secret?: string) =>
491
+ `Add secrets or variables in your repository's settings page\n\nGo to ${Logger.highlightText(
492
+ git.secretsUri
493
+ )}\n\n${
494
+ git.type === 'github'
495
+ ? `Add a "New repository secret"`
496
+ : `Expand "Variables" and hit "Add variable"`
497
+ }\n\n ${
498
+ git.type === 'github' ? `Secret name:` : `Key:`
499
+ } ${Logger.highlightText(`CONTENSIS_CLIENT_ID`)}\n ${
500
+ git.type === 'github' ? `Secret:` : `Value:`
501
+ } ${Logger.standardText(
502
+ id
503
+ )}\n\n ${`Add one more secret/variable to the repository`}\n\n ${
504
+ git.type === 'github' ? `Secret name:` : `Key:`
505
+ } ${Logger.highlightText(`CONTENSIS_SHARED_SECRET`)}\n ${
506
+ git.type === 'github' ? `Secret:` : `Value:`
507
+ } ${Logger.standardText(secret)}`,
508
+ success: () => `Contensis developer environment initialisation complete`,
509
+ partialSuccess: () =>
510
+ `Contensis developer environment initialisation completed with errors`,
511
+ failed: () => `Contensis developer environment initialisation failed`,
512
+ dryRun: () =>
513
+ `Contensis developer environment initialisation dry run completed`,
514
+ noChanges: () =>
515
+ `No changes were made to your project - run the command again without the --dry-run flag to update your project with these changes`,
516
+ startProjectTip: () =>
517
+ `Start up your project in the normal way for development`,
210
518
  },
211
519
  };
@@ -0,0 +1,44 @@
1
+ import ContensisCli from '~/services/ContensisCliService';
2
+
3
+ interface ISiteConfigYaml {
4
+ alias: string;
5
+ projectId: string;
6
+ accessToken: string;
7
+ clientId: string;
8
+ sharedSecret: string;
9
+ blocks: {
10
+ id: string;
11
+ baseUri: string;
12
+ }[];
13
+ }
14
+
15
+ export const mapSiteConfigYaml = async (cli: ContensisCli) => {
16
+ const credentials = await cli.GetCredentials(cli.env.lastUserId);
17
+
18
+ const blocks = [];
19
+ const blocksRaw = await cli.PrintBlocks();
20
+
21
+ for (const block of blocksRaw || []) {
22
+ const versions = await cli.PrintBlockVersions(
23
+ block.id,
24
+ 'default',
25
+ 'latest'
26
+ );
27
+ if (versions?.[0]) {
28
+ blocks.push({
29
+ id: versions[0].id,
30
+ baseUri: versions[0].previewUrl,
31
+ });
32
+ }
33
+ }
34
+
35
+ const siteConfig: ISiteConfigYaml = {
36
+ alias: cli.currentEnv,
37
+ projectId: cli.currentProject,
38
+ accessToken: '',
39
+ clientId: credentials?.current?.account || '',
40
+ sharedSecret: credentials?.current?.password || '',
41
+ blocks,
42
+ };
43
+ return siteConfig;
44
+ };