Add option --open/-o to open the result in your default browser. (#3493)

https://github.com/sitespeedio/sitespeed.io/issues/3492
This commit is contained in:
Peter Hedenskog 2021-10-29 08:42:52 +02:00 committed by GitHub
parent af148d9b75
commit e452fb532d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,8 @@
const fs = require('fs');
const cli = require('../lib/cli/cli');
const sitespeed = require('../lib/sitespeed');
const { execSync } = require('child_process');
const os = require('os');
async function run(options) {
process.exitCode = 1;
@ -20,6 +22,10 @@ async function run(options) {
fs.writeFileSync('result.json', JSON.stringify(result));
}
if ((options.open || options.o) && os.platform() === 'darwin') {
execSync('open ' + result.localPath + '/index.html');
}
if (
parsed.options.budget &&
Object.keys(result.budgetResult.failing).length > 0

View File

@ -1455,6 +1455,10 @@ module.exports.parseCommandLine = function parseCommandLine() {
.option('name', {
describe: 'Give your test a name.'
})
.option('open', {
alias: 'o',
describe: 'Open your test result in your default browser (Mac OS only).'
})
.option('slug', {
describe:
'Give your test a slug. The slug is used when you send the metrics to your data storage to identify the test and the folder of the tests. The max length of the slug is 200 characters and it can only contain a-z A-Z 0-9 and -_ characters.'

View File

@ -156,12 +156,14 @@ module.exports = {
if (options.summary && options.summary.out) {
console.log(options.summary.out); // eslint-disable-line no-console
}
return {
errors,
budgetResult,
resultUrl: resultUrls.hasBaseUrl()
? resultUrls.reportSummaryUrl() + '/index.html'
: ''
: '',
localPath: storageManager.getBaseDir()
};
} catch (err) {
log.error(err);