From ddc9aecc86e8cc81ee152783245477538f622286 Mon Sep 17 00:00:00 2001 From: Tom Gehder Date: Tue, 4 Jul 2023 13:20:29 +0200 Subject: [PATCH] TNDO-4488 Convert <> into () when uploading reports 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. --- src/bundler.spec.ts | 4 ++-- src/bundler.ts | 10 +++++++++- src/initializer.ts | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bundler.spec.ts b/src/bundler.spec.ts index dc77d47..c2dd1aa 100644 --- a/src/bundler.spec.ts +++ b/src/bundler.spec.ts @@ -11,7 +11,7 @@ describe('Bundler', () => { jest.spyOn(fileHelpers, 'loadPackageJson').mockReturnValue({ name: 'my-report', version: '1.0.0', - author: 'Jane Doe', + author: 'Jane Doe ', description: 'My report description', documentationLink: 'https://example.com', leanixReport: { @@ -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', diff --git a/src/bundler.ts b/src/bundler.ts index d432788..8266b5f 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -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 }, @@ -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); diff --git a/src/initializer.ts b/src/initializer.ts index 39d9582..630b8d5 100644 --- a/src/initializer.ts +++ b/src/initializer.ts @@ -34,7 +34,7 @@ export class Initializer { { type: 'input', name: 'author', - message: 'Who is the author of this report (e.g. LeanIX GmbH )' + message: 'Who is the author of this report (e.g. LeanIX GmbH)' }, { type: 'input',