|
| 1 | +import ansis from 'ansis'; |
| 2 | +import { logger } from '../src/index.js'; |
| 3 | + |
| 4 | +async function sleep(delay: number) { |
| 5 | + return new Promise(resolve => { |
| 6 | + setTimeout(resolve, delay); |
| 7 | + }); |
| 8 | +} |
| 9 | + |
| 10 | +logger.setVerbose(process.argv.includes('--verbose')); |
| 11 | + |
| 12 | +const errorStage = process.argv |
| 13 | + .find(arg => arg.startsWith('--error=')) |
| 14 | + ?.split('=')[1]; |
| 15 | + |
| 16 | +try { |
| 17 | + logger.info(ansis.bold.blue('Code PushUp CLI v0.80.1')); |
| 18 | + logger.newline(); |
| 19 | + |
| 20 | + await logger.task('Importing code-pushup.config.ts', async () => { |
| 21 | + await sleep(500); |
| 22 | + |
| 23 | + return 'Loaded configuration from code-pushup.config.ts'; |
| 24 | + }); |
| 25 | + logger.debug('2 plugins:'); |
| 26 | + logger.debug('• ESLint'); |
| 27 | + logger.debug('• Lighthouse'); |
| 28 | + |
| 29 | + await logger.group( |
| 30 | + `Running plugin "ESLint" ${ansis.gray('[1/2]')}`, |
| 31 | + async () => { |
| 32 | + const bin = 'npx eslint . --format=json'; |
| 33 | + await logger.command(bin, async () => { |
| 34 | + await sleep(3000); |
| 35 | + if (errorStage === 'plugin') { |
| 36 | + logger.info('Configuration file not found.'); |
| 37 | + throw new Error(`Command ${ansis.bold(bin)} exited with code 1`); |
| 38 | + } |
| 39 | + logger.debug('All files pass linting.'); |
| 40 | + }); |
| 41 | + |
| 42 | + logger.info('Found 0 lint problems'); |
| 43 | + |
| 44 | + logger.warn( |
| 45 | + 'Metadata not found for rule @angular-eslint/template/eqeqeq', |
| 46 | + ); |
| 47 | + |
| 48 | + return 'Completed "ESLint" plugin execution'; |
| 49 | + }, |
| 50 | + ); |
| 51 | + |
| 52 | + await logger.group( |
| 53 | + `Running plugin "Lighthouse" ${ansis.gray('[2/2]')}`, |
| 54 | + async () => { |
| 55 | + await logger.task( |
| 56 | + `Executing ${ansis.bold('runLighthouse')} function`, |
| 57 | + async () => { |
| 58 | + await sleep(8000); |
| 59 | + return `Executed ${ansis.bold('runLighthouse')} function`; |
| 60 | + }, |
| 61 | + ); |
| 62 | + |
| 63 | + logger.debug('Lighthouse category scores:'); |
| 64 | + logger.debug('• Accessibility: 100'); |
| 65 | + logger.debug('• SEO: 84'); |
| 66 | + |
| 67 | + return 'Completed "Lighthouse" plugin execution'; |
| 68 | + }, |
| 69 | + ); |
| 70 | + |
| 71 | + logger.info(ansis.bold('Collected report')); |
| 72 | + logger.newline(); |
| 73 | + |
| 74 | + await logger.task(ansis.bold('Uploading report to portal'), async () => { |
| 75 | + logger.debug( |
| 76 | + 'Sent GraphQL mutation to https://api.code-pushup.example.com/graphql (organization: "example", project: "website")', |
| 77 | + ); |
| 78 | + await sleep(2000); |
| 79 | + if (errorStage === 'core') { |
| 80 | + throw new Error('GraphQL error'); |
| 81 | + } |
| 82 | + return ansis.bold('Uploaded report to portal'); |
| 83 | + }); |
| 84 | +} catch (error) { |
| 85 | + logger.newline(); |
| 86 | + console.error(error); |
| 87 | + logger.newline(); |
| 88 | + logger.error(ansis.bold(`Code PushUp CLI failed (see error above)`)); |
| 89 | + // eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit |
| 90 | + process.exit(1); |
| 91 | +} |
0 commit comments