Skip to content

Commit

Permalink
refactor: default app name
Browse files Browse the repository at this point in the history
  • Loading branch information
aman19K committed Jul 24, 2024
1 parent 6f2a855 commit 17d1b5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ USAGE
FLAGS
-c, --config=<value> Path of the external config
-d, --data-dir=<value> Current working directory.
-n, --name=<value> [default: app-boilerplate] Name of the app to be created
-n, --name=<value> Name of the app to be created
--app-type=<option> [default: stack] Type of app
<options: stack|organization>
--boilerplate=<value> Provide a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or
Expand Down
25 changes: 13 additions & 12 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
sanitizePath,
selectedBoilerplate,
validateBoilerplate,
validateAppName,
} from "../../util";

export default class Create extends BaseCommand<typeof Create> {
Expand All @@ -61,7 +62,6 @@ export default class Create extends BaseCommand<typeof Create> {
static flags: FlagInput = {
name: flags.string({
char: "n",
default: "app-boilerplate",
description: appCreate.NAME_DESCRIPTION,
}),
"app-type": flags.string({
Expand Down Expand Up @@ -152,13 +152,11 @@ export default class Create extends BaseCommand<typeof Create> {
* @memberof Create
*/
async flagsPromptQueue() {
if (isEmpty(this.sharedConfig.appName)) {
this.sharedConfig.appName = await getAppName(
this.sharedConfig.defaultAppName
);
if (this.sharedConfig.appName) {
validateAppName(this.sharedConfig.appName);
}
let boilerplate: BoilerplateAppType | null = null;

let boilerplate: BoilerplateAppType | null = null;
if (isEmpty(this.sharedConfig.boilerplateName)) {
boilerplate = await selectedBoilerplate();
} else {
Expand All @@ -168,14 +166,17 @@ export default class Create extends BaseCommand<typeof Create> {
}

if (boilerplate) {
const transformedName = boilerplate.name
.toLowerCase()
.replace(/ /g, "-")
.substring(0, 20);
let boilerplateName = this.sharedConfig.appName || boilerplate.name;
if (isEmpty(this.sharedConfig.appName)) {
boilerplateName = boilerplateName
.toLowerCase()
.replace(/ /g, "-")
.substring(0, 20);
}

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

//Auto select org in case of oauth
Expand Down
10 changes: 7 additions & 3 deletions src/util/inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ async function askConfirmation(): Promise<boolean> {
});
}

const askProjectName = async (
projectName: string,
): Promise<string> => {
const askProjectName = async (projectName: string): Promise<string> => {
return await cliux.inquire({
type: "input",
name: "name",
Expand Down Expand Up @@ -402,6 +400,11 @@ const selectedBoilerplate = async (): Promise<any> => {
});
};

const validateAppName = (name: string) => {
if (name.length < 3 || name.length > 20) {
throw new Error($t(errors.INVALID_NAME, { min: "3", max: "20" }));
}
};
export {
getOrg,
getAppName,
Expand All @@ -418,4 +421,5 @@ export {
selectProject,
askProjectName,
selectedBoilerplate,
validateAppName,
};

0 comments on commit 17d1b5c

Please sign in to comment.