adgile
Version:
An easy-to-use automated front-end setup.
47 lines (39 loc) • 1.3 kB
JavaScript
/**
* A module for running the Page Speed Insights task
* @module task.psi
*/
let settings = require('../settings.default'),
helpers = require('../helpers/index');
const psi = require('psi'),
chalk = require('chalk'),
_ = require('lodash'),
flags = require('minimist')(process.argv.slice(2));
/**
* Run the Page Speed Insights task in response to gulp.
* Set API key if provided and print the result to console.
* @param {*} cb
*/
function runtask(cb) {
if(!settings.isPSI) {
cb(null);
return;
}
helpers.verbose(chalk.grey('Running task "psi"'));
console.log(chalk.grey('Running PageSpeed Insights (might take a while)...'));
if (!!flags.key && _.isString(flags.key)) {
settings.psiConfig.key = flags.key;
}
psi.output(settings.tunnelUrl, settings.psiConfig).then(() => {
if (settings.psiConfig.strategy === 'mobile') {
console.log(chalk.grey('Usability score: ', data.ruleGroups.USABILITY.score));
}
console.log(chalk.green('✔ Threshold of ' + settings.psiConfig.threshold + ' exceeded!'));
}).catch(err => {
console.error(chalk.red('✗ ' + err.message));
});
cb(null);
}
module.exports = {
runtask
}