Skip to content

Commit 967cdea

Browse files
Merge pull request #79 from contentstack/feat/CS-40500
fix: added suggestions made in the demo for delete and get commands
2 parents ad7f5e7 + 1c4d521 commit 967cdea

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
2020
$ csdx COMMAND
2121
running command...
2222
$ csdx (--version|-v)
23-
@contentstack/apps-cli/1.0.0 darwin-arm64 node-v16.19.0
23+
@contentstack/apps-cli/1.0.0 darwin-arm64 node-v20.3.1
2424
$ csdx --help [COMMAND]
2525
USAGE
2626
$ csdx COMMAND

src/commands/app/delete.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseCommand } from "./base-command";
2-
import { flags } from "@contentstack/cli-utilities";
2+
import { cliux, flags } from "@contentstack/cli-utilities";
33
import { $t, commonMsg, deleteAppMsg } from "../../messages";
44
import { getOrg, fetchAppInstallations, deleteApp, getApp } from "../../util";
55

@@ -40,15 +40,25 @@ export default class Delete extends BaseCommand<typeof Delete> {
4040
{ managementSdk: this.managementAppSdk, log: this.log }
4141
);
4242
if (appInstallations.length === 0) {
43-
await deleteApp(this.flags, this.sharedConfig.org, {
44-
managementSdk: this.managementAppSdk,
45-
log: this.log,
46-
});
47-
this.log(
48-
$t(deleteAppMsg.APP_DELETED_SUCCESSFULLY, {
49-
app: app?.name || (this.flags["app-uid"] as string),
50-
})
51-
);
43+
const userConfirmation = this.flags['yes'] || await cliux.inquire({
44+
type: "confirm",
45+
message: deleteAppMsg.DELETE_CONFIRMATION,
46+
name: "confirmation"
47+
})
48+
49+
if (userConfirmation) {
50+
await deleteApp(this.flags, this.sharedConfig.org, {
51+
managementSdk: this.managementAppSdk,
52+
log: this.log,
53+
});
54+
this.log(
55+
$t(deleteAppMsg.APP_DELETED_SUCCESSFULLY, {
56+
app: app?.name || (this.flags["app-uid"] as string),
57+
}), "info"
58+
);
59+
} else {
60+
this.log(commonMsg.USER_TERMINATION, "error")
61+
}
5262
} else {
5363
this.log(deleteAppMsg.APP_IS_INSTALLED, "error");
5464
}

src/messages/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const getApp = {
6363
FILE_WRITTEN_SUCCESS: "App data has been written to {file} successfully.",
6464
APPS_NOT_FOUND: "No apps found!",
6565
FILE_ALREADY_EXISTS:
66-
"{file} already exists. Would you like to save the app to a new file? (Selecting No will over-write {file}) (y/n)",
66+
"{file} already exists. Do you want to overwrite this file? (y/n) (Selecting 'n' creates a new file)",
6767
};
6868

6969
const appUpdate = {
@@ -79,6 +79,7 @@ const deleteAppMsg = {
7979
APP_DELETED_SUCCESSFULLY: "{app} deleted successfully.",
8080
APP_UID_INVALID: "App UID must be valid.",
8181
PLEASE_SELECT_APP_FROM_LIST: "Please select an app from the list",
82+
DELETE_CONFIRMATION: "Are you sure you want to delete this app?"
8283
}
8384

8485
const installAppMsg = {

src/util/fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export async function writeFile(dir: string=process.cwd(), force: boolean=false,
1313
if (existsSync(target)) {
1414
const userConfirmation: boolean = force || (await cliux.confirm($t(messages.FILE_ALREADY_EXISTS, { file: `${config.defaultAppFileName}.json` })))
1515
if (userConfirmation) {
16-
target = resolve(dir, `${incrementName(latestFileName)}.json`);
17-
} else {
1816
target = resolve(dir, `${config.defaultAppFileName}.json`);
17+
} else {
18+
target = resolve(dir, `${incrementName(latestFileName)}.json`);
1919
}
2020
}
2121
await writeFileSync(target, JSON.stringify(data))

test/unit/commands/app/delete.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ describe("app:delete", () => {
1717
.stdout({ print: process.env.PRINT === "true" || false })
1818
.stub(ux.action, "stop", () => {})
1919
.stub(ux.action, "start", () => {})
20+
.stub(cliux, "inquire", async (...args: any) => {
21+
const [prompt]: any = args;
22+
const cases = {
23+
confirmation: true,
24+
};
25+
26+
return (cases as Record<string, any>)[prompt.name];
27+
})
2028
.nock(region.cma, (api) =>
2129
api
2230
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
@@ -46,7 +54,8 @@ describe("app:delete", () => {
4654
const [prompt]: any = args;
4755
const cases = {
4856
Organization: 'test org 1',
49-
App: 'App 1'
57+
App: 'App 1',
58+
confirmation: true
5059
}
5160
return (cases as Record<string, any>)[prompt.name];
5261
})
@@ -93,7 +102,8 @@ describe("app:delete", () => {
93102
const [prompt]: any = args;
94103
const cases = {
95104
Organization: 'test org 1',
96-
App: 'App 1'
105+
App: 'App 1',
106+
confirmation: true
97107
}
98108
return (cases as Record<string, any>)[prompt.name];
99109
})

test/unit/commands/app/get.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe("app:get", () => {
119119

120120
return (cases as Record<string, any>)[prompt.name];
121121
})
122-
.stub(cliux, "confirm", async () => true)
122+
.stub(cliux, "confirm", async () => false)
123123
.nock(region.cma, (api) =>
124124
api
125125
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
@@ -171,7 +171,7 @@ describe("app:get", () => {
171171

172172
return (cases as Record<string, any>)[prompt.name];
173173
})
174-
.stub(cliux, "confirm", async () => false)
174+
.stub(cliux, "confirm", async () => true)
175175
.nock(region.cma, (api) =>
176176
api
177177
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")

0 commit comments

Comments
 (0)