@digigov/cli-metrics 1.1.0-rc.21 → 2.0.0-834daea4

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.
@@ -1,6 +1,5 @@
1
1
  {
2
- "../../tooling/cli-metrics": "../../tooling/cli-metrics:yNUoOtcjeRwFK803GopkZYVYFv+3au3VFsrnFJ5P2P8=:",
3
- "/execa@5.0.0": "Missing shrinkwrap entry!",
2
+ "../../tooling/cli-metrics": "../../tooling/cli-metrics:UjBVFJKzz/Jr1GScfFSUJ7GOnGw9l8DnfBjVNAoFRQ8=:",
4
3
  "/lighthouse@9.6.6(encoding@0.1.13)": "Missing shrinkwrap entry!",
5
4
  "/playwright-chromium@1.41.0": "Missing shrinkwrap entry!",
6
5
  "/playwright-lighthouse@2.2.2": "Missing shrinkwrap entry!",
package/index.js CHANGED
@@ -1,49 +1,44 @@
1
- const path = require('path');
2
- const { Command, flags } = require('@oclif/command')
3
- const execa = require('execa')
4
- const { makeConfig, DigigovCommand } = require('@digigov/cli/lib')
5
- const { playAudit } = require('playwright-lighthouse');
6
- const playwright = require('playwright-chromium');
7
- const lib = require('@digigov/cli/lib');
8
-
9
- module.exports = class Metrics extends DigigovCommand {
10
- static description = 'create digigov metrics'
11
- static id = 'metrics'
12
- static examples = [
13
- `$ digigov metrics`,
14
- ]
15
-
16
- static strict = false;
17
- static flags = {
18
- // migrate: flags.boolean({ char: '--migrate' }),
19
- };
20
-
21
- static load() { return Metrics }
22
- dirname = __dirname
23
- script = 'lighthouse'
24
- async run() {
25
- const { argv, flags } = this.parse(Metrics);
26
- const project = lib.resolveProject(process.cwd());
27
- let rc = require('./lighthouse.config');
28
- try{
29
- rc = require(`${project.root}/lighthouse.config.js`)
30
- }catch(err){
31
- console.log(err)
32
- console.log(`No lighthouse.config.js file is found. Fallback to sane defaults.`)
33
- }
34
- const browser = await playwright['chromium'].launch({
35
- args: ['--remote-debugging-port=9222'],
36
- });
37
- const page = await browser.newPage();
38
- await page.goto(argv[0]);
39
-
40
- await playAudit({
41
- page: page,
42
- port: 9222,
43
- ...rc
44
- });
45
-
46
- await browser.close();
47
- // return proc;
1
+ import { DigigovCommand } from "@digigov/cli/lib";
2
+ import { playAudit } from "playwright-lighthouse";
3
+ import playwright from "playwright-chromium";
4
+ import { resolveProject } from "@digigov/cli/lib";
5
+ import { createRequire } from "module";
6
+
7
+ const require = createRequire(import.meta.url);
8
+
9
+ const command = new DigigovCommand("metrics", import.meta.url);
10
+
11
+ command.argument("<url>", "URL to audit").action(getMetrics);
12
+
13
+ export default command;
14
+
15
+ /**
16
+ * @param {string} url - URL to audit
17
+ */
18
+ async function getMetrics(url) {
19
+ const project = resolveProject();
20
+
21
+ let rc = require("../lighthouse.config.cjs");
22
+ try {
23
+ rc = require(`${project.root}/lighthouse.config.js`);
24
+ } catch (err) {
25
+ logger.error(err);
26
+ logger.warn(
27
+ `No lighthouse.config.js file is found. Fallback to sane defaults.`,
28
+ );
48
29
  }
30
+
31
+ const browser = await playwright["chromium"].launch({
32
+ args: ["--remote-debugging-port=9222"],
33
+ });
34
+ const page = await browser.newPage();
35
+ await page.goto(url);
36
+
37
+ await playAudit({
38
+ page: page,
39
+ port: 9222,
40
+ ...rc,
41
+ });
42
+
43
+ await browser.close();
49
44
  }
@@ -1,17 +1,13 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const lib = require('@digigov/cli/lib');
1
+ const fs = require("fs");
2
+ const lib = require("@digigov/cli/lib");
4
3
 
5
4
  function makeLighthouseConfig(dir, options) {
6
5
  const project = lib.resolveProject(dir);
7
-
8
-
9
-
10
6
  return {
11
7
  thresholds: {
12
8
  performance: 75,
13
9
  accessibility: 75,
14
- 'best-practices': 75,
10
+ "best-practices": 75,
15
11
  seo: 75,
16
12
  pwa: 50,
17
13
  },
@@ -19,7 +15,7 @@ function makeLighthouseConfig(dir, options) {
19
15
  formats: {
20
16
  html: true, //defaults to false
21
17
  },
22
- name: `lighthouse-${new Date().getTime()}`, //defaults to `lighthouse-${new Date().getTime()}`
18
+ name: `lighthouse-${new Date().getTime()}`, //defaults to `lighthouse-${new Date().getTime()}`
23
19
  directory: `${project.root}/lighthouse`, //defaults to `${process.cwd()}/lighthouse`
24
20
  },
25
21
  };
@@ -0,0 +1 @@
1
+ module.exports = require("./lighthouse.common.cjs").config;
@@ -0,0 +1,8 @@
1
+ const { makeConfig } = require("@digigov/cli/lib");
2
+
3
+ module.exports = (overrides, options) => {
4
+ return makeConfig(
5
+ overrides,
6
+ require("./lighthouse.common.cjs").makeLighthouseConfig(null, options),
7
+ );
8
+ };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@digigov/cli-metrics",
3
- "version": "1.1.0-rc.21",
3
+ "version": "2.0.0-834daea4",
4
4
  "description": "Docs plugin for Digigov CLI",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "author": "GRNET Devs <devs@lists.grnet.gr>",
7
8
  "license": "BSD-2-Clause",
8
9
  "dependencies": {
@@ -15,8 +16,13 @@
15
16
  "publint": "0.1.8"
16
17
  },
17
18
  "peerDependencies": {
18
- "execa": "5.0.0",
19
- "@digigov/cli": "1.1.1-rc.21"
19
+ "@digigov/cli": "2.0.0-834daea4"
20
+ },
21
+ "exports": {
22
+ ".": "./index.js",
23
+ "./lighthouse.common": "./lighthouse.common.cjs",
24
+ "./lighthouse.config": "./lighthouse.config.cjs",
25
+ "./lighthouserc": "./lighthouserc.cjs"
20
26
  },
21
27
  "scripts": {
22
28
  "publint": "publint"
@@ -1 +0,0 @@
1
- module.exports = require('./lighthouse.common').config
package/lighthouserc.js DELETED
@@ -1,5 +0,0 @@
1
- const { makeConfig } = require('@digigov/cli/lib')
2
-
3
- module.exports = (overrides, options) => {
4
- return makeConfig(overrides, require('./lighthouse.common').makeLighthouseConfig(null, options));
5
- }