contensis-cli 1.0.0-beta.53 → 1.0.0-beta.55

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 (68) hide show
  1. package/.vscode/launch.json +15 -15
  2. package/README.md +1226 -1226
  3. package/dist/commands/connect.js.map +1 -1
  4. package/dist/commands/create.js.map +1 -1
  5. package/dist/commands/diff.js.map +1 -1
  6. package/dist/commands/get.js.map +1 -1
  7. package/dist/commands/globalOptions.js.map +1 -1
  8. package/dist/commands/import.js.map +1 -1
  9. package/dist/commands/index.js.map +1 -1
  10. package/dist/commands/list.js.map +1 -1
  11. package/dist/commands/login.js.map +1 -1
  12. package/dist/commands/push.js.map +1 -1
  13. package/dist/commands/release.js.map +1 -1
  14. package/dist/commands/remove.js.map +1 -1
  15. package/dist/commands/set.js.map +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/localisation/en-GB.js.map +1 -1
  18. package/dist/providers/CredentialProvider.js.map +1 -1
  19. package/dist/providers/SessionCacheProvider.js.map +1 -1
  20. package/dist/providers/file-provider.js.map +1 -1
  21. package/dist/services/ContensisAuthService.js.map +1 -1
  22. package/dist/services/ContensisCliService.js +4 -0
  23. package/dist/services/ContensisCliService.js.map +2 -2
  24. package/dist/shell.js.map +1 -1
  25. package/dist/util/console.printer.js +5 -5
  26. package/dist/util/console.printer.js.map +2 -2
  27. package/dist/util/csv.formatter.js.map +1 -1
  28. package/dist/util/index.js.map +1 -1
  29. package/dist/util/json.formatter.js.map +1 -1
  30. package/dist/util/logger.js.map +1 -1
  31. package/dist/util/xml.formatter.js.map +1 -1
  32. package/dist/version.js +1 -1
  33. package/dist/version.js.map +1 -1
  34. package/esbuild.config.js +49 -49
  35. package/headless-setup.sh +6 -6
  36. package/package.json +59 -59
  37. package/src/commands/connect.ts +24 -24
  38. package/src/commands/create.ts +70 -70
  39. package/src/commands/diff.ts +41 -41
  40. package/src/commands/get.ts +214 -214
  41. package/src/commands/globalOptions.ts +127 -127
  42. package/src/commands/import.ts +128 -128
  43. package/src/commands/index.ts +80 -80
  44. package/src/commands/list.ts +116 -116
  45. package/src/commands/login.ts +34 -34
  46. package/src/commands/push.ts +127 -127
  47. package/src/commands/release.ts +32 -32
  48. package/src/commands/remove.ts +85 -85
  49. package/src/commands/set.ts +96 -96
  50. package/src/index.ts +19 -19
  51. package/src/localisation/en-GB.ts +289 -289
  52. package/src/models/AppError.d.ts +40 -40
  53. package/src/models/Cache.d.ts +25 -25
  54. package/src/models/JsModules.d.ts +1 -1
  55. package/src/providers/CredentialProvider.ts +121 -121
  56. package/src/providers/SessionCacheProvider.ts +101 -101
  57. package/src/providers/file-provider.ts +76 -76
  58. package/src/services/ContensisAuthService.ts +70 -70
  59. package/src/services/ContensisCliService.ts +1749 -1745
  60. package/src/shell.ts +270 -270
  61. package/src/util/console.printer.ts +371 -371
  62. package/src/util/csv.formatter.ts +21 -21
  63. package/src/util/index.ts +73 -73
  64. package/src/util/json.formatter.ts +1 -1
  65. package/src/util/logger.ts +234 -234
  66. package/src/util/xml.formatter.ts +20 -20
  67. package/src/version.ts +1 -1
  68. package/tsconfig.json +22 -22
