Skip to content

Commit fe2cabf

Browse files
Merge pull request #275 from contentstack/fix/dx-544-update-documentation
updated with a flag and added example
2 parents e7e65e5 + 6528b3f commit fe2cabf

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

README.md

Lines changed: 15 additions & 11 deletions
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.2.1 darwin-arm64 node-v18.20.2
23+
@contentstack/apps-cli/1.3.0 darwin-arm64 node-v18.16.0
2424
$ csdx --help [COMMAND]
2525
USAGE
2626
$ csdx COMMAND
@@ -67,22 +67,24 @@ EXAMPLES
6767
$ csdx app:reinstall
6868
```
6969

70-
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/index.ts)_
70+
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/index.ts)_
7171

7272
## `csdx app:create`
7373

7474
Create a new app in Developer Hub and optionally clone a boilerplate locally.
7575

7676
```
7777
USAGE
78-
$ csdx app:create [-n <value>] [--app-type stack|organization] [-c <value>] [-d <value>]
78+
$ csdx app:create [-n <value>] [--app-type stack|organization] [-c <value>] [-d <value>] [--boilerplate
79+
<value>]
7980
8081
FLAGS
8182
-c, --config=<value> Path of the external config
8283
-d, --data-dir=<value> Current working directory.
8384
-n, --name=<value> [default: app-boilerplate] Name of the app to be created
8485
--app-type=<option> [default: stack] Type of app
8586
<options: stack|organization>
87+
--boilerplate=<value> Choose a boilerplate from search list
8688
8789
DESCRIPTION
8890
Create a new app in Developer Hub and optionally clone a boilerplate locally.
@@ -95,9 +97,11 @@ EXAMPLES
9597
$ csdx app:create --name App-2 --app-type stack -d ./boilerplate
9698
9799
$ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json
100+
101+
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplates <boilerplate-name>
98102
```
99103

100-
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/create.ts)_
104+
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/create.ts)_
101105

102106
## `csdx app:delete`
103107

@@ -121,7 +125,7 @@ EXAMPLES
121125
$ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
122126
```
123127

124-
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/delete.ts)_
128+
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/delete.ts)_
125129

126130
## `csdx app:deploy`
127131

@@ -158,7 +162,7 @@ EXAMPLES
158162
$ csdx app:deploy --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <new> --config <config-path>
159163
```
160164

161-
_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/deploy.ts)_
165+
_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/deploy.ts)_
162166

163167
## `csdx app:get`
164168

@@ -187,7 +191,7 @@ EXAMPLES
187191
$ csdx app:get --org <value> --app-uid <value> --app-type organization
188192
```
189193

190-
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/get.ts)_
194+
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/get.ts)_
191195

192196
## `csdx app:install`
193197

@@ -212,7 +216,7 @@ EXAMPLES
212216
$ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
213217
```
214218

215-
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/install.ts)_
219+
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/install.ts)_
216220

217221
## `csdx app:reinstall`
218222

@@ -237,7 +241,7 @@ EXAMPLES
237241
$ csdx app:reinstall --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
238242
```
239243

240-
_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/reinstall.ts)_
244+
_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/reinstall.ts)_
241245

242246
## `csdx app:uninstall`
243247

@@ -263,7 +267,7 @@ EXAMPLES
263267
$ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
264268
```
265269

266-
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/uninstall.ts)_
270+
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/uninstall.ts)_
267271

268272
## `csdx app:update`
269273

@@ -285,5 +289,5 @@ EXAMPLES
285289
$ csdx app:update --app-manifest ./boilerplate/manifest.json
286290
```
287291

288-
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/update.ts)_
292+
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/update.ts)_
289293
<!-- commandsstop -->

src/commands/app/create.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
getOrgAppUiLocation,
3535
sanitizePath,
3636
selectedBoilerplate,
37+
validateBoilerplate,
3738
} from "../../util";
3839

3940
export default class Create extends BaseCommand<typeof Create> {
@@ -52,6 +53,7 @@ export default class Create extends BaseCommand<typeof Create> {
5253
"$ <%= config.bin %> <%= command.id %> --name App-1 --app-type stack",
5354
"$ <%= config.bin %> <%= command.id %> --name App-2 --app-type stack -d ./boilerplate",
5455
"$ <%= config.bin %> <%= command.id %> --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json",
56+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplates <boilerplate-name>",
5557
];
5658

5759
static flags: FlagInput = {
@@ -73,11 +75,15 @@ export default class Create extends BaseCommand<typeof Create> {
7375
char: "d",
7476
description: commonMsg.CURRENT_WORKING_DIR,
7577
}),
78+
"boilerplate": flags.string({
79+
description: appCreate.BOILERPLATE_TEMPLATES,
80+
}),
7681
};
7782

