diff --git a/.talismanrc b/.talismanrc index a97dc03..7dbc0ab 100644 --- a/.talismanrc +++ b/.talismanrc @@ -11,13 +11,13 @@ fileignoreconfig: - filename: src/commands/content-type/audit.ts checksum: df9f0768c90f8e3a15cd70cbb1765a6c6f0dc5a8e4e7e74e42bfa8ca2ebf3bc9 - filename: src/commands/content-type/details.ts - checksum: 097682096da7632b396aa07074bd65b8c9a955f3bf841267fdf386c7b21e23d2 + checksum: db30263b288e1686d1fc8ff593a2e33c727a8d130ca7a943c28277c0985f00ff - filename: src/commands/content-type/diagram.ts - checksum: bfac9877807cad48faabea9d9e49634eb6a2fe62e97e36114ac70ba469b14ad9 + checksum: 276a57c16a4aa434ede1058134517feaf190c9c5db2c12116904daed82996303 - filename: src/commands/content-type/compare.ts checksum: 2d650febfa3f4671f716e79bb1f6446273046d7041f980733e5ac306a13f447d - filename: src/commands/content-type/list.ts - checksum: 5b4cff3a06fd66a615facfd3ad6844019bd8d0d819e147370ca8e09420249c85 + checksum: e7623d46577a9f5c209fd8d0d5abd0da0a2140f6cce30f68cfe81b29e292585c - filename: src/commands/content-type/compare-remote.ts checksum: 151b32699500c465378c4088240c5a25266141150261313434068740862949a1 version: "1.0" diff --git a/src/commands/content-type/audit.ts b/src/commands/content-type/audit.ts index aa98424..2fe1711 100644 --- a/src/commands/content-type/audit.ts +++ b/src/commands/content-type/audit.ts @@ -4,7 +4,6 @@ import { managementSDKClient, cliux, printFlagDeprecation, - authenticationHandler, } from "@contentstack/cli-utilities"; import buildOutput from "../../core/content-type/audit"; import { getStack, getUsers, getContentType } from "../../utils"; @@ -53,20 +52,7 @@ export default class AuditCommand extends Command { async run() { try { const { flags } = await this.parse(AuditCommand); - await authenticationHandler.getAuthDetails(); - const authToken = authenticationHandler.accessToken; - if (!authToken) { - this.error( - "You're not logged in. Run auth:login to sign in. Use auth:login --help for more details.", - { - exit: 2, - suggestions: [ - "https://www.contentstack.com/docs/developers/cli/authentication/", - ], - } - ); - } - this.setup(flags, authToken); + await this.setup(flags); this.contentTypeManagementClient = await managementSDKClient({ host: this.cmaHost, diff --git a/src/commands/content-type/compare-remote.ts b/src/commands/content-type/compare-remote.ts index 8f89530..9ecad35 100644 --- a/src/commands/content-type/compare-remote.ts +++ b/src/commands/content-type/compare-remote.ts @@ -1,81 +1,106 @@ -import Command from '../../core/command' -import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' -import buildOutput from '../../core/content-type/compare' -import { getStack, getContentType } from '../../utils' +import Command from "../../core/command"; +import { + flags, + FlagInput, + managementSDKClient, + cliux, + printFlagDeprecation, +} from "@contentstack/cli-utilities"; +import buildOutput from "../../core/content-type/compare"; +import { getStack, getContentType } from "../../utils"; export default class CompareRemoteCommand extends Command { - static description = 'compare two Content Types on different Stacks' + static description = "compare two Content Types on different Stacks"; static examples = [ - '$ csdx content-type:compare-remote --origin-stack "xxxxxxxxxxxxxxxxxxx" --remote-stack "xxxxxxxxxxxxxxxxxxx" -content-type "home_page"' - ] + '$ csdx content-type:compare-remote --origin-stack "xxxxxxxxxxxxxxxxxxx" --remote-stack "xxxxxxxxxxxxxxxxxxx" -content-type "home_page"', + ]; static flags: any = { - 'origin-stack': flags.string({ - char: 'o', - description: 'Origin Stack API Key', + "origin-stack": flags.string({ + char: "o", + description: "Origin Stack API Key", required: true, - dependsOn: ['remote-stack'], - parse: printFlagDeprecation(['-o'], ['--remote-stack']) + dependsOn: ["remote-stack"], + parse: printFlagDeprecation(["-o"], ["--remote-stack"]), }), - 'remote-stack': flags.string({ - char: 'r', - description: 'Remote Stack API Key', + "remote-stack": flags.string({ + char: "r", + description: "Remote Stack API Key", required: true, - dependsOn: ['origin-stack'], - parse: printFlagDeprecation(['-r'], ['--remote-stack']) + dependsOn: ["origin-stack"], + parse: printFlagDeprecation(["-r"], ["--remote-stack"]), }), - 'content-type': flags.string({ - char: 'c', - description: 'Content Type UID', + "content-type": flags.string({ + char: "c", + description: "Content Type UID", required: true, - parse: printFlagDeprecation(['-c'], ['--content-type']) - }) - } + parse: printFlagDeprecation(["-c"], ["--content-type"]), + }), + }; async run() { try { - const { flags } = await this.parse(CompareRemoteCommand) - this.setup({ alias: undefined, stack: flags['origin-stack'] }) + const { flags } = await this.parse(CompareRemoteCommand); + await this.setup({ alias: undefined, stack: flags["origin-stack"] }); this.contentTypeManagementClient = await managementSDKClient({ host: this.cmaHost, - 'X-CS-CLI': this.context?.analyticsInfo - }) + "X-CS-CLI": this.context?.analyticsInfo, + }); - const originStackApi = flags['origin-stack'] as string - const remoteStackApi = flags['remote-stack'] as string + const originStackApi = flags["origin-stack"] as string; + const remoteStackApi = flags["remote-stack"] as string; if (originStackApi === remoteStackApi) { - this.warn('You cannot compare the same stack. Please choose different stacks to compare.') + this.warn( + "You cannot compare the same stack. Please choose different stacks to compare." + ); } - const spinner = cliux.loaderV2(Command.RequestDataMessage) + const spinner = cliux.loaderV2(Command.RequestDataMessage); - const [originStackResp, remoteStackResp, originContentTypeResp, remoteContentTypeResp] = await Promise.all([ + const [ + originStackResp, + remoteStackResp, + originContentTypeResp, + remoteContentTypeResp, + ] = await Promise.all([ getStack(this.contentTypeManagementClient, originStackApi, spinner), getStack(this.contentTypeManagementClient, remoteStackApi, spinner), getContentType({ managementSdk: this.contentTypeManagementClient, apiKey: originStackApi, - uid: flags['content-type'], - spinner + uid: flags["content-type"], + spinner, }), getContentType({ managementSdk: this.contentTypeManagementClient, apiKey: remoteStackApi, - uid: flags['content-type'], - spinner - }) - ]) + uid: flags["content-type"], + spinner, + }), + ]); - cliux.loaderV2('', spinner) + cliux.loaderV2("", spinner); - const output = await buildOutput(flags['content-type'], originContentTypeResp, remoteContentTypeResp) - this.printOutput(output, 'changes', flags['content-type'], `${originStackResp.name} <-> ${remoteStackResp.name}`) + const output = await buildOutput( + flags["content-type"], + originContentTypeResp, + remoteContentTypeResp + ); + this.printOutput( + output, + "changes", + flags["content-type"], + `${originStackResp.name} <-> ${remoteStackResp.name}` + ); } catch (error: any) { - this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) + this.error(error?.message || "An error occurred.", { + exit: 1, + suggestions: error.suggestions, + }); } } } diff --git a/src/commands/content-type/details.ts b/src/commands/content-type/details.ts index d0e933d..726ad73 100644 --- a/src/commands/content-type/details.ts +++ b/src/commands/content-type/details.ts @@ -1,88 +1,101 @@ -import Command from '../../core/command' -import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' -import buildOutput from '../../core/content-type/details' -import { getStack, getContentType } from '../../utils' +import Command from "../../core/command"; +import { + flags, + FlagInput, + managementSDKClient, + cliux, + printFlagDeprecation, +} from "@contentstack/cli-utilities"; +import buildOutput from "../../core/content-type/details"; +import { getStack, getContentType } from "../../utils"; export default class DetailsCommand extends Command { - static description = 'Display Content Type details' + static description = "Display Content Type details"; static examples = [ '$ csdx content-type:details --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"', '$ csdx content-type:details --alias "management token" --content-type "home_page"', - '$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path' - ] + '$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path', + ]; static flags: any = { stack: flags.string({ - char: 's', - description: 'Stack UID', - exclusive: ['token-alias'], - parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key']) + char: "s", + description: "Stack UID", + exclusive: ["token-alias"], + parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]), }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'Stack API Key', - exclusive: ['token-alias'] + "stack-api-key": flags.string({ + char: "k", + description: "Stack API Key", + exclusive: ["token-alias"], }), - 'token-alias': flags.string({ - char: 'a', - description: 'Management token alias', - parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias']) + "token-alias": flags.string({ + char: "a", + description: "Management token alias", + parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]), }), alias: flags.string({ - char: 'a', - description: 'Alias of the management token' + char: "a", + description: "Alias of the management token", }), - 'content-type': flags.string({ - char: 'c', - description: 'Content Type UID', + "content-type": flags.string({ + char: "c", + description: "Content Type UID", required: true, - parse: printFlagDeprecation(['-c'], ['--content-type']) + parse: printFlagDeprecation(["-c"], ["--content-type"]), }), path: flags.boolean({ - char: 'p', - description: 'show path column', + char: "p", + description: "show path column", default: true, allowNo: true, - parse: printFlagDeprecation(['-p'], ['--path']) - }) - } + parse: printFlagDeprecation(["-p"], ["--path"]), + }), + }; async run() { try { - const { flags } = await this.parse(DetailsCommand) - this.setup(flags) + const { flags } = await this.parse(DetailsCommand); + await this.setup(flags); this.contentTypeManagementClient = await managementSDKClient({ host: this.cmaHost, - 'X-CS-CLI': this.context?.analyticsInfo - }) + "X-CS-CLI": this.context?.analyticsInfo, + }); - const spinner = cliux.loaderV2(Command.RequestDataMessage) + const spinner = cliux.loaderV2(Command.RequestDataMessage); const [stack, contentType, references] = await Promise.all([ getStack(this.contentTypeManagementClient, this.apiKey, spinner), getContentType({ managementSdk: this.contentTypeManagementClient, apiKey: this.apiKey, - uid: flags['content-type'], - spinner + uid: flags["content-type"], + spinner, }), - this.client.getContentTypeReferences(this.apiKey, flags['content-type'], spinner) - ]) + this.client.getContentTypeReferences( + this.apiKey, + flags["content-type"], + spinner + ), + ]); - cliux.loaderV2('', spinner) + cliux.loaderV2("", spinner); const output = buildOutput(contentType, references, { - showPath: flags.path - }) - this.printOutput(output, 'details', flags['content-type'], stack.name) + showPath: flags.path, + }); + this.printOutput(output, "details", flags["content-type"], stack.name); } catch (error: any) { - this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) + this.error(error?.message || "An error occurred.", { + exit: 1, + suggestions: error.suggestions, + }); } } } diff --git a/src/commands/content-type/diagram.ts b/src/commands/content-type/diagram.ts index 751e086..ebb8acd 100644 --- a/src/commands/content-type/diagram.ts +++ b/src/commands/content-type/diagram.ts @@ -1,100 +1,106 @@ -import Command from '../../core/command' -import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' -import { createDiagram } from '../../core/content-type/diagram' -import { CreateDiagramOptions, DiagramOrientation } from '../../types' -import { getStack, getContentTypes, getGlobalFields } from '../../utils' +import Command from "../../core/command"; +import { + flags, + FlagInput, + managementSDKClient, + cliux, + printFlagDeprecation, +} from "@contentstack/cli-utilities"; +import { createDiagram } from "../../core/content-type/diagram"; +import { CreateDiagramOptions, DiagramOrientation } from "../../types"; +import { getStack, getContentTypes, getGlobalFields } from "../../utils"; export default class DiagramCommand extends Command { - static description = "Create a visual diagram of a Stack's Content Types" + static description = "Create a visual diagram of a Stack's Content Types"; static examples = [ '$ csdx content-type:diagram --stack-api-key "xxxxxxxxxxxxxxxxxxx" --output "content-model.svg"', '$ csdx content-type:diagram --alias "management token" --output "content-model.svg"', '$ csdx content-type:diagram --alias "management token" --output "content-model.svg" --direction "landscape"', - '$ csdx content-type:diagram --alias "management token" --output "content-model.dot" --type "dot"' - ] + '$ csdx content-type:diagram --alias "management token" --output "content-model.dot" --type "dot"', + ]; static flags: any = { stack: flags.string({ - char: 's', - description: 'Stack UID', - exclusive: ['token-alias', 'alias'], - parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key']) + char: "s", + description: "Stack UID", + exclusive: ["token-alias", "alias"], + parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]), }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'Stack API Key', - exclusive: ['token-alias', 'alias'] + "stack-api-key": flags.string({ + char: "k", + description: "Stack API Key", + exclusive: ["token-alias", "alias"], }), - 'token-alias': flags.string({ - char: 'a', - description: 'Management token alias', - parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias']) + "token-alias": flags.string({ + char: "a", + description: "Management token alias", + parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]), }), alias: flags.string({ - char: 'a', - description: 'Alias of the management token' + char: "a", + description: "Alias of the management token", }), output: flags.string({ - char: 'o', - description: 'full path to output', + char: "o", + description: "full path to output", hidden: false, multiple: false, required: true, - parse: printFlagDeprecation(['-o'], ['--output']) + parse: printFlagDeprecation(["-o"], ["--output"]), }), direction: flags.string({ - char: 'd', - description: 'graph orientation', - default: 'portrait', - options: ['portrait', 'landscape'], + char: "d", + description: "graph orientation", + default: "portrait", + options: ["portrait", "landscape"], hidden: false, multiple: false, required: true, - parse: printFlagDeprecation(['-d'], ['--direction']) + parse: printFlagDeprecation(["-d"], ["--direction"]), }), type: flags.string({ - char: 't', - description: 'graph output file type', - default: 'svg', - options: ['svg', 'dot'], + char: "t", + description: "graph output file type", + default: "svg", + options: ["svg", "dot"], hidden: false, multiple: false, required: true, - parse: printFlagDeprecation(['-t'], ['--type']) - }) - } + parse: printFlagDeprecation(["-t"], ["--type"]), + }), + }; async run() { try { - const { flags } = await this.parse(DiagramCommand) + const { flags } = await this.parse(DiagramCommand); this.contentTypeManagementClient = await managementSDKClient({ host: this.cmaHost, - 'X-CS-CLI': this.context?.analyticsInfo - }) - this.setup(flags) + "X-CS-CLI": this.context?.analyticsInfo, + }); + await this.setup(flags); - const outputPath = flags.output + const outputPath = flags.output; if (!outputPath?.trim()) { - this.error('Please provide an output path.', { exit: 2 }) + this.error("Please provide an output path.", { exit: 2 }); } - const spinner = cliux.loaderV2(Command.RequestDataMessage) + const spinner = cliux.loaderV2(Command.RequestDataMessage); const [stack, contentTypes, globalFields] = await Promise.all([ getStack(this.contentTypeManagementClient, this.apiKey, spinner), getContentTypes(this.contentTypeManagementClient, this.apiKey, spinner), - getGlobalFields(this.contentTypeManagementClient, this.apiKey, spinner) - ]) + getGlobalFields(this.contentTypeManagementClient, this.apiKey, spinner), + ]); - cliux.loaderV2('', spinner) + cliux.loaderV2("", spinner); const diagramOptions: CreateDiagramOptions = { stackName: stack.name, @@ -103,14 +109,20 @@ export default class DiagramCommand extends Command { outputFileName: outputPath, outputFileType: flags.type, style: { - orientation: flags.direction === 'portrait' ? DiagramOrientation.Portrait : DiagramOrientation.Landscape - } - } - - const output = await createDiagram(diagramOptions) - this.log(`Created Graph: ${output.outputPath}`) + orientation: + flags.direction === "portrait" + ? DiagramOrientation.Portrait + : DiagramOrientation.Landscape, + }, + }; + + const output = await createDiagram(diagramOptions); + this.log(`Created Graph: ${output.outputPath}`); } catch (error: any) { - this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) + this.error(error?.message || "An error occurred.", { + exit: 1, + suggestions: error.suggestions, + }); } } } diff --git a/src/commands/content-type/list.ts b/src/commands/content-type/list.ts index e6a209a..2a7fe14 100644 --- a/src/commands/content-type/list.ts +++ b/src/commands/content-type/list.ts @@ -1,73 +1,82 @@ -import Command from '../../core/command' -import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' -import buildOutput from '../../core/content-type/list' -import { getStack, getContentTypes } from '../../utils' +import Command from "../../core/command"; +import { + flags, + FlagInput, + managementSDKClient, + cliux, + printFlagDeprecation, +} from "@contentstack/cli-utilities"; +import buildOutput from "../../core/content-type/list"; +import { getStack, getContentTypes } from "../../utils"; export default class ListCommand extends Command { - static description = 'List all Content Types in a Stack' + static description = "List all Content Types in a Stack"; static examples = [ '$ csdx content-type:list --stack-api-key "xxxxxxxxxxxxxxxxxxx"', '$ csdx content-type:list --alias "management token"', - '$ csdx content-type:list --alias "management token" --order modified' - ] + '$ csdx content-type:list --alias "management token" --order modified', + ]; static flags: any = { stack: flags.string({ - char: 's', - description: 'Stack UID', - exclusive: ['token-alias', 'alias'], - parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key']) + char: "s", + description: "Stack UID", + exclusive: ["token-alias", "alias"], + parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]), }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'Stack API Key', - exclusive: ['token-alias', 'alias'] + "stack-api-key": flags.string({ + char: "k", + description: "Stack API Key", + exclusive: ["token-alias", "alias"], }), - 'token-alias': flags.string({ - char: 'a', - description: 'Management token alias', - parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias']) + "token-alias": flags.string({ + char: "a", + description: "Management token alias", + parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]), }), alias: flags.string({ - char: 'a', - description: 'Alias of the management token' + char: "a", + description: "Alias of the management token", }), order: flags.string({ - char: 'o', - description: 'order by column', - options: ['title', 'modified'], - default: 'title', - parse: printFlagDeprecation(['-o'], ['--order']) - }) - } + char: "o", + description: "order by column", + options: ["title", "modified"], + default: "title", + parse: printFlagDeprecation(["-o"], ["--order"]), + }), + }; async run() { try { - const { flags } = await this.parse(ListCommand) - this.setup(flags) + const { flags } = await this.parse(ListCommand); this.contentTypeManagementClient = await managementSDKClient({ host: this.cmaHost, - 'X-CS-CLI': this.context?.analyticsInfo - }) + "X-CS-CLI": this.context?.analyticsInfo, + }); + await this.setup(flags); - const spinner = cliux.loaderV2(Command.RequestDataMessage) + const spinner = cliux.loaderV2(Command.RequestDataMessage); const [stack, contentTypes] = await Promise.all([ getStack(this.contentTypeManagementClient, this.apiKey, spinner), - getContentTypes(this.contentTypeManagementClient, this.apiKey, spinner) - ]) + getContentTypes(this.contentTypeManagementClient, this.apiKey, spinner), + ]); - cliux.loaderV2('', spinner) + cliux.loaderV2("", spinner); - const output = buildOutput(contentTypes, flags.order) - this.printOutput(output, 'Content Types', null, stack.name) + const output = buildOutput(contentTypes, flags.order); + this.printOutput(output, "Content Types", null, stack.name); } catch (error: any) { - this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) + this.error(error?.message || "An error occurred.", { + exit: 1, + suggestions: error.suggestions, + }); } } } diff --git a/src/core/command.ts b/src/core/command.ts index 5eb8d94..e74c1ae 100644 --- a/src/core/command.ts +++ b/src/core/command.ts @@ -12,7 +12,9 @@ export default class ContentTypeCommand extends Command { protected contentTypeManagementClient: any; - setup(flags: any, authToken?: string) { + async setup(flags: any) { + await authenticationHandler.getAuthDetails(); + const authToken = authenticationHandler.accessToken; if (!authToken) { this.error( "You're not logged in. Run auth:login to sign in. Use auth:login --help for more details.",