Skip to content

Commit 136d137

Browse files
committed
project: Add linter and prettier
1 parent 231eb14 commit 136d137

18 files changed

Lines changed: 1994 additions & 117 deletions

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

.lintstagedrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"*.{ts,tsx}": ["prettier --write", "eslint --fix"],
3+
"*.css": ["prettier --write", "stylelint --fix"],
4+
"*.{json,md}": ["prettier --write"]
5+
}

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
package-lock.json
4+
.husky

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 100,
6+
"tabWidth": 2,
7+
"arrowParens": "avoid",
8+
"endOfLine": "lf"
9+
}

CLAUDE.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Browser-based tool for flashing Magisk-patched `init_boot.img` to OnePlus Open (CPH2551) via WebUSB. Requires Chromium-based browsers (Chrome, Edge) — no Firefox/Safari support. Fetches patched images from the CruelKernel/oneplus_kernel_patcher GitHub repository and matches them to the device's firmware version.
8+
9+
## Commands
10+
11+
```bash
12+
npm install # Install dependencies
13+
npm run dev # Dev server at http://localhost:5173
14+
npm run build # TypeScript check + Vite production build
15+
npm run lint # ESLint
16+
npm run preview # Preview production build
17+
docker compose up # Docker dev at http://localhost:8080
18+
```
19+
20+
## Architecture
21+
22+
**Single-page React app** built with Vite + TypeScript + Tailwind CSS.
23+
24+
### State Machine (`src/App.tsx`)
25+
26+
The app is driven by a `FlashState` union type (23 states) that controls the entire UI and workflow:
27+
28+
`IDLE → ADB_CONNECTING → ADB_CONNECTED → DETECTING_FIRMWARE → FIRMWARE_DETECTED → FETCHING_RELEASES → RELEASE_MATCHED → DOWNLOADING_IMAGE → DOWNLOAD_COMPLETE → CONFIRMING_FLASH → REBOOTING_BOOTLOADER → WAITING_FASTBOOT → FASTBOOT_CONNECTING → FASTBOOT_CONNECTED → FLASHING → FLASH_COMPLETE → REBOOTING_SYSTEM → SUCCESS`
29+
30+
State transitions happen in `App.tsx` which is the main (~600 line) component containing all UI rendering and orchestration logic.
31+
32+
### Services (`src/services/`)
33+
34+
- **adb.ts** — WebUSB ADB connection via `@yume-chan/adb`. Reads device model, firmware version, serial number. Reboots to bootloader.
35+
- **fastboot.ts** — Fastboot protocol via `android-fastboot`. Validates unlocked bootloader, flashes `init_boot` partition with progress callbacks.
36+
- **github.ts** — Fetches releases from CruelKernel/oneplus_kernel_patcher. Caches in memory. Matches device firmware version to release tags (exact match on format `CPH2551_15.0.0.822(EX01)`).
37+
- **download.ts** — Downloads GitHub release assets through a CORS proxy (`api.codetabs.com`). Streams with progress tracking.
38+
39+
### Types (`src/types/`)
40+
41+
- **index.ts** — Core types: `FlashState`, `DeviceInfo`, `AppState`, progress types, GitHub API types.
42+
- **android-fastboot.d.ts** — Type declarations for the untyped `android-fastboot` library.
43+
44+
### Utils (`src/utils/version.ts`)
45+
46+
Parses firmware version strings (regex: `CPH\d+_\d+\.\d+\.\d+\.\d+\([A-Z0-9]+\)`), validates device is CPH2551, formats file sizes.
47+
48+
## Key Patterns
49+
50+
- Services are held as refs (`useRef`) in App.tsx — singleton instances persisted across renders.
51+
- ADB credentials stored in browser localStorage under key `'oneplus-flasher'`.
52+
- GitHub Pages deployment via `.github/workflows/deploy.yml` uses `VITE_BASE_PATH` env var for subdirectory routing.
53+
- No test framework is configured.

eslint.config.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
6-
import { defineConfig, globalIgnores } from 'eslint/config'
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import reactHooks from 'eslint-plugin-react-hooks';
4+
import reactRefresh from 'eslint-plugin-react-refresh';
5+
import tseslint from 'typescript-eslint';
6+
import { defineConfig, globalIgnores } from 'eslint/config';
7+
import eslintConfigPrettier from 'eslint-config-prettier/flat';
78

89
export default defineConfig([
910
globalIgnores(['dist']),
@@ -20,4 +21,5 @@ export default defineConfig([
2021
globals: globals.browser,
2122
},
2223
},
23-
])
24+
eslintConfigPrettier,
25+
]);

0 commit comments

Comments
 (0)