contensis-cli 1.0.12-beta.0 → 1.0.12-beta.10

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 (62) hide show
  1. package/README.md +9 -9
  2. package/dist/commands/get.js +13 -1
  3. package/dist/commands/get.js.map +2 -2
  4. package/dist/commands/globalOptions.js +9 -10
  5. package/dist/commands/globalOptions.js.map +2 -2
  6. package/dist/commands/import.js +25 -10
  7. package/dist/commands/import.js.map +2 -2
  8. package/dist/commands/index.js +2 -2
  9. package/dist/commands/index.js.map +2 -2
  10. package/dist/commands/list.js +9 -0
  11. package/dist/commands/list.js.map +2 -2
  12. package/dist/commands/remove.js +13 -0
  13. package/dist/commands/remove.js.map +2 -2
  14. package/dist/localisation/en-GB.js +8 -2
  15. package/dist/localisation/en-GB.js.map +2 -2
  16. package/dist/mappers/DevInit-to-CIWorkflow.js +6 -8
  17. package/dist/mappers/DevInit-to-CIWorkflow.js.map +2 -2
  18. package/dist/mappers/DevInit-to-RolePermissions.js.map +2 -2
  19. package/dist/providers/file-provider.js +5 -1
  20. package/dist/providers/file-provider.js.map +2 -2
  21. package/dist/services/ContensisAuthService.js +10 -8
  22. package/dist/services/ContensisAuthService.js.map +2 -2
  23. package/dist/services/ContensisCliService.js +168 -77
  24. package/dist/services/ContensisCliService.js.map +3 -3
  25. package/dist/services/ContensisDevService.js +47 -53
  26. package/dist/services/ContensisDevService.js.map +3 -3
  27. package/dist/shell.js +5 -0
  28. package/dist/shell.js.map +2 -2
  29. package/dist/util/console.printer.js +111 -10
  30. package/dist/util/console.printer.js.map +2 -2
  31. package/dist/util/error.js +36 -0
  32. package/dist/util/error.js.map +7 -0
  33. package/dist/util/find.js +10 -2
  34. package/dist/util/find.js.map +2 -2
  35. package/dist/util/git.js +1 -0
  36. package/dist/util/git.js.map +2 -2
  37. package/dist/util/logger.js +52 -9
  38. package/dist/util/logger.js.map +3 -3
  39. package/dist/version.js +1 -1
  40. package/dist/version.js.map +1 -1
  41. package/package.json +4 -4
  42. package/src/commands/get.ts +19 -1
  43. package/src/commands/globalOptions.ts +9 -7
  44. package/src/commands/import.ts +41 -13
  45. package/src/commands/index.ts +2 -3
  46. package/src/commands/list.ts +15 -0
  47. package/src/commands/remove.ts +20 -0
  48. package/src/localisation/en-GB.ts +10 -3
  49. package/src/mappers/DevInit-to-CIWorkflow.ts +6 -8
  50. package/src/mappers/DevInit-to-RolePermissions.ts +1 -0
  51. package/src/models/Cache.d.ts +1 -1
  52. package/src/providers/file-provider.ts +5 -1
  53. package/src/services/ContensisAuthService.ts +11 -9
  54. package/src/services/ContensisCliService.ts +215 -103
  55. package/src/services/ContensisDevService.ts +73 -66
  56. package/src/shell.ts +5 -0
  57. package/src/util/console.printer.ts +238 -12
  58. package/src/util/error.ts +7 -0
  59. package/src/util/find.ts +13 -2
  60. package/src/util/git.ts +2 -1
  61. package/src/util/logger.ts +90 -15
  62. package/src/version.ts +1 -1
@@ -1,6 +1,11 @@
1
1
  import { Command, Option } from 'commander';
2
2
  import { cliCommand } from '~/services/ContensisCliService';
3
- import { commit, mapContensisOpts } from './globalOptions';
3
+ import {
4
+ commit,
5
+ getEntryOptions,
6
+ ignoreErrors,
7
+ mapContensisOpts,
8
+ } from './globalOptions';
4
9
 
