Skip to content

Instantly share code, notes, and snippets.

@jasonwilliams
Created November 30, 2017 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwilliams/aa32fafda054a2f889716d3811fffea9 to your computer and use it in GitHub Desktop.
Save jasonwilliams/aa32fafda054a2f889716d3811fffea9 to your computer and use it in GitHub Desktop.
function generateReport(site, data, type) {
let promise = new Promise((resolve, reject) => {
launchChromeAndRunLighthouse(v.url, {output: type})
.then((data) => {
data = JSON.stringify(data);
// timestamep will be used on the filename
let timeStamp = DateTime.local().toISODate();
// Directory may not exist yet
if (!fs.existsSync(`reports/${v.name}`)) {
fs.mkdirSync(`reports/${v.name}`);
}
// Directory may not exist yet
if (!fs.existsSync(`reports/${v.name}/${type}`)) {
fs.mkdirSync(`reports/${v.name}/${type}`);
}
fs.writeFile(`reports/${v.name}/${v.name}-${timeStamp}.${type}`, data);
})
.catch(handleError);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment