From 22ee13a308e34c245c609de08981abb70208e843 Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Tue, 1 Sep 2015 16:03:23 +0200 Subject: [PATCH 01/12] add format-option to options to get json if needed --- tasks/lib/config.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tasks/lib/config.coffee b/tasks/lib/config.coffee index dd52a1b..8e25c37 100644 --- a/tasks/lib/config.coffee +++ b/tasks/lib/config.coffee @@ -37,6 +37,9 @@ exports.init = (grunt) -> strategy = -> config["strategy"] if config["strategy"] + + format = -> + config["format"] if config["format"] threshold = -> return DEFAULT_THRESHOLD unless config["threshold"] @@ -55,6 +58,7 @@ exports.init = (grunt) -> param["url"] = url() + path param["locale"] = locale() param["strategy"] = strategy() + param["format"] = format() param["threshold"] = threshold() param From ff1cf9b8c0e2e59a61c1d34a84021a1364b43597 Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Wed, 2 Sep 2015 16:48:45 +0200 Subject: [PATCH 02/12] add option to save output in a file --- tasks/pagespeed.coffee | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tasks/pagespeed.coffee b/tasks/pagespeed.coffee index a965207..54c0dc2 100644 --- a/tasks/pagespeed.coffee +++ b/tasks/pagespeed.coffee @@ -19,8 +19,24 @@ module.exports = (grunt) -> numOfTests = params.length current = 0 + output = [] + for index, options of params - psi.output(options.url, options, (err, response) -> - current++ - done(err) if numOfTests == current - ) + if options.file + psi(options.url, options, (err, data) -> + current++ + unless err + grunt.log.write '.' + output.push {'url': options.url, 'score': data.score, 'pageStats': data.pageStats } + if numOfTests == current + #console.log filepath + filename + grunt.file.write options.filepath + options.file, JSON.stringify(output, false, 4) + grunt.log.writeln(' ') + grunt.log.ok 'Wrote output to ' + options.filepath + options.file + done(err) + ) + else + psi.output(options.url, options, (err, response) -> + current++ + done(err) if numOfTests == current + ) From 9fb06756470958f48cf01522724bad1088700a0c Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Wed, 2 Sep 2015 16:49:29 +0200 Subject: [PATCH 03/12] add option to save output in a file --- tasks/lib/config.coffee | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tasks/lib/config.coffee b/tasks/lib/config.coffee index 8e25c37..9695e6e 100644 --- a/tasks/lib/config.coffee +++ b/tasks/lib/config.coffee @@ -13,10 +13,15 @@ exports.init = (grunt) -> exports = {} config = {} DEFAULT_THRESHOLD = 70 + DEFAULT_FORMAT = 'cli' key = -> config["key"] if config["key"] + format = -> + return config["format"] if config["format"] + return DEFAULT_FORMAT unless config["format"] + nokey = -> config["nokey"] if config["nokey"] @@ -37,9 +42,20 @@ exports.init = (grunt) -> strategy = -> config["strategy"] if config["strategy"] - + + timeout = -> + config["timeout"] if config["timeout"] + + file = -> + config["file"] + ".json" if config["file"] + + filepath = -> + config["filepath"] if config["filepath"] + format = -> - config["format"] if config["format"] + return "json" if config["file"] + return config["format"] if config["format"] && config['format'].match(/json|cli|tap/) + 'cli' unless config["format"] && config['format'].match(/json|cli|tap/) threshold = -> return DEFAULT_THRESHOLD unless config["threshold"] @@ -58,8 +74,10 @@ exports.init = (grunt) -> param["url"] = url() + path param["locale"] = locale() param["strategy"] = strategy() - param["format"] = format() param["threshold"] = threshold() + param["filepath"] = filepath() + param["file"] = file() + param["format"] = format() if config["format"] param params From aa60dac400cd56fb9bf1264883e3df72419cdfe1 Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Wed, 2 Sep 2015 16:56:19 +0200 Subject: [PATCH 04/12] add option to save output in a file --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 1e8e004..6d89113 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,14 @@ _This task is a [multi task][] so any targets, files and options should be speci threshold: 80 } } + saveOutputToFile: { + options: { + paths: ["/speed/docs/insights/v1/getting_started", "/speed/docs/about"], + format: "json", + file: "pagespeed.json", + filepath: "tests/" + } + } } ### Options @@ -85,6 +93,17 @@ Use the nokey option to test-drive PageSpeed Insights before acquiring a key for #### key Type: `String` +#### format +Type: `String`, values(json|cli|tap) + +#### file +Type: `String`, filename for output + +If file is set, format is set to json. + +#### filepath +Type: `String` path for output + [Google API Key](https://code.google.com/apis/console/) #### url From 6e023ac25005a69c4273a9bfbc84f192d00983d9 Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Thu, 3 Sep 2015 09:14:03 +0200 Subject: [PATCH 05/12] add test-task for file-output to gruntfile --- tasks/pagespeed.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/pagespeed.coffee b/tasks/pagespeed.coffee index 54c0dc2..340fbfe 100644 --- a/tasks/pagespeed.coffee +++ b/tasks/pagespeed.coffee @@ -22,6 +22,7 @@ module.exports = (grunt) -> output = [] for index, options of params + # safe output to file if options.file psi(options.url, options, (err, data) -> current++ @@ -35,6 +36,7 @@ module.exports = (grunt) -> grunt.log.ok 'Wrote output to ' + options.filepath + options.file done(err) ) + # print output to cli else psi.output(options.url, options, (err, response) -> current++ From c9cc6d1a1badf6f06463adb188cda5aa577f67fd Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Thu, 3 Sep 2015 09:14:49 +0200 Subject: [PATCH 06/12] add test-output (pagespeed.json) to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5466f24..a0908fe 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ results node_modules npm-debug.log + +pagespeed.json From e0202af5bf2a4e1fc93c8789e26335328b26591a Mon Sep 17 00:00:00 2001 From: Markus Schwarz Date: Thu, 3 Sep 2015 09:15:46 +0200 Subject: [PATCH 07/12] add test-task for file-output to gruntfile --- Gruntfile.coffee | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 7300000..bc36c1f 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -26,6 +26,13 @@ module.exports = (grunt) -> locale: "en_GB" strategy: "mobile" threshold: 62 + toFile: + options: + paths: ["/speed/docs/insights/about", "/speed/docs/insights/v1/getting_started"] + locale: "en_GB" + strategy: "desktop" + file: "pagespeed" + filepath: "./" grunt.loadTasks 'tasks' From 7c35cb67dbe2c576b067468c2e01dbf7a766c264 Mon Sep 17 00:00:00 2001 From: Matt Kilpatrick Date: Wed, 16 Dec 2015 11:21:34 -0500 Subject: [PATCH 08/12] Properly count on errors so the process can finish. --- tasks/pagespeed.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/pagespeed.coffee b/tasks/pagespeed.coffee index c13ab50..172df2f 100644 --- a/tasks/pagespeed.coffee +++ b/tasks/pagespeed.coffee @@ -20,8 +20,8 @@ module.exports = (grunt) -> current = 0 for index, options of params + current++ psi.output(options.url, options).then (response) -> - current++ done() if numOfTests == current .catch (err) -> done(err) if numOfTests == current From cd6d8791c0574c59c9cc021a35528f15dd1ceb48 Mon Sep 17 00:00:00 2001 From: Matt Kilpatrick Date: Wed, 16 Dec 2015 17:45:28 -0500 Subject: [PATCH 09/12] Fix count increment. --- tasks/pagespeed.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/pagespeed.coffee b/tasks/pagespeed.coffee index 172df2f..48641e6 100644 --- a/tasks/pagespeed.coffee +++ b/tasks/pagespeed.coffee @@ -20,8 +20,9 @@ module.exports = (grunt) -> current = 0 for index, options of params - current++ psi.output(options.url, options).then (response) -> + current++ done() if numOfTests == current .catch (err) -> + current++ done(err) if numOfTests == current From 0c3d74636c8b6f1564fd8c8641a6e8a302a83cb3 Mon Sep 17 00:00:00 2001 From: Paul Radzkov Date: Tue, 21 Jun 2016 00:03:26 +0300 Subject: [PATCH 10/12] continue on errors in cli mode --- tasks/pagespeed.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/pagespeed.coffee b/tasks/pagespeed.coffee index bc66b09..a50dfc9 100644 --- a/tasks/pagespeed.coffee +++ b/tasks/pagespeed.coffee @@ -38,7 +38,9 @@ module.exports = (grunt) -> ) # print output to cli else - psi.output(options.url, options, (err, response) -> + psi.output(options.url, options).then (response) -> + current++ + done() if numOfTests == current + .catch (err) -> current++ done(err) if numOfTests == current - ) From 25995e8770780e468784e1cb223a665c398b32aa Mon Sep 17 00:00:00 2001 From: Paul Radzkov Date: Tue, 21 Jun 2016 02:37:51 +0300 Subject: [PATCH 11/12] continue on errors in filemode --- README.md | 9 ++++++--- tasks/pagespeed.coffee | 17 ++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6d89113..169d874 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ _This task is a [multi task][] so any targets, files and options should be speci [multi task]: https://github.com/gruntjs/grunt/wiki/Configuring-tasks -###Usage Example +### Usage Example pagespeed: { @@ -76,9 +76,12 @@ _This task is a [multi task][] so any targets, files and options should be speci saveOutputToFile: { options: { paths: ["/speed/docs/insights/v1/getting_started", "/speed/docs/about"], + locale: "en_GB", + strategy: "desktop", + threshold: 80, format: "json", - file: "pagespeed.json", - filepath: "tests/" + file: "pagespeed", + filepath: "results/" } } } diff --git a/tasks/pagespeed.coffee b/tasks/pagespeed.coffee index a50dfc9..064a65a 100644 --- a/tasks/pagespeed.coffee +++ b/tasks/pagespeed.coffee @@ -24,18 +24,21 @@ module.exports = (grunt) -> for index, options of params # safe output to file if options.file - psi(options.url, options, (err, data) -> + psi(options.url, options).then (data) -> current++ - unless err - grunt.log.write '.' - output.push {'url': options.url, 'score': data.score, 'pageStats': data.pageStats } + grunt.log.write 'url:' + data.id + ' ' + grunt.log.ok 'score:' + data.ruleGroups.SPEED.score + # full output + # output.push {data} + output.push {'url': data.id, 'score': data.ruleGroups.SPEED.score, 'pageStats': data.pageStats } if numOfTests == current - #console.log filepath + filename grunt.file.write options.filepath + options.file, JSON.stringify(output, false, 4) grunt.log.writeln(' ') grunt.log.ok 'Wrote output to ' + options.filepath + options.file - done(err) - ) + done() + .catch (err) -> + current++ + done(err) if numOfTests == current # print output to cli else psi.output(options.url, options).then (response) -> From 5996f511a4bd2c75c3eb8396d4b030bca08e8f82 Mon Sep 17 00:00:00 2001 From: Paul Radzkov Date: Tue, 21 Jun 2016 02:40:09 +0300 Subject: [PATCH 12/12] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 169d874..0364559 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ _This task is a [multi task][] so any targets, files and options should be speci ### Usage Example - +```js pagespeed: { options: { nokey: true, @@ -85,6 +85,7 @@ _This task is a [multi task][] so any targets, files and options should be speci } } } +``` ### Options