Skip to content

Commit

Permalink
chore: update the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal committed Apr 30, 2024
1 parent 44d6d18 commit 471f602
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/commands/new/glee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Generator from '@asyncapi/generator';
import { green, gray } from 'picocolors';

const successMessage = (projectName: string) =>
`🎉 Your glee project "${projectName}" has been successfully created!
`🎉 Your glee project "${green(projectName)}" has been successfully created!
⏩ Next steps: follow the instructions ${green('below')} to manage your project:
cd ${projectName}\t\t ${gray('# Navigate to the project directory')}
Expand All @@ -22,10 +22,20 @@ const successMessage = (projectName: string) =>
You can also open the project in your favourite editor and start tweaking it.
`;

const errorMessages = {
alreadyExists: (projectName: string) =>
`Unable to create the project because the directory "${green(projectName)}" already exists at "${process.cwd()}/${projectName}".
To specify a different name for the new project, please run the command ${green('below')} with a unique project name:
${gray('asyncapi new glee --name ${projectName}-1')}
`,
};

export default class NewGlee extends Command {
static description = 'Creates a new Glee project';
protected commandName = 'glee';
static successMessage = successMessage;
static errorMessages = errorMessages;

static flags = {
help: Flags.help({ char: 'h' }),
Expand Down Expand Up @@ -106,12 +116,10 @@ export default class NewGlee extends Command {
fs.existsSync(PROJECT_DIRECTORY) &&
fs.readdirSync(PROJECT_DIRECTORY).length > 0
) {
throw new Error(
`Unable to create the project. We tried to use "${projectName}" as the directory of your new project but it already exists (${PROJECT_DIRECTORY}). Please specify a different name for the new project. For example, run the following command instead:\n\n asyncapi new ${this.commandName} -f ${file} --name ${projectName}-1\n`
);
throw new Error(errorMessages.alreadyExists(projectName));
}
} catch (error: any) {
this.error(error.message);
this.log(error.message);
}
}

Expand Down Expand Up @@ -212,9 +220,7 @@ export default class NewGlee extends Command {
} catch (err: any) {
switch (err.code) {
case 'EEXIST':
this.error(
`Unable to create the project. We tried to use "${projectName}" as the directory of your new project but it already exists (${PROJECT_DIRECTORY}). Please specify a different name for the new project. For example, run the following command instead:\n\n asyncapi new ${this.commandName} --name ${projectName}-1\n`
);
this.error(errorMessages.alreadyExists(projectName));
break;
case 'EACCES':
this.error(
Expand Down

0 comments on commit 471f602

Please sign in to comment.