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
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/apps-cli/1.0.7 darwin-arm64 node-v18.16.0
@contentstack/apps-cli/1.1.0 darwin-arm64 node-v18.16.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand All @@ -35,6 +35,7 @@ USAGE
* [`csdx app:delete`](#csdx-appdelete)
* [`csdx app:get`](#csdx-appget)
* [`csdx app:install`](#csdx-appinstall)
* [`csdx app:reinstall`](#csdx-appreinstall)
* [`csdx app:uninstall`](#csdx-appuninstall)
* [`csdx app:update`](#csdx-appupdate)

Expand All @@ -61,9 +62,11 @@ EXAMPLES
$ csdx app:install

$ csdx app:uninstall

$ csdx app:reinstall
```

_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/index.ts)_
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/index.ts)_

## `csdx app:create`

Expand Down Expand Up @@ -94,7 +97,7 @@ EXAMPLES
$ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json
```

_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/create.ts)_
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/create.ts)_

## `csdx app:delete`

Expand All @@ -119,7 +122,7 @@ EXAMPLES
$ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
```

_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/delete.ts)_
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/delete.ts)_

## `csdx app:get`

Expand Down Expand Up @@ -149,7 +152,7 @@ EXAMPLES
$ csdx app:get --org <value> --app-uid <value> --app-type organization
```

_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/get.ts)_
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/get.ts)_

## `csdx app:install`

Expand All @@ -175,7 +178,33 @@ EXAMPLES
$ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
```

_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/install.ts)_
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/install.ts)_

## `csdx app:reinstall`

Reinstall an app from the marketplace

```
USAGE
$ csdx app:reinstall [--org <value>] [--app-uid <value>] [--stack-api-key <value>]

FLAGS
--app-uid=<value> Provide the app UID of an existing app.
--org=<value> Provide the organization UID to fetch the app details for the desired operation.
--stack-api-key=<value> API key of the stack where the app is to be installed.

DESCRIPTION
Reinstall an app from the marketplace

EXAMPLES
$ csdx app:reinstall

$ csdx app:reinstall --org <UID> --app-uid <APP-UID-1>

$ csdx app:reinstall --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
```

_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/reinstall.ts)_

## `csdx app:uninstall`

Expand All @@ -202,7 +231,7 @@ EXAMPLES
$ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
```

_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/uninstall.ts)_
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/uninstall.ts)_

## `csdx app:update`

Expand All @@ -225,5 +254,5 @@ EXAMPLES
$ csdx app:update --app-manifest ./boilerplate/manifest.json
```

_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.0.7/src/commands/app/update.ts)_
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.1.0/src/commands/app/update.ts)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/apps-cli",
"version": "1.0.7",
"version": "1.1.0",
"description": "App ClI",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
Expand Down Expand Up @@ -96,7 +96,8 @@
"app:update": "APUPT",
"app:delete": "APDLT",
"app:install": "API",
"app:uninstall": "APUI"
"app:uninstall": "APUI",
"app:reinstall": "APRI"
}
}
}
1 change: 1 addition & 0 deletions src/commands/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class App extends Command {
"$ <%= config.bin %> <%= command.id %>:delete",
"$ <%= config.bin %> <%= command.id %>:install",
"$ <%= config.bin %> <%= command.id %>:uninstall",
"$ <%= config.bin %> <%= command.id %>:reinstall",
];

async run(): Promise<void> {
Expand Down
15 changes: 14 additions & 1 deletion src/commands/app/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export default class Install extends AppCLIBaseCommand {
this.displayStackUrl();
} catch (error: any) {
this.log(error?.errorMessage || error?.message || error, "error");
if (
error?.errorMessage === "Installation for app is already done" &&
error?.status === 400
) {
this.displayReInstallMsg();
}
this.exit(1);
}
}
Expand All @@ -136,4 +142,11 @@ export default class Install extends AppCLIBaseCommand {
"info"
);
}
}

/**
* @method displayStackUrl - show guid to stack after installing app successfully in the stack
*/
displayReInstallMsg(): void {
this.log(this.messages.APP_ALREADY_INSTALLED, "info");
}
}
134 changes: 134 additions & 0 deletions src/commands/app/reinstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { cliux, flags } from "@contentstack/cli-utilities";
import { AppCLIBaseCommand } from "../../app-cli-base-coomand";
import { $t, commonMsg, reinstallAppMsg } from "../../messages";
import {
getOrg,
getApp,
getStack,
reinstallApp,
fetchApp,
fetchStack,
} from "../../util";

export default class Reinstall extends AppCLIBaseCommand {
static description: string | undefined =
"Reinstall an app from the marketplace";

static examples = [
"$ <%= config.bin %> <%= command.id %>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>",
];

static flags = {
"app-uid": flags.string({
description: commonMsg.APP_UID,
}),
"stack-api-key": flags.string({
description: commonMsg.STACK_API_KEY,
}),
};

async run(): Promise<void> {
try {
let app, stack, appType;
this.flags["app-uid"] = this.manifestData?.uid ?? this.flags["app-uid"];

if (this.flags["stack-api-key"]) {
stack = await fetchStack(this.flags, {
managementSdk: this.managementSdk,
log: this.log,
});
}

this.sharedConfig.org =
this.manifestData?.organization_uid ??
(await getOrg(this.flags, {
managementSdk: this.managementSdk,
log: this.log,
}));

if (!this.flags["app-uid"]) {
app = await getApp(this.flags, this.sharedConfig.org, {
managementSdk: this.managementAppSdk,
log: this.log,
});
} else {
app = await fetchApp(this.flags, this.sharedConfig.org, {
managementSdk: this.managementAppSdk,
log: this.log,
});
}
appType = app?.["target_type"];
this.flags["app-uid"] = app?.uid;

if (appType === "organization" && this.flags["stack-api-key"]) {
appType = "organization";
const confirmation =
this.flags["yes"] ||
(await cliux.inquire({
type: "confirm",
message: $t(reinstallAppMsg.REINSTALL_ORG_APP_TO_STACK, {
app: app?.name || app?.uid,
}),
name: "confirmation",
}));
if (!confirmation) {
throw new Error(commonMsg.USER_TERMINATION);
}
}

if (appType === "stack" && !this.flags["stack-api-key"]) {
appType = "stack";

this.log(
$t(reinstallAppMsg.MISSING_STACK_API_KEY, {
app: app?.name || app?.uid,
}),
"warn"
);
stack = await getStack(this.sharedConfig.org, {
managementSdk: this.managementSdk,
log: this.log,
});
this.flags["stack-api-key"] = stack?.["api_key"];
}

this.log(
$t(reinstallAppMsg.REINSTALLING_APP_NOTICE, {
app: app?.name || app?.uid,
type: appType,
target: this.flags["stack-api-key"] || this.sharedConfig.org,
}),
"info"
);
await reinstallApp({
flags: this.flags,
type: appType,
developerHubBaseUrl: this.developerHubBaseUrl,
orgUid: this.sharedConfig.org,
manifestUid: this.manifestData.uid,
});
this.log(
$t(reinstallAppMsg.APP_REINSTALLED_SUCCESSFULLY, {
app: app?.name || (this.flags["app-uid"] as string),
target: stack?.name || this.sharedConfig.org,
}),
"info"
);

this.displayStackUrl();
} catch (error: any) {
this.log(error?.errorMessage || error?.message || error, "error");
this.exit(1);
}
}

displayStackUrl(): void {
const stackPath = `${this.uiHost}/#!/stack/${this.flags["stack-api-key"]}/dashboard`;
this.log(
`Please use the following URL to start using the stack: ${stackPath}`,
"info"
);
}
}
18 changes: 15 additions & 3 deletions src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const installAppMsg = {
INSTALL_ORG_APP_TO_STACK: "{app} is an organization app. It cannot be installed to a stack. Do you want to proceed?",
MISSING_STACK_API_KEY: "As {app} is a stack app, it can only be installed in a stack. Please select a stack.",
INSTALLING_APP_NOTICE: "Installing {app} on {type} {target}.",
APP_ALREADY_INSTALLED: "Please use $ csdx app:reinstall to reinstall the app.",
}

