lighthouse-badges 1.2.4 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,7 +68,7 @@ members of the project's leadership.
68
68
  ## Attribution
69
69
 
70
70
  This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
72
 
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Code Coverage](https://codecov.io/gh/emazzotta/lighthouse-badges/branch/master/graph/badge.svg)](https://github.com/emazzotta/lighthouse-badges/actions)
3
3
  [![NPM downloads](https://img.shields.io/npm/dt/lighthouse-badges?color=blue)](https://www.npmjs.org/package/lighthouse-badges)
4
4
  [![NPM version](https://img.shields.io/npm/v/lighthouse-badges.svg)](https://www.npmjs.org/package/lighthouse-badges)
5
- [![License](http://img.shields.io/:license-mit-blue.svg?style=flat)](https://emanuelemazzotta.com/mit-license)
5
+ [![License](https://img.shields.io/:license-mit-blue.svg?style=flat)](https://emanuelemazzotta.com/mit-license)
6
6
 
7
7
  # Lighthouse Badges
8
8
 
@@ -54,6 +54,32 @@ Required arguments:
54
54
  average score(s) of all the urls supplied, combined
55
55
  ```
56
56
 
57
+ Additionally, you can pass parameters configurations to the lighthouse process directly via environment variable path to the config file:
58
+
59
+ ```bash
60
+ # The variable name matters, but the path can be anything
61
+ export LIGHTHOUSE_BADGES_CONFIGURATION_PATH="~/.lhb-config.json"
62
+
63
+ # "extends": "lighthouse:default" is needed, the rest is optional
64
+ cat << EOF >! $LIGHTHOUSE_BADGES_CONFIGURATION_PATH
65
+ {
66
+ "extends": "lighthouse:default",
67
+ "settings": {
68
+ "extraHeaders": {
69
+ "Authorization": "Bearer ..."
70
+ },
71
+ "onlyCategories": [
72
+ "performance",
73
+ "pwa"
74
+ ],
75
+ "formFactor": "mobile"
76
+ }
77
+ }
78
+ EOF
79
+
80
+ lighthouse-badges --urls https://www.youtube.com/
81
+ ```
82
+
57
83
  ### Run
58
84
 
59
85
  node >= 16 is required.
@@ -78,6 +104,13 @@ docker run --rm \
78
104
  /bin/sh -c "lighthouse-badges --urls https://www.youtube.com/ https://www.youtube.com/feed/trending"
79
105
  ```
80
106
 
107
+ ### Develop
108
+
109
+ ```bash
110
+ npm run dev # Starts babel transpiler in watch mode
111
+ npm run start # To run the lighthouse-badges code on google.com
112
+ ```
113
+
81
114
  ## Contributing
82
115
 
83
116
  See [contribution guideline](./CONTRIBUTING.md)
@@ -46,7 +46,7 @@ describe('test index', () => {
46
46
  });
47
47
 
48
48
  it('should handle processing errors gracefully', async () => {
49
- parseMock.mockReturnValue(['--urls', 'http://example.org']);
49
+ parseMock.mockReturnValue(['--urls', 'https://example.org']);
50
50
  processMock.mockRejectedValue(new Error('Async error'));
51
51
 
52
52
  await handleUserInput(spinnerFake);
package/__tests__/util.js CHANGED
@@ -9,7 +9,7 @@ describe('test util', () => {
9
9
  });
10
10
 
11
11
  it('should return escaped http url', () => {
12
- const actualUrl = 'http://abcöd%f&/?get=hi';
12
+ const actualUrl = 'https://abcöd%f&/?get=hi';
13
13
  const expectedUrl = 'abc_d_f___get_hi';
14
14
  expect(urlEscaper(actualUrl)).toBe(expectedUrl);
15
15
  });
package/dist/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Code Coverage](https://codecov.io/gh/emazzotta/lighthouse-badges/branch/master/graph/badge.svg)](https://github.com/emazzotta/lighthouse-badges/actions)
3
3
  [![NPM downloads](https://img.shields.io/npm/dt/lighthouse-badges?color=blue)](https://www.npmjs.org/package/lighthouse-badges)
4
4
  [![NPM version](https://img.shields.io/npm/v/lighthouse-badges.svg)](https://www.npmjs.org/package/lighthouse-badges)
5
- [![License](http://img.shields.io/:license-mit-blue.svg?style=flat)](https://emanuelemazzotta.com/mit-license)
5
+ [![License](https://img.shields.io/:license-mit-blue.svg?style=flat)](https://emanuelemazzotta.com/mit-license)
6
6
 
7
7
  # Lighthouse Badges
8
8
 
@@ -54,6 +54,32 @@ Required arguments:
54
54
  average score(s) of all the urls supplied, combined
55
55
  ```
56
56
 
57
+ Additionally, you can pass parameters configurations to the lighthouse process directly via environment variable path to the config file:
58
+
59
+ ```bash
60
+ # The variable name matters, but the path can be anything
61
+ export LIGHTHOUSE_BADGES_CONFIGURATION_PATH="~/.lhb-config.json"
62
+
63
+ # "extends": "lighthouse:default" is needed, the rest is optional
64
+ cat << EOF >! $LIGHTHOUSE_BADGES_CONFIGURATION_PATH
65
+ {
66
+ "extends": "lighthouse:default",
67
+ "settings": {
68
+ "extraHeaders": {
69
+ "Authorization": "Bearer ..."
70
+ },
71
+ "onlyCategories": [
72
+ "performance",
73
+ "pwa"
74
+ ],
75
+ "formFactor": "mobile"
76
+ }
77
+ }
78
+ EOF
79
+
80
+ lighthouse-badges --urls https://www.youtube.com/
81
+ ```
82
+
57
83
  ### Run
58
84
 
59
85
  node >= 16 is required.
@@ -78,6 +104,13 @@ docker run --rm \
78
104
  /bin/sh -c "lighthouse-badges --urls https://www.youtube.com/ https://www.youtube.com/feed/trending"
79
105
  ```
80
106
 
107
+ ### Develop
108
+
109
+ ```bash
110
+ npm run dev # Starts babel transpiler in watch mode
111
+ npm run start # To run the lighthouse-badges code on google.com
112
+ ```
113
+
81
114
  ## Contributing
82
115
 
83
116
  See [contribution guideline](./CONTRIBUTING.md)
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse-badges",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "🚦Generate gh-badges (shields.io) based on Lighthouse performance.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -10,9 +10,11 @@
10
10
  "app:install": "npm run build && cd dist && npm i -g .",
11
11
  "app:reinstall": "npm-run-all app:uninstall app:install",
12
12
  "app:uninstall": "npm uninstall -g @emazzotta/lighthouse-badges; npm uninstall -g .; npm uninstall -g lighthouse-badges",
13
- "build": "npm run clean && babel src --out-dir dist/src && sed 's#\"dist/src/index.js\"#\"src/index.js\"#' package.json > ./dist/package.json && cp README.md dist && cp LICENSE.md dist && cp -r node_modules dist",
13
+ "build": "npm run build:prepare && babel src --out-dir dist/src",
14
+ "build:prepare": "npm run clean && mkdir dist && sed 's#\"dist/src/index.js\"#\"src/index.js\"#' package.json > ./dist/package.json && cp README.md dist && cp LICENSE.md dist && cp -r node_modules dist",
14
15
  "ci:publish": "npm run build && npm publish --prefix dist",
15
16
  "clean": "rm -rf *.svg *.html coverage dist results",
17
+ "dev": "npm run build:prepare && babel src --watch --out-dir dist/src",
16
18
  "docker:build": "npm run build && docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` --build-arg VERSION=latest -t emazzotta/lighthouse-badges .",
17
19
  "docker:system-test:run": "docker run emazzotta/lighthouse-badges /bin/sh -c 'lighthouse-badges -rsu https://google.com && EXEC_PATH=/home/chrome/reports npm run system-test:verify --prefix /home/lighthouse'",
18
20
  "lint": "eslint .",
@@ -20,6 +22,7 @@
20
22
  "pre-push": "npm-run-all lint:fix test:all",
21
23
  "run:global-installation": "[ -z ${PAGE} ] && PAGE=https://google.com ; lighthouse-badges -rsu ${PAGE} -o results",
22
24
  "run:local-installation": "[ -z ${PAGE} ] && PAGE=https://google.com ; node dist/src/index.js -rsu ${PAGE} -o results",
25
+ "start": "npm run run:local-installation",
23
26
  "system-test:full-run": "npm-run-all clean build app:reinstall run:global-installation system-test:verify",
24
27
  "system-test:light-run": "npm-run-all clean build run:local-installation system-test:verify",
25
28
  "system-test:verify": "[ -z ${EXEC_PATH} ] && EXEC_PATH=$PWD/results ; grep -q '<svg xmlns' ${EXEC_PATH}/*.svg && grep -q '<title>Lighthouse Report</title>' ${EXEC_PATH}/*.html",
@@ -43,26 +46,26 @@
43
46
  "url": "https://github.com/emazzotta/lighthouse-badges.git"
44
47
  },
45
48
  "dependencies": {
46
- "@babel/runtime": "^7.20.13",
49
+ "@babel/runtime": "^7.21.0",
47
50
  "argparse": "2.0.1",
48
51
  "badge-maker": "^3.3.1",
49
52
  "chrome-launcher": "^0.15.1",
50
53
  "clui": "^0.3.6",
51
- "lighthouse": "^10.0.1",
54
+ "lighthouse": "^10.0.2",
52
55
  "ramda": "^0.28.0"
53
56
  },
54
57
  "devDependencies": {
55
- "@babel/cli": "^7.20.7",
56
- "@babel/core": "^7.20.12",
57
- "@babel/plugin-transform-runtime": "^7.19.6",
58
+ "@babel/cli": "^7.21.0",
59
+ "@babel/core": "^7.21.0",
60
+ "@babel/plugin-transform-runtime": "^7.21.0",
58
61
  "@babel/preset-env": "^7.20.2",
59
62
  "@types/jest": "^29.4.0",
60
- "eslint": "^8.34.0",
63
+ "eslint": "^8.36.0",
61
64
  "eslint-config-airbnb-base": "^15.0.0",
62
65
  "eslint-plugin-import": "^2.27.5",
63
66
  "husky": "^8.0.3",
64
- "jest": "^29.4.2",
65
- "lint-staged": "^13.1.2",
67
+ "jest": "^29.5.0",
68
+ "lint-staged": "^13.2.0",
66
69
  "npm-run-all": "^4.1.5"
67
70
  },
68
71
  "engines": {
package/dist/src/index.js CHANGED
@@ -9,46 +9,56 @@ exports["default"] = void 0;
9
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
11
  var _clui = _interopRequireDefault(require("clui"));
12
+ var _fs = _interopRequireDefault(require("fs"));
12
13
  var _lighthouseBadges = require("./lighthouse-badges");
13
14
  var _argparser = _interopRequireDefault(require("./argparser"));
15
+ var CLI_SPINNER = new _clui["default"].Spinner('Running Lighthouse, please wait...', ['◜', '◠', '◝', '◞', '◡', '◟']);
14
16
  var handleUserInput = /*#__PURE__*/function () {
15
17
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(spinner) {
18
+ var lighthouseParameters, fileContent;
16
19
  return _regenerator["default"].wrap(function _callee$(_context) {
17
20
  while (1) switch (_context.prev = _context.next) {
18
21
  case 0:
19
22
  _context.prev = 0;
20
23
  spinner.start();
24
+ lighthouseParameters = {
25
+ "extends": 'lighthouse:default'
26
+ };
27
+ if (process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH) {
28
+ process.stdout.write(" LIGHTHOUSE_BADGES_CONFIGURATION_PATH: ".concat(process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH, "\n"));
29
+ fileContent = _fs["default"].readFileSync(process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH, 'utf8');
30
+ lighthouseParameters = JSON.parse(fileContent);
31
+ }
21
32
  _context.t0 = _lighthouseBadges.processParameters;
22
- _context.next = 5;
33
+ _context.next = 7;
23
34
  return _argparser["default"].parse_args();
24
- case 5:
35
+ case 7:
25
36
  _context.t1 = _context.sent;
26
37
  _context.t2 = _lighthouseBadges.calculateLighthouseMetrics;
27
- _context.next = 9;
28
- return (0, _context.t0)(_context.t1, _context.t2);
29
- case 9:
38
+ _context.t3 = lighthouseParameters;
39
+ _context.next = 12;
40
+ return (0, _context.t0)(_context.t1, _context.t2, _context.t3);
41
+ case 12:
30
42
  spinner.stop();
31
- _context.next = 16;
43
+ _context.next = 19;
32
44
  break;
33
- case 12:
34
- _context.prev = 12;
35
- _context.t3 = _context["catch"](0);
36
- process.stderr.write("".concat(_context.t3, "\n"));
45
+ case 15:
46
+ _context.prev = 15;
47
+ _context.t4 = _context["catch"](0);
48
+ process.stderr.write("".concat(_context.t4, "\n"));
37
49
  process.exit(1);
38
- case 16:
50
+ case 19:
39
51
  case "end":
40
52
  return _context.stop();
41
53
  }
42
- }, _callee, null, [[0, 12]]);
54
+ }, _callee, null, [[0, 15]]);
43
55
  }));
44
56
  return function handleUserInput(_x) {
45
57
  return _ref.apply(this, arguments);
46
58
  };
47
59
  }();
48
-
49
- // Only self-invoke if not imported but called directly as executable
60
+ var _default = handleUserInput; // Only self-invoke if not imported but called directly as executable
61
+ exports["default"] = _default;
50
62
  (function () {
51
- return !module.parent && handleUserInput(new _clui["default"].Spinner('Running Lighthouse, please wait...', ['◜', '◠', '◝', '◞', '◡', '◟']));
52
- })();
53
- var _default = handleUserInput;
54
- exports["default"] = _default;
63
+ return !module.parent && handleUserInput(CLI_SPINNER);
64
+ })();
@@ -124,33 +124,41 @@ var processRawLighthouseResult = /*#__PURE__*/function () {
124
124
  exports.processRawLighthouseResult = processRawLighthouseResult;
125
125
  var calculateLighthouseMetrics = /*#__PURE__*/function () {
126
126
  var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(url, shouldSaveReport) {
127
- var chromeParameters, chrome, options, runnerResult, reportHtml, reportJson;
127
+ var lighthouseParameters,
128
+ chromeParameters,
129
+ chrome,
130
+ options,
131
+ runnerResult,
132
+ reportHtml,
133
+ reportJson,
134
+ _args5 = arguments;
128
135
  return _regenerator["default"].wrap(function _callee5$(_context5) {
129
136
  while (1) switch (_context5.prev = _context5.next) {
130
137
  case 0:
138
+ lighthouseParameters = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {};
131
139
  chromeParameters = ['--headless', '--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage', '--no-default-browser-check', '--no-first-run', '--disable-default-apps'];
132
- _context5.next = 3;
140
+ _context5.next = 4;
133
141
  return chromeLauncher.launch({
134
142
  chromeFlags: chromeParameters
135
143
  });
136
- case 3:
144
+ case 4:
137
145
  chrome = _context5.sent;
138
146
  options = {
139
147
  logLevel: 'silent',
140
148
  output: 'html',
141
149
  port: chrome.port
142
150
  };
143
- _context5.next = 7;
144
- return (0, _index["default"])(url, options);
145
- case 7:
151
+ _context5.next = 8;
152
+ return (0, _index["default"])(url, options, lighthouseParameters);
153
+ case 8:
146
154
  runnerResult = _context5.sent;
147
155
  reportHtml = runnerResult.report;
148
156
  reportJson = runnerResult.lhr;
149
- _context5.next = 12;
157
+ _context5.next = 13;
150
158
  return chrome.kill();
151
- case 12:
152
- return _context5.abrupt("return", processRawLighthouseResult(reportJson, reportHtml, url, shouldSaveReport));
153
159
  case 13:
160
+ return _context5.abrupt("return", processRawLighthouseResult(reportJson, reportHtml, url, shouldSaveReport));
161
+ case 14:
154
162
  case "end":
155
163
  return _context5.stop();
156
164
  }
@@ -162,52 +170,59 @@ var calculateLighthouseMetrics = /*#__PURE__*/function () {
162
170
  }();
163
171
  exports.calculateLighthouseMetrics = calculateLighthouseMetrics;
164
172
  var processParameters = /*#__PURE__*/function () {
165
- var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(args, func) {
166
- var outputPath, results, metrics, reports, metricsResults;
173
+ var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(parserArgs, func) {
174
+ var lighthouseParameters,
175
+ outputPath,
176
+ results,
177
+ metrics,
178
+ reports,
179
+ metricsResults,
180
+ _args6 = arguments;
167
181
  return _regenerator["default"].wrap(function _callee6$(_context6) {
168
182
  while (1) switch (_context6.prev = _context6.next) {
169
183
  case 0:
170
- outputPath = args.output_path || process.cwd();
184
+ lighthouseParameters = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
185
+ outputPath = parserArgs.output_path || process.cwd();
171
186
  _fs["default"].mkdir(outputPath, {
172
187
  recursive: true
173
188
  }, function (err) {
174
189
  if (err) throw err;
175
190
  });
176
- _context6.next = 4;
177
- return Promise.all(args.urls.map(function (url) {
178
- return func(url, args.save_report);
191
+ _context6.next = 5;
192
+ return Promise.all(parserArgs.urls.map(function (url) {
193
+ return func(url, parserArgs.save_report, lighthouseParameters);
179
194
  }));
180
- case 4:
195
+ case 5:
181
196
  results = _context6.sent;
182
197
  metrics = R.pluck('metrics', results);
183
198
  reports = R.pluck('report', results);
184
- if (!args.single_badge) {
185
- _context6.next = 13;
199
+ if (!parserArgs.single_badge) {
200
+ _context6.next = 14;
186
201
  break;
187
202
  }
188
- _context6.next = 10;
203
+ _context6.next = 11;
189
204
  return (0, _calculations.getSquashedScore)(metrics);
190
- case 10:
205
+ case 11:
191
206
  _context6.t0 = _context6.sent;
192
- _context6.next = 16;
207
+ _context6.next = 17;
193
208
  break;
194
- case 13:
195
- _context6.next = 15;
209
+ case 14:
210
+ _context6.next = 16;
196
211
  return (0, _calculations.getAverageScore)(metrics);
197
- case 15:
198
- _context6.t0 = _context6.sent;
199
212
  case 16:
213
+ _context6.t0 = _context6.sent;
214
+ case 17:
200
215
  metricsResults = _context6.t0;
201
- _context6.next = 19;
216
+ _context6.next = 20;
202
217
  return generateArtifacts({
203
218
  reports: reports,
204
219
  svg: {
205
220
  results: metricsResults,
206
- style: args.badge_style
221
+ style: parserArgs.badge_style
207
222
  },
208
223
  outputPath: outputPath
209
224
  });
210
- case 19:
225
+ case 20:
211
226
  case "end":
212
227
  return _context6.stop();
213
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse-badges",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "🚦Generate gh-badges (shields.io) based on Lighthouse performance.",
5
5
  "main": "dist/src/index.js",
6
6
  "bin": {
@@ -10,9 +10,11 @@
10
10
  "app:install": "npm run build && cd dist && npm i -g .",
11
11
  "app:reinstall": "npm-run-all app:uninstall app:install",
12
12
  "app:uninstall": "npm uninstall -g @emazzotta/lighthouse-badges; npm uninstall -g .; npm uninstall -g lighthouse-badges",
13
- "build": "npm run clean && babel src --out-dir dist/src && sed 's#\"dist/src/index.js\"#\"src/index.js\"#' package.json > ./dist/package.json && cp README.md dist && cp LICENSE.md dist && cp -r node_modules dist",
13
+ "build": "npm run build:prepare && babel src --out-dir dist/src",
14
+ "build:prepare": "npm run clean && mkdir dist && sed 's#\"dist/src/index.js\"#\"src/index.js\"#' package.json > ./dist/package.json && cp README.md dist && cp LICENSE.md dist && cp -r node_modules dist",
14
15
  "ci:publish": "npm run build && npm publish --prefix dist",
15
16
  "clean": "rm -rf *.svg *.html coverage dist results",
17
+ "dev": "npm run build:prepare && babel src --watch --out-dir dist/src",
16
18
  "docker:build": "npm run build && docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` --build-arg VERSION=latest -t emazzotta/lighthouse-badges .",
17
19
  "docker:system-test:run": "docker run emazzotta/lighthouse-badges /bin/sh -c 'lighthouse-badges -rsu https://google.com && EXEC_PATH=/home/chrome/reports npm run system-test:verify --prefix /home/lighthouse'",
18
20
  "lint": "eslint .",
@@ -20,6 +22,7 @@
20
22
  "pre-push": "npm-run-all lint:fix test:all",
21
23
  "run:global-installation": "[ -z ${PAGE} ] && PAGE=https://google.com ; lighthouse-badges -rsu ${PAGE} -o results",
22
24
  "run:local-installation": "[ -z ${PAGE} ] && PAGE=https://google.com ; node dist/src/index.js -rsu ${PAGE} -o results",
25
+ "start": "npm run run:local-installation",
23
26
  "system-test:full-run": "npm-run-all clean build app:reinstall run:global-installation system-test:verify",
24
27
  "system-test:light-run": "npm-run-all clean build run:local-installation system-test:verify",
25
28
  "system-test:verify": "[ -z ${EXEC_PATH} ] && EXEC_PATH=$PWD/results ; grep -q '<svg xmlns' ${EXEC_PATH}/*.svg && grep -q '<title>Lighthouse Report</title>' ${EXEC_PATH}/*.html",
@@ -43,26 +46,26 @@
43
46
  "url": "https://github.com/emazzotta/lighthouse-badges.git"
44
47
  },
45
48
  "dependencies": {
46
- "@babel/runtime": "^7.20.13",
49
+ "@babel/runtime": "^7.21.0",
47
50
  "argparse": "2.0.1",
48
51
  "badge-maker": "^3.3.1",
49
52
  "chrome-launcher": "^0.15.1",
50
53
  "clui": "^0.3.6",
51
- "lighthouse": "^10.0.1",
54
+ "lighthouse": "^10.0.2",
52
55
  "ramda": "^0.28.0"
53
56
  },
54
57
  "devDependencies": {
55
- "@babel/cli": "^7.20.7",
56
- "@babel/core": "^7.20.12",
57
- "@babel/plugin-transform-runtime": "^7.19.6",
58
+ "@babel/cli": "^7.21.0",
59
+ "@babel/core": "^7.21.0",
60
+ "@babel/plugin-transform-runtime": "^7.21.0",
58
61
  "@babel/preset-env": "^7.20.2",
59
62
  "@types/jest": "^29.4.0",
60
- "eslint": "^8.34.0",
63
+ "eslint": "^8.36.0",
61
64
  "eslint-config-airbnb-base": "^15.0.0",
62
65
  "eslint-plugin-import": "^2.27.5",
63
66
  "husky": "^8.0.3",
64
- "jest": "^29.4.2",
65
- "lint-staged": "^13.1.2",
67
+ "jest": "^29.5.0",
68
+ "lint-staged": "^13.2.0",
66
69
  "npm-run-all": "^4.1.5"
67
70
  },
68
71
  "engines": {
package/src/index.js CHANGED
@@ -1,13 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import CLI from 'clui';
4
+ import fs from 'fs';
4
5
  import { calculateLighthouseMetrics, processParameters } from './lighthouse-badges';
5
6
  import parser from './argparser';
6
7
 
8
+ const CLI_SPINNER = new CLI.Spinner('Running Lighthouse, please wait...', ['◜', '◠', '◝', '◞', '◡', '◟']);
9
+
7
10
  const handleUserInput = async (spinner) => {
8
11
  try {
9
12
  spinner.start();
10
- await processParameters(await parser.parse_args(), calculateLighthouseMetrics);
13
+ let lighthouseParameters = { extends: 'lighthouse:default' };
14
+ if (process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH) {
15
+ process.stdout.write(` LIGHTHOUSE_BADGES_CONFIGURATION_PATH: ${process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH}\n`);
16
+ const fileContent = fs.readFileSync(process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH, 'utf8');
17
+ lighthouseParameters = JSON.parse(fileContent);
18
+ }
19
+ await processParameters(
20
+ await parser.parse_args(),
21
+ calculateLighthouseMetrics,
22
+ lighthouseParameters,
23
+ );
11
24
  spinner.stop();
12
25
  } catch (err) {
13
26
  process.stderr.write(`${err}\n`);
@@ -15,7 +28,7 @@ const handleUserInput = async (spinner) => {
15
28
  }
16
29
  };
17
30
 
18
- // Only self-invoke if not imported but called directly as executable
19
- (() => !module.parent && handleUserInput(new CLI.Spinner('Running Lighthouse, please wait...', ['◜', '◠', '◝', '◞', '◡', '◟'])))();
20
-
21
31
  export default handleUserInput;
32
+
33
+ // Only self-invoke if not imported but called directly as executable
34
+ (() => !module.parent && handleUserInput(CLI_SPINNER))();
@@ -59,7 +59,11 @@ export const processRawLighthouseResult = async (data, html, url, shouldSaveRepo
59
59
  return { metrics: lighthouseMetrics, report: { [url]: htmlReport } };
60
60
  };
61
61
 
62
- export const calculateLighthouseMetrics = async (url, shouldSaveReport) => {
62
+ export const calculateLighthouseMetrics = async (
63
+ url,
64
+ shouldSaveReport,
65
+ lighthouseParameters = {},
66
+ ) => {
63
67
  const chromeParameters = [
64
68
  '--headless',
65
69
  '--no-sandbox',
@@ -71,7 +75,7 @@ export const calculateLighthouseMetrics = async (url, shouldSaveReport) => {
71
75
  ];
72
76
  const chrome = await chromeLauncher.launch({ chromeFlags: chromeParameters });
73
77
  const options = { logLevel: 'silent', output: 'html', port: chrome.port };
74
- const runnerResult = await lighthouse(url, options);
78
+ const runnerResult = await lighthouse(url, options, lighthouseParameters);
75
79
  const reportHtml = runnerResult.report;
76
80
  const reportJson = runnerResult.lhr;
77
81
  await chrome.kill();
@@ -79,27 +83,27 @@ export const calculateLighthouseMetrics = async (url, shouldSaveReport) => {
79
83
  return processRawLighthouseResult(reportJson, reportHtml, url, shouldSaveReport);
80
84
  };
81
85
 
82
- export const processParameters = async (args, func) => {
83
- const outputPath = args.output_path || process.cwd();
86
+ export const processParameters = async (parserArgs, func, lighthouseParameters = {}) => {
87
+ const outputPath = parserArgs.output_path || process.cwd();
84
88
 
85
89
  fs.mkdir(outputPath, { recursive: true }, (err) => {
86
90
  if (err) throw err;
87
91
  });
88
92
 
89
- const results = await Promise.all(args.urls.map(
90
- (url) => func(url, args.save_report),
93
+ const results = await Promise.all(parserArgs.urls.map(
94
+ (url) => func(url, parserArgs.save_report, lighthouseParameters),
91
95
  ));
92
96
 
93
97
  const metrics = R.pluck('metrics', results);
94
98
  const reports = R.pluck('report', results);
95
99
 
96
- const metricsResults = args.single_badge
100
+ const metricsResults = parserArgs.single_badge
97
101
  ? await getSquashedScore(metrics)
98
102
  : await getAverageScore(metrics);
99
103
 
100
104
  await generateArtifacts({
101
105
  reports,
102
- svg: { results: metricsResults, style: args.badge_style },
106
+ svg: { results: metricsResults, style: parserArgs.badge_style },
103
107
  outputPath,
104
108
  });
105
109
  };