Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalid boilerplate error #278

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ FLAGS
-n, --name=<value> [default: app-boilerplate] Name of the app to be created
--app-type=<option> [default: stack] Type of app
<options: stack|organization>
--boilerplate=<value> Choose a boilerplate from search list
--boilerplate=<value> Provide a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or
Ecommerce App Boilerplate

DESCRIPTION
Create a new app in Developer Hub and optionally clone a boilerplate locally.
Expand All @@ -98,7 +99,11 @@ EXAMPLES

$ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json

$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplates <boilerplate-name>
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>

$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>

$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>
```

_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/create.ts)_
Expand Down
36 changes: 21 additions & 15 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default class Create extends BaseCommand<typeof Create> {
"$ <%= config.bin %> <%= command.id %> --name App-1 --app-type stack",
"$ <%= config.bin %> <%= command.id %> --name App-2 --app-type stack -d ./boilerplate",
"$ <%= config.bin %> <%= command.id %> --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json",
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplates <boilerplate-name>",
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>",
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>",
"$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>",
];

static flags: FlagInput = {
Expand All @@ -75,7 +77,7 @@ export default class Create extends BaseCommand<typeof Create> {
char: "d",
description: commonMsg.CURRENT_WORKING_DIR,
}),
"boilerplate": flags.string({
boilerplate: flags.string({
description: appCreate.BOILERPLATE_TEMPLATES,
}),
};
Expand Down Expand Up @@ -155,22 +157,26 @@ export default class Create extends BaseCommand<typeof Create> {
this.sharedConfig.defaultAppName
);
}
let boilerplate: BoilerplateAppType | null = null;

if (isEmpty(this.sharedConfig.boilerplateName)) {
const boilerplate: BoilerplateAppType = await selectedBoilerplate();

if (boilerplate) {
this.sharedConfig.boilerplateName = boilerplate.name
.toLowerCase()
.replace(/ /g, "-");
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
this.sharedConfig.appName = await getAppName(
this.sharedConfig.boilerplateName
);
}
boilerplate = await selectedBoilerplate();
} else {
await validateBoilerplate(this.sharedConfig.boilerplateName);
boilerplate = (await validateBoilerplate(
this.sharedConfig.boilerplateName
)) as BoilerplateAppType;
}

if (boilerplate) {
const transformedName = boilerplate.name
.toLowerCase()
.replace(/ /g, "-")
.substring(0, 20);

this.sharedConfig.boilerplateName = transformedName;
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
this.sharedConfig.appName = transformedName;
}
this.sharedConfig.appName = this.sharedConfig.boilerplateName;

//Auto select org in case of oauth
this.sharedConfig.org =
Expand Down
2 changes: 1 addition & 1 deletion src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const appCreate = {
REGISTER_THE_APP_ON_DEVELOPER_HUB:
"Registering the app with the name {appName} on the Developer Hub...",
START_APP_COMMAND: "Start the app using the following command: {command}",
BOILERPLATE_TEMPLATES: "Choose a boilerplate from search list"
BOILERPLATE_TEMPLATES: "Provide a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or Ecommerce App Boilerplate"
};

const getAppMsg = {
Expand Down
15 changes: 9 additions & 6 deletions src/util/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,19 @@ async function fetchBoilerplateDetails(): Promise<Record<string, any>[]> {
throw error;
}
}
async function validateBoilerplate(boilerplateName: string): Promise<void> {

async function validateBoilerplate(boilerplateName: string) {
const boilerplates = await fetchBoilerplateDetails();
const isValid = find(
const boilerplate = find(
boilerplates,
(boilerplate) => boilerplate.name.toLowerCase()
.replace(/ /g, "-") === boilerplateName
(boilerplate) => boilerplate.name === boilerplateName
);
if (!isValid) {
throw new Error("Invalid boilerplate. Please enter a valid boilerplate.");
if (!boilerplate) {
throw new Error(
"Invalid boilerplate! Please select a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or Ecommerce App Boilerplate"
);
}
return boilerplate;
}

export {
Expand Down
Loading