From baabad1729db1eb85b8c35a1b8eb5251495e45f0 Mon Sep 17 00:00:00 2001 From: kola-web Date: Wed, 13 May 2026 12:30:55 +0800 Subject: [PATCH] init --- AGENTS.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..ddea265 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,51 @@ +# AGENTS.md + +## Project + +WeChat Mini Program (微信小程序) — school campus app. Source root is `src/` (set via `miniprogramRoot` in `project.config.json`). + +## Commands + +- **Lint:** `pnpm run lint:fix` (eslint only; no separate typecheck or test commands exist) +- **npm build:** Must use WeChat DevTools → "Build npm" menu. Output goes to `src/miniprogram_npm/` (gitignored). Do not edit `miniprogram_npm/` manually. +- **JSX compile:** `pnpm run beforeCompile` — Babel-transforms `.jsx` files under `src/pages/` using `@babel/plugin-transform-react-jsx` (automatic runtime). WeChat DevTools runs this automatically via `project.config.json` scripts before compile/preview/upload. No `.jsx` files currently exist, but the pipeline is wired. + +## Architecture + +- **Custom Page wrapper** (`src/utils/page.ts`): The global `Page` constructor is replaced in `app.ts` `onLaunch`. Every page automatically gets navbar setup, image params, scroll-based nav background, and a default `onShareAppMessage`. When adding page lifecycle hooks, be aware these wrappers run before your own handlers. +- **`wx.ajax`**: Custom property added to `wx` in `app.ts` `onLaunch`. It is a curried version of `src/api/request.ts` with the base URL baked in. Use `wx.ajax(...)` for network requests — do not call `request` directly from pages. +- **Login flow**: Managed in `App` via `globalData.loginState` / `globalData.initLoginInfo`. Pages call `getApp().waitLogin()` before making authenticated requests. +- **Custom tabbar**: `app.json` has `"custom": true`; the tabbar UI is implemented in components. + +## Path Aliases + +- `@/*` → `src/*` (configured in both `tsconfig.json` paths and `app.json` resolveAlias) + +## Style & Lint + +- ESLint: `@antfu/eslint-config` + `eslint-config-prettier` (stylistic rules off). Globals `wx`, `App`, `Page`, `Component`, `getApp`, `getCurrentPages`, `requirePlugin`, `requireMiniProgram` are declared. +- Prettier: no semicolons, single quotes, trailing commas, printWidth 120. Uses `html` parser for `.wxml`, `css` for `.wxss`, `babel` for `.wxs`. +- TypeScript: strict mode (but `noImplicitAny: false`), target ES5, CommonJS modules. Typings in `typings/index.d.ts` declare `IAppOption`, `IAgaxParams`, and extend `WechatMiniprogram.Wx` with `ajax`. + +## File Structure + +Each page/component follows the standard miniprogram quad: `.ts`, `.wxml`, `.scss`, `.json`. + +``` +src/ + app.ts / app.json / app.scss # App entry + api/request.ts # HTTP request wrapper + utils/ + page.ts # Custom Page wrapper (global) + util.ts # Helpers + dayjs/ # Manually bundled dayjs plugins (not from npm) + pages/{name}/index.{ts,wxml,scss,json} + components/{name}/index.{ts,wxml,scss,json} +``` + +## Gotchas + +- `src/utils/dayjs/` contains hand-copied dayjs locale/plugin files, not npm imports. Do not replace with npm imports without testing. +- `src/miniprogram_npm/` is build output — never edit directly. +- The `beforeCompile` Babel step only processes `src/pages/**/*.jsx`. If you add JSX outside `pages/`, the script won't catch it. +- No test framework is configured.