contensis-cli 1.0.0-beta.8 → 1.0.0-beta.80

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 (81) hide show
  1. package/README.md +1146 -78
  2. package/dist/commands/connect.js +3 -3
  3. package/dist/commands/connect.js.map +2 -2
  4. package/dist/commands/create.js +45 -10
  5. package/dist/commands/create.js.map +2 -2
  6. package/dist/commands/diff.js +57 -0
  7. package/dist/commands/diff.js.map +7 -0
  8. package/dist/commands/execute.js +103 -0
  9. package/dist/commands/execute.js.map +7 -0
  10. package/dist/commands/get.js +107 -18
  11. package/dist/commands/get.js.map +2 -2
  12. package/dist/commands/globalOptions.js +22 -17
  13. package/dist/commands/globalOptions.js.map +2 -2
  14. package/dist/commands/import.js +46 -11
  15. package/dist/commands/import.js.map +2 -2
  16. package/dist/commands/index.js +16 -2
  17. package/dist/commands/index.js.map +2 -2
  18. package/dist/commands/list.js +53 -10
  19. package/dist/commands/list.js.map +2 -2
  20. package/dist/commands/login.js +3 -3
  21. package/dist/commands/login.js.map +2 -2
  22. package/dist/commands/push.js +9 -5
  23. package/dist/commands/push.js.map +2 -2
  24. package/dist/commands/remove.js +51 -8
  25. package/dist/commands/remove.js.map +2 -2
  26. package/dist/commands/set.js +139 -12
  27. package/dist/commands/set.js.map +2 -2
  28. package/dist/index.js +1 -1
  29. package/dist/index.js.map +2 -2
  30. package/dist/localisation/en-GB.js +193 -49
  31. package/dist/localisation/en-GB.js.map +2 -2
  32. package/dist/providers/CredentialProvider.js +36 -7
  33. package/dist/providers/CredentialProvider.js.map +3 -3
  34. package/dist/providers/SessionCacheProvider.js +21 -1
  35. package/dist/providers/SessionCacheProvider.js.map +2 -2
  36. package/dist/providers/file-provider.js +8 -4
  37. package/dist/providers/file-provider.js.map +3 -3
  38. package/dist/services/ContensisCliService.js +1092 -410
  39. package/dist/services/ContensisCliService.js.map +3 -3
  40. package/dist/shell.js +48 -14
  41. package/dist/shell.js.map +3 -3
  42. package/dist/util/console.printer.js +171 -55
  43. package/dist/util/console.printer.js.map +2 -2
  44. package/dist/util/diff.js +39 -0
  45. package/dist/util/diff.js.map +7 -0
  46. package/dist/util/index.js +8 -2
  47. package/dist/util/index.js.map +3 -3
  48. package/dist/util/logger.js +61 -29
  49. package/dist/util/logger.js.map +3 -3
  50. package/dist/util/timers.js +49 -0
  51. package/dist/util/timers.js.map +7 -0
  52. package/dist/version.js +1 -1
  53. package/dist/version.js.map +1 -1
  54. package/esbuild.config.js +3 -1
  55. package/package.json +2 -2
  56. package/src/commands/connect.ts +3 -2
  57. package/src/commands/create.ts +61 -8
  58. package/src/commands/diff.ts +41 -0
  59. package/src/commands/execute.ts +117 -0
  60. package/src/commands/get.ts +150 -14
  61. package/src/commands/globalOptions.ts +18 -17
  62. package/src/commands/import.ts +57 -7
  63. package/src/commands/index.ts +16 -1
  64. package/src/commands/list.ts +85 -11
  65. package/src/commands/login.ts +3 -2
  66. package/src/commands/push.ts +10 -3
  67. package/src/commands/remove.ts +66 -4
  68. package/src/commands/set.ts +189 -9
  69. package/src/index.ts +1 -4
  70. package/src/localisation/en-GB.ts +269 -66
  71. package/src/providers/CredentialProvider.ts +39 -6
  72. package/src/providers/SessionCacheProvider.ts +29 -2
  73. package/src/providers/file-provider.ts +12 -4
  74. package/src/services/ContensisCliService.ts +1384 -484
  75. package/src/shell.ts +52 -15
  76. package/src/util/console.printer.ts +240 -78
  77. package/src/util/diff.ts +17 -0
  78. package/src/util/index.ts +16 -7
  79. package/src/util/logger.ts +111 -31
  80. package/src/util/timers.ts +24 -0
  81. package/src/version.ts +1 -1
