Skip to content

Commit a64a2c4

Browse files
authored
Merge pull request #112 from JacobLinCool/upgrade
Upgrade deps and support self-hosting docker image
2 parents 2079265 + 9b4689c commit a64a2c4

34 files changed

+5038
-4637
lines changed

.github/workflows/pr_check.yml

+2-10
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
15-
16-
- name: Cache PNPM Modules
17-
uses: actions/cache@v3
18-
with:
19-
path: ~/.pnpm-store
20-
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
21-
restore-keys: |
22-
${{ runner.os }}-pnpm-
14+
uses: actions/checkout@v4
2315

2416
- name: Setup PNPM
25-
uses: pnpm/action-setup@v2.2.4
17+
uses: pnpm/action-setup@v3
2618
with:
2719
run_install: true
2820

.github/workflows/publish.yml

+3-11
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,17 @@ jobs:
1414
name: Deploy
1515
steps:
1616
- name: Checkout Repository
17-
uses: actions/checkout@v3
18-
19-
- name: Cache PNPM Modules
20-
uses: actions/cache@v3
21-
with:
22-
path: ~/.pnpm-store
23-
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
24-
restore-keys: |
25-
${{ runner.os }}-pnpm-
17+
uses: actions/checkout@v4
2618

2719
- name: Setup PNPM
28-
uses: pnpm/action-setup@v2.2.4
20+
uses: pnpm/action-setup@v3
2921
with:
3022
run_install: true
3123

3224
- name: Build Worker
3325
run: pnpm build
3426

