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
@@ -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,186 @@ 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
+ imported: (env: string, commit: boolean, count: number) =>
159
+ `[${env}] ${commit ? `Imported` : `Will import`} ${count} nodes`,
160
+ failedImport: (env: string) => `[${env}] Unable to import nodes`,
161
+ removed: (env: string, commit: boolean) =>
162
+ `[${env}] ${commit ? `Deleted` : `Will delete`} nodes`,
163
+ failedRemove: (env: string) => `[${env}] Unable to delete nodes`,
164
+ notFound: (env: string) => `[${env}] Nodes were not found `,
165
+ commitTip: () => `Add --commit flag to commit the previewed changes`,
166
+ failedGet: (projectId: string) =>
167
+ `[${projectId}] Cannot retrieve nodes from Site view`,
168
+ get: (projectId: string, root: string, depth: number) =>
169
+ `[${projectId}] Site view nodes at: ${Logger.highlightText(root)}${
170
+ depth ? ` to a depth of ${depth}` : ``
171
+ }\n`,
172
+ noChange: (env: string) => `[${env}] No changes to be made`,
173
+ },
174
+ contenttypes: {
175
+ list: (projectId: string) =>
176
+ `Content types in ${Logger.highlightText(projectId)}:`,
177
+ get: (projectId: string, id: string) =>
178
+ `[${projectId}] Content type ${Logger.highlightText(id)}`,
179
+ failedGet: (projectId: string, id: string) =>
180
+ `[${projectId}] Unable to get content type ${Logger.highlightText(id)}`,
181
+ created: (projectId: string, id: string, status?: string) =>
182
+ `[${projectId}] Content type ${status}d ${Logger.highlightText(id)}`,
148
183
  removed: (env: string, id: string, commit: boolean) =>
149
- `[${env}] ${commit ? `Deleted` : `Will delete`} entry "${id}"`,
184
+ `[${env}] ${
185
+ commit ? `Deleted` : `Will delete`
186
+ } content type ${Logger.highlightText(id)}`,
150
187
  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`,
188
+ `[${env}] Unable to delete content type ${Logger.highlightText(id)}`,
189
+ },
190
+ components: {
191
+ list: (projectId: string) =>
192
+ `Components in ${Logger.highlightText(projectId)}:`,
193
+ get: (projectId: string, id: string) =>
194
+ `[${projectId}] Component ${Logger.highlightText(id)}`,
195
+ failedGet: (projectId: string, id: string) =>
196
+ `[${projectId}] Unable to get component ${Logger.highlightText(id)}`,
197
+ created: (projectId: string, id: string, status?: string) =>
198
+ `[${projectId}] Component ${status}d ${Logger.highlightText(id)}`,
199
+ removed: (env: string, id: string, commit: boolean) =>
200
+ `[${env}] ${
201
+ commit ? `Deleted` : `Will delete`
202
+ } component ${Logger.highlightText(id)}`,
203
+ failedRemove: (env: string, id: string) =>
204
+ `[${env}] Unable to delete component ${Logger.highlightText(id)}`,
205
+ },
206
+ version: {
207
+ set: (env: string, versionStatus: string) =>
208
+ `[${env}] Content version status set to "${versionStatus}"`,
209
+ invalid: (versionStatus: string) =>
210
+ `Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
211
+ noEnv: () =>
212
+ `No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
213
+ },
214
+ entries: {
215
+ imported: (env: string, commit: boolean, count: number) =>
216
+ `[${env}] ${commit ? `Imported` : `Will import`} ${count} entries`,
217
+ failedImport: (env: string) => `[${env}] Unable to import entries`,
218
+ removed: (env: string, commit: boolean) =>
219
+ `[${env}] ${commit ? `Deleted` : `Will delete`} entries`,
220
+ failedRemove: (env: string) => `[${env}] Unable to delete entries`,
221
+ notFound: (env: string) => `[${env}] Entries were not found`,
222
+ commitTip: () => `Add --commit flag to commit the previewed changes`,
154
223
  },
155
224
  keys: {
156
225
  list: (env: string) => `[${env}] API keys:`,
157
- noList: (env: string) => `[${env}] Cannot retrieve API`,
226
+ noList: (env: string) => `[${env}] Cannot retrieve API keys`,
158
227
  created: (env: string, name: string) =>
159
- `[${env}] Created API key "${name}"`,
228
+ `[${env}] Created API key ${Logger.highlightText(name)}`,
229
+ tip: () =>
230
+ `Assign your new key to a role with "set role assignments", or create a new role with "create role"`,
160
231
  failedCreate: (env: string, name: string) =>
161
- `[${env}] Unable to create API key "${name}"`,
162
- removed: (env: string, id: string) => `[${env}] Deleted API key "${id}"`,
232
+ `[${env}] Unable to create API key ${Logger.highlightText(name)}`,
233
+ failedUpdate: (env: string, name: string) =>
234
+ `[${env}] Unable to update API key ${Logger.highlightText(name)}`,
235
+ removed: (env: string, id: string) =>
236
+ `[${env}] Deleted API key ${Logger.highlightText(id)}`,
237
+ failedRemove: (env: string, id: string) =>
238
+ `[${env}] Unable to delete API key ${Logger.highlightText(id)}`,
239
+ },
240
+ proxies: {
241
+ list: (env: string, projectId: string | undefined) =>
242
+ `[${env}] Retrieved proxies in project ${projectId}:`,
243
+ noList: (env: string, projectId: string | undefined) =>
244
+ `[${env}] Cannot retrieve proxies in project ${projectId}`,
245
+ // noneExist: () => `Create a role with "create renderer"`,
246
+ failedGet: (env: string, name: string, projectId: string) =>
247
+ `[${env}] Unable to find proxy ${Logger.highlightText(
248
+ name
249
+ )} in project ${projectId}`,
250
+ created: (env: string, name: string, projectId: string) =>
251
+ `[${env}] Created proxy ${Logger.highlightText(
252
+ name
253
+ )} in project ${projectId}\n`,
254
+ failedCreate: (env: string, name: string, projectId: string) =>
255
+ `[${env}] Unable to create proxy ${Logger.highlightText(
256
+ name
257
+ )} in project ${projectId}`,
258
+ setPayload: () => `Updating proxy with details\n`,
259
+ set: () => `Succesfully updated proxy\n`,
260
+ failedSet: (env: string, name: string, projectId: string) =>
261
+ `[${env}] Unable to update proxy ${Logger.highlightText(
262
+ name
263
+ )} in project ${projectId}`,
264
+ removed: (env: string, id: string, projectId: string) =>
265
+ `[${env}] Deleted proxy ${Logger.highlightText(
266
+ id
267
+ )} in project ${projectId}\n`,
268
+ failedRemove: (env: string, id: string, projectId: string) =>
269
+ `[${env}] Unable to delete proxy ${Logger.highlightText(
270
+ id
271
+ )} in project ${projectId}`,
272
+ },
273
+ renderers: {
274
+ list: (env: string, projectId: string | undefined) =>
275
+ `[${env}] Retrieved renderers in project ${projectId}:`,
276
+ noList: (env: string, projectId: string | undefined) =>
277
+ `[${env}] Cannot retrieve renderers in project ${projectId}`,
278
+ // noneExist: () => `Create a role with "create renderer"`,
279
+ failedGet: (env: string, name: string, projectId: string) =>
280
+ `[${env}] Unable to find renderer ${Logger.highlightText(
281
+ name
282
+ )} in project ${projectId}`,
283
+ created: (env: string, name: string, projectId: string) =>
284
+ `[${env}] Created renderer ${Logger.highlightText(
285
+ name
286
+ )} in project ${projectId}\n`,
287
+ failedCreate: (env: string, name: string, projectId: string) =>
288
+ `[${env}] Unable to create renderer ${Logger.highlightText(
289
+ name
290
+ )} in project ${projectId}`,
291
+ setPayload: () => `Updating renderer with details\n`,
292
+ set: () => `Succesfully updated renderer\n`,
293
+ failedSet: (env: string, name: string, projectId: string) =>
294
+ `[${env}] Unable to update renderer ${Logger.highlightText(
295
+ name
296
+ )} in project ${projectId}`,
297
+ removed: (env: string, id: string, projectId: string) =>
298
+ `[${env}] Deleted renderer ${Logger.highlightText(
299
+ id
300
+ )} in project ${projectId}\n`,
301
+ failedRemove: (env: string, id: string, projectId: string) =>
302
+ `[${env}] Unable to delete renderer ${Logger.highlightText(
303
+ id
304
+ )} in project ${projectId}`,
305
+ },
306
+ roles: {
307
+ list: (env: string) => `[${env}] Retrieved roles`,
308
+ noList: (env: string) => `[${env}] Cannot retrieve roles`,
309
+ noneExist: () => `Create a role with "create role"`,
310
+ failedGet: (env: string, name: string) =>
311
+ `[${env}] Unable to find role ${Logger.highlightText(name)}`,
312
+ created: (env: string, name: string) =>
313
+ `[${env}] Created role ${Logger.highlightText(name)}\n`,
314
+ tip: () =>
315
+ `Give access to your role with "set role assignments", allow your role to do things with "set role permissions"`,
316
+ failedCreate: (env: string, name?: string) =>
317
+ `[${env}] Unable to create role ${Logger.highlightText(name)}`,
318
+ setPayload: () => `Updating role with details\n`,
319
+ set: () => `Succesfully updated role\n`,
320
+ failedSet: (env: string, name?: string) =>
321
+ `[${env}] Unable to update role ${Logger.highlightText(name)}`,
322
+ removed: (env: string, id: string) =>
323
+ `[${env}] Deleted role ${Logger.highlightText(id)}\n`,
163
324
  failedRemove: (env: string, id: string) =>
164
- `[${env}] Unable to delete API key "${id}"`,
325
+ `[${env}] Unable to delete role ${Logger.highlightText(id)}`,
165
326
  },
166
327
  blocks: {
167
328
  runningStatus: (status: BlockRunningStatus | 'broken') => {
@@ -180,32 +341,233 @@ export const LogMessages = {
180
341
  return Logger.infoText(status);
181
342
  }
182
343
  },
183
- get: (env: string) => `[${env}] Block versions:`,
344
+ get: (id: string, env: string, projectId?: string) =>
345
+ `[${env}] Block ${id} in project ${projectId}:`,
184
346
  list: (env: string, projectId?: string) =>
185
347
  `[${env}] Blocks in project ${projectId}:`,
186
348
  noList: (env: string, projectId?: string) =>
187
349
  `[${env}] Cannot retrieve blocks in project ${projectId}`,
350
+ getLogs: (id: string, branch: string, env: string, projectId?: string) =>
351
+ `[${env}] Requesting logs from block ${Logger.highlightText(
352
+ id
353
+ )} in branch ${branch} in project ${projectId}`,
354
+ failedGetLogs: (id: string, env: string, projectId?: string) =>
355
+ `[${env}] Unable to fetch block logs for ${Logger.highlightText(
356
+ id
357
+ )} in project ${projectId}`,
188
358
  tryPush: (id: string, branch: string, env: string, projectId?: string) =>
189
- `[${env}] Request to push block "${id}" in branch ${branch} in project ${projectId}`,
359
+ `[${env}] Request to push block ${Logger.highlightText(
360
+ id
361
+ )} in branch ${branch} in project ${projectId}`,
190
362
  pushed: (id: string, branch: string, env: string, projectId?: string) =>
191
- `[${env}] Pushed block "${id}" in branch ${branch} in project ${projectId}`,
363
+ `[${env}] Pushed block ${Logger.highlightText(
364
+ id
365
+ )} in branch ${branch} in project ${projectId}`,
192
366
  failedPush: (id: string, env: string, projectId?: string) =>
193
- `[${env}] Unable to push block "${id}" in project ${projectId}`,
367
+ `[${env}] Unable to push block ${Logger.highlightText(
368
+ id
369
+ )} in project ${projectId}`,
370
+ latestVersion: (
371
+ version: string,
372
+ id: string,
373
+ env: string,
374
+ projectId?: string
375
+ ) =>
376
+ `[${env}] Found latest block version ${Logger.highlightText(
377
+ id
378
+ )} in project ${projectId} ${Logger.highlightText(version)}`,
379
+ failedParsingVersion: () =>
380
+ `Did not find a "version.versionNo" in response`,
381
+ actionComplete: (
382
+ action: BlockActionType,
383
+ id: string,
384
+ env: string,
385
+ projectId?: string
386
+ ) =>
387
+ `[${env}] Action ${Logger.highlightText(
388
+ action
389
+ )} on ${Logger.highlightText(
390
+ id
391
+ )} in project ${projectId} requested successfully`,
392
+ actionFailed: (
393
+ action: BlockActionType,
394
+ id: string,
395
+ env: string,
396
+ projectId?: string
397
+ ) =>
398
+ `[${env}] Problem executing ${action} on block ${Logger.highlightText(
399
+ id
400
+ )} in project ${projectId}`,
194
401
  deleted: (id: string, env: string, projectId?: string) =>
195
- `[${env}] Deleted block "${id}" in project ${projectId}`,
402
+ `[${env}] Deleted block ${Logger.highlightText(
403
+ id
404
+ )} in project ${projectId}`,
196
405
  failedDelete: (id: string, env: string, projectId?: string) =>
197
- `[${env}] Unable to delete block "${id}" in project ${projectId}`,
406
+ `[${env}] Unable to delete block ${Logger.highlightText(
407
+ id
408
+ )} in project ${projectId}`,
409
+ stopFollow: (id: string, env: string, projectId?: string) =>
410
+ `[${env}]\n\n 👌 stop fetching new ${Logger.highlightText(
411
+ id
412
+ )} logs in project ${projectId}`,
413
+ timeoutFollow: (id: string, env: string, projectId?: string) =>
414
+ `[${env}]\n\n 🤏 pausing fetching new ${Logger.highlightText(
415
+ id
416
+ )} logs in project ${projectId} due to too many requests`,
198
417
  },
199
418
  webhooks: {
200
419
  list: (env: string) => `[${env}] Webhook subscriptions:`,
201
420
  noList: (env: string) => `[${env}] Cannot retrieve webhook subscriptions`,
421
+ noneExist: () => `No webhook subscriptions exist`,
202
422
  created: (env: string, name: string) =>
203
- `[${env}] Created Webhook subscription "${name}"`,
423
+ `[${env}] Created Webhook subscription ${Logger.highlightText(name)}`,
204
424
  failedCreate: (env: string, name: string) =>
205
- `[${env}] Unable to create Webhook subscription "${name}"`,
425
+ `[${env}] Unable to create Webhook subscription ${Logger.highlightText(
426
+ name
427
+ )}`,
206
428
  deleted: (env: string, id: string) =>
207
- `[${env}] Deleted Webhook subscription "${id}"`,
429
+ `[${env}] Deleted Webhook subscription ${Logger.highlightText(id)}`,
208
430
  failedDelete: (env: string, id: string) =>
209
- `[${env}] Unable to delete Webhook subscription "${id}"`,
431
+ `[${env}] Unable to delete Webhook subscription ${Logger.highlightText(
432
+ id
433
+ )}`,
434
+ },
435
+ devinit: {
436
+ intro: () => `Contensis developer environment initialisation`,
437
+ //`This will initialise your local working directory to develop with the current connected Contensis project`,
438
+ projectDetails: (
439
+ name: string,
440
+ env: string,
441
+ projectId: string,
442
+ git: GitHelper
443
+ ) =>
444
+ `Project: ${Logger.highlightText(name)} set arg --name to override
445
+ - Home: ${Logger.standardText(process.cwd())}
446
+ - Repository: ${git.home}
447
+
448
+ Connect to Contensis instance: ${Logger.standardText(env)}
449
+ - Project id: ${Logger.standardText(projectId)}`,
450
+ developmentKey: (name: string, existing: boolean) =>
451
+ ` - ${
452
+ !existing ? 'Create development API key' : 'Development API key found'
453
+ }: ${Logger[!existing ? 'highlightText' : 'standardText'](name)}`,
454
+ deploymentKey: (name: string, existing: boolean) =>
455
+ ` - ${
456
+ !existing ? 'Create deployment API key' : 'Deployment API key found'
457
+ }: ${Logger[!existing ? 'highlightText' : 'standardText'](name)}`,
458
+ ciIntro: (git: GitHelper, location: 'git' | 'env') =>
459
+ `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.
460
+ ${
461
+ location === 'git'
462
+ ? `We will ask you to add secrets/variables to your git repository to give your workflow permission to push a Block to Contensis.
463
+ ${Logger.infoText(`You could visit ${git.secretsUri} to check that you can see repository settings,
464
+ a page not found generally indicates you need to ask the repo owner for permission to add repository secrets,
465
+ or ask the repo owner to add these secrets for you.`)}`
466
+ : ''
467
+ }`,
468
+ ciDetails: (filename: string) =>
469
+ `Add push-block job to CI file: ${Logger.highlightText(filename)}\n`,
470
+ ciMultipleChoices: () =>
471
+ `Multiple GitHub workflow files found\n${Logger.infoText(
472
+ `Tell us which GitHub workflow builds a container image after each push:`
473
+ )}`,
474
+ ciMultipleBuildJobChoices: () =>
475
+ `Multiple build jobs found in workflow\n${Logger.infoText(
476
+ `Choose the build job that produces a fresh container image to push to a block:`
477
+ )}`,
478
+ ciMultipleJobChoices: () =>
479
+ `Other jobs found in workflow\n${Logger.infoText(
480
+ `Choose the job that produces a fresh container image we can push to a block:`
481
+ )}`,
482
+ ciMultipleAppImageVarChoices: () =>
483
+ `Do one of these variables point to your tagged app image?\n${Logger.infoText(
484
+ `we have included a default choice - ensure your build image is tagged exactly the same as this`
485
+ )}`,
486
+ ciEnterOwnAppImagePrompt: (git: GitHelper) =>
487
+ `Tell us the registry uri your app image is tagged and pushed with (⏎ accept default) \n${Logger.infoText(
488
+ `Tip: ${
489
+ git.type === 'github'
490
+ ? `GitHub context variables available\nhttps://docs.github.com/en/actions/learn-github-actions/variables#using-contexts-to-access-variable-values`
491
+ : `GitLab CI/CD variables available\nhttps://docs.gitlab.com/ee/ci/variables/`
492
+ }`
493
+ )}\n`,
494
+ confirm: () =>
495
+ `Confirm these details are correct so we can make changes to your project`,
496
+ accessTokenPrompt: () =>
497
+ ` To continue setting up we need permission to fetch your Delivery API token. (Press (Y + ⏎) to continue or (N + ⏎) to exit the set up process)`,
498
+ createDevKey: (keyName: string, existing: boolean) =>
499
+ `${
500
+ !existing ? 'Created' : 'Checked permissions for'
501
+ } development API key ${Logger.standardText(keyName)}`,
502
+ createDeployKey: (keyName: string, existing: boolean) =>
503
+ `${
504
+ !existing ? 'Created' : 'Checked permissions for'
505
+ } deployment API key ${Logger.standardText(keyName)}`,
506
+ createKeyFail: (keyName: string, existing: boolean) =>
507
+ `Failed to ${
508
+ !existing ? 'create' : 'update'
509
+ } API key ${Logger.highlightText(keyName)}`,
510
+ writeEnvFile: () => `Written .env file to project home directory`,
511
+ useEnvFileTip: () =>
512
+ `You should alter existing project code that connects a Contensis client to use the variables from this file`,
513
+ writeCiFile: (ciFilePath: string) =>
514
+ `Updated CI file ${Logger.standardText(winSlash(ciFilePath))}`,
515
+ ciFileNoChanges: (ciFilePath: string) =>
516
+ `No updates needed for CI file ${Logger.standardText(
517
+ winSlash(ciFilePath)
518
+ )}`,
519
+ ciBlockTip: (blockId: string, env: string, projectId: string) =>
520
+ `A job is included to deploy your built container image to ${Logger.standardText(
521
+ projectId
522
+ )} at ${Logger.standardText(env)} in a block called ${Logger.standardText(
523
+ blockId
524
+ )}`,
525
+ addGitSecretsIntro: () =>
526
+ `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.`,
527
+ addGitSecretsHelp: (git: GitHelper, id?: string, secret?: string) =>
528
+ `Add secrets or variables in your repository's settings page\n\nGo to ${Logger.highlightText(
529
+ git.secretsUri
530
+ )}\n\n${
531
+ git.type === 'github'
532
+ ? `Add a "New repository secret"`
533
+ : `Expand "Variables" and hit "Add variable"`
534
+ }\n\n ${
535
+ git.type === 'github' ? `Secret name:` : `Key:`
536
+ } ${Logger.highlightText(`CONTENSIS_CLIENT_ID`)}\n ${
537
+ git.type === 'github' ? `Secret:` : `Value:`
538
+ } ${Logger.standardText(
539
+ id
540
+ )}\n\n ${`Add one more secret/variable to the repository`}\n\n ${
541
+ git.type === 'github' ? `Secret name:` : `Key:`
542
+ } ${Logger.highlightText(`CONTENSIS_SHARED_SECRET`)}\n ${
543
+ git.type === 'github' ? `Secret:` : `Value:`
544
+ } ${Logger.standardText(secret)}`,
545
+ accessTokenFetch: () => `Please wait, fecthing Delivery API token ⏳`,
546
+ accessTokenSuccess: (token: string) =>
547
+ `Successfully fetched Delivery API token 👉 ${Logger.infoText(token)}`,
548
+ accessTokenFailed: () =>
549
+ `Something went wrong! If the problem persists, please contact our support team 🛟`,
550
+ accessTokenPermission: () =>
551
+ `We need permission to fetch your Delivery API token, please try again ⚠️`,
552
+ clientDetailsLocation: () =>
553
+ `Which option would you like to use for storing your client ID and secret`,
554
+ clientDetailsInGit: (git: GitHelper) =>
555
+ `${
556
+ git.type === 'github' ? 'GitHub' : 'GitLab'
557
+ } variables (recommended for public repositories)`,
558
+ clientDetailsInEnv: () =>
559
+ `.env file (recommended for private repositories)`,
560
+ success: () => `Contensis developer environment initialisation complete`,
561
+ partialSuccess: () =>
562
+ `Contensis developer environment initialisation completed with errors`,
563
+ failed: () => `Contensis developer environment initialisation failed`,
564
+ dryRun: () =>
565
+ `Contensis developer environment initialisation dry run completed`,
566
+ noChanges: () =>
567
+ `No changes were made to your project, run the command again without the ${Logger.highlightText(
568
+ '--dry-run'
569
+ )} flag to update your project with these changes`,
570
+ startProjectTip: () =>
571
+ `Start up your project in the normal way for development`,
210
572
  },
211
573
  };
@@ -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
+ };