-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add --view flag which will start a server and host report.html #1130
Changes from 6 commits
aff780a
06f884e
2e079bf
19a0b6e
bfa8235
6d1bb36
4aca0ab
1e20465
4ab4a75
59a178e
aaaf92d
2575124
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ import * as Printer from './printer'; | |
const lighthouse = require('../lighthouse-core'); | ||
const assetSaver = require('../lighthouse-core/lib/asset-saver.js'); | ||
const log = require('../lighthouse-core/lib/log'); | ||
const server = require('./server/server'); | ||
const opn = require('opn'); | ||
import {ChromeLauncher} from './chrome-launcher'; | ||
import * as Commands from './commands/commands'; | ||
|
||
|
@@ -90,12 +92,14 @@ const cliFlags = yargs | |
|
||
.group([ | ||
'output', | ||
'output-path' | ||
'output-path', | ||
'view' | ||
], 'Output:') | ||
.describe({ | ||
'output': 'Reporter for the results', | ||
'output-path': `The file path to output the results | ||
Example: --output-path=./lighthouse-results.html` | ||
Example: --output-path=./lighthouse-results.html`, | ||
'view': 'Open report.html in browser' | ||
}) | ||
|
||
// boolean values | ||
|
@@ -112,7 +116,8 @@ Example: --output-path=./lighthouse-results.html` | |
'select-chrome', | ||
'verbose', | ||
'quiet', | ||
'help' | ||
'help', | ||
'view' | ||
]) | ||
.choices('output', Printer.GetValidOutputOptions()) | ||
|
||
|
@@ -198,7 +203,7 @@ function initPort(flags: {port: number}): Promise<undefined> { | |
|
||
function launchChromeAndRun(addresses: Array<string>, | ||
config: Object, | ||
flags: {port: number, selectChrome: boolean}) { | ||
flags: {port: number, selectChrome: boolean, view: boolean}) { | ||
|
||
return initPort(flags).then(() => { | ||
const launcher = new ChromeLauncher({ | ||
|
@@ -219,7 +224,7 @@ function launchChromeAndRun(addresses: Array<string>, | |
}) | ||
} | ||
|
||
function lighthouseRun(addresses: Array<string>, config: Object, flags: Object) { | ||
function lighthouseRun(addresses: Array<string>, config: Object, flags: {view: boolean}) { | ||
// Process URLs once at a time | ||
const address = addresses.shift(); | ||
if (!address) { | ||
|
@@ -229,11 +234,21 @@ function lighthouseRun(addresses: Array<string>, config: Object, flags: Object) | |
return lighthouse(address, flags, config) | ||
.then((results: Results) => Printer.write(results, outputMode, outputPath)) | ||
.then((results: Results) => { | ||
const filename = `./${assetSaver.getFilenamePrefix({url: address})}.report.html`; | ||
|
||
if (outputMode === Printer.OutputMode[Printer.OutputMode.pretty]) { | ||
const filename = `./${assetSaver.getFilenamePrefix({url: address})}.report.html`; | ||
Printer.write(results, 'html', filename); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove blank line |
||
// Generate report.html, host it and open it in the default browser | ||
if (flags.view) { | ||
server.listen().then((port: number) => { | ||
const fileAbsPath = `${__dirname}/server/reports/${filename}`; | ||
Printer.write(results, 'html', fileAbsPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are already saving the file to disk in the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the report page is a static page. But the new report page should allow developers to interact with that. The server will then need to host a different report page (eventually). So I think we cannot use the same html file unless we want to update the old report page to the new one as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah gotcha. now i see what you were thinking here. one way we could handle this is append a generally this has some advantages, in that we can keep the reporting stuff really consistent between our static and interactive reports. wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow I didn't know we could do it in that approach. Thanks for the suggestion! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already changed. Also, server.js now uses 'http' instead of 'express'. |
||
opn(`http://localhost:${port}/reports/${filename}`); | ||
}); | ||
} | ||
|
||
return lighthouseRun(addresses, config, flags); | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore everything in this directory | ||
* | ||
# Except this file | ||
!.gitignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a more descriptive directory name we can use here since this is going to become specifically the performance experiments server? |
||
* @license | ||
* Copyright 2016 Google Inc. 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 express = require('express'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we try to do the server without express? it's so simple I think we can get away with not using it and instead reusing https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-cli/test/fixtures/static-server.js It might need a feature or two, but augmenting that seems better. |
||
const app = express(); | ||
let portPromise; | ||
|
||
app.use('/reports', express.static(`${__dirname}/reports`)); | ||
|
||
function listen() { | ||
if (portPromise) { | ||
portPromise = new Promise((resolve, reject) => { | ||
const server = app.listen(0, () => { | ||
resolve(server.address().port); | ||
}); | ||
}); | ||
} | ||
return portPromise; | ||
} | ||
|
||
module.exports = { | ||
listen: listen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to listen: app.listen.bind(app) |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
--view
overrides output pretty?