contensis-cli 1.0.12-beta.2 → 1.0.12-beta.21

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 (71) 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 +22 -12
  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 +12 -4
  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 +4 -4
  19. package/dist/mappers/DevInit-to-RolePermissions.js.map +2 -2
  20. package/dist/providers/file-provider.js +5 -1
  21. package/dist/providers/file-provider.js.map +2 -2
  22. package/dist/services/ContensisAuthService.js.map +2 -2
  23. package/dist/services/ContensisCliService.js +158 -40
  24. package/dist/services/ContensisCliService.js.map +2 -2
  25. package/dist/services/ContensisDevService.js +51 -56
  26. package/dist/services/ContensisDevService.js.map +3 -3
  27. package/dist/shell.js +6 -0
  28. package/dist/shell.js.map +2 -2
  29. package/dist/util/console.printer.js +61 -52
  30. package/dist/util/console.printer.js.map +3 -3
  31. package/dist/util/csv.formatter.js +3 -11
  32. package/dist/util/csv.formatter.js.map +3 -3
  33. package/dist/util/diff.js +1 -1
  34. package/dist/util/diff.js.map +2 -2
  35. package/dist/util/error.js +36 -0
  36. package/dist/util/error.js.map +7 -0
  37. package/dist/util/find.js +10 -2
  38. package/dist/util/find.js.map +2 -2
  39. package/dist/util/git.js +1 -0
  40. package/dist/util/git.js.map +2 -2
  41. package/dist/util/json.formatter.js +35 -3
  42. package/dist/util/json.formatter.js.map +3 -3
  43. package/dist/util/logger.js +52 -9
  44. package/dist/util/logger.js.map +3 -3
  45. package/dist/version.js +1 -1
  46. package/dist/version.js.map +1 -1
  47. package/package.json +4 -4
  48. package/src/commands/get.ts +19 -1
  49. package/src/commands/globalOptions.ts +9 -7
  50. package/src/commands/import.ts +35 -15
  51. package/src/commands/index.ts +2 -3
  52. package/src/commands/list.ts +15 -0
  53. package/src/commands/remove.ts +20 -0
  54. package/src/localisation/en-GB.ts +15 -5
  55. package/src/mappers/DevInit-to-CIWorkflow.ts +8 -8
  56. package/src/mappers/DevInit-to-RolePermissions.ts +5 -2
  57. package/src/models/Cache.d.ts +2 -1
  58. package/src/providers/file-provider.ts +5 -1
  59. package/src/services/ContensisAuthService.ts +1 -1
  60. package/src/services/ContensisCliService.ts +195 -55
  61. package/src/services/ContensisDevService.ts +76 -70
  62. package/src/shell.ts +8 -0
  63. package/src/util/console.printer.ts +151 -72
  64. package/src/util/csv.formatter.ts +1 -4
  65. package/src/util/diff.ts +1 -1
  66. package/src/util/error.ts +7 -0
  67. package/src/util/find.ts +13 -2
  68. package/src/util/git.ts +2 -1
  69. package/src/util/json.formatter.ts +32 -1
  70. package/src/util/logger.ts +90 -15
  71. package/src/version.ts +1 -1
package/src/util/git.ts CHANGED
@@ -75,7 +75,7 @@ export class GitHelper {
75
75
  }
76
76
  gitcwd = () => path.join(this.gitRepoPath);
77
77
  gitInfo = (url: string = this.originUrl) => hostedGitInfo.fromUrl(url);
