@qlover/create-app 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/react-app/README.en.md +257 -0
- package/dist/templates/react-app/README.md +29 -231
- package/dist/templates/react-app/config/IOCIdentifier.ts +13 -0
- package/dist/templates/react-app/docs/en/bootstrap.md +562 -0
- package/dist/templates/react-app/docs/en/development-guide.md +523 -0
- package/dist/templates/react-app/docs/en/env.md +482 -0
- package/dist/templates/react-app/docs/en/global.md +509 -0
- package/dist/templates/react-app/docs/en/i18n.md +268 -0
- package/dist/templates/react-app/docs/en/index.md +173 -0
- package/dist/templates/react-app/docs/en/ioc.md +424 -0
- package/dist/templates/react-app/docs/en/project-structure.md +434 -0
- package/dist/templates/react-app/docs/en/request.md +425 -0
- package/dist/templates/react-app/docs/en/router.md +404 -0
- package/dist/templates/react-app/docs/en/store.md +321 -0
- package/dist/templates/react-app/docs/en/theme.md +424 -0
- package/dist/templates/react-app/docs/en/typescript-guide.md +473 -0
- package/dist/templates/react-app/docs/zh/bootstrap.md +562 -0
- package/dist/templates/react-app/docs/zh/development-guide.md +523 -0
- package/dist/templates/react-app/docs/zh/env.md +479 -0
- package/dist/templates/react-app/docs/zh/global.md +511 -0
- package/dist/templates/react-app/docs/zh/i18n.md +268 -0
- package/dist/templates/react-app/docs/zh/index.md +173 -0
- package/dist/templates/react-app/docs/zh/ioc.md +422 -0
- package/dist/templates/react-app/docs/zh/project-structure.md +434 -0
- package/dist/templates/react-app/docs/zh/request.md +429 -0
- package/dist/templates/react-app/docs/zh/router.md +408 -0
- package/dist/templates/react-app/docs/zh/store.md +321 -0
- package/dist/templates/react-app/docs/zh/theme.md +424 -0
- package/dist/templates/react-app/docs/zh/typescript-guide.md +473 -0
- package/dist/templates/react-app/package.json +2 -2
- package/dist/templates/react-app/src/base/apis/AiApi.ts +10 -5
- package/dist/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +10 -17
- package/dist/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +2 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiType.ts +7 -5
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +3 -2
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +33 -0
- package/dist/templates/react-app/src/base/cases/RequestLogger.ts +1 -1
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +2 -2
- package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +1 -1
- package/dist/templates/react-app/src/base/services/RouteService.ts +5 -2
- package/dist/templates/react-app/src/base/services/UserService.ts +8 -10
- package/dist/templates/react-app/src/core/IOC.ts +73 -83
- package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +52 -4
- package/dist/templates/react-app/src/core/bootstraps/{index.ts → BootstrapsRegistry.ts} +2 -3
- package/dist/templates/react-app/src/core/registers/IocRegisterImpl.ts +25 -0
- package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +11 -17
- package/dist/templates/react-app/src/core/registers/RegisterControllers.ts +10 -4
- package/dist/templates/react-app/src/core/registers/RegisterGlobals.ts +6 -15
- package/dist/templates/react-app/src/main.tsx +2 -5
- package/dist/templates/react-app/src/styles/css/antd-themes/dark.css +3 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/index.css +1 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/pink.css +6 -1
- package/dist/templates/react-app/src/styles/css/page.css +1 -1
- package/dist/templates/react-app/src/uikit/controllers/JSONStorageController.ts +1 -1
- package/dist/templates/react-app/tsconfig.app.json +2 -1
- package/dist/templates/react-app/tsconfig.node.json +2 -1
- package/package.json +2 -2
- package/dist/templates/react-app/src/base/port/ApiTransactionInterface.ts +0 -7
- package/dist/templates/react-app/src/base/port/RequestCatcherInterface.ts +0 -12
- package/dist/templates/react-app/src/core/bootstrap.ts +0 -58
- package/dist/templates/react-app/src/core/registers/RegisterApi.ts +0 -5
- package/dist/templates/react-app/src/core/registers/index.ts +0 -32
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
# Development Guidelines
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
1. [Project Structure Standards](#project-structure-standards)
|
|
6
|
+
2. [Code Style Standards](#code-style-standards)
|
|
7
|
+
3. [Component Development Standards](#component-development-standards)
|
|
8
|
+
4. [State Management Standards](#state-management-standards)
|
|
9
|
+
5. [Router Development Standards](#router-development-standards)
|
|
10
|
+
6. [Internationalization Development Standards](#internationalization-development-standards)
|
|
11
|
+
7. [Theme Style Standards](#theme-style-standards)
|
|
12
|
+
8. [Testing Standards](#testing-standards)
|
|
13
|
+
9. [Documentation Standards](#documentation-standards)
|
|
14
|
+
|
|
15
|
+
## Project Structure Standards
|
|
16
|
+
|
|
17
|
+
> 💡 Only basic standards are listed here. For complete project structure documentation, please refer to [Project Structure Documentation](./project-structure.md)
|
|
18
|
+
|
|
19
|
+
### 1. Directory Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/
|
|
23
|
+
├── base/ # Base functionality implementation
|
|
24
|
+
│ ├── cases/ # Business scenario implementations
|
|
25
|
+
│ ├── services/ # Core service implementations
|
|
26
|
+
│ └── types/ # Type definitions
|
|
27
|
+
├── core/ # Core functionality
|
|
28
|
+
│ ├── bootstraps/ # Startup related
|
|
29
|
+
│ ├── registers/ # Registries
|
|
30
|
+
│ └── IOC.ts # IOC container
|
|
31
|
+
├── pages/ # Page components
|
|
32
|
+
│ ├── auth/ # Authentication related pages
|
|
33
|
+
│ └── base/ # Base pages
|
|
34
|
+
├── styles/ # Style files
|
|
35
|
+
│ └── css/
|
|
36
|
+
│ ├── themes/ # Theme related
|
|
37
|
+
│ └── antd-themes/ # Ant Design themes
|
|
38
|
+
├── uikit/ # UI component library
|
|
39
|
+
│ ├── components/ # Common components
|
|
40
|
+
│ ├── contexts/ # React Contexts
|
|
41
|
+
│ ├── hooks/ # Custom Hooks
|
|
42
|
+
│ └── providers/ # Provider components
|
|
43
|
+
└── App.tsx # Application entry
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Naming Conventions
|
|
47
|
+
|
|
48
|
+
- **File Naming**:
|
|
49
|
+
- Component files: `PascalCase.tsx` (e.g., `UserProfile.tsx`)
|
|
50
|
+
- Utility files: `camelCase.ts` (e.g., `formatDate.ts`)
|
|
51
|
+
- Type files: `PascalCase.types.ts` (e.g., `User.types.ts`)
|
|
52
|
+
- Style files: `camelCase.css` (e.g., `buttonStyles.css`)
|
|
53
|
+
|
|
54
|
+
- **Directory Naming**:
|
|
55
|
+
- All lowercase, using hyphens (e.g., `user-profile/`)
|
|
56
|
+
- Feature modules use singular form (e.g., `auth/`, not `auths/`)
|
|
57
|
+
|
|
58
|
+
## Code Style Standards
|
|
59
|
+
|
|
60
|
+
> 💡 Only basic standards are listed here. For more TypeScript and React development standards, please refer to [TypeScript Development Standards](./typescript-guide.md)
|
|
61
|
+
|
|
62
|
+
### 1. TypeScript Standards
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Use interface for object types
|
|
66
|
+
interface UserProfile {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
age?: number; // Optional properties use ?
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Use type for union types or utility types
|
|
73
|
+
type Theme = 'light' | 'dark' | 'pink';
|
|
74
|
+
type Nullable<T> = T | null;
|
|
75
|
+
|
|
76
|
+
// Use enum for constant enumerations
|
|
77
|
+
enum UserRole {
|
|
78
|
+
ADMIN = 'ADMIN',
|
|
79
|
+
USER = 'USER',
|
|
80
|
+
GUEST = 'GUEST'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Function type declarations
|
|
84
|
+
function processUser(user: UserProfile): void {
|
|
85
|
+
// Implementation
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Use meaningful names for generics
|
|
89
|
+
interface Repository<TEntity> {
|
|
90
|
+
find(id: string): Promise<TEntity>;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 2. React Standards
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
// Function components use FC type
|
|
98
|
+
interface Props {
|
|
99
|
+
name: string;
|
|
100
|
+
age: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const UserCard: FC<Props> = ({ name, age }) => {
|
|
104
|
+
return (
|
|
105
|
+
<div>
|
|
106
|
+
<h3>{name}</h3>
|
|
107
|
+
<p>{age}</p>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Hooks standards
|
|
113
|
+
const useUser = (userId: string) => {
|
|
114
|
+
const [user, setUser] = useState<UserProfile | null>(null);
|
|
115
|
+
const [loading, setLoading] = useState(false);
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
// Implementation
|
|
119
|
+
}, [userId]);
|
|
120
|
+
|
|
121
|
+
return { user, loading };
|
|
122
|
+
};
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Component Development Standards
|
|
126
|
+
|
|
127
|
+
> 💡 Only basic standards are listed here. For complete component development guide, please refer to [Component Development Guide](./component-guide.md)
|
|
128
|
+
|
|
129
|
+
### 1. Component Categories
|
|
130
|
+
|
|
131
|
+
- **Page Components**: Located in `pages/` directory
|
|
132
|
+
- **Business Components**: Located in corresponding business module directories
|
|
133
|
+
- **Common Components**: Located in `uikit/components/` directory
|
|
134
|
+
- **Layout Components**: Located in `uikit/layouts/` directory
|
|
135
|
+
|
|
136
|
+
### 2. Component Implementation
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
// 1. Import order
|
|
140
|
+
import { FC, useEffect, useState } from 'react'; // React related
|
|
141
|
+
import { useTranslation } from 'react-i18next'; // Third-party libraries
|
|
142
|
+
import { UserService } from '@/services/user'; // Internal project imports
|
|
143
|
+
import { Button } from './Button'; // Relative path imports
|
|
144
|
+
|
|
145
|
+
// 2. Type definitions
|
|
146
|
+
interface Props {
|
|
147
|
+
userId: string;
|
|
148
|
+
onUpdate?: (user: User) => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 3. Component implementation
|
|
152
|
+
export const UserProfile: FC<Props> = ({ userId, onUpdate }) => {
|
|
153
|
+
// 3.1 Hooks declarations
|
|
154
|
+
const { t } = useTranslation();
|
|
155
|
+
const [user, setUser] = useState<User | null>(null);
|
|
156
|
+
|
|
157
|
+
// 3.2 Side effects
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
// Implementation
|
|
160
|
+
}, [userId]);
|
|
161
|
+
|
|
162
|
+
// 3.3 Event handlers
|
|
163
|
+
const handleUpdate = () => {
|
|
164
|
+
// Implementation
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// 3.4 Render methods
|
|
168
|
+
const renderHeader = () => {
|
|
169
|
+
return <h2>{user?.name}</h2>;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// 3.5 Return JSX
|
|
173
|
+
return (
|
|
174
|
+
<div>
|
|
175
|
+
{renderHeader()}
|
|
176
|
+
<Button onClick={handleUpdate}>{t('common.update')}</Button>
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## State Management Standards
|
|
183
|
+
|
|
184
|
+
> 💡 Only basic standards are listed here. For complete state management guide, please refer to [Store Development Guide](./store.md)
|
|
185
|
+
|
|
186
|
+
### 1. Store Implementation
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
// 1. State interface definition
|
|
190
|
+
interface UserState extends StoreStateInterface {
|
|
191
|
+
currentUser: User | null;
|
|
192
|
+
loading: boolean;
|
|
193
|
+
error: string | null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 2. Store implementation
|
|
197
|
+
@injectable()
|
|
198
|
+
export class UserStore extends StoreInterface<UserState> {
|
|
199
|
+
constructor() {
|
|
200
|
+
super(() => ({
|
|
201
|
+
currentUser: null,
|
|
202
|
+
loading: false,
|
|
203
|
+
error: null
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 3. Selector definitions
|
|
208
|
+
selector = {
|
|
209
|
+
currentUser: (state: UserState) => state.currentUser,
|
|
210
|
+
loading: (state: UserState) => state.loading
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// 4. Operation methods
|
|
214
|
+
async fetchUser(id: string) {
|
|
215
|
+
try {
|
|
216
|
+
this.emit({ ...this.state, loading: true });
|
|
217
|
+
const user = await api.getUser(id);
|
|
218
|
+
this.emit({ ...this.state, currentUser: user, loading: false });
|
|
219
|
+
} catch (error) {
|
|
220
|
+
this.emit({
|
|
221
|
+
...this.state,
|
|
222
|
+
error: error.message,
|
|
223
|
+
loading: false
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 2. Store Usage
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
function UserProfile() {
|
|
234
|
+
const userStore = IOC(UserStore);
|
|
235
|
+
const user = useStore(userStore, userStore.selector.currentUser);
|
|
236
|
+
const loading = useStore(userStore, userStore.selector.loading);
|
|
237
|
+
|
|
238
|
+
return <div>{loading ? <Loading /> : <UserInfo user={user} />}</div>;
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Router Development Standards
|
|
243
|
+
|
|
244
|
+
> 💡 Only basic standards are listed here. For complete router development guide, please refer to [Router Development Guide](./router.md)
|
|
245
|
+
|
|
246
|
+
### 1. Basic Standards
|
|
247
|
+
|
|
248
|
+
- Route configurations are centrally managed in `config/app.router.ts`
|
|
249
|
+
- Use declarative route configuration
|
|
250
|
+
- Route components are placed in the `pages` directory
|
|
251
|
+
- Support route-level code splitting
|
|
252
|
+
- Route configurations include metadata support
|
|
253
|
+
|
|
254
|
+
### 2. Example
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// Route configuration example
|
|
258
|
+
export const baseRoutes: RouteConfigValue[] = [
|
|
259
|
+
{
|
|
260
|
+
path: '/:lng',
|
|
261
|
+
element: 'base/Layout',
|
|
262
|
+
meta: {
|
|
263
|
+
category: 'main'
|
|
264
|
+
},
|
|
265
|
+
children: [
|
|
266
|
+
{
|
|
267
|
+
path: 'users',
|
|
268
|
+
element: 'users/UserList',
|
|
269
|
+
meta: {
|
|
270
|
+
title: i18nKeys.PAGE_USERS_TITLE,
|
|
271
|
+
auth: true
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
];
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
For more route configuration and usage examples, please refer to [Router Development Guide](./router.md).
|
|
280
|
+
|
|
281
|
+
## Internationalization Development Standards
|
|
282
|
+
|
|
283
|
+
> 💡 Only basic standards are listed here. For complete internationalization development guide, please refer to [Internationalization Development Guide](./i18n.md)
|
|
284
|
+
|
|
285
|
+
### 1. Basic Standards
|
|
286
|
+
|
|
287
|
+
- Use identifier constants to manage translation keys
|
|
288
|
+
- Generate translation resources through TypeScript comments
|
|
289
|
+
- Support multi-language routes
|
|
290
|
+
- Centrally manage translation files
|
|
291
|
+
|
|
292
|
+
### 2. Example
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
/**
|
|
296
|
+
* @description User list page title
|
|
297
|
+
* @localZh 用户列表
|
|
298
|
+
* @localEn User List
|
|
299
|
+
*/
|
|
300
|
+
export const PAGE_USERS_TITLE = 'page.users.title';
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
For more internationalization configuration and usage examples, please refer to [Internationalization Development Guide](./i18n.md).
|
|
304
|
+
|
|
305
|
+
## Theme Style Standards
|
|
306
|
+
|
|
307
|
+
> 💡 Only basic standards are listed here. For complete theme development guide, please refer to [Theme Development Guide](./theme.md)
|
|
308
|
+
|
|
309
|
+
### 1. Basic Standards
|
|
310
|
+
|
|
311
|
+
- Use CSS variables to manage themes
|
|
312
|
+
- Follow Tailwind CSS usage standards
|
|
313
|
+
- Modularize component styles
|
|
314
|
+
- Support multiple theme switching
|
|
315
|
+
|
|
316
|
+
### 2. Example
|
|
317
|
+
|
|
318
|
+
```css
|
|
319
|
+
:root {
|
|
320
|
+
--color-brand: 37 99 235;
|
|
321
|
+
--text-primary: 15 23 42;
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
For more theme configuration and usage examples, please refer to [Theme Development Guide](./theme.md).
|
|
326
|
+
|
|
327
|
+
## Testing Standards
|
|
328
|
+
|
|
329
|
+
> 💡 Only basic standards are listed here. For complete testing guide, please refer to [Testing Development Guide](./testing.md)
|
|
330
|
+
|
|
331
|
+
### 1. Basic Standards
|
|
332
|
+
|
|
333
|
+
- Unit tests cover core logic
|
|
334
|
+
- Component tests focus on interaction and rendering
|
|
335
|
+
- Use Jest and Testing Library
|
|
336
|
+
- Keep tests simple and maintainable
|
|
337
|
+
|
|
338
|
+
### 2. Example
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
describe('UserProfile', () => {
|
|
342
|
+
it('should render user info', () => {
|
|
343
|
+
const user = { id: '1', name: 'Test' };
|
|
344
|
+
render(<UserProfile user={user} />);
|
|
345
|
+
expect(screen.getByText(user.name)).toBeInTheDocument();
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
For more testing examples and best practices, please refer to [Testing Development Guide](./testing.md).
|
|
351
|
+
|
|
352
|
+
## Documentation Standards
|
|
353
|
+
|
|
354
|
+
> 💡 Only basic standards are listed here. For complete documentation writing guide, please refer to [Documentation Writing Guide](./documentation.md)
|
|
355
|
+
|
|
356
|
+
### 1. Code Comments
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
/**
|
|
360
|
+
* User service
|
|
361
|
+
*
|
|
362
|
+
* @description Handles user-related business logic
|
|
363
|
+
* @example
|
|
364
|
+
* const userService = IOC(UserService);
|
|
365
|
+
* await userService.login(credentials);
|
|
366
|
+
*/
|
|
367
|
+
@injectable()
|
|
368
|
+
export class UserService {
|
|
369
|
+
/**
|
|
370
|
+
* User login
|
|
371
|
+
*
|
|
372
|
+
* @param credentials - Login credentials
|
|
373
|
+
* @returns Logged-in user information
|
|
374
|
+
* @throws {AuthError} Thrown when authentication fails
|
|
375
|
+
*/
|
|
376
|
+
async login(credentials: Credentials): Promise<User> {
|
|
377
|
+
// Implementation
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### 2. Documentation Structure
|
|
383
|
+
|
|
384
|
+
- **README.md**: Project overview, installation instructions, quick start
|
|
385
|
+
- **docs/**:
|
|
386
|
+
- `zh/`: Chinese documentation
|
|
387
|
+
- `en/`: English documentation
|
|
388
|
+
- Organize documentation files by feature modules
|
|
389
|
+
|
|
390
|
+
### 3. Documentation Format
|
|
391
|
+
|
|
392
|
+
```markdown
|
|
393
|
+
# Module Name
|
|
394
|
+
|
|
395
|
+
## Overview
|
|
396
|
+
|
|
397
|
+
Brief explanation of module functionality and purpose.
|
|
398
|
+
|
|
399
|
+
## Usage
|
|
400
|
+
|
|
401
|
+
Code examples and usage instructions.
|
|
402
|
+
|
|
403
|
+
## API Documentation
|
|
404
|
+
|
|
405
|
+
Detailed API descriptions.
|
|
406
|
+
|
|
407
|
+
## Best Practices
|
|
408
|
+
|
|
409
|
+
Usage suggestions and considerations.
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Git Commit Standards
|
|
413
|
+
|
|
414
|
+
> 💡 Only basic standards are listed here. For complete Git workflow, please refer to [Git Workflow Guide](./git-workflow.md)
|
|
415
|
+
|
|
416
|
+
### 1. Commit Message Format
|
|
417
|
+
|
|
418
|
+
```
|
|
419
|
+
<type>(<scope>): <subject>
|
|
420
|
+
|
|
421
|
+
<body>
|
|
422
|
+
|
|
423
|
+
<footer>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
- **type**:
|
|
427
|
+
- `feat`: New feature
|
|
428
|
+
- `fix`: Bug fix
|
|
429
|
+
- `docs`: Documentation updates
|
|
430
|
+
- `style`: Code formatting (changes that don't affect code execution)
|
|
431
|
+
- `refactor`: Code refactoring
|
|
432
|
+
- `test`: Adding tests
|
|
433
|
+
- `chore`: Build process or auxiliary tool changes
|
|
434
|
+
|
|
435
|
+
- **scope**: Impact scope (optional)
|
|
436
|
+
- **subject**: Brief description
|
|
437
|
+
- **body**: Detailed description (optional)
|
|
438
|
+
- **footer**: Breaking changes, issue closure (optional)
|
|
439
|
+
|
|
440
|
+
### 2. Example
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
feat(auth): add user role management functionality
|
|
444
|
+
|
|
445
|
+
- Add role creation and editing interface
|
|
446
|
+
- Implement role permission configuration
|
|
447
|
+
- Add role assignment functionality
|
|
448
|
+
|
|
449
|
+
Closes #123
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## Performance Optimization Standards
|
|
453
|
+
|
|
454
|
+
> 💡 Only basic standards are listed here. For complete performance optimization guide, please refer to [Performance Optimization Guide](./performance.md)
|
|
455
|
+
|
|
456
|
+
### 1. Code Splitting
|
|
457
|
+
|
|
458
|
+
```typescript
|
|
459
|
+
// Route-level code splitting
|
|
460
|
+
const UserModule = lazy(() => import('./pages/users'));
|
|
461
|
+
|
|
462
|
+
// Component-level code splitting
|
|
463
|
+
const HeavyComponent = lazy(() => import('./components/Heavy'));
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### 2. Performance Considerations
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
// Use useMemo to cache computation results
|
|
470
|
+
const sortedUsers = useMemo(() => {
|
|
471
|
+
return users.sort((a, b) => a.name.localeCompare(b.name));
|
|
472
|
+
}, [users]);
|
|
473
|
+
|
|
474
|
+
// Use useCallback to cache functions
|
|
475
|
+
const handleUpdate = useCallback(() => {
|
|
476
|
+
// Implementation
|
|
477
|
+
}, [dependencies]);
|
|
478
|
+
|
|
479
|
+
// Use React.memo to avoid unnecessary re-renders
|
|
480
|
+
const UserCard = React.memo(({ user }) => {
|
|
481
|
+
return <div>{user.name}</div>;
|
|
482
|
+
});
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
## Security Standards
|
|
486
|
+
|
|
487
|
+
> 💡 Only basic standards are listed here. For complete security development guide, please refer to [Security Development Guide](./security.md)
|
|
488
|
+
|
|
489
|
+
### 1. Data Handling
|
|
490
|
+
|
|
491
|
+
```typescript
|
|
492
|
+
// Sensitive data encryption
|
|
493
|
+
const encryptedData = encrypt(sensitiveData);
|
|
494
|
+
|
|
495
|
+
// XSS protection
|
|
496
|
+
const sanitizedHtml = sanitizeHtml(userInput);
|
|
497
|
+
|
|
498
|
+
// CSRF protection
|
|
499
|
+
api.defaults.headers['X-CSRF-Token'] = getCsrfToken();
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### 2. Permission Control
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
// Route permissions
|
|
506
|
+
const PrivateRoute: FC = ({ children }) => {
|
|
507
|
+
const auth = useAuth();
|
|
508
|
+
return auth.isAuthenticated ? children : <Navigate to="/login" />;
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// Operation permissions
|
|
512
|
+
function AdminPanel() {
|
|
513
|
+
const { hasPermission } = useAuth();
|
|
514
|
+
|
|
515
|
+
return (
|
|
516
|
+
<div>
|
|
517
|
+
{hasPermission('ADMIN') && (
|
|
518
|
+
<button>Admin Operation</button>
|
|
519
|
+
)}
|
|
520
|
+
</div>
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
```
|