-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc(build): add build step for report (#12707)
- Loading branch information
1 parent
557c527
commit b877878
Showing
16 changed files
with
124 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
function concatRendererCode() { | ||
return [ | ||
fs.readFileSync(__dirname + '/../report/renderer/util.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/dom.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/details-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/crc-details-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/snippet-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/element-screenshot-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../lighthouse-core/lib/file-namer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/logger.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/report-ui-features.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/category-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/performance-category-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/pwa-category-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/report-renderer.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/i18n.js', 'utf8'), | ||
fs.readFileSync(__dirname + '/../report/renderer/text-encoding.js', 'utf8'), | ||
].join(';\n'); | ||
} | ||
|
||
async function buildStandaloneReport() { | ||
const REPORT_JAVASCRIPT = [ | ||
concatRendererCode(), | ||
fs.readFileSync(__dirname + '/../report/clients/standalone.js', 'utf8'), | ||
].join(';\n'); | ||
fs.mkdirSync(__dirname + '/../dist/report', {recursive: true}); | ||
fs.writeFileSync(__dirname + '/../dist/report/standalone.js', REPORT_JAVASCRIPT); | ||
} | ||
|
||
if (require.main === module) { | ||
buildStandaloneReport(); | ||
} | ||
|
||
module.exports = { | ||
buildStandaloneReport, | ||
concatRendererCode, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/* global document window ga DOM ReportRenderer ReportUIFeatures Logger */ | ||
|
||
(function __initLighthouseReport__() { | ||
const dom = new DOM(document); | ||
const renderer = new ReportRenderer(dom); | ||
const container = dom.find('main', document); | ||
/** @type {LH.ReportResult} */ | ||
// @ts-expect-error | ||
const lhr = window.__LIGHTHOUSE_JSON__; | ||
renderer.renderReport(lhr, container); | ||
|
||
// Hook in JS features and page-level event listeners after the report | ||
// is in the document. | ||
const features = new ReportUIFeatures(dom); | ||
features.initFeatures(lhr); | ||
})(); | ||
|
||
document.addEventListener('lh-analytics', /** @param {Event} e */ e => { | ||
// @ts-expect-error | ||
if (window.ga) ga(e.detail.cmd, e.detail.fields); | ||
}); | ||
|
||
document.addEventListener('lh-log', /** @param {Event} e */ e => { | ||
const el = document.querySelector('#lh-log'); | ||
if (!el) return; | ||
|
||
const logger = new Logger(el); | ||
// @ts-expect-error | ||
const detail = e.detail; | ||
|
||
switch (detail.cmd) { | ||
case 'log': | ||
logger.log(detail.msg); | ||
break; | ||
case 'warn': | ||
logger.warn(detail.msg); | ||
break; | ||
case 'error': | ||
logger.error(detail.msg); | ||
break; | ||
case 'hide': | ||
logger.hide(); | ||
break; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters