[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(build): generate report variants in deployment #9280

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly unrelated. just a driveby.

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do en-xa-local once #9192 lands? 😃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. definitely will.

};

mkdirp(DIST);

// Generate and write reports
Object.entries(filenameToLhr).forEach(([filename, lhr]) => {
let html = ReportGenerator.generateReportHtml(lhr);
for (const variant of ['', '-devtools']) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future, PSI will be another report variant.

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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

"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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundlephobia says this is 2KB minified+gzipped, so basically a nonfactor for folks already invoking npm install lighthouse 😆

"lookup-closest-locale": "6.0.4",
"metaviewport-parser": "0.2.0",
"mkdirp": "0.5.1",
Expand Down