-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
54 lines (43 loc) · 1.73 KB
/
dangerfile.js
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
const { markdown, message } = require('danger');
const fse = require('fs-extra');
const path = require('path');
const prettier = require('prettier');
const dangerCommand = process.env.DANGER_COMMAND;
async function reportBundleSize() {
const snapshotPath = path.join(__dirname, './performance-snapshot.json');
const prettierConfigPath = path.join(__dirname, './prettier.config.js');
const snapshot = await fse.readJSON(snapshotPath);
const headers = `
| Test case | Unit | Min | Max | Median | Mean | σ |
| --------- | ---- | --- | --- | ------ | ---- | - |`;
let text = `These are the results for the performance tests:
${headers}\n`;
const formatter = new Intl.NumberFormat('en');
Object.entries(snapshot).forEach(([name, values]) => {
const min = formatter.format(values.min);
const max = formatter.format(values.max);
const mean = formatter.format(values.mean);
const median = formatter.format(values.median);
const stdDev = formatter.format(values.stdDev);
text += `| ${name} | ms | ${min} | ${max} | ${median} | ${mean} | ${stdDev} |\n`;
});
const prettierConfig = prettier.resolveConfig.sync(snapshotPath, {
config: prettierConfigPath,
});
markdown(prettier.format(text, { prettierConfig, parser: 'markdown' }));
}
async function run() {
const netlifyPreview = `https://deploy-preview-${process.env.CIRCLE_PR_NUMBER}--material-ui-x.netlify.app/`;
message(`Netlify deploy preview: <a href="${netlifyPreview}">${netlifyPreview}</a>`);
switch (dangerCommand) {
case 'reportPerformance':
await reportBundleSize();
break;
default:
throw new TypeError(`Unrecognized danger command '${dangerCommand}'`);
}
}
run().catch((error) => {
console.error(error);
process.exit(1);
});