softleader-nuxt-core 1.0.8 → 1.1.1

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.
Files changed (73) hide show
  1. package/README.md +91 -64
  2. package/assets/css/layout.css +56 -20
  3. package/bin/init.mjs +316 -50
  4. package/commitlint.config.cjs +1 -0
  5. package/components/templates/Welcome.vue +715 -0
  6. package/components/uiBusiness/BDataTable.vue +977 -888
  7. package/components/uiBusiness/CitySelect.vue +2 -2
  8. package/components/uiBusiness/PolicyForm.vue +9 -3
  9. package/components/uiInterface/IAlert.vue +1 -1
  10. package/components/uiInterface/IAvatar.vue +1 -1
  11. package/components/uiInterface/IBreadcrumbs.vue +1 -1
  12. package/components/uiInterface/IButton.vue +77 -20
  13. package/components/uiInterface/ICard.vue +9 -4
  14. package/components/uiInterface/ICheckbox.vue +12 -6
  15. package/components/uiInterface/IDataTable.vue +534 -515
  16. package/components/uiInterface/IRadio.vue +8 -2
  17. package/components/uiInterface/ISelect.vue +44 -19
  18. package/components/uiInterface/IStack.vue +9 -2
  19. package/components/uiInterface/ISwitch.vue +14 -3
  20. package/components/uiInterface/ITextField.vue +51 -24
  21. package/components/uiInterface/ITextarea.vue +54 -33
  22. package/composables/useApiRegistry.ts +1 -1
  23. package/composables/useErrorHandler.ts +12 -0
  24. package/composables/useFeatureFlag.ts +1 -1
  25. package/composables/useFileUpload.ts +2 -1
  26. package/composables/useFormatter.ts +2 -2
  27. package/composables/useModules.ts +18 -0
  28. package/composables/useOptions.ts +41 -22
  29. package/composables/useRepo.ts +49 -0
  30. package/configs/default.json +36 -9
  31. package/core/config/app.ts +9 -20
  32. package/core/config/components.ts +13 -25
  33. package/core/config/css.ts +4 -1
  34. package/core/config/eslint.config.mjs +180 -0
  35. package/core/config/git/commit-types.cjs +30 -0
  36. package/core/config/git/commitlint.config.cjs +17 -0
  37. package/core/config/git/cz-config.cjs +21 -0
  38. package/core/config/git/lint-staged.config.js +6 -0
  39. package/core/config/gitignore +30 -0
  40. package/core/config/layout.ts +17 -12
  41. package/core/config/modules.ts +10 -6
  42. package/core/config/nitro.ts +13 -15
  43. package/core/config/prettier.json +14 -0
  44. package/core/config/runtime.ts +5 -29
  45. package/core/config/theme-tokens.ts +34 -269
  46. package/core/config/vite.ts +3 -4
  47. package/core/options/registry.ts +13 -2
  48. package/core/options/types.ts +1 -1
  49. package/core/repositories/index.ts +1 -1
  50. package/core/templates/gitignore +38 -0
  51. package/core/templates/husky/commit-msg +6 -0
  52. package/core/templates/husky/pre-commit +6 -0
  53. package/core/templates/vscode/extensions.json +8 -0
  54. package/core/templates/vscode/settings.json +69 -0
  55. package/core/templates/vscode/snippets.code-snippets +16 -0
  56. package/core/templates/vscode/vue3Template.code-snippets +165 -0
  57. package/cz.config.cjs +1 -0
  58. package/eslint.config.mjs +3 -0
  59. package/lint-staged.config.js +1 -0
  60. package/modules/options-scanner.ts +113 -0
  61. package/modules/repositories-scanner.ts +95 -0
  62. package/nuxt.config.ts +66 -13
  63. package/package.json +26 -5
  64. package/plugins/api.ts +7 -4
  65. package/plugins/vuetify.ts +10 -10
  66. package/prettier.config.cjs +1 -0
  67. package/scripts/product-loader.ts +104 -22
  68. package/scripts/release.mjs +24 -0
  69. package/scripts/sync-configs.mjs +53 -0
  70. package/stores/common.ts +3 -3
  71. package/tsconfig.json +16 -1
  72. package/types/repo.ts +13 -0
  73. package/components/uiInterface/layout/IBreadcrumbs.vue +0 -120
package/README.md CHANGED
@@ -1,91 +1,118 @@
1
- # Nuxt Core Layer (`softleader-nuxt-core`)
1
+ # Nuxt Core 核心開發包 (`softleader-nuxt-core`)
2
2
 
