|
1 | | -import Command from "../../core/command"; |
2 | | -import { |
3 | | - flags, |
4 | | - FlagInput, |
5 | | - managementSDKClient, |
6 | | - cliux, |
7 | | - printFlagDeprecation, |
8 | | -} from "@contentstack/cli-utilities"; |
9 | | -import buildOutput from "../../core/content-type/compare"; |
10 | | -import { getStack, getContentType } from "../../utils"; |
| 1 | +import Command from '../../core/command' |
| 2 | +import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' |
| 3 | +import buildOutput from '../../core/content-type/compare' |
| 4 | +import { getStack, getContentType } from '../../utils' |
11 | 5 |
|
12 | 6 | export default class CompareCommand extends Command { |
13 | | - static description = "Compare two Content Type versions"; |
| 7 | + static description = 'Compare two Content Type versions' |
14 | 8 |
|
15 | 9 | static examples = [ |
16 | 10 | '$ csdx content-type:compare --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"', |
17 | 11 | '$ csdx content-type:compare --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page" --left # --right #', |
18 | | - '$ csdx content-type:compare --alias "management token" --content-type "home_page" --left # --right #', |
19 | | - ]; |
| 12 | + '$ csdx content-type:compare --alias "management token" --content-type "home_page" --left # --right #' |
| 13 | + ] |
20 | 14 |
|
21 | 15 | static flags: any = { |
22 | 16 | stack: flags.string({ |
23 | | - char: "s", |
24 | | - description: "Stack UID", |
25 | | - exclusive: ["token-alias"], |
26 | | - parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]), |
| 17 | + char: 's', |
| 18 | + description: 'Stack UID', |
| 19 | + exclusive: ['token-alias'], |
| 20 | + parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key']) |
27 | 21 | }), |
28 | 22 |
|
29 | | - "stack-api-key": flags.string({ |
30 | | - char: "k", |
31 | | - description: "Stack API Key", |
32 | | - exclusive: ["token-alias"], |
| 23 | + 'stack-api-key': flags.string({ |
| 24 | + char: 'k', |
| 25 | + description: 'Stack API Key', |
| 26 | + exclusive: ['token-alias'] |
33 | 27 | }), |
34 | 28 |
|
35 | | - "token-alias": flags.string({ |
36 | | - char: "a", |
37 | | - description: "Management token alias", |
38 | | - parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]), |
| 29 | + 'token-alias': flags.string({ |
| 30 | + char: 'a', |
| 31 | + description: 'Management token alias', |
| 32 | + parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias']) |
39 | 33 | }), |
40 | 34 |
|
41 | 35 | alias: flags.string({ |
42 | | - char: "a", |
43 | | - description: "Alias of the management token", |
| 36 | + char: 'a', |
| 37 | + description: 'Alias of the management token' |
44 | 38 | }), |
45 | 39 |
|
46 | | - "content-type": flags.string({ |
47 | | - char: "c", |
48 | | - description: "Content Type UID", |
| 40 | + 'content-type': flags.string({ |
| 41 | + char: 'c', |
| 42 | + description: 'Content Type UID', |
49 | 43 | required: true, |
50 | | - parse: printFlagDeprecation(["-c"], ["--content-type"]), |
| 44 | + parse: printFlagDeprecation(['-c'], ['--content-type']) |
51 | 45 | }), |
52 | 46 |
|
53 | 47 | left: flags.integer({ |
54 | | - char: "l", |
55 | | - description: "Content Type version, i.e. prev version", |
56 | | - dependsOn: ["right"], |
57 | | - parse: printFlagDeprecation(["-l"], ["--left"]), |
| 48 | + char: 'l', |
| 49 | + description: 'Content Type version, i.e. prev version', |
| 50 | + dependsOn: ['right'], |
| 51 | + parse: printFlagDeprecation(['-l'], ['--left']) |
58 | 52 | }), |
59 | 53 |
|
60 | 54 | right: flags.integer({ |
61 | | - char: "r", |
62 | | - description: "Content Type version, i.e. later version", |
63 | | - dependsOn: ["left"], |
64 | | - parse: printFlagDeprecation(["-r"], ["--right"]), |
65 | | - }), |
66 | | - }; |
| 55 | + char: 'r', |
| 56 | + description: 'Content Type version, i.e. later version', |
| 57 | + dependsOn: ['left'], |
| 58 | + parse: printFlagDeprecation(['-r'], ['--right']) |
| 59 | + }) |
| 60 | + } |
67 | 61 |
|
68 | 62 | async run() { |
69 | 63 | try { |
70 | | - const { flags } = await this.parse(CompareCommand); |
71 | | - this.setup(flags); |
| 64 | + const { flags } = await this.parse(CompareCommand) |
| 65 | + this.setup(flags) |
72 | 66 | this.contentTypeManagementClient = await managementSDKClient({ |
73 | 67 | host: this.cmaHost, |
74 | | - "X-CS-CLI": this.context?.analyticsInfo, |
75 | | - }); |
| 68 | + 'X-CS-CLI': this.context?.analyticsInfo |
| 69 | + }) |
76 | 70 |
|
77 | 71 | if (!flags.left) { |
78 | | - const spinner1 = cliux.loaderV2(Command.RequestDataMessage); |
| 72 | + const spinner1 = cliux.loaderV2(Command.RequestDataMessage) |
79 | 73 | const discovery = await getContentType({ |
80 | 74 | managementSdk: this.contentTypeManagementClient, |
81 | 75 | apiKey: this.apiKey, |
82 | | - uid: flags["content-type"], |
83 | | - spinner: spinner1, |
84 | | - }); |
85 | | - const version = discovery._version; |
86 | | - |
87 | | - flags.left = version; |
88 | | - flags.right = version > 1 ? version - 1 : version; |
89 | | - cliux.loaderV2("", spinner1); |
90 | | - this.log(`Comparing versions: ${flags.left} <-> ${flags.right}.`); |
| 76 | + uid: flags['content-type'], |
| 77 | + spinner: spinner1 |
| 78 | + }) |
| 79 | + const version = discovery._version |
| 80 | + |
| 81 | + flags.left = version |
| 82 | + flags.right = version > 1 ? version - 1 : version |
| 83 | + cliux.loaderV2('', spinner1) |
| 84 | + this.log(`Comparing versions: ${flags.left} <-> ${flags.right}.`) |
91 | 85 | } |
92 | 86 |
|
93 | | - const spinner = cliux.loaderV2(Command.RequestDataMessage); |
| 87 | + const spinner = cliux.loaderV2(Command.RequestDataMessage) |
94 | 88 |
|
95 | 89 | const [stack, previous, current] = await Promise.all([ |
96 | 90 | getStack(this.contentTypeManagementClient, this.apiKey, spinner), |
97 | 91 | getContentType({ |
98 | 92 | managementSdk: this.contentTypeManagementClient, |
99 | 93 | apiKey: this.apiKey, |
100 | | - uid: flags["content-type"], |
| 94 | + uid: flags['content-type'], |
101 | 95 | ctVersion: flags.left, |
102 | | - spinner, |
| 96 | + spinner |
103 | 97 | }), |
104 | 98 | getContentType({ |
105 | 99 | managementSdk: this.contentTypeManagementClient, |
106 | 100 | apiKey: this.apiKey, |
107 | | - uid: flags["content-type"], |
| 101 | + uid: flags['content-type'], |
108 | 102 | ctVersion: flags.right, |
109 | | - spinner, |
110 | | - }), |
111 | | - ]); |
| 103 | + spinner |
| 104 | + }) |
| 105 | + ]) |
112 | 106 |
|
113 | | - cliux.loaderV2("", spinner); |
| 107 | + cliux.loaderV2('', spinner) |
114 | 108 |
|
115 | | - const output = await buildOutput( |
116 | | - flags["content-type"], |
117 | | - previous, |
118 | | - current |
119 | | - ); |
120 | | - this.printOutput(output, "changes", flags["content-type"], stack.name); |
| 109 | + const output = await buildOutput(flags['content-type'], previous, current) |
| 110 | + this.printOutput(output, 'changes', flags['content-type'], stack.name) |
121 | 111 |
|
122 | 112 | if (flags.left && flags.left === flags.right) { |
123 | | - this.warn( |
124 | | - "You cannot compare the same version. Please select different versions to compare." |
125 | | - ); |
| 113 | + this.warn('You cannot compare the same version. Please select different versions to compare.') |
126 | 114 | } |
127 | 115 | } catch (error: any) { |
128 | | - this.error(error?.message || "An error occurred.", { |
129 | | - exit: 1, |
130 | | - suggestions: error.suggestions, |
131 | | - }); |
| 116 | + this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) |
132 | 117 | } |
133 | 118 | } |
134 | 119 | } |
0 commit comments