Last active
March 14, 2018 16:47
-
-
Save vikramvi/1a65486153cf7a62d6bf6a000de799c0 to your computer and use it in GitHub Desktop.
lh.js ( working script - running command line using node-cmd package )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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