@udi-organization/udi-package 1.0.51 → 1.0.55

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/README.md CHANGED
@@ -1,102 +1,344 @@
1
- # test1202
1
+ # 前端套件”udi-pacakge”開發流程:
2
2
 
3
- 測試用的 npm 套件,包含 React Button component 和實用工具函數。
3
+ ## 概述
4
4
 
5
- ## 安裝
5
+ 前端專案共用套件 udi-package 開發規範
6
+ 目的:集中管理跨專案Component、Utils Function
7
+
8
+ ---
9
+
10
+ ## 架構說明
11
+
12
+ ### 編譯工具分工
13
+
14
+ - **Rollup**: 編譯套件輸出為標準 npm 包格式
15
+ - **Webpack**: 編譯 sandbox 本地開發環境,提供熱更新與套件獨立的即時預覽
16
+
17
+ ### 開發模式
18
+
19
+ 1. **正常開發模式**: 使用 npm 官方發布的套件版本
20
+ 2. **Link 開發模式**: 使用本地 udi-package 進行即時開發
21
+
22
+ ---
23
+
24
+ ## 資料夾結構
25
+
26
+ ```
27
+ project-root/
28
+ ├── frontend-project/ # 前端專案
29
+ │ ├── node_modules/
30
+ │ ├── package.json
31
+ │ └── .git/
32
+ │ └── hooks/
33
+ │ └── pre-push # Git hook 防護
34
+ └── udi-package/ # 共用套件 (與前端專案同層)
35
+ ├── src/
36
+ ├── dist/ # Rollup 編譯輸出
37
+ └── package.json
38
+
39
+ ```
40
+
41
+ ⚠️ **重要**: `udi-package` 必須與前端專案放在同一層級,因為 Docker volume 需要使用固定路徑進行映射。
42
+
43
+ ---
44
+
45
+ ## 前置作業
46
+
47
+ ### 1. 資料夾配置
48
+
49
+ 將 `udi-package` 放置在與前端專案相同的目錄層級。
50
+
51
+ ### 2. 設置 Git Hook 防護
52
+
53
+ 在前端專案中執行以下命令:
54
+
55
+ ```bash
56
+ nano .git/hooks/pre-push
57
+
58
+ ```
59
+
60
+ 貼上以下內容:
61
+
62
+ ```bash
63
+ #!/bin/bash
64
+
65
+ # 檢查 @udi-organization/udi-package 是否為 symlink (npm link)
66
+ PACKAGE_PATH="node_modules/@udi-organization/udi-package"
67
+
68
+ if [ -L "$PACKAGE_PATH" ]; then
69
+ echo "❌ 錯誤: 檢測到使用 npm link"
70
+ echo ""
71
+ echo "目前 @udi-organization/udi-package 是使用本地 link"
72
+ echo "請先執行以下命令切換回正式版本:"
73
+ echo ""
74
+ echo " npm run get-udi-o"
75
+ echo ""
76
+ echo "或手動執行:"
77
+ echo " npm uninstall @udi-organization/udi-package --legacy-peer"
78
+ echo " npm install @udi-organization/udi-package@latest --legacy-peer"
79
+ echo ""
80
+ exit 1
81
+ fi
82
+
83
+ # 檢查通過
84
+ echo "✓ 檢查通過: 未使用本地 link"
85
+ exit 0
86
+
87
+ ```
88
+
89
+ 儲存並設置執行權限:
6
90
 
7
91
  ```bash
8
- npm install test1202
92
+ # Ctrl+O (儲存) → Enter → Ctrl+X (退出)
93
+ chmod +x .git/hooks/pre-push
94
+
9
95
  ```
10
96
 
11
- ## 使用方式
97
+ ### 3. NPM 組織設定
98
+
99
+ ### 建立並加入組織
12
100
 
13
- ### Button Component
101
+ 1. 建立個人 npm 帳號
102
+ 2. 由管理員邀請加入 `@udi-organization` 組織
103
+ 3. 執行登入:
104
+
105
+ ```bash
106
+ npm login
107
+
108
+ ```
109
+
110
+ 會自動開啟瀏覽器完成登入
111
+
112
+ 4. 確認登入狀態:
113
+
114
+ ```bash
115
+ npm whoami
116
+
117
+ ```
118
+
14
119
 
