Skip to content

Commit

Permalink
chore: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal committed May 1, 2024
1 parent e37da15 commit 9c548ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/commands/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { load } from '../models/SpecificationFile';
import { SpecificationFileNotFound } from '../errors/specification-file';
import { convert } from '@asyncapi/converter';
import type { ConvertVersion } from '@asyncapi/converter';
import { cyan, green } from 'picocolors';

// @ts-ignore
import specs from '@asyncapi/specs';
Expand Down Expand Up @@ -42,9 +43,9 @@ export default class Convert extends Command {
convertedFile = convert(this.specFile.text(), flags['target-version'] as ConvertVersion);
if (convertedFile) {
if (this.specFile.getFilePath()) {
this.log(`🎉 The ${this.specFile.getFilePath()} file has been successfully converted to version ${flags['target-version']}!!`);
this.log(`🎉 The ${cyan(this.specFile.getFilePath())} file has been successfully converted to version ${green(flags['target-version'])}!!`);
} else if (this.specFile.getFileURL()) {
this.log(`🎉 The URL ${this.specFile.getFileURL()} has been successfully converted to version ${flags['target-version']}!!`);
this.log(`🎉 The URL ${cyan(this.specFile.getFileURL())} has been successfully converted to version ${green(flags['target-version'])}!!`);
}
}

Expand All @@ -66,7 +67,7 @@ export default class Convert extends Command {
filepath: filePath
}));
} else if (this.specFile?.toJson().asyncapi > flags['target-version']) {
this.error(`The ${filePath} file cannot be converted to an older version. Downgrading is not supported.`);
this.error(`The ${cyan(filePath)} file cannot be converted to an older version. Downgrading is not supported.`);
} else {
this.error(err as Error);
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/new/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as inquirer from 'inquirer';
import { start as startStudio, DEFAULT_PORT } from '../../models/Studio';
import { resolve } from 'path';
import { load } from '../../models/SpecificationFile';
import { cyan } from 'picocolors';

const { writeFile, readFile } = fPromises;
const DEFAULT_ASYNCAPI_FILE_NAME = 'asyncapi.yaml';
Expand Down Expand Up @@ -163,11 +164,11 @@ export default class NewFile extends Command {
}
} catch (e:any) {
if (e.code === 'EACCES') {
this.error('Permission has been denied to access the file');
this.error('Permission has been denied to access the file.');
}
}
await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' });
console.log(`The ${fileNameToWriteToDisk} has been successfully created.`);
console.log(`The ${cyan(fileNameToWriteToDisk)} has been successfully created.`);
this.specFile = await load(fileNameToWriteToDisk);
this.metricsMetadata.selected_template = selectedTemplate;
}
Expand Down
12 changes: 6 additions & 6 deletions src/commands/new/glee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { prompt } from 'inquirer';
// eslint-disable-next-line
// @ts-ignore
import Generator from '@asyncapi/generator';
import { green, gray } from 'picocolors';
import { cyan, gray } from 'picocolors';

export const successMessage = (projectName: string) =>
`🎉 Your glee project "${green(projectName)}" has been successfully created!
⏩ Next steps: follow the instructions ${green('below')} to manage your project:
`🎉 Your Glee project has been successfully created!
⏩ Next steps: follow the instructions ${cyan('below')} to manage your project:
cd ${projectName}\t\t ${gray('# Navigate to the project directory')}
npm install\t\t ${gray('# Install the project dependencies')}
Expand All @@ -24,9 +24,9 @@ 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:
`Unable to create the project because the directory "${cyan(projectName)}" already exists at "${process.cwd()}/${projectName}".
To specify a different name for the new project, please run the command below with a unique project name:
${gray('asyncapi new glee --name ') + gray(projectName) + gray('-1')}`,
};

Expand Down
10 changes: 3 additions & 7 deletions test/integration/new/glee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import { expect } from '@oclif/test';

const testHelper = new TestHelper();
const successMessage = (projectName: string) =>
`🎉 Your glee project "${projectName}" has been successfully created!
`;
'🎉 Your Glee project has been successfully created!';

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

describe('new glee', () => {
before(() => {
Expand All @@ -38,7 +34,7 @@ describe('new glee', () => {
.command(['new:glee', '-n=test-project'])
.it('runs new glee command with name flag', async (ctx,done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(successMessage('test-project'));
expect(ctx.stdout).to.contains(successMessage('test-project'));
done();
});
});
Expand Down

0 comments on commit 9c548ee

Please sign in to comment.