5
10
  export const makeImportCommand = () => {
6
11
  const program = new Command()
@@ -94,13 +99,15 @@ Example call:
94
99
  );
95
100
  });
96
101
 
97
- program
98
- .command('entries')
99
- .description('import entries')
100
- .argument(
101
- '[search phrase]',
102
- 'get entries with the search phrase, use quotes for multiple words'
103
- )
102
+ getEntryOptions(
103
+ program
104
+ .command('entries')
105
+ .description('import entries')
106
+ .argument(
107
+ '[search phrase]',
108
+ 'get entries with the search phrase, use quotes for multiple words'
109
+ )
110
+ )
104
111
  .addOption(commit)
105
112
  .option(
106
113
  '-preserve --preserve-guids',
@@ -114,6 +121,7 @@ Example call:
114
121
  .choices(['errors', 'changes', 'all'])
115
122
  .default('errors')
116
123
  )
124
+ .addOption(ignoreErrors)
117
125
  .addHelpText(
118
126
  'after',
119
127
  `
@@ -137,24 +145,44 @@ Example call:
137
145
  program
138
146
  .command('nodes')
139
147
  .description('import nodes')
148
+ .argument('[root]', 'import nodes from the specified path e.g. /blog', '/')
149
+ .option(
150
+ '-preserve --preserve-guids',
151
+ 'include this flag when you are importing nodes that you have previously exported and wish to update'
152
+ )
153
+ .addOption(ignoreErrors)
140
154
  .addOption(commit)
155
+ .addOption(
156
+ new Option(
157
+ '-od --output-detail <outputDetail>',
158
+ 'how much detail to output from the import'
159
+ )
160
+ .choices(['errors', 'changes', 'all'])
161
+ .default('errors')
162
+ )
163
+ .option(
164
+ '-ol --output-limit <outputLimit>',
165
+ 'expand or limit the number of records output to the console',
166
+ '200'
167
+ )
141
168
  .addHelpText(
142
169
  'after',
143
170
  `
144
171
  Example call:
145
- > import nodes --from-file component-backup.json
146
- > import nodes --source-alias example-alias --source-project-id example-project
172
+ > import nodes /blog --source-alias example-alias --source-project-id example-project
173
+ > import nodes --from-file site-backup.json --preserve-guids
147
174
  `
148
175
  )
149
- .action(async opts => {
176
+ .action(async (root: string, opts) => {
150
177
  await cliCommand(
151
178
  ['import', 'nodes'],
152
179
  opts,
153
- mapContensisOpts({ ...opts })
180
+ mapContensisOpts({ paths: root.split(' '), ...opts })
154
181
  ).ImportNodes({
155
182
  commit: opts.commit,
156
183
  fromFile: opts.fromFile,
157
- logOutput: opts.outputNodes,
184
+ logOutput: opts.outputDetail,
185
+ logLimit: Number(opts.outputLimit),
158
186
  });
159
187
  });
160
188
 
@@ -10,7 +10,6 @@ import { makeGetCommand } from './get';
10
10
  import {
11
11
  addAuthenticationOptions,
12
12
  addConnectOptions,
13
- addGetEntryOptions,
14
13
  addGlobalOptions,
15
14
  addImportOptions,
16
15
  } from './globalOptions';
@@ -60,7 +59,7 @@ const commands = () => {
60
59
  );
61
60
  program.addCommand(
62
61
  addGlobalOptions(
63
- addGetEntryOptions(addImportOptions(makeDiffCommand()))
62
+ addImportOptions(makeDiffCommand())
64
63
  ).copyInheritedSettings(program)
65
64
  );
66
65
  program.addCommand(
@@ -68,7 +67,7 @@ const commands = () => {
68
67
  );
69
68
  program.addCommand(
70
69
  addGlobalOptions(
71
- addGetEntryOptions(addImportOptions(makeImportCommand()))
70
+ addImportOptions(makeImportCommand())
72
71
  ).copyInheritedSettings(program)
73
72
  );
74
73
  program.addCommand(
@@ -160,5 +160,20 @@ Example call:
160
160
  name ? [name] : id
161
161
  );
162
162
  });
163
+
164
+ list
165
+ .command('workflows')
166
+ .description('print list of workflow definitions')
167
+ .addHelpText(
168
+ 'after',
169
+ `
170
+ Example call:
171
+ > list workflows
172
+ `
173
+ )
174
+ .action(async opts => {
175
+ await cliCommand(['list', 'workflows'], opts).PrintWorkflows();
176
+ });
177
+
163
178
  return list;
164
179
  };
@@ -135,5 +135,25 @@ Example call:
135
135
  }
136
136
  });
137
137
 
138
+ remove
139
+ .command('nodes')
140
+ .description('delete nodes from the site view tree')
141
+ .argument('<root>', 'remove nodes from the specified path e.g. /blog or /')
142
+ .addOption(commit)
143
+ .addHelpText(
144
+ 'after',
145
+ `
146
+ Example call:
147
+ > remove nodes /blog
148
+ `
149
+ )
150
+ .action(async (root: string, opts) => {
151
+ await cliCommand(
152
+ ['remove', 'nodes', root],
153
+ opts,
154
+ mapContensisOpts({ paths: root.split(' '), ...opts })
155
+ ).RemoveNodes(opts.commit);
156
+ });
157
+
138
158
  return remove;
139
159
  };
@@ -158,8 +158,8 @@ export const LogMessages = {
158
158
  imported: (env: string, commit: boolean, count: number) =>
159
159
  `[${env}] ${commit ? `Imported` : `Will import`} ${count} nodes`,
160
160
  failedImport: (env: string) => `[${env}] Unable to import nodes`,
161
- removed: (env: string, commit: boolean) =>
162
- `[${env}] ${commit ? `Deleted` : `Will delete`} nodes`,
161
+ removed: (env: string, commit: boolean, root: string) =>
162
+ `[${env}] ${commit ? `Deleted` : `Will delete`} nodes at ${root}`,
163
163
  failedRemove: (env: string) => `[${env}] Unable to delete nodes`,
164
164
  notFound: (env: string) => `[${env}] Nodes were not found `,
165
165
  commitTip: () => `Add --commit flag to commit the previewed changes`,
@@ -432,6 +432,13 @@ export const LogMessages = {
432
432
  id
433
433
  )}`,
434
434
  },