3
- 這是 Nuxt 3 Core Layer,提供可重用的基礎架構、元件和工具,協助開發團隊快速建立一致且高品質的 Nuxt 3 應用。
3
+ 一個基於 Nuxt 3 的企業級 Layer 開發框架,提供可重用的基礎架構、元件與工具。
4
4
 
5
- ## 包含內容
5
+ ## 快速開始
6
6
 
7
- - 設計系統元件
8
- - 基礎 Layout 與路由設定
9
- - 全域樣式與設計 Tokens
10
- - 共用 Composables 與 Utils
11
- - 統一的開發工具配置(搭配 Nuxt 3 Eslint 等)
7
+ ### 1. 安裝相依套件
12
8
 
13
- ## 使用情境一:在既有專案中使用 (Layer 繼承)
9
+ 在你的 Nuxt 3 專案中執行:
14
10
 
15
- 如果你已經有一個 Nuxt 3 專案,你可以直接將此 Layer 擴展進你的專案中,藉此享有所有組件、功能和設定。
11
+ ```bash
12
+ npm install softleader-nuxt-core
13
+ ```
16
14
 
17
- 1. **安裝依賴**
15
+ ### 2. 層級繼承 (Setup Layer)
18
16
 
19
- ```bash
20
- npm install softleader-nuxt-core
21
- ```
17
+ 在你的 `nuxt.config.ts` 中擴寫核心層:
22
18
 
23
- 2. **配置 `nuxt.config.ts`**
19
+ ```typescript
20
+ export default defineNuxtConfig({
21
+ extends: ['softleader-nuxt-core']
22
+ // ... 其他專案設定
23
+ })
24
+ ```
24
25
 
25
- ```typescript
26
- export default defineNuxtConfig({
27
- extends: ["softleader-nuxt-core"],
28
- // ... 其他你的專案設定
29
- });
30
- ```
26
+ ### 3. 配置產品參數 (Configuration)
31
27
 