@@ -6,11 +6,14 @@ import { cliCommand } from '~/services/ContensisCliService';
6
6
  export const makePushCommand = () => {
7
7
  const push = new Command()
8
8
  .command('push')
9
+ .description('push command')
10
+ .addHelpText('after', `\n`)
9
11
  .showHelpAfterError(true)
10
12
  .exitOverride();
11
13
 
12
14
  push
13
15
  .command('block')
16
+ .description('push a block')
14
17
  .argument('<block-id>', 'the name of the block to push to')
15
18
  .argument(
16
19
  '<image uri:tag>',
@@ -55,7 +58,7 @@ export const makePushCommand = () => {
55
58
  'after',
56
59
  `
57
60
  Example call:
58
- > push block contensis-app ghcr.io/contensis/contensis-app/build-4359 master --release\n`
61
+ > push block contensis-app ghcr.io/contensis/contensis-app/app:build-4359 master --release\n`
59
62
  )
60
63
  .action(async (blockId: string, imageUri: string, branch: string, opts) => {
61
64
  const cli = cliCommand(['push', 'block', blockId], opts);
@@ -68,7 +71,7 @@ Example call:
68
71
  };
69
72
 
70
73
  const blockRequest = mapJson(mapSourceVars, {
71
- autoRelease: { $path: 'release', $default: () => false },
74
+ release: { $path: 'release', $default: () => false },
72
75
  id: ['blockId'],
73
76
  image: () => {
74
77
  const lastIndexOfColon = imageUri.lastIndexOf(':');
@@ -99,7 +102,11 @@ Example call:
99
102
  branch: ['branch', 'CI_COMMIT_REF_NAME', 'GITHUB_REF_NAME'],
100
103
  commit: {
101
104
  id: ['commitId', 'CI_COMMIT_SHORT_SHA', 'GITHUB_SHA'],
102
- message: ['commitMessage', 'CI_COMMIT_MESSAGE'], // ${{ github.event.head_commit.message }}
105
+ message: {
106
+ $path: ['commitMessage', 'CI_COMMIT_MESSAGE'], // ${{ github.event.head_commit.message }}
107
+ $formatting: (msg?: string) =>
108
+ msg?.replace(/\\n/g, ' ').replace(/\\n/g, ' ').trim(),
109
+ },
103
110
  dateTime: ['commitDatetime', 'CI_COMMIT_TIMESTAMP'], // ${{ github.event.head_commit.timestamp }}
104
111
  authorEmail: ['authorEmail', 'GITLAB_USER_EMAIL', 'GITHUB_ACTOR'], // ${{ github.event.head_commit.author.email }}
105
112
  committerEmail: [
@@ -1,27 +1,34 @@
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 { Logger } from '~/util/logger';
5
+ import { commit, mapContensisOpts, zenql } from './globalOptions';
5
6
 
6
7
  export const makeRemoveCommand = () => {
7
8
  const remove = new Command()
8
9
  .command('remove')
10
+ .description('remove command')
11
+ .addHelpText('after', `\n`)
9
12
  .showHelpAfterError(true)
10
13
  .exitOverride();
11
14
 
12
15
  remove
13
16
  .command('project')
17
+ .description('remove an entire project')
14
18
  .argument('<projectId>', 'the project id to delete')
15
19
  .usage('<projectId>')
20
+ .addHelpText('after', `\n`)
16
21
  .action(async (projectId, opts) => {
17
22
  const project = await cliCommand(
18
23
  ['remove', 'project', projectId],
19
24
  opts
20
25
  ).SetProject(projectId);
21
- if (project) await shell().start();
26
+ if (project) await shell().restart();
22
27
  });
28
+
23
29
  remove
24
30
  .command('key')
31
+ .description('remove api key')
25
32
  .argument('<id>', 'the id of the API key to delete')
26
33
  .usage('<id>')
27
34
  .addHelpText(
@@ -35,8 +42,25 @@ Example call:
35
42
  await cliCommand(['remove', 'key', id], opts).RemoveApiKey(id);
36
43
  });
37
44
 
45
+ remove
46
+ .command('role')
47
+ .description('remove a role')
48
+ .argument('<"Role name" or id>', 'the existing role name or id to delete')
49
+ .addHelpText(
50
+ 'after',
51
+ `
52
+ Example call:
53
+ > remove role "My role"\n`
54
+ )
55
+ .action(async (roleNameOrId: string, opts) => {
56
+ await cliCommand(['remove', 'role', roleNameOrId], opts).RemoveRole(
57
+ roleNameOrId
58
+ );
59
+ });
60
+
38
61
  remove
39
62
  .command('components')
63
+ .description('delete components')
40
64
  .argument('<id...>', 'the id(s) of the components to delete')
41
65
  .addOption(commit)
42
66
  .usage('<id> [--commit]')
@@ -49,13 +73,14 @@ Example call:
49
73
  )
50
74
  .action(async (id: string[], opts) => {
51
75
  await cliCommand(
52
- ['remove', 'components', id.join(', ')],
76
+ ['remove', 'components', id.join(' ')],
53
77
  opts
54
78
  ).RemoveComponents(id, opts.commit);
55
79
  });
56
80
 
57
81
  remove
58
82
  .command('contenttypes')
83
+ .description('delete content types')
59
84
  .argument('<id...>', 'the id(s) of the content types to delete')
60
85
  .addOption(commit)
61
86
  .usage('<id> [--commit]')
@@ -68,10 +93,47 @@ Example call:
68
93
  )
69
94
  .action(async (id: string[], opts) => {
70
95
  await cliCommand(
71
- ['remove', 'contenttypes', id.join(', ')],
96
+ ['remove', 'contenttypes', id.join(' ')],
72
97
  opts
73
98
  ).RemoveContentTypes(id, opts.commit);
74
99
  });
75
100
 
101
+ const removeEntries = remove
102
+ .command('entries')
103
+ .description('delete entries')
104
+ .argument(
105
+ '[ids...]',
106
+ 'the entry id(s) to delete ...or add *** if you wish to delete all entries in all content types'
107
+ )
108
+ .addOption(zenql)
109
+ .addOption(commit)
110
+ .addHelpText(
111
+ 'after',
112
+ `
113
+ Example call:
114
+ > remove entries a1c25591-8c9b-50e2-96d8-f6c774fcf023 8df914cc-1da1-59d6-86e0-8ea4ebd99aaa
115
+ > remove entries --zenql "sys.contentTypeId = test"
116
+ `
117
+ )
118
+ .action(async (entryIds: string[], opts) => {
119
+ const removeAll = entryIds?.[0] === '***';
120
+
121
+ // Remove all asterisks from args
122
+ if (entryIds?.[0] && !entryIds[0].replace(/\*/g, '')) entryIds.pop();
123
+
124
+ const hasArgs = !!(entryIds?.length || opts.zenql || removeAll);
125
+ if (!hasArgs) {
126
+ Logger.help(
127
+ `Not enough arguments supplied\n\n${removeEntries.helpInformation()}`
128
+ );
129
+ } else {
130
+ await cliCommand(
131
+ ['remove', 'entries', entryIds.join(' ')],
132
+ opts,
133
+ mapContensisOpts({ entryIds, ...opts })
134
+ ).RemoveEntries(opts.commit);
135
+ }
136
+ });
137
+
76
138
  return remove;
77
139
  };
@@ -5,35 +5,215 @@ 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
- set
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 project = await cliCommand([
25
+ const nextProjectId = cliCommand([
16
26
  'set',
17
27
  'project',
18
28
  projectId,
19
29
  ]).SetProject(projectId);
20
- if (project) await shell().start();
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
+ await cliCommand(['set', 'project', 'name'], opts).UpdateProject({
46
+ name,
47
+ });
48
+ });
49
+
50
+ project
51
+ .command('description')
52
+ .description('update project description')
53
+ .argument(
54
+ '<"Project description">',
55
+ 'update the current project description'
56
+ )
57
+ .usage('<"Project description">')
58
+ .addHelpText(
59
+ 'after',
60
+ `
61
+ Example call:
62
+ > set project description "Description of project"\n`
63
+ )
64
+ .action(async (description: string, opts) => {
65
+ await cliCommand(['set', 'project', 'description'], opts).UpdateProject({
66
+ description,
67
+ });
68
+ });
69
+
70
+ const role = set.command('role').description('update a role');
71
+
72
+ role
73
+ .command('name')
74
+ .description('update role name')
75
+ .argument('<"Role name">', 'update the existing role name')
76
+ .argument('<"New name">', 'the new name for the role')
77
+ .usage('<"Role name"> <"New name">')
78
+ .addHelpText(
79
+ 'after',
80
+ `
81
+ Example call:
82
+ > set role name "Existing name" "New role name"\n`
83
+ )
84
+ .action(async (roleNameOrId: string, newName: string, opts) => {
85
+ await cliCommand(['set', 'role', 'name'], opts).UpdateRole(roleNameOrId, {
86
+ name: newName,
87
+ });
88
+ });
89
+
90
+ role
91
+ .command('description')
92
+ .description('update role description')
93
+ .argument('<"Role name" or id>', 'the existing role name or id to update')
94
+ .argument('<"New description">', 'the new description for the role')
95
+ .usage('<"Role name"> <"New description">')
96
+ .addHelpText(
97
+ 'after',
98
+ `
99
+ Example call:
100
+ > set role description "Existing role" "New role description"\n`
101
+ )
102
+ .action(async (roleNameOrId: string, description: string, opts) => {
103
+ await cliCommand(['set', 'role', 'description'], opts).UpdateRole(
104
+ roleNameOrId,
105
+ {
106
+ description,
107
+ }
108
+ );
21
109
  });
110
+
111
+ role
112
+ .command('enabled')
113
+ .description('enable or disable a role')
114
+ .argument('<"Role name" or id>', 'the existing role name or id to update')
115
+ .usage('<"Role name"> --disabled')
116
+ .option('--disabled', 'disable the role', false)
117
+ .addHelpText(
118
+ 'after',
119
+ `
120
+ Example call:
121
+ > set role enabled "Existing role"\n
122
+ > set role enabled "Other role" --disabled\n`
123
+ )
124
+ .action(async (roleNameOrId: string, opts) => {
125
+ await cliCommand(
126
+ ['set', 'role', opts.disabled ? 'disabled' : 'enabled'],
127
+ opts
128
+ ).UpdateRole(roleNameOrId, {
129
+ enabled: !opts.disabled,
130
+ });
131
+ });
132
+
133
+ role
134
+ .command('assignments')
135
+ .description('assign users, groups or keys to a role')
136
+ .argument('<"Role name" or id>', 'the role name or id to update')
137
+ .option(
138
+ '-users --assign-users [assign-users...]',
139
+ 'the user id(s) to assign'
140
+ )
141
+ .option(
142
+ '-groups --assign-groups [assign-groups...]',
143
+ 'the groups name(s) to assign'
144
+ )
145
+ .option('-keys --assign-keys [assign-keys...]', 'the key name(s) to assign')
146
+ .addHelpText(
147
+ 'after',
148
+ `
149
+ Example call:
150
+ > set role assignments "My role" --assign-users admin \n`
151
+ )
152
+ .action(async (roleNameOrId: string, opts) => {
153
+ await cliCommand(['set', 'role', 'assignments'], opts).UpdateRole(
154
+ roleNameOrId,
155
+ {
156
+ assignments: {
157
+ apiKeys: opts.assignKeys || undefined,
158
+ groups: opts.assignGroups || undefined,
159
+ users: opts.assignUsers || undefined,
160
+ },
161
+ }
162
+ );
163
+ });
164
+
165
+ role
166
+ .command('permissions')
167
+ .description('add entry permissions to a role')
168
+ .argument('<"Role name" or id>', 'the role name or id to update')
169
+ .option(
170
+ '-contenttypes, --content-type-ids [content-type-id...]',
171
+ 'any content type ids to add permissions for'
172
+ )
173
+ .option(
174
+ '--entry-actions [entry-actions...]',
175
+ 'the entry actions to add to the role permissions'
176
+ )
177
+ .option(
178
+ '--entry-languages [entry-languages...]',
179
+ 'the entry languages to add to the role permissions'
180
+ )
181
+ .addHelpText(
182
+ 'after',
183
+ `
184
+ Example call:
185
+ > set role permissions "My role" --content-type-id blogs -- \n`
186
+ )
187
+ .action(async (roleNameOrId: string, opts) => {
188
+ await cliCommand(['set', 'role', 'permissions'], opts).UpdateRole(
189
+ roleNameOrId,
190
+ {
191
+ permissions: {
192
+ entries: opts.contentTypeIds?.map((id: string) => ({
193
+ id,
194
+ actions: opts.entryActions || [],
195
+ languages: opts.entryLanguages || [],
196
+ })),
197
+ },
198
+ }
199
+ );
200
+ });
201
+
22
202
  set
23
203
  .command('version')
204
+ .description('set content version')
24
205
  .addArgument(
25
206
  new Argument('<versionStatus>', 'content version status')
26
207
  .choices(['latest', 'published'])
27
208
  .default('latest')
28
209
  )
29
210
  .usage('<latest/published>')
211
+ .addHelpText('after', `\n`)
30
212
  .action(async versionStatus => {
31
- const success = await cliCommand([
32
- 'set',
33
- 'version',
34
- versionStatus,
35
- ]).SetVersion(versionStatus);
36
- if (success) await shell().start();
213
+ const success = cliCommand(['set', 'version', versionStatus]).SetVersion(
214
+ versionStatus
215
+ );
216
+ if (success) await shell().restart();
37
217
  });
38
218
 
39
219
  return set;
package/src/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import commands from './commands';
2
2
  import { logError } from './util/logger';
3
3
  import ContensisCli from './services/ContensisCliService';
4
- import { jsonFormatter } from './util/json.formatter';
5
- // new ContensisCli(process.argv).DoCommandTasksAsync();
6
4
 
7
5
  // This is the CLI part of the app
8
6
  const program = commands();
@@ -12,8 +10,7 @@ program
12
10
  ContensisCli.quit();
13
11
  })
14
12
  .catch((err: any) => {
15
- if (!err.name?.includes('CommanderError'))
13
+ if (err && !err.name?.includes('CommanderError'))
16
14
  logError(err, `CLI ${err.toString()}`);
17
15
  ContensisCli.quit(err);
18
16
  });
19
- //.exitOverride(() => console.log('exit override!!!'));