Skip to content

Commit

Permalink
TNDO-4488 Convert <> into () when uploading reports
Browse files Browse the repository at this point in the history
THis way the standard format of package.json is kept as it is, but the user is able to upload it via the API. Since we are not showing the author's name anywhere we don't care how it is displayed at the end.
  • Loading branch information
tog-leanix committed Jul 4, 2023
1 parent 2dbde0c commit ddc9aec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/bundler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Bundler', () => {
jest.spyOn(fileHelpers, 'loadPackageJson').mockReturnValue({
name: 'my-report',
version: '1.0.0',
author: 'Jane Doe',
author: 'Jane Doe <jane.doe@mail.com>',
description: 'My report description',
documentationLink: 'https://example.com',
leanixReport: {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Bundler', () => {
JSON.stringify({
name: 'my-report',
version: '1.0.0',
author: 'Jane Doe',
author: 'Jane Doe (jane.doe@mail.com)',
description: 'My report description',
documentationLink: 'https://example.com',
id: 'com.example.myReport',
Expand Down
10 changes: 9 additions & 1 deletion src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Bundler {
{
name: packageJson.name,
version: packageJson.version,
author: packageJson.author,
author: this.getReportAuthor(packageJson.author),
description: packageJson.description,
documentationLink: packageJson.documentationLink
},
Expand All @@ -29,6 +29,14 @@ export class Bundler {
return writeFileAsync(metadataFile, JSON.stringify(metadata));
}

private getReportAuthor(author: string | { name: string; email: string }): string {
if (typeof author === 'string') {
return author.replace('<', '(').replace('>', ')');
} else {
return `${author.name} (${author.email})`;
}
}

private createTarFromDistFolder(distPath: string) {
const files = fs.readdirSync(distPath);
return tar.c({ gzip: true, cwd: distPath, file: 'bundle.tgz' }, files);
Expand Down
2 changes: 1 addition & 1 deletion src/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Initializer {
{
type: 'input',
name: 'author',
message: 'Who is the author of this report (e.g. LeanIX GmbH <support@leanix.net>)'
message: 'Who is the author of this report (e.g. LeanIX GmbH)'
},
{
type: 'input',
Expand Down

0 comments on commit ddc9aec

Please sign in to comment.