32
- 3. **啟用 ESLint / Prettier (選用)**
33
- 由於此專案依賴 `@nuxt/eslint-config`,建議你的專案也在根目錄設定對應的 Eslint 配置:
34
- ```bash
35
- npm i -D @nuxt/eslint-config eslint
36
- ```
37
- 並在你的 `eslint.config.mjs` 中繼承 Nuxt 預設配置。
28
+ 在專案根目錄建立 `configs/default.json`。核心層會自動讀取此檔案並應用於全域。詳細配置請參考 **[環境與產品配置指南](#)**。
38
29
 
39
30
  ---
40
31
 
41
- ## 使用情境二:快速建立全新專案 (Scaffolding CLI)
32
+ ## 開發指南 (Development Guide)
33
+
34
+ 為了讓開發人員能順利建立與維護專案,請參考以下文件循序漸進地了解核心功能:
35
+
36
+ ### 1. 核心架構與基礎 (Core Architecture & Basics)
37
+
38
+ 了解層級設計理念、如何透過繼承快速啟動,以及配置系統。
39
+
40
+ - **[Nuxt Core 導論與介面理念 (README_TEAM.md)](./README_TEAM.md)**
41
+ - **[核心配置系統 (nuxt.schema.ts)](./nuxt.schema.ts)**
42
+ - **[開發環境與 Playground 聯動 (README.md)](../../README.md)**
43
+
44
+ ### 2. UI 與組件規範 (UI & Component Standards)
45
+
46
+ 學習如何使用介面層組件,確保 UI 一致性與可替換性。
47
+
48
+ - **[UI Interface 封裝理念 (IButton.vue)](./components/uiInterface/IButton.vue)**
49
+ - **[設計系統與 Tokens (styles/)](./styles/)**
50
+ - **[透傳屬性 ($attrs) 與彈性設計 (IDataTable.vue)](./components/uiInterface/IDataTable.vue)**
51
+
52
+ ### 3. 資料映射與業務邏輯 (Data Mapping & Logic)
53
+
54
+ 掌握自動化的資料層掃描與全域選項系統。
42
55
 
43
- 如果你想在一個新的(或空的)資料夾內建立完整包含 `softleader-nuxt-core` 的專案,我們提供了一個內建的命令列工具。
56
+ - **[Smart Client 與 API 請求 (useApi.ts)](./composables/useApi.ts)**
57
+ - **[自動化儲存庫掃描 (repositories-scanner.ts)](./modules/repositories-scanner.ts)**
58
+ - **[全域與本地選項管理 (useOptions.ts)](./composables/useOptions.ts)**
44
59
 
45
- 1. **透過 npx 執行初始化腳本**
46
- 你可以直接使用 `npx` 搭配套件名稱,並指定你的專案名稱(例如 `my-new-app`):
60
+ ### 4. 架構進階應用 (Advanced Layer Usage)
47
61
 
48
- ```bash
49
- npx softleader-nuxt-core init my-new-app
50
- ```
62
+ 深入了解路由擴充、Mock Server 以及攔截器機制。
51
63
 
52
- 2. **進入專案並啟動**
53
- 指令執行完成後,請進入生成的專案資料夾並啟動開發伺服器:
54
- ```bash
55
- cd my-new-app
56
- npm install # CLI 尚未安裝完畢
57
- npm run dev
58
- ```
59
- 這會自動生成 `package.json`、`app.vue`、`nuxt.config.ts` 等必要檔案,並且已經預先設定好 `extends: ['softleader-nuxt-core']`。
64
+ - **[動態路由掃描 (routes-scanner.ts)](./router/routes-scanner.ts)**
65
+ - **[API 請求與回應攔截器 (interceptors/)](./utils/api/interceptors/)**
66
+ - **[純前端 Mock 機制實作 (useApi.ts)](./composables/useApi.ts)**
67
+
68
+ ### 5. 發布與維運 (Publish & Maintenance)
69
+
70
+ 了解如何維護核心包、發布至套件庫以及版本管理。
71
+
72
+ - **[NPM 套件打包與發布流程 (package.json)](./package.json)**
73
+ - **[Git 工作流與 Commit 規範 (README.md)](../../README.md)**
74
+ - **[疑難排解與除錯指南 (error.ts)](./utils/api/error.ts)**
75
+ - **[CLI 工具設計原理 - 為何 `init` 不放在 scripts? (bin/init.mjs)](./bin/init.mjs)**
76
+ - **全域執行能力**:放到 `bin` 欄位,才能讓使用者在「沒有專案的空目錄」下,直接透過 `npx softleader-nuxt-core init` 從無到有建立專案。如果是 `scripts`,就必須先有專案且安裝了套件才能跑,這會有雞生蛋的問題。
77
+ - **系統整合**:`bin` 腳本(搭配 `#!/usr/bin/env node`)會被 npm 註冊為命令列工具,自動建立符號連結並賦予執行權限。
78
+ - **職責分離**:`scripts` 是給「當下這個專案」的開發者用的任務;而 `bin` 則是提供給「套件的使用者」在終端機呼叫的工具。
60
79
 
61
80
  ---
62
81
 
63
- ## 開發 Core Layer 說明
82
+ ## 文件索引
64
83
 
65
- 若你是 `softleader-nuxt-core` 的開發者:
84
+ ### 1. 核心手冊 (必讀)
66
85
 
67
- ```bash
68
- # 安裝依賴
69
- npm install
86
+ - **[團隊開發指南 (README_TEAM.md)](./README_TEAM.md)**: 小組員如何快速上手與配置。
87
+ - **[核心配置系統 (nuxt.schema.ts)](./nuxt.schema.ts)**: 配置項架構定義。
88
+ - **[核心入口 (nuxt.config.ts)](./nuxt.config.ts)**: Layer 的主配置入口。
70
89
 
71
- # Lint
72
- npm run lint
90
+ ### 2. 結構參考
73
91
 
74
- # 型別檢查
75
- npm run typecheck
76
- ```
92
+ - **[產品配置腳本 (scripts/product-loader.ts)](./scripts/product-loader.ts)**: 處理 JSON 配置的載入核心。
93
+ - **[自動掃描器 (modules/)](./modules/)**: Repositories 與 Options 的掃描實作。
94
+
95
+ ### 3. 元件與 Composable
96
+
97
+ - **[介面層組件範例 (IButton)](./components/uiInterface/IButton.vue)**: 標準化組件實作。
98
+ - **[核心 Composable (useApi)](./composables/useApi.ts)**: 統一的 API 連線封裝。
99
+ - **[選項管理 (useOptions)](./composables/useOptions.ts)**: 全域選項代理實作。
100
+
101
+ ### 4. 設定檔優先級規則 (Configuration Precedence)
102
+
103
+ 當你在不同的地方定義了相同的變數時(例如 API URL 或逾時設定),系統會依照以下**嚴格的優先順序**覆蓋:
104
+
105
+ 1. **`.env` (最高)**:系統環境變數,通常由 CI/CD 或本地開發者手動設置。
106
+ 2. **`nuxt.config.ts` (次之)**:專案層級的 `runtimeConfig`。
107
+ 3. **`configs/default.json` (最底)**:全域的預設藍圖設置。
108
+
109
+ > **最佳實踐**:請將「固定的開發結構設定(如模組開關)」寫進 JSON,將「隨環境變動的機敏資訊(如連線字串、API 端點)」寫進 `.env`。
110
+
111
+ ### 5. 資料串接
77
112
 
78
- ### 發布至 npm
113
+ - **[API 錯誤處理](./utils/api/error.ts)**: 統一的報錯處理機制。
114
+ - **[認證攔截器](./utils/api/interceptors/request.ts)**: 處理 Header 注入邏輯。
79
115
 
80
- 為了讓其他開發者能透過 `npx` 使用此腳本或載入此 Layer,您必須將本專案發布到 npm registry。
116
+ ### 5. 疑難排解
81
117
 
82
- 1. **更新版本號**:確保 `package.json` 中的 `version` 已更新。
83
- 2. **登入 npm** (若尚未登入):
84
- ```bash
85
- npm login
86
- ```
87
- 3. **發布套件**:
88
- ```bash
89
- npm publish
90
- ```
91
- _(若是發布到公司私有 registry,請確認 `.npmrc` 中有設定正確的 registry url)_
118
+ - **[Repository 型別修正範例 (repositories/user.ts)](../../apps/playground-app/repositories/user.ts)**: 解決 TS 推導問題的示範。
@@ -166,28 +166,64 @@ body {
166
166
  }
167
167
 
168
168
  /* Margin Utilities */
169
- .mt-sm { margin-top: var(--spacing-sm); }
170
- .mt-md { margin-top: var(--spacing-md); }
171
- .mt-lg { margin-top: var(--spacing-lg); }
172
- .mt-xl { margin-top: var(--spacing-xl); }
173
- .mt-2xl { margin-top: var(--spacing-2xl); }
174
-
175
- .mb-sm { margin-bottom: var(--spacing-sm); }
176
- .mb-md { margin-bottom: var(--spacing-md); }
177
- .mb-lg { margin-bottom: var(--spacing-lg); }
178
- .mb-xl { margin-bottom: var(--spacing-xl); }
179
- .mb-2xl { margin-bottom: var(--spacing-2xl); }
169
+ .mt-sm {
170
+ margin-top: var(--spacing-sm);
171
+ }
172
+ .mt-md {
173
+ margin-top: var(--spacing-md);
174
+ }
175
+ .mt-lg {
176
+ margin-top: var(--spacing-lg);
177
+ }
178
+ .mt-xl {
179
+ margin-top: var(--spacing-xl);
180
+ }
181
+ .mt-2xl {
182
+ margin-top: var(--spacing-2xl);
183
+ }
184
+
185
+ .mb-sm {
186
+ margin-bottom: var(--spacing-sm);
187
+ }
188
+ .mb-md {
189
+ margin-bottom: var(--spacing-md);
190
+ }
191
+ .mb-lg {
192
+ margin-bottom: var(--spacing-lg);
193
+ }
194
+ .mb-xl {
195
+ margin-bottom: var(--spacing-xl);
196
+ }
197
+ .mb-2xl {
198
+ margin-bottom: var(--spacing-2xl);
199
+ }
180
200
 
181
201
  /* Padding Utilities */
182
- .pt-sm { padding-top: var(--spacing-sm); }
183
- .pt-md { padding-top: var(--spacing-md); }
184
- .pt-lg { padding-top: var(--spacing-lg); }
185
- .pt-xl { padding-top: var(--spacing-xl); }
186
-
187
- .pb-sm { padding-bottom: var(--spacing-sm); }
188
- .pb-md { padding-bottom: var(--spacing-md); }
189
- .pb-lg { padding-bottom: var(--spacing-lg); }
190
- .pb-xl { padding-bottom: var(--spacing-xl); }
202
+ .pt-sm {
203
+ padding-top: var(--spacing-sm);
204
+ }
205
+ .pt-md {
206
+ padding-top: var(--spacing-md);
207
+ }
208
+ .pt-lg {
209
+ padding-top: var(--spacing-lg);
210
+ }
211
+ .pt-xl {
212
+ padding-top: var(--spacing-xl);
213
+ }
214
+
215
+ .pb-sm {
216
+ padding-bottom: var(--spacing-sm);
217
+ }
218
+ .pb-md {
219
+ padding-bottom: var(--spacing-md);
220
+ }
221
+ .pb-lg {
222
+ padding-bottom: var(--spacing-lg);
223
+ }
224
+ .pb-xl {
225
+ padding-bottom: var(--spacing-xl);
226
+ }
191
227
 
192
228
  /* Responsive Utilities */
193
229
  .hidden {