Skip to content

Commit

Permalink
Merge pull request #12 from gotomi/eslint_config
Browse files Browse the repository at this point in the history
eslint config update
  • Loading branch information
gotomi authored Feb 8, 2025
2 parents 42949c0 + 11da5cd commit f267cc8
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 152 deletions.
33 changes: 0 additions & 33 deletions .eslintrc.json

This file was deleted.

23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ npm install -g kruk
## Usage

Basic syntax:

```bash
kruk --key YOUR_API_KEY --urls URL1,URL2 [options]
```
Expand All @@ -34,33 +35,39 @@ kruk --key YOUR_API_KEY --urls URL1,URL2 [options]
### Examples

1. Basic usage with multiple URLs:

```bash
kruk --key YOUR_API_KEY --urls www.google.com,www.bing.com
```

2. Check specific connection type:

```bash
kruk --key YOUR_API_KEY --urls www.google.com,www.bing.com --ect 4G
```

3. Check desktop metrics:

```bash
kruk --key YOUR_API_KEY --urls www.google.com,www.bing.com --formFactor DESKTOP
```

4. Get origin-level data:

```bash
kruk --key YOUR_API_KEY --urls www.google.com --checkOrigin
```

5. Get data for tablet users on 3G:

```bash
kruk --key YOUR_API_KEY --urls www.google.com,www.bing.com --formFactor TABLET --ect 3G
```

## Output Metrics

The tool provides data for the following Core Web Vitals and additional metrics:

- CLS (Cumulative Layout Shift)
- FCP (First Contentful Paint)
- LCP (Largest Contentful Paint)
Expand All @@ -74,8 +81,6 @@ The tool provides data for the following Core Web Vitals and additional metrics:
3. **CSV**: Outputs data in CSV format for further processing
4. **JSON**: Raw JSON output of the data



## Programmatic Usage

Kruk can also be used as a module in your Node.js applications.
Expand All @@ -89,17 +94,17 @@ npm install kruk
### Basic Usage

```javascript
import { getReports } from 'kruk';
import { getReports } from "kruk";

async function fetchCruxData() {
const urls = ['www.google.com', 'www.bing.com'];
const API_KEY = 'YOUR_API_KEY';
const urls = ["www.google.com", "www.bing.com"];
const API_KEY = "YOUR_API_KEY";

const params = {
effectiveConnectionType: '4G', // optional
formFactor: 'PHONE', // optional
origin: false, // optional, set true for origin-level data
history: false // optional, set true for historical data
effectiveConnectionType: "4G", // optional
formFactor: "PHONE", // optional
origin: false, // optional, set true for origin-level data
history: false, // optional, set true for historical data
};

try {
Expand Down
61 changes: 40 additions & 21 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
#!/usr/bin/env node
import { printTable, printDistribution, printCSV, printHeading } from '../src/crux-output.js';
import { getReports } from '../src/crux.js';
import { prepareParams } from '../src/prepareParams.js';
import { Command, Option } from 'commander';
import { readFile } from 'fs/promises';
import {
printTable,
printDistribution,
printCSV,
printHeading,
} from "../src/crux-output.js";
import { getReports } from "../src/crux.js";
import { prepareParams } from "../src/prepareParams.js";
import { Command, Option } from "commander";
import { readFile } from "fs/promises";

const info = JSON.parse(await readFile(new URL('../package.json', import.meta.url)));
const info = JSON.parse(
await readFile(new URL("../package.json", import.meta.url)),
);
const program = new Command();

function commaSeparatedList(value) {
return value.split(',');
return value.split(",");
}

program
.name('kruk')
.name("kruk")
.version(info.version)
.requiredOption('--urls <url>', 'one or more comma seperated urls', commaSeparatedList)
.requiredOption(
"--urls <url>",
"one or more comma seperated urls",
commaSeparatedList,
)
.addOption(
new Option(
'--key <string>',
'get API key from https://developers.google.com/web/tools/chrome-user-experience-report/api/guides/getting-started#APIKey',
"--key <string>",
"get API key from https://developers.google.com/web/tools/chrome-user-experience-report/api/guides/getting-started#APIKey",
).makeOptionMandatory(),
)
.addOption(
new Option('--formFactor <string>', 'form factor')
.choices(['ALL_FORM_FACTORS', 'DESKTOP', 'TABLET', 'PHONE'])
.default('PHONE'),
new Option("--formFactor <string>", "form factor")
.choices(["ALL_FORM_FACTORS", "DESKTOP", "TABLET", "PHONE"])
.default("PHONE"),
)
.addOption(
new Option('--ect <string>', 'effective connection type').choices(['offline', 'slow-2G', '2G', '3G', '4G']),
new Option("--ect <string>", "effective connection type").choices([
"offline",
"slow-2G",
"2G",
"3G",
"4G",
]),
)
.addOption(new Option('--checkOrigin', 'get data for origin'))
.addOption(new Option('--history', 'use CrUX history API'))
.addOption(new Option("--checkOrigin", "get data for origin"))
.addOption(new Option("--history", "use CrUX history API"))
.addOption(
new Option('--output <string>', 'output format').choices(['distribution', 'json', 'csv', 'table']).default('table'),
new Option("--output <string>", "output format")
.choices(["distribution", "json", "csv", "table"])
.default("table"),
).description(`Usage:
kruk --key [YOUR_API_KEY] --urls www.google.com,www.bing.com --ect 4G
kruk --key [YOUR_API_KEY] --urls www.google.com,www.bing.com
Expand All @@ -53,13 +72,13 @@ if (data.error) {
process.exit();
}

if (argv.output === 'json' || argv.history) {
if (argv.output === "json" || argv.history) {
//todo - other view for history data
console.log(JSON.stringify(data));
} else if (argv.output === 'csv') {
} else if (argv.output === "csv") {
printHeading(data.params);
printCSV(data.metrics);
} else if (argv.output === 'distribution') {
} else if (argv.output === "distribution") {
printHeading(data.params);
printDistribution(data.metrics);
} else {
Expand Down
Loading

0 comments on commit f267cc8

Please sign in to comment.