Skip to content

Commit

Permalink
use page link for bundle label in pages table
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 4, 2020
1 parent ce8de72 commit 76e0610
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,6 @@ function formatDiff(absoluteChange, relativeChange) {
)})`;
}

function computeBundleLabel(bundleId) {
if (bundleId === 'packages/material-ui/build/umd/material-ui.production.min.js') {
return '@material-ui/core[umd]';
}
if (bundleId === '@material-ui/core/Textarea') {
return 'TextareaAutosize';
}
if (bundleId === 'docs.main') {
return 'docs:/_app';
}
if (bundleId === 'docs.landing') {
return 'docs:/';
}
return bundleId.replace(/^@material-ui\/core\//, '').replace(/\.esm$/, '');
}

/**
* Generates a Markdown table
* @param {{ label: string, align: 'left' | 'center' | 'right'}[]} headers
Expand Down Expand Up @@ -135,7 +119,15 @@ function generateEmphasizedChange([bundle, { parsed, gzip }]) {
return `**${bundle}**: parsed: ${changeParsed}, gzip: ${changeGzip}`;
}

function createComparisonTable(entries) {
/**
*
* @param {[string, object][]} entries
* @param {object} options
* @param {function (string): string} options.computeBundleLabel
*/
function createComparisonTable(entries, options) {
const { computeBundleLabel } = options;

return generateMDTable(
[
{ label: 'bundle' },
Expand Down Expand Up @@ -228,8 +220,30 @@ async function run() {
markdown(importantChanges.join('\n'));
}

const mainDetailsTable = createComparisonTable(mainResults);
const pageDetailsTable = createComparisonTable(pageResults);
const mainDetailsTable = createComparisonTable(mainResults, {
computeBundleLabel: bundleId => {
if (bundleId === 'packages/material-ui/build/umd/material-ui.production.min.js') {
return '@material-ui/core[umd]';
}
if (bundleId === '@material-ui/core/Textarea') {
return 'TextareaAutosize';
}
if (bundleId === 'docs.main') {
return 'docs:/_app';
}
if (bundleId === 'docs.landing') {
return 'docs:/';
}
return bundleId.replace(/^@material-ui\/core\//, '').replace(/\.esm$/, '');
},
});
const pageDetailsTable = createComparisonTable(pageResults, {
computeBundleLabel: bundleId => {
const host = `https://deploy-preview-${danger.github.pr.number}--material-ui.netlify.com`;
const page = bundleId.replace(/^docs:/, '');
return `[${page}](${host}${page})`;
},
});

const details = `
<details>
Expand Down

0 comments on commit 76e0610

Please sign in to comment.