Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 1 addition & 15 deletions src/commands/content-type/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
109 changes: 67 additions & 42 deletions src/commands/content-type/compare-remote.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
}
101 changes: 57 additions & 44 deletions src/commands/content-type/details.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
}
Loading