How to use the lighthouse/lighthouse-cli/printer.write function in lighthouse

To help you get started, we’ve selected a few lighthouse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github addyosmani / webpack-lighthouse-plugin / src / lighthouse-bin.js View on Github external
return promise.then(_ => {
      if (Array.isArray(flags.output)) {
        return flags.output.reduce((innerPromise, outputType) => {
          const outputPath = `${resolvedPath}.report.${typeToExtension(outputType)}`;
          return innerPromise.then((_) => Printer.write(results, outputType, outputPath));
        }, Promise.resolve(results));
      } else {
        const outputPath =
            flags.outputPath || `${resolvedPath}.report.${typeToExtension(flags.output)}`;
        return Printer.write(results.report, flags.output, outputPath).then(results => {
          if (flags.output === Printer.OutputMode[Printer.OutputMode.html] ||
              flags.output === Printer.OutputMode[Printer.OutputMode.domhtml]) {
            if (flags.view) {
              opn(outputPath, {wait: false});
            } else {
              log.log(
                  'CLI',
                  'Protip: Run lighthouse with `--view` to immediately open the HTML report in your browser');
            }
          }
  
          return results;
        });
      }
    });
  }
github addyosmani / webpack-lighthouse-plugin / src / lighthouse-bin.js View on Github external
          return innerPromise.then((_) => Printer.write(results, outputType, outputPath));
        }, Promise.resolve(results));