diff --git a/README.md b/README.md index ca7761f..8f335d6 100644 --- a/README.md +++ b/README.md @@ -1,126 +1,133 @@ -# psi [![Dependency Status](https://david-dm.org/addyosmani/psi.svg)](https://david-dm.org/addyosmani/psi) [![devDependency Status](https://david-dm.org/addyosmani/psi/dev-status.svg)](https://david-dm.org/addyosmani/psi#info=devDependencies) [![Build Status](https://travis-ci.org/addyosmani/psi.svg?branch=master)](https://travis-ci.org/addyosmani/psi) +# psi [![Build Status](https://travis-ci.org/addyosmani/psi.svg?branch=master)](https://travis-ci.org/addyosmani/psi) -> PageSpeed Insights With Reporting +> PageSpeed Insights with reporting ![](screenshot.png) -Run mobile and desktop performance tests for your deployed site using [Google PageSpeed Insights](https://developers.google.com/speed/docs/insights/v1/getting_started) with tidy reporting for your build process. A sample [Gulpfile](https://github.com/addyosmani/psi-gulp-sample) demonstrating use is also available. +Run mobile and desktop performance tests for your deployed site using [Google PageSpeed Insights](https://developers.google.com/speed/docs/insights/v1/getting_started) with tidy reporting for your build process. ## Install -```sh +``` $ npm install --save psi ``` ## Usage -When using this module for a production-level build process, registering for an API key from the [Google Developer Console](https://developers.google.com/speed/docs/insights/v1/getting_started#auth) is recommended. - ```js var psi = require('psi'); -psi({ - // key: '...', optional - url: 'http://html5rocks.com', - paths: '', // optional - locale: 'en_GB', // optional - strategy: 'mobile', // optional - threshold: 80 // optional +// get the PageSpeed Insights report +psi({url: 'html5rocks.com'}, function (err, data) { + console.log(data.score); + console.log(data.pageStats); }); -``` -Optionally, a callback is also available with access to the response: - -```js -psi(options, function (err, data) { - console.log(data.score); - console.log(data.pageStats); +// output a formatted report to the terminal +psi.output({url: 'html5rocks.com'}, function (err) { + console.log('done'); }); ``` -### Options -#### url +## API + +### psi(options, callback) + +#### options + +*Required* +Type: `object` + +##### url *Required* Type: `string` URL of the page for which the PageSpeed Insights API should generate results. -#### locale +##### key Type: `string` -Default: `en_US` +Default: `Free tier` -The locale that results should be generated in (e.g 'en_GB'). +When using this module for a production-level build process, registering for an API key from the [Google Developer Console](https://developers.google.com/speed/docs/insights/v1/getting_started#auth) is recommended. -#### strategy +##### strategy Type: `string` -Default: `mobile` +Default: `mobile` Values: `mobile`, `desktop` -The strategy to use when analyzing the page. +Strategy to use when analyzing the page. + +##### locale + +Type: `string` +Default: `en_US` -#### threshold +Locale results should be generated in. + +##### threshold Type: `number` Default: `70` -Threshold score that is needed to pass the pagespeed test +Threshold score to pass the PageSpeed test. + +#### callback(error, data) -#### paths +*Required* +Type: `function` -Type: `array` +##### data -An array of URL paths that are appended to the URL +Type: `object` -#### key +The response from Google PageSpeed Insights. -Type: `string` -Default: `nokey` +### psi.output(options, [callback]) -[Google API Key](https://code.google.com/apis/console/) +Output the formatted report to the terminal. -Unless Specified defaults to use the free tier on PageSpeed Insights. Good for getting a feel for how well this tool works for you. +#### options -#### format +*Required* +Type: `object` -Type: `string` -Default: `cli` +Same as for `psi()`. -The format of the report generated from the PageSpeed Insights API. Supported formats: cli, json and tap. +#### callback(error) + +Type: `function` ## CLI -```sh +``` $ npm install --global psi ``` -You can then casually use it with your key: - -```sh -$ psi http://todomvc.com --key 'YOUR_KEY_GOES_HERE' ``` +$ psi --help -Humanized URLs are also supported: + Usage + a11y -``` -$ psi todomvc.com -``` - -The following optional flags are also supported: + Example + a11y todomvc.com -```sh -$ psi --key= --prettyprint= --userIp= --locale= --strategy= --format + Options + --key Google API Key. By default the free tier is used. + --strategy Strategy to use when analyzing the page: mobile|desktop + --format Output format: cli|json|tap + --locale Locale results should be generated in. + --threshold Threshold score to pass the PageSpeed test. + --prettyprint Pretty print the result. ``` -```sh -$ psi http://www.html5rocks.com --strategy=mobile -``` ## Getting PSI into your build diff --git a/cli.js b/cli.js index 2033748..c182a7c 100755 --- a/cli.js +++ b/cli.js @@ -15,10 +15,11 @@ var cli = meow({ '', 'Options', ' --key Google API Key. By default the free tier is used.', - ' --format Output format: cli|json|tap', ' --strategy Strategy to use when analyzing the page: mobile|desktop', - ' --prettyprint Pretty print the result.', - ' --locale Locale results should be generated in.' + ' --format Output format: cli|json|tap', + ' --locale Locale results should be generated in.', + ' --threshold Threshold score to pass the PageSpeed test.', + ' --prettyprint Pretty print the result.' ].join('\n') });