Skip to content

Commit

Permalink
misc(build): generate report variants in deployment (#9280)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Jun 25, 2019
1 parent 3819339 commit 5a8c18b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
19 changes: 0 additions & 19 deletions .build-for-now.sh

This file was deleted.

1 change: 1 addition & 0 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class Runner {
gatherMode: undefined,
auditMode: undefined,
output: undefined,
channel: undefined,
budgets: undefined,
};
const normalizedGatherSettings = Object.assign({}, artifacts.settings, overrides);
Expand Down
32 changes: 27 additions & 5 deletions lighthouse-core/scripts/build-report-for-autodeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp').sync;
const swapLocale = require('../lib/i18n/swap-locale.js');

const ReportGenerator = require('../../lighthouse-core/report/report-generator.js');
const lhr = /** @type {LH.Result} */ (require('../../lighthouse-core/test/results/sample_v2.json'));

const DIST = path.join(__dirname, `../../dist`);

// Add a plugin to demo plugin rendering.
lhr.categories['lighthouse-plugin-someplugin'] = {
id: 'lighthouse-plugin-someplugin',
Expand All @@ -22,8 +26,26 @@ lhr.categories['lighthouse-plugin-someplugin'] = {
auditRefs: [],
};

console.log('🕒 Generating report for sample_v2.json...');
const html = ReportGenerator.generateReport(lhr, 'html');
const filename = path.join(__dirname, '../../dist/index.html');
fs.writeFileSync(filename, html, {encoding: 'utf-8'});
console.log('✅', filename, 'written.');
(async function() {
const filenameToLhr = {
'english': lhr,
'espanol': swapLocale(lhr, 'es').lhr,
'arabic': swapLocale(lhr, 'ar').lhr,
};

mkdirp(DIST);

// Generate and write reports
Object.entries(filenameToLhr).forEach(([filename, lhr]) => {
let html = ReportGenerator.generateReportHtml(lhr);
for (const variant of ['', '-devtools']) {
if (variant === '-devtools') {
html = html.replace(`"lh-root lh-vars"`, `"lh-root lh-vars lh-devtools"`);
}
const filepath = `${DIST}/${filename}${variant}/index.html`;
mkdirp(path.dirname(filepath));
fs.writeFileSync(filepath, html, {encoding: 'utf-8'});
console.log('✅', filepath, 'written.');
}
});
})();
2 changes: 1 addition & 1 deletion now.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 2,
"builds": [
{
"src": ".build-for-now.sh",
"src": "package.json",
"use": "@now/static-build"
}
],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"chrome": "node lighthouse-core/scripts/manual-chrome-launcher.js",
"fast": "yarn start --emulated-form-factor=none --throttlingMethod=provided",
"deploy-viewer": "yarn build-viewer --deploy",
"now-build": "node lighthouse-core/scripts/build-report-for-autodeployment.js",
"bundlesize": "bundlesize",
"timing-trace": "node lighthouse-core/scripts/generate-timing-trace.js",
"changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file",
Expand Down Expand Up @@ -122,7 +123,6 @@
"isomorphic-fetch": "^2.2.1",
"jest": "^24.3.0",
"jsdom": "^12.2.0",
"lodash.set": "^4.3.2",
"make-dir": "^1.3.0",
"npm-run-posix-or-windows": "^2.0.2",
"nyc": "^13.3.0",
Expand Down Expand Up @@ -152,6 +152,7 @@
"jsonlint-mod": "^1.7.4",
"lighthouse-logger": "^1.2.0",
"lodash.isequal": "^4.5.0",
"lodash.set": "^4.3.2",
"lookup-closest-locale": "6.0.4",
"metaviewport-parser": "0.2.0",
"mkdirp": "0.5.1",
Expand Down

0 comments on commit 5a8c18b

Please sign in to comment.