15
- ```jsx
16
- import { Button } from 'test1202';
120
+ ---
17
121
 
18
- function App() {
19
- return (
20
- <div>
21
- <Button onClick={() => alert('Clicked!')}>
22
- Primary Button
23
- </Button>
122
+ ## NPM Scripts 說明
24
123
 
25
- <Button variant="secondary" onClick={() => console.log('Secondary')}>
26
- Secondary Button
27
- </Button>
124
+ ### 前端專案指令
28
125
 
29
- <Button variant="success">
30
- Success Button
31
- </Button>
126
+ ```json
127
+ {
128
+ "scripts": {
129
+ // 正常開發模式 自動取得最新版本udi-package - 使用 npm 官方套件
130
+ "dev": "npm i @udi-organization/udi-package@latest --legacy-peer && NODE_ENV=development webpack-dev-server --progress --hot --mode=development --host=0.0.0.0",,
32
131
 
33
- <Button variant="danger">
34
- Danger Button
35
- </Button>
132
+ // Link 開發模式 - 使用本地 udi-package
133
+ "dev-udi": "npm uninstall @udi-organization/udi-package --legacy-peer && cd ../udi-package && sudo npm link && cd ../build && npm link @udi-organization/udi-package --legacy-peer && npm run dev",
36
134
 
37
- <Button disabled>
38
- Disabled Button
39
- </Button>
40
- </div>
41
- );
135
+ // 切換回正常模式 (不啟動專案) 也可用於取得最新版本udi-package
136
+ "get-udi-o": "npm i @udi-organization/udi-package@latest --legacy-peer",
137
+ }
42
138
  }
139
+
43
140
  ```
44
141
 
45
- #### Props
142
+ ### udi-package 套件指令
46
143
 
47
- | Prop | Type | Default | Description |
48
- |------|------|---------|-------------|
49
- | `children` | `ReactNode` | - | 按鈕內容 |
50
- | `onClick` | `Function` | - | 點擊事件處理函數 |
51
- | `variant` | `'primary'` \| `'secondary'` \| `'success'` \| `'danger'` | `'primary'` | 按鈕樣式變體 |
52
- | `disabled` | `boolean` | `false` | 是否禁用按鈕 |
53
- | `className` | `string` | `''` | 自訂 CSS class |
144
+ ```json
145
+ {
146
+ "scripts": {
147
+ // 監聽模式 - 自動編譯變更
148
+ "watch": "rollup -c --watch",
54
149
 
55
- ### 工具函數
150
+ // 單次編譯
151
+ "build": "rollup -c",
56
152
 
57
- ```javascript
58
- import { greet, add } from 'test1202';
153
+ // 發布新版本
154
+ "release": "自動更新版本號並發布至 npm"
155
+ }
156
+ }
59
157
 
60
- console.log(greet('World')); // "Hello, World! 103"
61
- console.log(add(2, 3)); // 5
62
- console.log(add(10, 25)); // 35
63
158
  ```
64
159
 
65
- ## 功能特色
160
+ ---
66
161
 
67
- - ✅ 同時支援 CommonJS 和 ES Modules
68
- - ✅ 包含多種按鈕樣式變體
69
- - ✅ 輕量且無額外依賴(除了 React peer dependency)
162
+ ## 開發流程
70
163
 
71
- ## 開發
164
+ ### 情境一: 不需修改 udi-package
72
165
 
73
166
  ```bash
74
- # 安裝依賴
75
- npm install
76
-
77
- # 啟動開發環境
167
+ # 直接啟動專案
78
168
  npm run dev
79
169
 
80
- # 建置套件
170
+ ```
171
+
172
+ ### 情境二: 需要開發 udi-package
173
+
174
+ ### 步驟 1: 啟動套件監聽
175
+
176
+ 在 `udi-package` 目錄執行:
177
+
178
+ ```bash
179
+ npm run watch
180
+ # 或單次編譯
81
181
  npm run build
182
+
82
183
  ```
83
184
 
84
- 開發環境會在 `http://localhost:3000` 啟動,您可以在瀏覽器中即時預覽和測試 component。
185
+ ### 步驟 2: 啟動 Link 開發模式
85
186
 
86
- ## 專案結構
187
+ 在前端專案目錄執行:
188
+
189
+ ```bash
190
+ npm run dev-udi
87
191
 
88
192
  ```
89
- npmPackageTest/
90
- ├── dev/ # 開發測試環境
91
- ├── src/ # 原始碼
92
- │ ├── Button.jsx # Button component
93
- │ └── index.js # 主入口
94
- ├── dist/ # 建置輸出
95
- │ ├── index.cjs.js # CommonJS 版本
96
- │ └── index.esm.js # ES Module 版本
97
- └── package.json
193
+
194
+ ### 步驟 3: 開發與測試
195
+
196
+ - 修改 `udi-package/src` 中的程式碼
197
+ - Rollup 會自動編譯至 `dist/` 目錄
198
+ - 前端專案透過 link 即時取得更新
199
+
200
+ ### 步驟 4: 發布新版本
201
+
202
+ ⚠️ **發布前檢查**:
203
+
204
+ - 確保所有變更已 commit
205
+ - 不可有未被 Git 追蹤的檔案
206
+
207
+ ```bash
208
+ # 在 udi-package 目錄
209
+ git add .
210
+ git commit -m "feat: 新功能說明"
211
+ npm run release
212
+
98
213
  ```
99
214
 
100
- ## License
215
+ ---
216
+
217
+ ## Git 推送流程
218
+
219
+ ### 完整推送步驟
220
+
221
+ 1. **建立 Feature Branch**
222
+
223
+ ```bash
224
+ git checkout -b feature/your-feature-name
225
+
226
+ ```
227
+
228
+ 2. **持續開發與提交**
229
+
230
+ ```bash
231
+ git add .
232
+ git commit -m "feat: 功能描述"
233
+ git push origin feature/your-feature-name
234
+
235
+ ```
236
+
237
+ 3. **推送前切換回正常模式**
238
+
239
+ ```bash
240
+ # 方法一: 只切換不啟動
241
+ npm run get-udi-o
242
+
243
+ # 方法二: 切換並驗證專案
244
+ npm run dev
245
+
246
+ ```
247
+
248
+ 4. **驗證專案正常運作**
249
+ - 確認專案可正常啟動
250
+ - 確認功能運作正常
251
+ - 確認 package.json 包含正式的套件依賴
252
+ 5. **推送到 GitLab**
253
+
254
+ ```bash
255
+ git push origin feature/your-feature-name
256
+
257
+ ```
258
+
259
+ > Git hook 會自動檢查是否為 link 模式,防止錯誤推送
260
+ >
261
+ 6. **通過 Pipeline 後合併**
262
+ - 確認 GitLab CI/CD Pipeline 全部通過
263
+ - 提交 Merge Request 至 `dev` 分支
264
+ - Code Review 通過後合併
265
+
266
+ ---
267
+
268
+ ## 常見問題處理
269
+
270
+ ### Q1: 推送時出現 "檢測到使用 npm link" 錯誤
271
+
272
+ **原因**: 目前處於 link 開發模式
273
+
274
+ **解決**:
275
+
276
+ ```bash
277
+ npm run get-udi-o
278
+ # 或
279
+ npm run dev # 切換並驗證專案
280
+
281
+ ```
282
+
283
+ ### Q2: udi-package 修改後前端專案沒有更新
284
+
285
+ **檢查項目**:
286
+
287
+ 1. 確認 `udi-package` 目錄是否執行 `npm run watch`
288
+ 2. 確認前端專案是否使用 `npm run dev-udi` 啟動
289
+ 3. 檢查編譯是否有錯誤訊息
290
+
291
+ ### Q3: npm link 權限問題
292
+
293
+ **解決**: 使用 `sudo` 執行 link 指令
294
+
295
+ ```bash
296
+ cd ../udi-package
297
+ sudo npm link
298
+
299
+ ```
300
+
301
+ ### Q4: 發布失敗 - 未登入或權限不足
302
+
303
+ **解決**:
304
+
305
+ ```bash
306
+ npm login
307
+ npm whoami # 確認登入狀態
308
+
309
+ ```
310
+
311
+ ---
312
+
313
+ ## 快速參考
314
+
315
+ ### 常用指令速查
316
+
317
+ | 情境 | 指令 |
318
+ | --- | --- |
319
+ | 正常開發 | `npm run dev` |
320
+ | 開發套件 | `npm run dev-udi` |
321
+ | 切換回正常模式 | `npm run get-udi-o` |
322
+ | 套件監聽編譯 | `npm run watch` (在 udi-package) |
323
+ | 發布新版本 | `npm run release` (在 udi-package) |
324
+ | 檢查登入狀態 | `npm whoami` |
325
+
326
+ ### 檢查清單
327
+
328
+ **開發前**
329
+
330
+ - [ ] udi-package 與專案在同層目錄
331
+ - [ ] Git hook 已設置
332
+ - [ ] npm 已登入正確組織
333
+
334
+ **推送前**
335
+
336
+ - [ ] 切換回正常模式 (`npm run get-udi-o`)
337
+ - [ ] 專案可正常運作
338
+ - [ ] 所有變更已 commit
339
+
340
+ **發布套件前**
101
341
 
102
- ISC
342
+ - [ ] 所有變更已 commit
343
+ - [ ] 無未追蹤檔案
344
+ - [ ] npm 已登入