Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyfallWasTaken committed Jun 27, 2024
1 parent 150df70 commit de4017d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run linter and deploy

on:
push:
branches:
- main

permissions:
contents: read

jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install Dependencies
run: bun install

- name: Run ESLint and Prettier check
run: bun lint
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# arcade-monitor

To install dependencies:

```bash
bun install
```

To run:

```bash
wrangler dev
```

This project was created using `bun init` in bun v1.1.17. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file modified bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-check
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, {
ignores: [".wrangler/"],
});
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
"name": "arcade-monitor",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev --test-scheduled",
"start": "wrangler dev --test-scheduled",
"cf-typegen": "wrangler types",
"format": "prettier --write .",
"lint": "prettier --check ."
"lint": "eslint . && prettier --check ."
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"eslint": "^9.5.0",
"prettier": "^3.3.2",
"typescript": "^5.5.2",
"wrangler": "^3.62.0"
"wrangler": "^3.62.0",
"@eslint/js": "^9.5.0",
"@types/eslint__js": "^8.42.3",
"typescript-eslint": "^7.14.1",
"@types/common-tags": "^1.8.4"
},
"dependencies": {
"@types/common-tags": "^1.8.4",
"deep-object-diff": "^1.1.9",
"node-html-parser": "^6.1.13"
}
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
*
* Learn more at https://developers.cloudflare.com/workers/
*/
import parseArcadeShopHtml, { ShopItem, ShopItemDiff } from "./parser";
import parseArcadeShopHtml, { type ShopItem, type ShopItemDiff } from "./parser";
import { DetailedDiff, detailedDiff } from "deep-object-diff";

export default {
async scheduled(event, env, ctx): Promise<void> {
async scheduled(event, env): Promise<void> {
console.log(`trigger fired at ${event.cron}`);
await runScrape(env, ctx);
await runScrape(env);
},

async fetch(request, env, ctx) {
return new Response(await runScrape(env, ctx));
async fetch(_request, env) {
return new Response(await runScrape(env));
},
} satisfies ExportedHandler<Env>;

async function runScrape(env: Env, ctx: ExecutionContext) {
async function runScrape(env: Env) {
const response = await fetch(env.ARCADE_SHOP_URL);
const html = await response.text();
const latestItems = parseArcadeShopHtml(html);
Expand Down
2 changes: 2 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export type ShopItemDiff = {

export default function parseArcadeShopHtml(html: string): ShopItem[] {
const document = parseHtml(html);
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
const inner = document.getElementById("__NEXT_DATA__")?.text!;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const items = JSON.parse(inner).props.pageProps.availableItems.map((item: any) => {
return {
name: item["Name"],
Expand Down

0 comments on commit de4017d

Please sign in to comment.