Skip to content

Instantly share code, notes, and snippets.

@vikramvi
Last active March 14, 2018 16:47
Show Gist options
  • Save vikramvi/1a65486153cf7a62d6bf6a000de799c0 to your computer and use it in GitHub Desktop.
Save vikramvi/1a65486153cf7a62d6bf6a000de799c0 to your computer and use it in GitHub Desktop.
lh.js ( working script - running command line using node-cmd package )
const lighthouse = require('lighthouse');
const nodeCmd = require('node-cmd');
const opts = {
disableDeviceEmulation: true,
disableCpuThrottling: true,
disableNetworkThrottling: true,
view: true
};
function getSnakeCase(value) {
value = value.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();});
return '--' + value;
}
function generateCmd(flags) {
let keys = Object.keys(flags);
let list = [];
for(let i = 0; i < keys.length; i++) {
if (flags[keys[i]] == true) {
list.push(getSnakeCase(keys[i]));
} else {
list.push(getSnakeCase(keys[i]) + '=' + flags[keys[i]]);
}
}
return list.join(" ");
}
function getLightHouseCmd(opts) {
console.log("lighthouse " + "https://www.smava.de " + generateCmd(opts));
return "lighthouse " + "https://www.smava.de " + generateCmd(opts);
}
nodeCmd.run(getLightHouseCmd(opts));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment