Skip to content

Commit

Permalink
Remove not needed dependencies (plus lodash) (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
midudev authored Mar 8, 2020
1 parent a3115ce commit 8d40a91
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 65 deletions.
8 changes: 4 additions & 4 deletions lib/formats/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const _ = require('lodash');

const chalk = require('chalk');
const utils = require('../utils');

Expand All @@ -13,22 +13,22 @@ const renderOverview = item => {
};

const getDataOutput = (data, msg = 'No info provided') => data.length > 0 ?
_.map(data, renderSection).join('\n') :
data.map(renderSection).join('\n') :
renderInfo(msg);

module.exports = (overview, statistics, ruleSetResults, opportunities) => {
return [
utils.divider,
setTitle('Summary'),
_.map(overview, renderOverview).join('\n') + '\n',
overview.map(renderOverview).join('\n') + '\n',
setTitle('Field Data'),
getDataOutput(
statistics,
'The Chrome User Experience Report does not have sufficient real-world speed data for this page.'
),
'',
setTitle('Lab Data'),
_.map(ruleSetResults, renderSection).join('\n'),
ruleSetResults.map(renderSection).join('\n'),
'',
setTitle('Opportunities'),
getDataOutput(
Expand Down
23 changes: 10 additions & 13 deletions lib/formats/json.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
'use strict';
const _ = require('lodash');

module.exports = (overview, statistics, ruleSetResults, opportunities) => {
const mapSection = section => section.label;
const zip = (section, labelMapping) => _.zipObject(_.map(section, labelMapping), _.map(section, 'value'));

overview = zip(overview, 'label');
statistics = zip(statistics, mapSection);
ruleSetResults = zip(ruleSetResults, mapSection);
opportunities = zip(opportunities, mapSection);
const zip = section => section.reduce((acc, current) => {
const {label, value} = current;
acc[label] = value;
return acc;
}, {});

module.exports = (overview, statistics, ruleSetResults, opportunities) => {
return JSON.stringify({
overview,
statistics,
ruleResults: ruleSetResults,
opportunities
overview: zip(overview),
statistics: zip(statistics),
ruleResults: zip(ruleSetResults),
opportunities: zip(opportunities)
}, null, 2);
};
78 changes: 34 additions & 44 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ const prettyMs = require('pretty-ms');
const {getThreshold, getReporter} = require('./../lib/options-handler');

function overview(url, strategy, scores) {
const ret = [];

ret.push({
label: 'URL',
value: url
});

ret.push({
label: 'Strategy',
value: strategy
});

ret.push({
label: 'Performance',
value: convertToPercentum(scores.categories.performance.score)
});

return ret;
return [
{
label: 'URL',
value: url
},
{
label: 'Strategy',
value: strategy
},
{
label: 'Performance',
value: convertToPercentum(scores.categories.performance.score)
}
];
}

const fieldData = stats => {
Expand All @@ -40,45 +36,39 @@ const fieldData = stats => {
return sortOn(ret, 'label');
};

const getRules = (rules, group) => {
return rules.filter(rule => {
return rule.group === group;
});
};
const getRules = (rules, group) => rules.filter(rule => rule.group === group);

const labData = lighthouseResult => {
const ret = [];

const rules = getRules(lighthouseResult.categories.performance.auditRefs, 'metrics');

rules.forEach(rule => {
const {audits} = lighthouseResult;
ret.push({
label: audits[rule.id].title,
value: audits[rule.id].displayValue.replace(/\s/g, '')
});
const {audits, categories} = lighthouseResult;
const rules = getRules(categories.performance.auditRefs, 'metrics');

const ret = rules.map(rule => {
const {title, displayValue} = audits[rule.id];
return {
label: title,
value: displayValue.replace(/\s/g, '')
};
});

return sortOn(ret, 'label');
};

const opportunities = lighthouseResult => {
const ret = [];

const rules = getRules(lighthouseResult.categories.performance.auditRefs, 'load-opportunities');
const {audits, categories} = lighthouseResult;
const rules = getRules(categories.performance.auditRefs, 'load-opportunities');

const opportunityRules = rules.filter(rule => {
const {details} = lighthouseResult.audits[rule.id];
const {details} = audits[rule.id];
return details.type === 'opportunity' && details.overallSavingsMs > 0;
});

for (const rule of opportunityRules) {
const {audits} = lighthouseResult;
ret.push({
label: audits[rule.id].title,
value: prettyMs(audits[rule.id].details.overallSavingsMs)
});
}
const ret = opportunityRules.map(rule => {
const {title, details} = audits[rule.id];
return {
label: title,
value: prettyMs(details.overallSavingsMs)
};
});

return sortOn(ret, 'label');
};
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@
],
"dependencies": {
"chalk": "^2.4.2",
"download": "^7.0.0",
"googleapis": "^38.0.0",
"humanize-url": "^2.1.0",
"lodash": "^4.17.11",
"meow": "^5.0.0",
"pify": "^4.0.0",
"prepend-http": "^2.0.0",
"pretty-bytes": "^5.1.0",
"pretty-ms": "^4.0.0",
"sort-on": "^3.0.0",
"strip-ansi": "^5.1.0",
"update-notifier": "^2.5.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.0.2",
"strip-ansi": "^5.1.0",
"nyc": "^14.1.1",
"xo": "^0.25.3"
},
Expand Down

0 comments on commit 8d40a91

Please sign in to comment.