-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
672 additions
and
70 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { cliui } from '@poppinss/cliui'; | ||
import chalk from 'chalk'; | ||
import { UploadConfig } from '@code-pushup/models'; | ||
import { link, portalCommitDashboardLink } from '@code-pushup/utils'; | ||
|
||
export type CliUi = ReturnType<typeof cliui>; | ||
|
||
// eslint-disable-next-line import/no-mutable-exports,functional/no-let | ||
export let singletonUiInstance: CliUi | undefined; | ||
export function ui(): CliUi { | ||
if (singletonUiInstance === undefined) { | ||
singletonUiInstance = cliui(); | ||
} | ||
return singletonUiInstance; | ||
} | ||
|
||
export function renderConfigureCategoriesHint(): void { | ||
ui().logger.info( | ||
chalk.gray( | ||
`💡 Configure categories to see the scores in an overview table. See: ${link( | ||
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md', | ||
)}`, | ||
), | ||
); | ||
} | ||
export function uploadSuccessfulLog( | ||
options: UploadConfig, | ||
commit: string, | ||
): void { | ||
ui().logger.success('Upload successful!'); | ||
ui().logger.success( | ||
link( | ||
// @TODO extend config to maintain baseUrl under upload | ||
portalCommitDashboardLink( | ||
{ ...options, baseUrl: '<YOUR_PORTAL_URL>' }, | ||
commit, | ||
), | ||
), | ||
); | ||
} | ||
export function collectSuccessfulLog(): void { | ||
ui().logger.success('Collecting report successful!'); | ||
} | ||
|
||
export function renderIntegratePortalHint(): void { | ||
ui() | ||
.sticker() | ||
.add(chalk.bold(chalk.gray('💡 Integrate the portal'))) | ||
.add('') | ||
.add( | ||
`${chalk.gray('❯')} Upload a report to the server - ${chalk.gray( | ||
'npx code-pushup upload', | ||
)}`, | ||
) | ||
.add( | ||
` ${link( | ||
'https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command', | ||
)}`, | ||
) | ||
.add( | ||
`${chalk.gray('❯')} ${chalk.gray('Portal Integration')} - ${link( | ||
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration', | ||
)}`, | ||
) | ||
.add( | ||
`${chalk.gray('❯')} ${chalk.gray('Upload Command')} - ${link( | ||
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration', | ||
)}`, | ||
) | ||
.render(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { expect } from 'vitest'; | ||
import { ui } from './logging'; | ||
|
||
describe('ui', () => { | ||
it('should return singleton', () => { | ||
expect(ui()).toBe(ui()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
import chalk from 'chalk'; | ||
import { ArgumentsCamelCase, CommandModule } from 'yargs'; | ||
import { UploadOptions, upload } from '@code-pushup/core'; | ||
import { getLatestCommit, validateCommitData } from '@code-pushup/utils'; | ||
import { CLI_NAME } from '../constants'; | ||
import { | ||
renderIntegratePortalHint, | ||
ui, | ||
uploadSuccessfulLog, | ||
} from '../implementation/logging'; | ||
|
||
export function yargsUploadCommandObject() { | ||
const command = 'upload'; | ||
return { | ||
command, | ||
describe: 'Upload report results to the portal', | ||
handler: async <T>(args: ArgumentsCamelCase<T>) => { | ||
console.info(chalk.bold(CLI_NAME)); | ||
console.info(chalk.gray(`Run ${command}...`)); | ||
ui().logger.log(chalk.bold(CLI_NAME)); | ||
ui().logger.info(chalk.gray(`Run ${command}...`)); | ||
|
||
const options = args as unknown as UploadOptions; | ||
if (!options.upload) { | ||
console.info( | ||
[ | ||
'💡 Integrate the portal:', | ||
'- npx code-pushup upload - Run upload to upload the created report to the server', | ||
' https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command', | ||
'- Portal Integration - https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration', | ||
'- Upload Command - https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration', | ||
].join('\n'), | ||
); | ||
renderIntegratePortalHint(); | ||
throw new Error('Upload configuration not set'); | ||
} | ||
await upload(options); | ||
|
||
const commitData = await getLatestCommit(); | ||
if (validateCommitData(commitData, { throwError: true })) { | ||
uploadSuccessfulLog(options.upload, commitData.hash); | ||
} | ||
}, | ||
} satisfies CommandModule; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.