Skip to content

Commit e597a70

Browse files
committed
fix: invalid boilerplate error
1 parent fe2cabf commit e597a70

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ FLAGS
8484
-n, --name=<value> [default: app-boilerplate] Name of the app to be created
8585
--app-type=<option> [default: stack] Type of app
8686
<options: stack|organization>
87-
--boilerplate=<value> Choose a boilerplate from search list
87+
--boilerplate=<value> Provide a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or
88+
Ecommerce App Boilerplate
8889
8990
DESCRIPTION
9091
Create a new app in Developer Hub and optionally clone a boilerplate locally.
@@ -98,7 +99,11 @@ EXAMPLES
9899
99100
$ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json
100101
101-
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplates <boilerplate-name>
102+
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>
103+
104+
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>
105+
106+
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>
102107
```
103108

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

src/commands/app/create.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export default class Create extends BaseCommand<typeof Create> {
5353
"$ <%= config.bin %> <%= command.id %> --name App-1 --app-type stack",
5454
"$ <%= config.bin %> <%= command.id %> --name App-2 --app-type stack -d ./boilerplate",
5555
"$ <%= 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>",
56+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>",
57+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>",
58+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>",
5759
];
5860

5961
static flags: FlagInput = {
@@ -75,7 +77,7 @@ export default class Create extends BaseCommand<typeof Create> {
7577
char: "d",
7678
description: commonMsg.CURRENT_WORKING_DIR,
7779
}),
78-
"boilerplate": flags.string({
80+
boilerplate: flags.string({
7981
description: appCreate.BOILERPLATE_TEMPLATES,
8082
}),
8183
};
@@ -155,22 +157,26 @@ export default class Create extends BaseCommand<typeof Create> {
155157
this.sharedConfig.defaultAppName
156158
);
157159
}
160+
let boilerplate: BoilerplateAppType | null = null;
161+
158162
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-
}
163+
boilerplate = await selectedBoilerplate();
170164
} else {
171-
await validateBoilerplate(this.sharedConfig.boilerplateName);
165+
boilerplate = (await validateBoilerplate(
166+
this.sharedConfig.boilerplateName
167+
)) as BoilerplateAppType;
168+
}
169+
170+
if (boilerplate) {
171+
const transformedName = boilerplate.name
172+
.toLowerCase()
173+
.replace(/ /g, "-")
174+
.substring(0, 20);
175+
176+
this.sharedConfig.boilerplateName = transformedName;
177+
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
178+
this.sharedConfig.appName = transformedName;
172179
}
173-
this.sharedConfig.appName = this.sharedConfig.boilerplateName;
174180

175181
//Auto select org in case of oauth
176182
this.sharedConfig.org =

src/messages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +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"
61+
BOILERPLATE_TEMPLATES: "Provide a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or Ecommerce App Boilerplate"
6262
};
6363

6464
const getAppMsg = {

src/util/common-utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,19 @@ async function fetchBoilerplateDetails(): Promise<Record<string, any>[]> {
407407
throw error;
408408
}
409409
}
410-
async function validateBoilerplate(boilerplateName: string): Promise<void> {
410+
411+
async function validateBoilerplate(boilerplateName: string) {
411412
const boilerplates = await fetchBoilerplateDetails();
412-
const isValid = find(
413+
const boilerplate = find(
413414
boilerplates,
414-
(boilerplate) => boilerplate.name.toLowerCase()
415-
.replace(/ /g, "-") === boilerplateName
415+
(boilerplate) => boilerplate.name === boilerplateName
416416
);
417-
if (!isValid) {
418-
throw new Error("Invalid boilerplate. Please enter a valid boilerplate.");
417+
if (!boilerplate) {
418+
throw new Error(
419+
"Invalid boilerplate! Please select a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or Ecommerce App Boilerplate"
420+
);
419421
}
422+
return boilerplate;
420423
}
421424

422425
export {

0 commit comments

Comments
 (0)