7883
async run(): Promise<void> {
7984
this.sharedConfig.org = this.flags.org;
8085
this.sharedConfig.appName = this.flags.name;
86+
this.sharedConfig.boilerplateName = this.flags.boilerplate;
8187

8288
await this.flagsPromptQueue();
8389

@@ -97,18 +103,7 @@ export default class Create extends BaseCommand<typeof Create> {
97103
message: this.messages.CONFIRM_CLONE_BOILERPLATE,
98104
}))
99105
) {
100-
const boilerplate: BoilerplateAppType = await selectedBoilerplate();
101-
102-
if (boilerplate) {
103-
this.sharedConfig.boilerplateName = boilerplate.name
104-
.toLowerCase()
105-
.replace(/ /g, "-");
106-
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
107-
this.sharedConfig.appName = await getAppName(
108-
this.sharedConfig.boilerplateName
109-
);
110-
await this.boilerplateFlow();
111-
}
106+
await this.boilerplateFlow();
112107
} else {
113108
this.manageManifestToggeling();
114109
await this.registerTheAppOnDeveloperHub(false);
@@ -160,6 +155,22 @@ export default class Create extends BaseCommand<typeof Create> {
160155
this.sharedConfig.defaultAppName
161156
);
162157
}
158+
if (isEmpty(this.sharedConfig.boilerplateName)) {
159+
const boilerplate: BoilerplateAppType = await selectedBoilerplate();
160+
161+
if (boilerplate) {
162+
this.sharedConfig.boilerplateName = boilerplate.name
163+
.toLowerCase()
164+
.replace(/ /g, "-");
165+
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
166+
this.sharedConfig.appName = await getAppName(
167+
this.sharedConfig.boilerplateName
168+
);
169+
}
170+
} else {
171+
await validateBoilerplate(this.sharedConfig.boilerplateName);
172+
}
173+
this.sharedConfig.appName = this.sharedConfig.boilerplateName;
163174

164175
//Auto select org in case of oauth
165176
this.sharedConfig.org =
@@ -314,10 +325,7 @@ export default class Create extends BaseCommand<typeof Create> {
314325
this.appData = merge(this.appData, pick(response, validKeys));
315326
if (saveManifest) {
316327
writeFileSync(
317-
resolve(
318-
this.sharedConfig.folderPath,
319-
"manifest.json"
320-
),
328+
resolve(this.sharedConfig.folderPath, "manifest.json"),
321329
JSON.stringify(this.appData),
322330
{
323331
encoding: "utf8",

src/config/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { resolve } from "path";
33
const config = {
44
defaultAppName: "app-boilerplate",
55
manifestPath: resolve(__dirname, "manifest.json"),
6-
boilerplateName: "marketplace-app-boilerplate-main",
76
developerHubBaseUrl: "",
87
appBoilerplateGithubUrl:
98
"https://codeload.github.com/contentstack/marketplace-app-boilerplate/zip/refs/heads/main",

src/messages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const appCreate = {
5858
REGISTER_THE_APP_ON_DEVELOPER_HUB:
5959
"Registering the app with the name {appName} on the Developer Hub...",
6060
START_APP_COMMAND: "Start the app using the following command: {command}",
61+
BOILERPLATE_TEMPLATES: "Choose a boilerplate from search list"
6162
};
6263

6364
const getAppMsg = {

src/util/common-utils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { askProjectName } from "./inquirer";
2222
import { deployAppMsg } from "../messages";
2323
import config from "../config";
24+
import find from "lodash/find";
2425

2526
export type CommonOptions = {
2627
log: LogFn;
@@ -406,6 +407,17 @@ async function fetchBoilerplateDetails(): Promise<Record<string, any>[]> {
406407
throw error;
407408
}
408409
}
410+
async function validateBoilerplate(boilerplateName: string): Promise<void> {
411+
const boilerplates = await fetchBoilerplateDetails();
412+
const isValid = find(
413+
boilerplates,
414+
(boilerplate) => boilerplate.name.toLowerCase()
415+
.replace(/ /g, "-") === boilerplateName
416+
);
417+
if (!isValid) {
418+
throw new Error("Invalid boilerplate. Please enter a valid boilerplate.");
419+
}
420+
}
409421

410422
export {
411423
getOrganizations,
@@ -428,5 +440,6 @@ export {
428440
disconnectApp,
429441
formatUrl,
430442
handleProjectNameConflict,
431-
fetchBoilerplateDetails
443+
fetchBoilerplateDetails,
444+
validateBoilerplate,
432445
};

src/util/inquirer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { AppTarget } from "@contentstack/management/types/app/index";
1414

1515
import messages, {
1616
$t,
17+
appCreate,
1718
deployAppMsg,
1819
errors,
1920
uninstallAppMsg,
@@ -394,7 +395,7 @@ const selectedBoilerplate = async (): Promise<any> => {
394395
type: "search-list",
395396
name: "App",
396397
choices: boilerplates.map((bp) => bp.name),
397-
message: "Select a boilerplate from search list",
398+
message: appCreate.BOILERPLATE_TEMPLATES,
398399
})
399400
.then((name) => {
400401
return find(boilerplates, (boilerplate) => boilerplate.name === name);

0 commit comments

Comments
 (0)