78
- hostType = (url: string = this.originUrl): GitTypes => {
78
+ hostType = (url: string = this.originUrl): GitTypes | undefined => {
79
79
  if (url) {
80
80
  if (url.includes('github.com')) return 'github';
81
81
  else return 'gitlab';
@@ -87,6 +87,7 @@ export class GitHelper {
87
87
  gitConfig = (cwd = this.gitRepoPath) => {
88
88
  // Find .git/config in project cwd
89
89
  const config = parseGitConfig.sync({
90
+ cwd,
90
91
  path: '.git/config',
91
92
  expandKeys: true,
92
93
  });
@@ -1 +1,32 @@
1
- export const jsonFormatter = <T>(obj: T) => JSON.stringify(obj, null, 2);
1
+ import { flatten, unflatten } from 'flat';
2
+ import cleaner from 'deep-cleaner';
3
+
4
+ // Format a JSON object for a nice output
5
+ export const jsonFormatter = <T>(obj: T, fields?: string[]) =>
6
+ JSON.stringify(limitFields(obj, fields), null, 2);
7
+
8
+ // Flatten a JSON object such as an entry so there are no
9
+ // nested object and the keys are presented like "sys.version.versionNo": "1.0"
10
+ export const flattenObject = (obj: any) => flatten(cleaner(obj, ['workflow']));
11
+
12
+ // Will limit and sort an object's keys by an array of supplied fields
13
+ export const limitFields = (obj: any, fields?: string[]): any => {
14
+ if (!fields) return obj;
15
+ if (obj && Array.isArray(obj)) {
16
+ const arr = [];
17
+ for (const child of obj) arr.push(limitFields(child, fields));
18
+ return arr;
19
+ }
20
+
21
+ if (obj && typeof obj === 'object') {
22
+ const flattenedObj = flatten(obj) as any;
23
+ const sortedObj = {} as any;
24
+ for (const field of fields) {
25
+ sortedObj[field] = flattenedObj[field];
26
+ }
27
+
28
+ return unflatten(sortedObj);
29
+ }
30
+
31
+ return obj;
32
+ };
@@ -2,7 +2,12 @@
2
2
  import chalk from 'chalk';
3
3
  import dateFormat from 'dateformat';
4
4
  import deepCleaner from 'deep-cleaner';
5
- import { ansiEscapeCodes, first, strlen } from 'printable-characters';
5
+ import {
6
+ ansiEscapeCodes,
7
+ first,
8
+ partition,
9
+ strlen,
10
+ } from 'printable-characters';
6
11
  // import ProgressBar from 'progress';
7
12
  import { isSysError, tryStringify } from '.';
8
13
 
@@ -225,24 +230,41 @@ export class Logger {
225
230
  else console.log(content);
226
231
  };
227
232
 
228
- static limits = (content: string, displayLength = 30) => {
229
- const consoleWidth = process.stdout.columns;
230
- console.info(
231
- consoleWidth
232
- ? content
233
- .split('\n')
234
- .slice(0, consoleWidth ? displayLength : undefined)
235
- .map((line: string) =>
236
- consoleWidth && strlen(line) > consoleWidth
237
- ? first(line, consoleWidth)
238
- : line
233
+ static limits = (
234
+ content: string,
235
+ displayLength = 30,
236
+ consoleWidth = process.stdout.columns,
237
+ logMethod: Function = console.info
238
+ ) => {
239
+ if (consoleWidth) {
240
+ const contentArray = content.endsWith('\n')
241
+ ? content.split('\n').slice(0, -1)
242
+ : content.split('\n');
243
+ const contentLines = contentArray.slice(
244
+ 0,
245
+ consoleWidth ? displayLength : undefined
246
+ );
247
+ for (const line of contentLines)
248
+ logMethod(
249
+ line
250
+ .split('~n')
251
+ .map(l =>
252
+ consoleWidth && strlen(l) > consoleWidth
253
+ ? first(l, consoleWidth)
254
+ : l
239
255
  )
240
256
  .join('\n')
241
- : content.replace(ansiEscapeCodes, '')
242
- );
257
+ );
258
+ } else {
259
+ logMethod(content.replace(ansiEscapeCodes, '').replaceAll('~n', '\n'));
260
+ }
261
+
243
262
  const tableArray = content.split('\n');
244
263
  if (consoleWidth && tableArray.length > displayLength)
245
- console.info(`\n`, `- and ${tableArray.length - displayLength} more...`);
264
+ console.info(
265
+ `\n`,
266
+ `- and ${tableArray.length - displayLength} more...\n`
267
+ );
246
268
  };
247
269
  }
248
270
 
@@ -265,6 +287,59 @@ export const logError: LogErrorFunc = (
265
287
  return null;
266
288
  };
267
289
 
290
+ export const addNewLines = (
291
+ message = '',
292
+ newLineSeparater = '\n',
293
+ atPosition = process.stdout.columns
294
+ ) => {
295
+ if (message === '' || atPosition === 0) {
296
+ return '';
297
+ }
298
+
299
+ let result = '';
300
+ let lengthCounter = 0;
301
+
302
+ // Partition the message string into an array of
303
+ // [nonPrintable, printable][]
304
+ const partitioned = partition(message);
305
+ const addSeparater = () => {
306
+ // If line length counter has exceeded the console width
307
+ // add a new line separater and reset the line length counter
308
+ if (lengthCounter >= atPosition) {
309
+ result += newLineSeparater;
310
+ lengthCounter = 0;
311
+ }
312
+ };
313
+
314
+ // Loop through the partitioned message parts
315
+ for (const [nonPrintable, printable] of partitioned) {
316
+ // Convert string to array as this will provide accurate
317
+ // lengths and splicing methods with all unicode chars
318
+ const textParts = Array.from(printable);
319
+ // Splice the remaining allowable line length from the text parts array
320
+ const text = textParts.splice(0, atPosition - lengthCounter);
321
+ // In the first iteration append the non printable unicode chars
322
+ // to the beginning of the spliced text
323
+ result += nonPrintable + text.join('');
324
+ // Keep a count of the current line length
325
+ // as one line of output could span multiple "partitions"
326
+ lengthCounter += text.length;
327
+ addSeparater();
328
+
329
+ // Handle any remaining text in this "partition"
330
+ while (textParts.length) {
331
+ // Splice the remaining allowable line length from the text parts array
332
+ const text = textParts.splice(0, atPosition - lengthCounter);
333
+ // Append the spliced text to the result
334
+ result += text.join('');
335
+ // Increase line length counter
336
+ lengthCounter += text.length;
337
+ addSeparater();
338
+ }
339
+ }
340
+ return result;
341
+ };
342
+
268
343
  export const progress = {
269
344
  current: { interrupt: (x: string) => {} },
270
345
  active: false,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.12-beta.2";
1
+ export const LIB_VERSION = "1.0.12-beta.21";