435
+ workflows: {
436
+ list: (env: string) => `[${env}] Retrieved workflows`,
437
+ noList: (env: string) => `[${env}] Cannot retrieve workflows`,
438
+ noneExist: () => `No workflows found`,
439
+ failedGet: (env: string, name: string) =>
440
+ `[${env}] Unable to find workflow ${Logger.highlightText(name)}`,
441
+ },
435
442
  devinit: {
436
443
  intro: () => `Contensis developer environment initialisation`,
437
444
  //`This will initialise your local working directory to develop with the current connected Contensis project`,
@@ -444,7 +451,7 @@ export const LogMessages = {
444
451
  ) =>
445
452
  `
446
453
  Project: ${Logger.standardText(name)}
447
- - Home: ${Logger.standardText(process.cwd())}
454
+ - Home: ${Logger.standardText(git.gitcwd())}
448
455
  - Repository: ${Logger.standardText(git.home)}
449
456
  - Block id: ${Logger.highlightText(blockId)}
450
457
 
@@ -102,12 +102,10 @@ const mapGitLabCIWorkflowContent = async (
102
102
  alias: cli.currentEnv,
103
103
  project_id: cli.currentProject,
104
104
  client_id:
105
- loc === 'env'
106
- ? cli.devinit?.credentials.clientId
107
- : '$CONTENSIS_CLIENT_ID',
105
+ loc === 'env' ? cli.deployCredentials.clientId : '$CONTENSIS_CLIENT_ID',
108
106
  shared_secret:
109
107
  loc === 'env'
110
- ? cli.devinit?.credentials.clientSecret
108
+ ? cli.deployCredentials.clientSecret
111
109
  : '$CONTENSIS_SHARED_SECRET',
112
110
  },
113
111
  };
@@ -120,12 +118,12 @@ const mapGitLabCIWorkflowContent = async (
120
118
  setWorkflowElement(
121
119
  workflowDoc,
122
120
  `variables.CONTENSIS_CLIENT_ID`,
123
- `${cli.devinit.credentials.clientId}`
121
+ `${cli.deployCredentials.clientId}`
124
122
  );
125
123
  setWorkflowElement(
126
124
  workflowDoc,
127
125
  `variables.CONTENSIS_CLIENT_SECRET`,
128
- `${cli.devinit.credentials.clientSecret}`
126
+ `${cli.deployCredentials.clientSecret}`
129
127
  );
130
128
  }
131
129
 
@@ -298,12 +296,12 @@ const mapGitHubActionCIWorkflowContent = async (
298
296
  setWorkflowElement(
299
297
  workflowDoc,
300
298
  `env.CONTENSIS_CLIENT_ID`,
301
- cli.devinit?.credentials.clientId
299
+ cli.deployCredentials.clientId
302
300
  );
303
301
  setWorkflowElement(
304
302
  workflowDoc,
305
303
  'env.CONTENSIS_SHARED_SECRET',
306
- cli.devinit?.credentials.clientSecret
304
+ cli.deployCredentials.clientSecret
307
305
  );
308
306
  }
309
307
 
@@ -1,6 +1,7 @@
1
1
  import { Role } from 'contensis-management-api/lib/models';
2
2
 
3
3
  export const devKeyPermissions = {} as Partial<Role['permissions']>;
4
+
4
5
  export const deployKeyPermissions = {
5
6
  blocks: { actions: ['push', 'release', 'view'] },
6
7
  } as Role['permissions'];
@@ -19,7 +19,7 @@ type EnvironmentCache = {
19
19
 
20
20
  type CliCommand = {
21
21
  createdDate: string;
22
- createdUserId: string;
22
+ invokedBy: string;
23
23
  commandText: string;
24
24
  result?: any;
25
25
  };
@@ -11,7 +11,8 @@ export const appRootDir =
11
11
  : path.join(userHomeDir, '.contensis/');
12
12
 
13
13
  export const readJsonFile = <T>(filePath: string) => {
14
- const file = readFile(filePath);
14
+ const directoryPath = cwdPath(filePath);
15
+ const file = readFile(directoryPath);
15
16
  if (file) return tryParse(file) as T | string;
16
17
  return undefined;
17
18
  };
@@ -81,3 +82,6 @@ export const checkDir = (filePath: string) => {
81
82
 
82
83
  export const localPath = (filePath: string) =>
83
84
  path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);
85
+
86
+ export const cwdPath = (filePath: string) =>
87
+ path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath);
@@ -25,7 +25,15 @@ class ContensisAuthService {
25
25
  clientType: ClientGrantType;
26
26
  clientDetails: ClientGrants;
27
27
  };
28
- if (username && password) {
28
+ if (clientId && clientSecret) {
29
+ credentials = {
30
+ clientType: 'client_credentials',
31
+ clientDetails: {
32
+ clientId,
33
+ clientSecret,
34
+ },
35
+ };
36
+ } else if (username && password) {
29
37
  credentials = {
30
38
  clientType: 'contensis_classic',
31
39
  clientDetails: {
@@ -41,13 +49,7 @@ class ContensisAuthService {
41
49
  },
42
50
  };
43
51
  } else {
44
- credentials = {
45
- clientType: 'client_credentials',
46
- clientDetails: {
47
- clientId,
48
- clientSecret,
49
- },
50
- };
52
+ credentials = { clientType: 'none', clientDetails: { refreshToken: '' } };
51
53
  }
52
54
 
53
55
  this.client = NodejsClient.create({
@@ -57,7 +59,7 @@ class ContensisAuthService {
57
59
  });
58
60
  }
59
61
 
60
- ClassicToken = async () => {
62
+ ClassicToken = async (): Promise<string | null | undefined> => {
61
63
  // make sure our token isn't expried.
62
64
  await this.client.ensureBearerToken();
63
65
  return (this.client as any).contensisClassicToken;