Allow budget to be specified inline on cli. (#1441)
Split --budget into --budget.config (for passing a JSON string) and --budget.configPath for passing a path to a json file. Switch to yargs 6 (because of #1399 and #1431).
This commit is contained in:
parent
d52dce4a82
commit
904f9230f0
|
|
@ -25,7 +25,7 @@ module.exports = {
|
|||
case 'pagexray.pageSummary':
|
||||
case 'coach.pageSummary':
|
||||
{
|
||||
verify(message, this.result, this.options);
|
||||
verify(message, this.result, this.options.budget.config);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ function getHelperFunction(metric) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
verify(message, result, options) {
|
||||
const budgets = options.budget;
|
||||
verify(message, result, budgets) {
|
||||
const failing = [];
|
||||
const working = [];
|
||||
// do we have an etry in the budget for this kind of message?
|
||||
|
|
|
|||
|
|
@ -190,10 +190,14 @@ module.exports.parseCommandLine = function parseCommandLine() {
|
|||
group: 'Plugins'
|
||||
})
|
||||
/** Budget */
|
||||
.option('budget', {
|
||||
.option('budget.configPath', {
|
||||
describe: 'Path to the JSON budget file.',
|
||||
group: 'Budget'
|
||||
})
|
||||
.option('budget.config', {
|
||||
describe: 'The JSON budget config as a string.',
|
||||
group: 'Budget'
|
||||
})
|
||||
.option('budget.output', {
|
||||
choices: ['junit', 'tap'],
|
||||
describe: 'The output format of the budget.',
|
||||
|
|
@ -395,7 +399,16 @@ module.exports.parseCommandLine = function parseCommandLine() {
|
|||
.config('config')
|
||||
.alias('version', 'V')
|
||||
.coerce('budget', function(arg) {
|
||||
return JSON.parse(fs.readFileSync(arg, 'utf8'))
|
||||
if (typeof arg === 'object' && !Array.isArray(arg)) {
|
||||
if (arg.configPath) {
|
||||
arg.config = JSON.parse(fs.readFileSync(arg.configPath, 'utf8'));
|
||||
} else if (arg.config){
|
||||
arg.config = JSON.parse(arg.config);
|
||||
}
|
||||
return arg;
|
||||
} else {
|
||||
throw new Error('Something looks wrong with your budget configuration. Since sitespeed.io 4.4 you should pass the path to your budget file through the --budget.file flag instead of directly through the --budget flag.');
|
||||
}
|
||||
})
|
||||
// .describe('browser', 'Specify browser')
|
||||
.wrap(yargs.terminalWidth())
|
||||
|
|
|
|||
|
|
@ -97,6 +97,6 @@
|
|||
"uuid": "^3.0.0",
|
||||
"webcoach": "0.30.4",
|
||||
"webpagetest": "0.3.4",
|
||||
"yargs": "5.0.0"
|
||||
"yargs": "6.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue