@cyberskill/shared 1.169.0 → 1.170.0

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.
@@ -1,185 +0,0 @@
1
- # Hướng Dẫn Sử Dụng Dự Án
2
-
3
- ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
4
- ![License](https://img.shields.io/badge/license-MIT-blue)
5
-
6
- <!-- Mục lục -->
7
-
8
- - [Yêu Cầu](#yêu-cầu)
9
- - [Cài Đặt](#cài-đặt)
10
- - [Chạy Dự Án](#chạy-dự-án)
11
- - [Chạy ở môi trường development với Docker](#chạy-ở-môi-trường-development-với-docker)
12
- - [Chạy ở môi trường development (Local)](#chạy-ở-môi-trường-development-local)
13
- - [Các Script & Ý Nghĩa](#các-script--ý-nghĩa)
14
- - [Quy Ước Viết Code & Đặt Tên](#quy-ước-viết-code--đặt-tên)
15
- - [Quy Ước Đặt Tên](#quy-ước-đặt-tên)
16
- - [Quy Ước Đặt Tên Chung](#quy-ước-đặt-tên-chung)
17
- - [Quy Ước Tiền Tố Trong TypeScript](#quy-ước-tiền-tố-trong-typescript)
18
- - [Quy Ước Đặt Tên Type Trong GraphQL](#quy-ước-đặt-tên-type-trong-graphql)
19
- - [Quy Ước Đặt Tên Biến Môi Trường](#quy-ước-đặt-tên-biến-môi-trường)
20
- - [Quy Ước Khi Import](#quy-ước-khi-import)
21
- - [Quy Ước Viết Code](#quy-ước-viết-code)
22
- - [Quy Ước Đặt Commit Message](#quy-ước-đặt-commit-message)
23
- - [Quy Trình Làm Việc Với Git](#quy-trình-làm-việc-với-git)
24
-
25
- ---
26
-
27
- ## Yêu Cầu
28
-
29
- - **nvm (Node Version Manager):**
30
- - MacOS: [nvm-sh/nvm](https://github.com/nvm-sh/nvm)
31
- - Windows: [coreybutler/nvm-windows](https://github.com/coreybutler/nvm-windows)
32
- - **Node.js:** 22.15.0
33
- _(nvm sẽ tự động cài đặt phiên bản này nếu chưa có)_
34
- - MacOS: [node-v22.15.0.pkg](https://nodejs.org/dist/v22.15.0/node-v22.15.0.pkg)
35
- - Windows: [node-v22.15.0-x64.msi](https://nodejs.org/dist/v22.15.0/node-v22.15.0-x64.msi)
36
- - **Docker:** [Docker Desktop](https://www.docker.com/products/docker-desktop)
37
- - **Ghi chú:** Dùng **pnpm** để tránh xung đột với các công cụ khác.
38
-
39
- ---
40
-
41
- ## Cài Đặt
42
-
43
- 1. **Tạo file cấu hình môi trường:**
44
- Sao chép file `.env.example` thành `.env`.
45
- 2. **Chỉnh sửa file `.env`:**
46
- Cập nhật các trường cần thiết phù hợp với môi trường máy.
47
-
48
- ---
49
-
50
- ## Chạy Dự Án
51
-
52
- ### Chạy ở môi trường development với Docker
53
-
54
- _(Lưu ý: Hãy bật Docker trước khi chạy)_
55
-
56
- ```bash
57
- make build-development
58
- make start-development
59
- ```
60
-
61
- ### Chạy ở môi trường development (Local)
62
-
63
- ```bash
64
- pnpm i
65
- pnpm run dev
66
- ```
67
-
68
- ---
69
-
70
- ## Các Script & Ý Nghĩa
71
-
72
- | Script | Ý nghĩa |
73
- | ---------------- | --------------------------------------- |
74
- | **lint** | Kiểm tra lỗi lint và typescript |
75
- | **lint:fix** | Tự động sửa các lỗi có thể sửa |
76
- | **lint:inspect** | Xem chi tiết các lint rule đang dùng |
77
- | **reset** | Cài đặt lại dependencies |
78
- | **prepare** | Tự động nâng cấp @cyberskill/shared |
79
- | **inspect** | Xem chi tiết các dependencies đang dùng |
80
-
81
- ---
82
-
83
- ## Quy Ước Viết Code & Đặt Tên
84
-
85
- ### Quy Ước Đặt Tên
86
-
87
- | Loại | Quy Ước | Ví Dụ |
88
- | ------------- | ------------ | ------------------- |
89
- | **Biến** | `camelCase` | `userName` |
90
- | **Hàm** | `camelCase` | `getUserInfo()` |
91
- | **Parameter** | `camelCase` | `id, userData` |
92
- | **Argument** | `camelCase` | `fetchData(userId)` |
93
- | **Private** | `_camelCase` | `_isHidden` |
94
- | **Class** | `PascalCase` | `UserProfile` |
95
- | **Hằng số** | `UPPER_CASE` | `MAX_RETRY_COUNT` |
96
- | **File** | `kebab-case` | `user-service.ts` |
97
- | **Thư mục** | `kebab-case` | `services/` |
98
-
99
- ### Quy Ước Đặt Tên Chung
100
-
101
- | Loại | Tiền Tố | Quy Tắc | Ví Dụ |
102
- | ------------------------ | ------------- | ----------------------------- | --------------------------- |
103
- | **Biến đại diện input** | `I_Input_` | Tiền tố + loại + kiểu dữ liệu | `interface I_Input_User` |
104
- | **Biến đại diện output** | `I_Response_` | Tiền tố + loại + kiểu dữ liệu | `interface I_Response_User` |
105
-
106
- ### Quy Ước Tiền Tố Trong TypeScript
107
-
108
- | Loại | Tiền Tố | Ví Dụ |
109
- | ------------- | ------- | ------------------ |
110
- | **Interface** | `I_` | `interface I_User` |
111
- | **Type** | `T_` | `type T_User` |
112
- | **Enum** | `E_` | `enum E_User` |
113
- | **Constant** | `C_` | `enum C_User` |
114
-
115
- ### Quy Ước Đặt Tên Type Trong GraphQL
116
-
117
- | Loại | Tiền Tố | Ví Dụ |
118
- | ------------- | -------- | ------------------------ |
119
- | **Type** | `T_` | `type T_User` |
120
- | **Input** | `Input_` | `input Input_CreateUser` |
121
- | **Interface** | `I_` | `input I_User` |
122
- | **Union** | `U_` | `input U_SearchResult` |
123
-
124
- ### Quy Ước Đặt Tên Biến Môi Trường
125
-
126
- | Loại | Tiền Tố | Ví Dụ |
127
- | ----------- | -------------- | --------------------- |
128
- | **Vite** | `VITE_` | `VITE_API_SECRET` |
129
- | **Next.js** | `NEXT_PUBLIC_` | `NEXT_PUBLIC_API_KEY` |
130
- | **Node.js** | `NODE_` | `NODE_ENV` |
131
-
132
- ### Quy Ước Khi Import
133
-
134
- 1. Các thư viện bên ngoài **ở trên cùng**.
135
- 2. Các module/hàm tiện ích **ở dưới**, cách một dòng trắng với phần trên.
136
- 3. Định cấu hình đường dẫn để **import nhanh** trong `tsconfig.json`.
137
-
138
- ```ts
139
- import React from 'react'; // Thư viện bên ngoài
140
-
141
- import { formatDate } from '#shared/util'; // Module nội bộ
142
- ```
143
-
144
- ### Quy Ước Viết Code
145
-
146
- ✅ **Làm**
147
-
148
- - Dùng `let` và `const` thay vì `var`.
149
- - Dùng `===` thay vì `==`.
150
- - Xóa `console.log`, `alert` và `debugger` trước khi commit.
151
-
152
- ❌ **Không làm**
153
-
154
- - Không dùng `any`, `unknown`, `never`.
155
- - Không dùng `@ts-ignore`, `@ts-nocheck`.
156
-
157
- ### Quy Ước Đặt Commit Message
158
-
159
- | Loại Commit | Cú Pháp | Ví Dụ |
160
- | ----------------- | ------------------------ | ------------------------------------------ |
161
- | **Tính năng mới** | `feat(module): message` | `feat(user): add user login form` |
162
- | **Sửa lỗi** | `fix(module): message` | `fix(auth): incorrect password validation` |
163
- | **Dọn dẹp** | `chore(module): message` | `chore(product): refactor product filter` |
164
-
165
- ## Quy Trình Làm Việc Với Git
166
-
167
- 1. **Tạo nhánh mới từ `develop`**:
168
-
169
- ```bash
170
- git checkout develop
171
- git pull origin develop
172
- git checkout -b feature/new-feature
173
- ```
174
-
175
- 2. **Commit theo chuẩn**:
176
-
177
- ```bash
178
- git commit -m "feat(module): mô tả ngắn gọn"
179
- ```
180
-
181
- 3. **Tạo Pull Request (PR)** và đợi review trước khi merge vào `develop`.
182
-
183
- ---
184
-
185
- > **Ghi chú:** Nếu có bất kỳ thắc mắc nào, vui lòng liên hệ team phát triển!
@@ -1,29 +0,0 @@
1
- ## ✅ Bước 1: Cài đặt mongo 8.0 (Ubuntu 24.04)
2
-
3
- ```
4
- sudo apt-get install gnupg curl
5
- ```
6
-
7
- ```
8
- curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
9
- sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
10
- --dearmor
11
- ```
12
-
13
- ```
14
- echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
15
- ```
16
-
17
- ```
18
- sudo apt-get update
19
- ```
20
-
21
- ```
22
- sudo apt-get install -y mongodb-org
23
- ```
24
-
25
- ## ✅ Bước 2: Chạy mongo
26
-
27
- ```
28
- sudo systemctl start mongod
29
- ```
@@ -1,50 +0,0 @@
1
- ## ✅ Bước 1: Cài đặt nginx
2
-
3
- ```
4
- sudo apt update
5
- sudo apt install nginx
6
- ```
7
-
8
- ## ✅ Bước 2: Cấu hình nginx
9
-
10
- ```
11
- cd /etc/nginx/sites-enabled
12
- ```
13
-
14
- ```
15
- sudo nano default
16
- ```
17
-
18
- Thiết lập cấu hình
19
-
20
- ```
21
- server {
22
- listen port-sẽ-chạy;
23
- server_name địa-chỉ-ip;
24
-
25
- location / {
26
- proxy_pass http://localhost:port-sẽ-chạy;
27
- proxy_http_version 1.1;
28
- proxy_set_header Upgrade $http_upgrade;
29
- proxy_set_header Connection 'upgrade';
30
- proxy_set_header Host $host;
31
- proxy_cache_bypass $http_upgrade;
32
- }
33
- }
34
- ```
35
-
36
- ## ✅ Bước 3: Kiểm tra cấu hình
37
-
38
- ```
39
- sudo nginx -t
40
- ```
41
-
42
- Nếu hiện như sau là cấu hình ok
43
- `nginx: the configuration file /etc/nginx/nginx.conf syntax is ok`
44
- `nginx: configuration file /etc/nginx/nginx.conf test is successful`
45
-
46
- ## ✅ Bước 4: Khởi động lại nginx với cấu hình mới
47
-
48
- ```
49
- sudo nginx -s reload
50
- ```
@@ -1,29 +0,0 @@
1
- ## ✅ Bước 1: Cài đặt homebrew (nếu chưa cài)
2
-
3
- ```
4
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
5
- ```
6
-
7
- ## ✅ Bước 2: Cài đặt nvm
8
-
9
- ```
10
- brew install nvm
11
- ```
12
-
13
- Thêm đoạn script dưới đây vào `~/.profile` hoặc `~/.zshrc`
14
-
15
- ```
16
- export NVM_DIR="$HOME/.nvm"
17
- [ -s "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" # This loads nvm
18
- [ -s "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
19
- ```
20
-
21
- Tắt mở lại terminal hoặc chạy lệnh `source ~/.profile` hoặc `source ~/.zshrc`
22
-
23
- ## ✅ Bước 3: Cài đặt phiên bản node tương ứng
24
-
25
- ```
26
- nvm install phiên-bản-node
27
- ```
28
-
29
- > ⚠️ Lưu ý: ví dụ `nvm install 22.15.0`
@@ -1,27 +0,0 @@
1
- ## ✅ Bước 1: Cài đặt node (nếu chưa cài)
2
-
3
- [Xem tại đây](./setup-node.md)
4
-
5
- ## ✅ Bước 2: Cài đặt pm2
6
-
7
- ```
8
- npm install pm2 -g
9
- ```
10
-
11
- ## ✅ Bước 3: Chạy pm2
12
-
13
- Chạy bằng node mặc định
14
-
15
- ```
16
- pm2 start tên-file.js --name tên-app
17
- ```
18
-
19
- > ⚠️ Lưu ý: ví dụ `pm2 start index.js --name cyberskill-example`
20
-
21
- Đối với dự án có script chạy từ package.json
22
-
23
- ```
24
- pm2 start pnpm --name tên-app -- run tên-script-chạy
25
- ```
26
-
27
- > ⚠️ Lưu ý: ví dụ `pm2 start pnpm --name cyberskill-example -- run start`
@@ -1,17 +0,0 @@
1
- ## ✅ Bước 1: Cài đặt homebrew (nếu chưa cài)
2
-
3
- ```
4
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
5
- ```
6
-
7
- ## ✅ Bước 2: Cài đặt redis
8
-
9
- ```
10
- brew install redis
11
- ```
12
-
13
- ## ✅ Bước 3: Chạy redis
14
-
15
- ```
16
- brew services start redis
17
- ```
@@ -1,102 +0,0 @@
1
- ## ✅ Bước 1: Cài đặt certbot
2
-
3
- ```
4
- sudo apt update
5
- ```
6
-
7
- ```
8
- sudo apt install certbot python3-certbot-nginx
9
- ```
10
-
11
- ## ✅ Bước 2: Chạy certbot
12
-
13
- ```
14
- sudo certbot --nginx -d tên-miền
15
- ```
16
-
17
- > ⚠️ Lưu ý: nếu có nhiều tên miền có thể ghi liên tục, ví dụ `sudo certbot --nginx -d cyberskill.example -d api.cyberskill.example -d www.cyberskill.example`
18
-
19
- Nếu hiện như sau là cấu hình ok
20
- `Successfully received certificate.`
21
- `Certificate is saved at: đường-dẫn/fullchain.pem`
22
- `Key is saved at: đường-dẫn/privkey.pem`
23
- `This certificate expires on năm-tháng-ngày.`
24
- `These files will be updated when the certificate renews.`
25
- `Certbot has set up a scheduled task to automatically renew this certificate in the background.`
26
-
27
- ## ✅ Bước 3: Cập nhật cấu hình nginx
28
-
29
- Ví dụ cho cấu hình Backend và Frontend
30
-
31
- ```
32
- server {
33
- listen 80 default_server;
34
- listen [::]:80 default_server;
35
-
36
- server_name cyberskill.example www.cyberskill.example api.cyberskill.example;
37
-
38
- return 301 https://$host$request_uri;
39
- }
40
-
41
- server {
42
- listen 443 ssl;
43
- listen [::]:443 ssl;
44
-
45
- server_name cyberskill.example www.cyberskill.example;
46
-
47
- ssl_certificate /etc/letsencrypt/live/cyberskill.example/fullchain.pem;
48
- ssl_certificate_key /etc/letsencrypt/live/cyberskill.example/privkey.pem;
49
- include /etc/letsencrypt/options-ssl-nginx.conf;
50
- ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
51
-
52
- location / {
53
- proxy_pass http://localhost:port-frontend;
54
- proxy_http_version 1.1;
55
- proxy_set_header Upgrade $http_upgrade;
56
- proxy_set_header Connection 'upgrade';
57
- proxy_set_header Host $host;
58
- proxy_cache_bypass $http_upgrade;
59
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
60
- proxy_set_header X-Forwarded-Proto $scheme;
61
- }
62
- }
63
-
64
- server {
65
- listen 443 ssl;
66
- listen [::]:443 ssl;
67
-
68
- server_name api.cyberskill.example;
69
-
70
- ssl_certificate /etc/letsencrypt/live/cyberskill.example/fullchain.pem;
71
- ssl_certificate_key /etc/letsencrypt/live/cyberskill.example/privkey.pem;
72
- include /etc/letsencrypt/options-ssl-nginx.conf;
73
- ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
74
-
75
- location / {
76
- proxy_pass http://localhost:port-backend;
77
- proxy_http_version 1.1;
78
- proxy_set_header Upgrade $http_upgrade;
79
- proxy_set_header Connection 'upgrade';
80
- proxy_set_header Host $host;
81
- proxy_cache_bypass $http_upgrade;
82
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
83
- proxy_set_header X-Forwarded-Proto $scheme;
84
- }
85
- }
86
- ```
87
-
88
- ## ✅ Bước 4: Kiểm tra cấu hình
89
-
90
- ```
91
- sudo nginx -t
92
- ```
93
-
94
- Nếu hiện như sau là cấu hình ok
95
- `nginx: the configuration file /etc/nginx/nginx.conf syntax is ok`
96
- `nginx: configuration file /etc/nginx/nginx.conf test is successful`
97
-
98
- ## ✅ Bước 5: Khởi động lại nginx với cấu hình mới
99
-
100
- ```
101
- sudo nginx -s reload
102
- ```