Skip to content

Commit fc98779

Browse files
fix flag prompt
1 parent cc5d597 commit fc98779

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ 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>] [--boilerplates
78+
$ csdx app:create [-n <value>] [--app-type stack|organization] [-c <value>] [-d <value>] [--boilerplate
7979
<value>]
8080
8181
FLAGS
@@ -84,7 +84,7 @@ 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-
--boilerplates=<value> Choose a boilerplate from search list
87+
--boilerplate=<value> Choose a boilerplate from search list
8888
8989
DESCRIPTION
9090
Create a new app in Developer Hub and optionally clone a boilerplate locally.

src/commands/app/create.ts

Lines changed: 22 additions & 26 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> {
@@ -74,14 +75,15 @@ export default class Create extends BaseCommand<typeof Create> {
7475
char: "d",
7576
description: commonMsg.CURRENT_WORKING_DIR,
7677
}),
77-
"boilerplates": flags.string({
78+
"boilerplate": flags.string({
7879
description: appCreate.BOILERPLATE_TEMPLATES,
7980
}),
8081
};
8182

8283
async run(): Promise<void> {
8384
this.sharedConfig.org = this.flags.org;
8485
this.sharedConfig.appName = this.flags.name;
86+
this.sharedConfig.boilerplateName = this.flags.boilerplate;
8587

8688
await this.flagsPromptQueue();
8789

@@ -93,34 +95,15 @@ export default class Create extends BaseCommand<typeof Create> {
9395
}
9496

9597
try {
96-
if (this.flags.boilerplates) {
97-
this.sharedConfig.boilerplateName = this.flags.boilerplates
98-
.toLowerCase()
99-
.replace(/ /g, "-");
100-
this.sharedConfig.appName = await getAppName(
101-
this.sharedConfig.boilerplateName
102-
);
103-
await this.boilerplateFlow();
104-
} else if (
98+
if (
10599
this.flags.yes ||
106100
(await cliux.inquire({
107101
type: "confirm",
108102
name: "cloneBoilerplate",
109103
message: this.messages.CONFIRM_CLONE_BOILERPLATE,
110104
}))
111105
) {
112-
const boilerplate: BoilerplateAppType = await selectedBoilerplate();
113-
114-
if (boilerplate) {
115-
this.sharedConfig.boilerplateName = boilerplate.name
116-
.toLowerCase()
117-
.replace(/ /g, "-");
118-
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
119-
this.sharedConfig.appName = await getAppName(
120-
this.sharedConfig.boilerplateName
121-
);
122-
await this.boilerplateFlow();
123-
}
106+
await this.boilerplateFlow();
124107
} else {
125108
this.manageManifestToggeling();
126109
await this.registerTheAppOnDeveloperHub(false);
@@ -172,6 +155,22 @@ export default class Create extends BaseCommand<typeof Create> {
172155
this.sharedConfig.defaultAppName
173156
);
174157
}
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;
175174

176175
//Auto select org in case of oauth
177176
this.sharedConfig.org =
@@ -326,10 +325,7 @@ export default class Create extends BaseCommand<typeof Create> {
326325
this.appData = merge(this.appData, pick(response, validKeys));
327326
if (saveManifest) {
328327
writeFileSync(
329-
resolve(
330-
this.sharedConfig.folderPath,
331-
"manifest.json"
332-
),
328+
resolve(this.sharedConfig.folderPath, "manifest.json"),
333329
JSON.stringify(this.appData),
334330
{
335331
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/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";
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
};

0 commit comments

Comments
 (0)