3527
- name: Publish to Cloudflare
36-
uses: cloudflare/wrangler-action@1.3.0
28+
uses: cloudflare/wrangler-action@v3
3729
with:
3830
apiToken: ${{ secrets.CF_API_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ lib/
8080
**/.DS_Store
8181
.wrangler/
8282

83+
worker.capnp
84+
.storage/

.hadolint.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ignored:
2+
- DL3007
3+
- DL3045

.husky/pre-commit

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pnpm i --frozen-lockfile
2+
pnpm build
3+
pnpm lint-staged

.prettierrc.yml

+1-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,4 @@ overrides:
1010
options:
1111
tabWidth: 2
1212
plugins:
13-
- "./node_modules/@trivago/prettier-plugin-sort-imports/lib/src/index.js"
14-
15-
# sort-imports plugin
16-
importOrder:
17-
- "^node:"
18-
- "^[^@.]"
19-
- "^@"
20-
- "^\\."
21-
importOrderSortSpecifiers: true
13+
- prettier-plugin-organize-imports

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM jacoblincool/workerd:latest
2+
3+
COPY ./worker.capnp ./worker.capnp
4+
5+
CMD ["serve", "--experimental", "--binary", "worker.capnp"]

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ LeetCode and LeetCode CN are both supported.
2222

2323
It also has a [NPM package](https://www.npmjs.com/package/leetcode-card) and a [highly extensible system](./src/core/index.ts), so you can easily customize it to your needs.
2424

25-
CLI tool will be created if I have time.
2625
Want to contribute? Feel free to open a pull request!
2726

27+
## Self-hosting
28+
29+
You can also self-host this service using the [`jacoblincool/leetcode-stats-card`](https://hub.docker.com/r/jacoblincool/leetcode-stats-card) Docker image.
30+
31+
To build the image by yourself, use `pnpm build:image` script.
32+
33+
See [docker-compose.yml](./docker-compose.yml) for an example.
34+
2835
## Usage
2936

3037
Simply copy the code below, paste it into your `README.md`, and change the path to your leetcode username (case-insensitive).

docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "3.8"
2+
3+
services:
4+
worker:
5+
build: .
6+
image: jacoblincool/leetcode-stats-card
7+
volumes:
8+
- ./.storage/cache:/worker/cache
9+
ports:
10+
- "8080:8080"

eslint.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import prettier from "eslint-config-prettier";
5+
import tseslint from "typescript-eslint";
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
...tseslint.configs.recommended,
10+
prettier,
11+
{
12+
ignores: ["dist/**.js", "lib/**.js"],
13+
},
14+
);

jestconfig.json

-7
This file was deleted.

package.json

+34-34
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,47 @@
1313
"lib"
1414
],
1515
"scripts": {
16-
"test": "jest --config jestconfig.json --coverage",
17-
"prepare": "npm run build",
16+
"test": "vitest --coverage --coverage.include src",
17+
"prepare": "husky",
1818
"dev": "wrangler dev",
19-
"build:worker": "esbuild src/cloudflare-worker/index.ts --outfile=dist/worker.js --bundle --minify --format=esm --loader:.html=text --external:events --keep-names",
20-
"build:package": "esbuild src/core/index.ts --outfile=lib/index.js --bundle --format=esm --external:events --keep-names",
19+
"build:worker": "esbuild src/cloudflare-worker/index.ts --outfile=dist/worker.js --bundle --minify --format=esm --loader:.html=text --keep-names",
20+
"build:package": "esbuild src/core/index.ts --outfile=lib/index.js --bundle --format=esm --keep-names",
21+
"build:image": "selflare compile --script dist/worker.js && docker compose build",
2122
"build": "npm run build:worker && npm run build:package",
2223
"format": "prettier --write . --ignore-path .gitignore",
2324
"lint": "eslint .",
24-
"push": "wrangler publish"
25+
"push": "wrangler deploy"
2526
},
2627
"keywords": [
2728
"leetcode",
2829
"stats",
2930
"card"
3031
],
31-
"eslintConfig": {
32-
"root": true,
33-
"extends": [
34-
"typescript",
35-
"prettier"
36-
],
37-
"ignorePatterns": [
38-
"dist/**.js",
39-
"lib/**.js"
40-
]
41-
},
4232
"dependencies": {
43-
"itty-router": "3.0.11",
44-
"leetcode-query": "0.2.7",
33+
"itty-router": "4.0.27",
34+
"leetcode-query": "1.0.0",
4535
"nano-font": "0.3.1"
4636
},
4737
"devDependencies": {
48-
"@cloudflare/workers-types": "^4.20230404.0",
49-
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
50-
"@types/jest": "29.5.0",
51-
"@types/node": "^18.15.11",
52-
"@typescript-eslint/eslint-plugin": "^5.57.1",
53-
"@typescript-eslint/parser": "^5.57.1",
54-
"esbuild": "^0.15.18",
55-
"eslint": "^8.38.0",
56-
"eslint-config-prettier": "^8.8.0",
57-
"jest": "29.5.0",
58-
"prettier": "^2.8.7",
59-
"ts-jest": "29.1.0",
60-
"tsup": "6.7.0",
61-
"typescript": "^5.0.4",
62-
"wrangler": "^2.14.0"
38+
"@cloudflare/workers-types": "^4.20240222.0",
39+
"@eslint/js": "^8.57.0",
40+
"@types/node": "^20.11.24",
41+
"@typescript-eslint/eslint-plugin": "^7.1.0",
42+
"@typescript-eslint/parser": "^7.1.0",
43+
"@vitest/coverage-v8": "^1.3.1",
44+
"esbuild": "^0.20.1",
45+
"eslint": "^8.57.0",
46+
"eslint-config-prettier": "^9.1.0",
47+
"husky": "^9.0.11",
48+
"lint-staged": "^15.2.2",
49+
"prettier": "^3.2.5",
50+
"prettier-plugin-organize-imports": "^3.2.4",
51+
"selflare": "^1.0.0",
52+
"tsup": "8.0.2",
53+
"typescript": "^5.3.3",
54+
"typescript-eslint": "^7.1.0",
55+
"vitest": "^1.3.1",
56+
"wrangler": "^3.30.1"
6357
},
6458
"repository": {
6559
"type": "git",
@@ -69,5 +63,11 @@
6963
"url": "https://github.com/JacobLinCool/LeetCode-Stats-Card/issues"
7064
},
7165
"homepage": "https://github.com/JacobLinCool/LeetCode-Stats-Card#readme",
72-
"packageManager": "[email protected]"
66+
"packageManager": "[email protected]",
67+
"lint-staged": {
68+
"*.{js,ts}": [
69+
"eslint --fix",
70+
"prettier --write"
71+
]
72+
}
7373
}

0 commit comments

Comments
 (0)