const uninstallAppMsg = {
Expand All @@ -100,22 +101,33 @@ const uninstallAppMsg = {
UNINSTALL_ALL: "Please select stacks from where the app must be uninstalled.",
}

const reinstallAppMsg = {
CHOOSE_A_STACK: "Please select a stack",
APP_REINSTALLED_SUCCESSFULLY: "{app} reinstalled successfully in {target}.",
REINSTALL_ORG_APP_TO_STACK: "{app} is an organization app. It cannot be reinstalled to a stack. Do you want to proceed?",
MISSING_STACK_API_KEY: "As {app} is a stack app, it can only be reinstalled in a stack. Please select a stack.",
REINSTALLING_APP_NOTICE: "Reinstalling {app} on {type} {target}.",
APP_UID: "Provide the app UID of an existing app to be reinstalled.",
}

const messages: typeof errors &
typeof commonMsg &
typeof appCreate &
typeof appUpdate &
typeof getAppMsg &
typeof deleteAppMsg &
typeof installAppMsg &
typeof uninstallAppMsg = {
typeof uninstallAppMsg &
typeof reinstallAppMsg = {
...errors,
...commonMsg,
...appCreate,
...appUpdate,
...getAppMsg,
...deleteAppMsg,
...installAppMsg,
...uninstallAppMsg
...uninstallAppMsg,
...reinstallAppMsg
};

const $t = (msg: string, args: Record<string, string>): string => {
Expand All @@ -130,4 +142,4 @@ const $t = (msg: string, args: Record<string, string>): string => {
};

export default messages;
export { $t, errors, commonMsg, appCreate, appUpdate, getAppMsg, deleteAppMsg, installAppMsg, uninstallAppMsg };
export { $t, errors, commonMsg, appCreate, appUpdate, getAppMsg, deleteAppMsg, installAppMsg, uninstallAppMsg, reinstallAppMsg };
12 changes: 12 additions & 0 deletions src/types/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { FlagInput } from "@contentstack/cli-utilities";
import { ConfigType } from "./utils";

export interface TokenConfiguration {
enabled?: boolean;
scopes?: string[];
Expand Down Expand Up @@ -113,3 +116,12 @@ export interface AppManifest {
export interface AppManifestWithUiLocation extends AppManifest {
ui_location: LocationConfiguration;
}

export interface ReinstallParams {
flags: FlagInput,
type: string,
orgUid: string,
manifestUid: string,
configType: ConfigType,
developerHubBaseUrl: string
};
Loading