package/src/shell.ts CHANGED
@@ -1,270 +1,270 @@
1
- import figlet from 'figlet';
2
- import inquirer from 'inquirer';
3
- import inquirerPrompt from 'inquirer-command-prompt';
4
- import commands from './commands';
5
- import { LogMessages } from './localisation/en-GB';
6
- import CredentialProvider from './providers/CredentialProvider';
7
- import { appRootDir } from './providers/file-provider';
8
- import ContensisCli, { cliCommand } from './services/ContensisCliService';
9
- import { Logging } from './util';
10
- import { logError, Logger } from './util/logger';
11
- import { LIB_VERSION } from './version';
12
-
13
- class ContensisShell {
14
- private currentEnvironment!: string;
15
- private emptyInputCounter: number = 0;
16
- private env!: EnvironmentCache;
17
- private firstStart = true;
18
- private userId: string = '';
19
- private log = Logger;
20
- private messages = LogMessages;
21
-
22
- private refreshEnvironment = () => {
23
- // Reload any persisted changes from the disk cache
24
- const {
25
- cache: { currentEnvironment = '', environments = {} },
26
- } = new ContensisCli([]);
27
- // console.log(`refreshing env w/${currentEnvironment}`);
28
- this.currentEnvironment = currentEnvironment;
29
- this.env = environments[currentEnvironment];
30
-
31
- // Reload logging here to support changing language
32
- Logging('en-GB').then(({ messages, Log }) => {
33
- this.log = Log;
34
- this.messages = messages;
35
- });
36
- };
37
-
38
- constructor() {
39
- this.refreshEnvironment();
40
- inquirerPrompt.setConfig({
41
- history: {
42
- save: true,
43
- folder: appRootDir,
44
- limit: 100,
45
- blacklist: ['quit'],
46
- },
47
- });
48
-
49
- const { log, messages } = this;
50
-
51
- figlet.text(
52
- messages.app.contensis(),
53
- {
54
- font: 'Block',
55
- horizontalLayout: 'default',
56
- verticalLayout: 'default',
57
- width: process.stdout.columns,
58
- whitespaceBreak: true,
59
- },
60
- (err, data) => {
61
- if (err) {
62
- log.error(messages.app.unknownError());
63
- console.dir(err);
64
- return;
65
- }
66
- console.log(log.successText(data));
67
- console.log(log.infoText(messages.app.startup(LIB_VERSION)));
68
- console.log(log.helpText(messages.app.help()));
69
-
70
- this.start().catch(ex => log.error(ex));
71
- }
72
- );
73
- }
74
-
75
- restart = async () => {
76
- this.firstStart = false;
77
- this.log.line(); // add a line so we can see where the shell has been restarted
78
- await this.start();
79
- };
80
-
81
- start = async () => {
82
- this.refreshEnvironment();
83
- this.userId = '';
84
- const { currentEnvironment, env, log, messages } = this;
85
-
86
- if (env?.lastUserId) {
87
- const [credsErr, credentials] = await new CredentialProvider(
88
- {
89
- userId: env.lastUserId,
90
- alias: currentEnvironment,
91
- },
92
- env.passwordFallback
93
- ).Init();
94
- if (credsErr && !credentials.current) {
95
- log.error(credsErr.message);
96
- }
97
- if (credentials.current) {
98
- if (this.firstStart) {
99
- const token = await cliCommand(['login', env.lastUserId]).Login(
100
- env.lastUserId,
101
- {
102
- promptPassword: false,
103
- silent: true,
104
- }
105
- );
106
- if (token) {
107
- this.userId = env.lastUserId;
108
- if (!env.currentProject) log.warning(messages.projects.tip());
109
- }
110
- this.firstStart = false;
111
- this.refreshEnvironment();
112
- } else {
113
- this.userId = env.lastUserId;
114
- }
115
- }
116
- }
117
- await this.contensisPrompt();
118
- };
119
-
120
- contensisPrompt = async (): Promise<any> => {
121
- const { currentEnvironment, env, log, messages, userId } = this;
122
-
123
- const availableCommands = [
124
- {
125
- filter: (str: string) => {
126
- return str.replace(/ \[.*$/, '');
127
- },
128
- },
129
- 'connect',
130
- 'list envs',
131
- 'quit',
132
- ];
133
-
134
- if (currentEnvironment)
135
- availableCommands.push('login', 'list projects', 'set project');
136
- if (userId)
137
- availableCommands.push(
138
- 'create project',
139
- 'diff models',
140
- 'get block',
141
- 'get block logs',
142
- 'get contenttype',
143
- 'get component',
144
- 'get entries',
145
- 'get model',
146
- 'get project',
147
- 'get version',
148
- 'import contenttypes',
149
- 'import components',
150
- 'import entries',
151
- 'import models',
152
- 'list blocks',
153
- 'list contenttypes',
154
- 'list components',
155
- 'list models',
156
- 'list keys',
157
- 'list webhooks',
158
- 'create key',
159
- 'push block',
160
- 'release block',
161
- 'remove key',
162
- 'remove entries',
163
- 'remove contenttypes',
164
- 'remove components',
165
- 'set project name',
166
- 'set project description'
167
- );
168
-
169
- const prompt = inquirer.createPromptModule();
170
- prompt.registerPrompt('command', inquirerPrompt);
171
- return prompt([
172
- {
173
- type: 'command',
174
- name: 'cmd',
175
- autoCompletion: availableCommands,
176
- autocompletePrompt: log.infoText(messages.app.autocomplete()),
177
- message: `${userId ? `${userId}@` : ''}${currentEnvironment || ''}>`,
178
- context: 0,
179
- validate: (val: string) => {
180
- if (!val) this.emptyInputCounter++;
181
- if (this.emptyInputCounter > 1)
182
- console.log(this.log.infoText(this.messages.app.suggestions()));
183
- if (val) {
184
- this.emptyInputCounter = 0;
185
- return true;
186
- }
187
- },
188
- prefix: `${env?.currentProject || log.infoText('contensis')}`,
189
- short: true,
190
- },
191
- ])
192
- .then(async (answers: { cmd: string }) => {
193
- if (answers.cmd === 'quit') {
194
- this.quit();
195
- } else {
196
- try {
197
- if (answers.cmd) {
198
- const program = commands();
199
- await program.parseAsync(
200
- answers.cmd
201
- .match(/"[^"]+"|[^\s]+/g)
202
- ?.map(e => e.replace(/"(.+)"/, '$1')),
203
- {
204
- from: 'user',
205
- }
206
- );
207
- }
208
- } catch (ex: any) {
209
- const str = ex.toString();
210
- if (!str.includes('CommanderError'))
211
- logError(ex, `Shell ${ex.toString()}`);
212
- } finally {
213
- return this.contensisPrompt();
214
- }
215
- }
216
- })
217
- .catch((err: Error) => {
218
- log.error(err.message);
219
- this.quit();
220
- });
221
- };
222
-
223
- quit = (error?: Error) => {
224
- const { log, messages } = this;
225
- process.removeAllListeners('exit');
226
-
227
- if (error) {
228
- log.error(error.message);
229
- process.exit(1);
230
- } else {
231
- log.success(messages.app.quit());
232
- process.exitCode = 0;
233
- process.exit(0);
234
- }
235
- };
236
- }
237
-
238
- let globalShell: ContensisShell;
239
-
240
- export const shell = () => {
241
- // Return a benign function for shell().restart() when used in cli context
242
- // as some commands need to restart the shell to show an updated prompt
243
- // after successful connect / login / set project
244
- if (typeof process.argv?.[2] !== 'undefined') return { restart() {} } as any;
245
- if (!globalShell) globalShell = new ContensisShell();
246
- return globalShell;
247
- };
248
-
249
- process.on('uncaughtException', function (err) {
250
- // Handle the error safely
251
- console.log(err);
252
- });
253
-
254
- process.on('SIGINT', () => {
255
- console.log('catching SIGINT');
256
- shell().quit();
257
- });
258
-
259
- process.on('SIGTERM', () => {
260
- console.log('catching SIGTERM');
261
- shell().quit();
262
- });
263
-
264
- process.stdin.on('data', key => {
265
- if ((key as any) == '\u0003') {
266
- console.log('');
267
- Logger.info(`[CTRL]+[C] detected, exiting shell...`);
268
- shell().quit();
269
- }
270
- });
1
+ import figlet from 'figlet';
2
+ import inquirer from 'inquirer';
3
+ import inquirerPrompt from 'inquirer-command-prompt';
4
+ import commands from './commands';
5
+ import { LogMessages } from './localisation/en-GB';
6
+ import CredentialProvider from './providers/CredentialProvider';
7
+ import { appRootDir } from './providers/file-provider';
8
+ import ContensisCli, { cliCommand } from './services/ContensisCliService';
9
+ import { Logging } from './util';
10
+ import { logError, Logger } from './util/logger';
11
+ import { LIB_VERSION } from './version';
12
+
13
+ class ContensisShell {
14
+ private currentEnvironment!: string;
15
+ private emptyInputCounter: number = 0;
16
+ private env!: EnvironmentCache;
17
+ private firstStart = true;
18
+ private userId: string = '';
19
+ private log = Logger;
20
+ private messages = LogMessages;
21
+
22
+ private refreshEnvironment = () => {
23
+ // Reload any persisted changes from the disk cache
24
+ const {
25
+ cache: { currentEnvironment = '', environments = {} },
26
+ } = new ContensisCli([]);
27
+ // console.log(`refreshing env w/${currentEnvironment}`);
28
+ this.currentEnvironment = currentEnvironment;
29
+ this.env = environments[currentEnvironment];
30
+
31
+ // Reload logging here to support changing language
32
+ Logging('en-GB').then(({ messages, Log }) => {
33
+ this.log = Log;
34
+ this.messages = messages;
35
+ });
36
+ };
37
+
38
+ constructor() {
39
+ this.refreshEnvironment();
40
+ inquirerPrompt.setConfig({
41
+ history: {
42
+ save: true,
43
+ folder: appRootDir,
44
+ limit: 100,
45
+ blacklist: ['quit'],
46
+ },
47
+ });
48
+
49
+ const { log, messages } = this;
50
+
51
+ figlet.text(
52
+ messages.app.contensis(),
53
+ {
54
+ font: 'Block',
55
+ horizontalLayout: 'default',
56
+ verticalLayout: 'default',
57
+ width: process.stdout.columns,
58
+ whitespaceBreak: true,
59
+ },
60
+ (err, data) => {
61
+ if (err) {
62
+ log.error(messages.app.unknownError());
63
+ console.dir(err);
64
+ return;
65
+ }
66
+ console.log(log.successText(data));
67
+ console.log(log.infoText(messages.app.startup(LIB_VERSION)));
68
+ console.log(log.helpText(messages.app.help()));
69
+
70
+ this.start().catch(ex => log.error(ex));
71
+ }
72
+ );
73
+ }
74
+
75
+ restart = async () => {
76
+ this.firstStart = false;
77
+ this.log.line(); // add a line so we can see where the shell has been restarted
78
+ await this.start();
79
+ };
80
+
81
+ start = async () => {
82
+ this.refreshEnvironment();
83
+ this.userId = '';
84
+ const { currentEnvironment, env, log, messages } = this;
85
+
86
+ if (env?.lastUserId) {
87
+ const [credsErr, credentials] = await new CredentialProvider(
88
+ {
89
+ userId: env.lastUserId,
90
+ alias: currentEnvironment,
91
+ },
92
+ env.passwordFallback
93
+ ).Init();
94
+ if (credsErr && !credentials.current) {
95
+ log.error(credsErr.message);
96
+ }
97
+ if (credentials.current) {
98
+ if (this.firstStart) {
99
+ const token = await cliCommand(['login', env.lastUserId]).Login(
100
+ env.lastUserId,
101
+ {
102
+ promptPassword: false,
103
+ silent: true,
104
+ }
105
+ );
106
+ if (token) {
107
+ this.userId = env.lastUserId;
108
+ if (!env.currentProject) log.warning(messages.projects.tip());
109
+ }
110
+ this.firstStart = false;
111
+ this.refreshEnvironment();
112
+ } else {
113
+ this.userId = env.lastUserId;
114
+ }
115
+ }
116
+ }
117
+ await this.contensisPrompt();
118
+ };
119
+
120
+ contensisPrompt = async (): Promise<any> => {
121
+ const { currentEnvironment, env, log, messages, userId } = this;
122
+
123
+ const availableCommands = [
124
+ {
125
+ filter: (str: string) => {
126
+ return str.replace(/ \[.*$/, '');
127
+ },
128
+ },
129
+ 'connect',
130
+ 'list envs',
131
+ 'quit',
132
+ ];
133
+
134
+ if (currentEnvironment)
135
+ availableCommands.push('login', 'list projects', 'set project');
136
+ if (userId)
137
+ availableCommands.push(
138
+ 'create project',
139
+ 'diff models',
140
+ 'get block',
141
+ 'get block logs',
142
+ 'get contenttype',
143
+ 'get component',
144
+ 'get entries',
145
+ 'get model',
146
+ 'get project',
147
+ 'get version',
148
+ 'import contenttypes',
149
+ 'import components',
150
+ 'import entries',
151
+ 'import models',
152
+ 'list blocks',
153
+ 'list contenttypes',
154
+ 'list components',
155
+ 'list models',
156
+ 'list keys',
157
+ 'list webhooks',
158
+ 'create key',
159
+ 'push block',
160
+ 'release block',
161
+ 'remove key',
162
+ 'remove entries',
163
+ 'remove contenttypes',
164
+ 'remove components',
165
+ 'set project name',
166
+ 'set project description'
167
+ );
168
+
169
+ const prompt = inquirer.createPromptModule();
170
+ prompt.registerPrompt('command', inquirerPrompt);
171
+ return prompt([
172
+ {
173
+ type: 'command',
174
+ name: 'cmd',
175
+ autoCompletion: availableCommands,
176
+ autocompletePrompt: log.infoText(messages.app.autocomplete()),
177
+ message: `${userId ? `${userId}@` : ''}${currentEnvironment || ''}>`,
178
+ context: 0,
179
+ validate: (val: string) => {
180
+ if (!val) this.emptyInputCounter++;
181
+ if (this.emptyInputCounter > 1)
182
+ console.log(this.log.infoText(this.messages.app.suggestions()));
183
+ if (val) {
184
+ this.emptyInputCounter = 0;
185
+ return true;
186
+ }
187
+ },
188
+ prefix: `${env?.currentProject || log.infoText('contensis')}`,
189
+ short: true,
190
+ },
191
+ ])
192
+ .then(async (answers: { cmd: string }) => {
193
+ if (answers.cmd === 'quit') {
194
+ this.quit();
195
+ } else {
196
+ try {
197
+ if (answers.cmd) {
198
+ const program = commands();
199
+ await program.parseAsync(
200
+ answers.cmd
201
+ .match(/"[^"]+"|[^\s]+/g)
202
+ ?.map(e => e.replace(/"(.+)"/, '$1')),
203
+ {
204
+ from: 'user',
205
+ }
206
+ );
207
+ }
208
+ } catch (ex: any) {
209
+ const str = ex.toString();
210
+ if (!str.includes('CommanderError'))
211
+ logError(ex, `Shell ${ex.toString()}`);
212
+ } finally {
213
+ return this.contensisPrompt();
214
+ }
215
+ }
216
+ })
217
+ .catch((err: Error) => {
218
+ log.error(err.message);
219
+ this.quit();
220
+ });
221
+ };
222
+
223
+ quit = (error?: Error) => {
224
+ const { log, messages } = this;
225
+ process.removeAllListeners('exit');
226
+
227
+ if (error) {
228
+ log.error(error.message);
229
+ process.exit(1);
230
+ } else {
231
+ log.success(messages.app.quit());
232
+ process.exitCode = 0;
233
+ process.exit(0);
234
+ }
235
+ };
236
+ }
237
+
238
+ let globalShell: ContensisShell;
239
+
240
+ export const shell = () => {
241
+ // Return a benign function for shell().restart() when used in cli context
242
+ // as some commands need to restart the shell to show an updated prompt
243
+ // after successful connect / login / set project
244
+ if (typeof process.argv?.[2] !== 'undefined') return { restart() {} } as any;
245
+ if (!globalShell) globalShell = new ContensisShell();
246
+ return globalShell;
247
+ };
248
+
249
+ process.on('uncaughtException', function (err) {
250
+ // Handle the error safely
251
+ console.log(err);
252
+ });
253
+
254
+ process.on('SIGINT', () => {
255
+ console.log('catching SIGINT');
256
+ shell().quit();
257
+ });
258
+
259
+ process.on('SIGTERM', () => {
260
+ console.log('catching SIGTERM');
261
+ shell().quit();
262
+ });
263
+
264
+ process.stdin.on('data', key => {
265
+ if ((key as any) == '\u0003') {
266
+ console.log('');
267
+ Logger.info(`[CTRL]+[C] detected, exiting shell...`);
268
+ shell().quit();
269
+ }
270
+ });