Browse Source

chore: optimize npm scripts (#11719)

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
pull/11720/head
Alex Zhu 6 months ago
committed by GitHub
parent
commit
00eeebb9f1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 13
      docs/cheatsheet.en-US.md
  2. 13
      docs/cheatsheet.zh-CN.md
  3. 23
      package.json

13
docs/cheatsheet.en-US.md

@ -55,18 +55,23 @@ npm install # Update dependencies
| Command | Description |
|---------|-------------|
| `npm start` | Start dev server (UMI_ENV=dev, with Mock) |
| `npm run dev` | Start dev server (no Mock) |
| `npm run start:dev` | Same as dev, UMI_ENV=dev, no Mock |
| `npm run dev` | Start dev server (UMI_ENV=dev, no Mock) |
| `npm run start:no-mock` | Start without Mock |
| `npm run start:pre` | Pre-production environment |
| `npm run start:test` | Test environment |
| `npm run build` | Build for production |
| `npm run preview` | Build and preview locally (port 8000) |
| `npm run preview` | Preview built output (run `npm run build` first, port 8000) |
| `npm run preview:build` | Build and preview (port 8000) |
| `npm run deploy` | Build and deploy to GitHub Pages |
| `npm run analyze` | Analyze bundle size |
| `npm run lint` | Lint (Biome + TypeScript) |
| `npm run biome` | Auto-fix with Biome |
| `npm test` | Run tests |
| `npm run test:coverage` | Test with coverage |
| `npm run test:update` | Update test snapshots |
| `npm run tsc` | Type check without emitting |
| `npm run i18n-remove` | Remove i18n wrappers (locale=zh-CN) |
| `npm run record` | Record request data for login scene |
| `npm run openapi` | Generate API code from OpenAPI schema |
| `npm run simple` | Strip demo pages and unused deps |
@ -465,7 +470,7 @@ Edit `colorPrimary` in `config/defaultSettings.ts`. Use SettingDrawer for live p
Create a file in `src/models/` exporting a custom Hook, then use `useModel('filename')` in components.
**Q: How to deploy?**
`npm run build` generates `dist/`. Deploy to any static file server. Set `publicPath` for non-root deployments.
`npm run build` generates `dist/`. Deploy to any static file server. Set `publicPath` for non-root deployments. `npm run deploy` builds and publishes to GitHub Pages automatically (pushes to gh-pages branch).
**Q: How to use OpenAPI code generation?**
1. Configure `openAPI` in `config/config.ts` 2. Run `npm run openapi` 3. Code is auto-generated under `src/services/`

13
docs/cheatsheet.zh-CN.md

@ -55,18 +55,23 @@ npm install # 更新依赖
| 命令 | 说明 |
|------|------|
| `npm start` | 启动开发服务器(UMI_ENV=dev,带 Mock) |
| `npm run dev` | 启动开发服务器(无 Mock) |
| `npm run start:dev` | 同 dev,UMI_ENV=dev,无 Mock |
| `npm run dev` | 启动开发服务器(UMI_ENV=dev,无 Mock) |
| `npm run start:no-mock` | 无 Mock 启动 |
| `npm run start:pre` | 预发布环境启动 |
| `npm run start:test` | 测试环境启动 |
| `npm run build` | 构建生产产物 |
| `npm run preview` | 构建并本地预览(端口 8000) |
| `npm run preview` | 预览已构建产物(需先 `npm run build`,端口 8000) |
| `npm run preview:build` | 构建并本地预览(端口 8000) |
| `npm run deploy` | 构建并部署到 GitHub Pages |
| `npm run analyze` | 构建产物体积分析 |
| `npm run lint` | 代码检查(Biome + TypeScript) |
| `npm run biome` | Biome 自动修复 |
| `npm test` | 运行测试 |
| `npm run test:coverage` | 测试覆盖率 |
| `npm run test:update` | 更新测试快照 |
| `npm run tsc` | 类型检查(不生成文件) |
| `npm run i18n-remove` | 移除国际化(locale=zh-CN) |
| `npm run record` | 录制登录场景请求数据 |
| `npm run openapi` | 根据 OpenAPI 生成 API 代码 |
| `npm run simple` | 精简模式(删除示例页面和多余依赖) |
@ -465,7 +470,7 @@ export default {
在 `src/models/` 下创建文件,导出自定义 Hook,组件中通过 `useModel('文件名')` 使用。
**Q: 如何部署?**
`npm run build` 生成 `dist/` 目录,部署到任意静态服务器。配置 `publicPath` 处理非根目录部署。
`npm run build` 生成 `dist/` 目录,部署到任意静态服务器。配置 `publicPath` 处理非根目录部署。`npm run deploy` 会自动构建并发布到 GitHub Pages(推送到 gh-pages 分支)。
**Q: 如何使用 OpenAPI 代码生成?**
1. 在 `config/config.ts` 配置 `openAPI` 2. 运行 `npm run openapi` 3. 自动生成 `src/services/` 下的代码

23
package.json

@ -7,30 +7,26 @@
"scripts": {
"analyze": "cross-env ANALYZE=1 max build",
"build": "max build",
"deploy": "cross-env CI=true npm run build && npm run gh-pages",
"dev": "npm run start:dev",
"gh-pages": "gh-pages -d dist",
"deploy": "cross-env CI=true max build && gh-pages -d dist",
"dev": "cross-env UMI_ENV=dev MOCK=none max dev",
"i18n-remove": "max i18n-remove --locale=zh-CN --write",
"postinstall": "max setup",
"jest": "jest",
"lint": "npm run biome:lint && npm run tsc",
"lint-staged": "lint-staged",
"biome:lint": "npx @biomejs/biome lint",
"biome:lint": "biome lint",
"biome": "biome check --write",
"openapi": "max openapi",
"prepare": "husky",
"preview": "npm run build && max preview --port 8000",
"prepare": "husky && max setup",
"preview": "max preview --port 8000",
"preview:build": "max build && max preview --port 8000",
"record": "cross-env NODE_ENV=development UMI_ENV=test max record --scene=login",
"serve": "umi-serve",
"simple": "node scripts/simple.js",
"start": "cross-env UMI_ENV=dev max dev",
"start:dev": "cross-env UMI_ENV=dev MOCK=none max dev",
"start:no-mock": "cross-env MOCK=none max dev",
"start:pre": "cross-env UMI_ENV=pre MOCK=none max dev",
"start:test": "cross-env UMI_ENV=test MOCK=none max dev",
"test": "jest",
"test:coverage": "npm run jest -- --coverage",
"test:update": "npm run jest -- -u",
"test:coverage": "jest --coverage",
"test:update": "jest -u",
"tsc": "tsc --noEmit"
},
"browserslist": [
@ -85,8 +81,7 @@
"mockjs": "^1.1.0",
"tailwindcss": "^4.0.0",
"ts-node": "^10.9.2",
"typescript": "^6.0.3",
"umi-serve": "^1.9.11"
"typescript": "^6.0.3"
},
"engines": {
"node": ">=20.0.0"

Loading…
Cancel
Save