Skip to content

Commit f9cc4dd

Browse files
authored
Merge pull request #278 from contentstack/fix/DX-992
fix: invalid boilerplate error
2 parents 158bb13 + 7ae18a8 commit f9cc4dd

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ USAGE
8181
FLAGS
8282
-c, --config=<value> Path of the external config
8383
-d, --data-dir=<value> Current working directory.
84-
-n, --name=<value> [default: app-boilerplate] Name of the app to be created
84+
-n, --name=<value> 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: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
sanitizePath,
3636
selectedBoilerplate,
3737
validateBoilerplate,
38+
validateAppName,
3839
} from "../../util";
3940

4041
export default class Create extends BaseCommand<typeof Create> {
@@ -53,13 +54,14 @@ export default class Create extends BaseCommand<typeof Create> {
5354
"$ <%= config.bin %> <%= command.id %> --name App-1 --app-type stack",
5455
"$ <%= config.bin %> <%= command.id %> --name App-2 --app-type stack -d ./boilerplate",
5556
"$ <%= 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>",
57+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>",
58+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>",
59+
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>",
5760
];
5861

5962
static flags: FlagInput = {
6063
name: flags.string({
6164
char: "n",
62-
default: "app-boilerplate",
6365
description: appCreate.NAME_DESCRIPTION,
6466
}),
6567
"app-type": flags.string({
@@ -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
};
@@ -150,27 +152,32 @@ export default class Create extends BaseCommand<typeof Create> {
150152
* @memberof Create
151153
*/
152154
async flagsPromptQueue() {
153-
if (isEmpty(this.sharedConfig.appName)) {
154-
this.sharedConfig.appName = await getAppName(
155-
this.sharedConfig.defaultAppName
156-
);
155+
if (this.sharedConfig.appName) {
156+
validateAppName(this.sharedConfig.appName);
157157
}
158+
159+
let boilerplate: BoilerplateAppType | null = null;
158160
if (isEmpty(this.sharedConfig.boilerplateName)) {
159-
const boilerplate: BoilerplateAppType = await selectedBoilerplate();
161+
boilerplate = await selectedBoilerplate();
162+
} else {
163+
boilerplate = (await validateBoilerplate(
164+
this.sharedConfig.boilerplateName
165+
)) as BoilerplateAppType;
166+
}
160167

161-
if (boilerplate) {
162-
this.sharedConfig.boilerplateName = boilerplate.name
168+
if (boilerplate) {
169+
let boilerplateName = this.sharedConfig.appName || boilerplate.name;
170+
if (isEmpty(this.sharedConfig.appName)) {
171+
boilerplateName = boilerplateName
163172
.toLowerCase()
164-
.replace(/ /g, "-");
165-
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
166-
this.sharedConfig.appName = await getAppName(
167-
this.sharedConfig.boilerplateName
168-
);
173+
.replace(/ /g, "-")
174+
.substring(0, 20);
169175
}
170-
} else {
171-
await validateBoilerplate(this.sharedConfig.boilerplateName);
176+
177+
this.sharedConfig.boilerplateName = boilerplateName;
178+
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
179+
this.sharedConfig.appName = boilerplateName;
172180
}
173-
this.sharedConfig.appName = this.sharedConfig.boilerplateName;
174181

175182
//Auto select org in case of oauth
176183
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 {

src/util/inquirer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ async function askConfirmation(): Promise<boolean> {
368368
});
369369
}
370370

371-
const askProjectName = async (
372-
projectName: string,
373-
): Promise<string> => {
371+
const askProjectName = async (projectName: string): Promise<string> => {
374372
return await cliux.inquire({
375373
type: "input",
376374
name: "name",
@@ -402,6 +400,11 @@ const selectedBoilerplate = async (): Promise<any> => {
402400
});
403401
};
404402

403+
const validateAppName = (name: string) => {
404+
if (name.length < 3 || name.length > 20) {
405+
throw new Error($t(errors.INVALID_NAME, { min: "3", max: "20" }));
406+
}
407+
};
405408
export {
406409
getOrg,
407410
getAppName,
@@ -418,4 +421,5 @@ export {
418421
selectProject,
419422
askProjectName,
420423
selectedBoilerplate,
424+
validateAppName,
421425
};

0 commit comments

Comments
 (0)