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