Skip to content

Commit 7ae18a8

Browse files
committed
refactor: default app name
1 parent e597a70 commit 7ae18a8

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ 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>
8787
--boilerplate=<value> Provide a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or

src/commands/app/create.ts

Lines changed: 13 additions & 12 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> {
@@ -61,7 +62,6 @@ export default class Create extends BaseCommand<typeof Create> {
6162
static flags: FlagInput = {
6263
name: flags.string({
6364
char: "n",
64-
default: "app-boilerplate",
6565
description: appCreate.NAME_DESCRIPTION,
6666
}),
6767
"app-type": flags.string({
@@ -152,13 +152,11 @@ export default class Create extends BaseCommand<typeof Create> {
152152
* @memberof Create
153153
*/
154154
async flagsPromptQueue() {
155-
if (isEmpty(this.sharedConfig.appName)) {
156-
this.sharedConfig.appName = await getAppName(
157-
this.sharedConfig.defaultAppName
158-
);
155+
if (this.sharedConfig.appName) {
156+
validateAppName(this.sharedConfig.appName);
159157
}
160-
let boilerplate: BoilerplateAppType | null = null;
161158

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

170168
if (boilerplate) {
171-
const transformedName = boilerplate.name
172-
.toLowerCase()
173-
.replace(/ /g, "-")
174-
.substring(0, 20);
169+
let boilerplateName = this.sharedConfig.appName || boilerplate.name;
170+
if (isEmpty(this.sharedConfig.appName)) {
171+
boilerplateName = boilerplateName
172+
.toLowerCase()
173+
.replace(/ /g, "-")
174+
.substring(0, 20);
175+
}
175176

176-
this.sharedConfig.boilerplateName = transformedName;
177+
this.sharedConfig.boilerplateName = boilerplateName;
177178
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
178-
this.sharedConfig.appName = transformedName;
179+
this.sharedConfig.appName = boilerplateName;
179180
}
180181

181182
//Auto select org in case of oauth

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)