zcw-shared 1.29.0 → 1.30.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.
- package/README.md +87 -55
- package/dist/functions/platform/tencent-cloud/deploy.tcb.d.ts +13 -0
- package/dist/functions/platform/tencent-cloud/deploy.tcb.js +46 -0
- package/dist/functions/platform/tencent-cloud/deploy.tcb.js.map +1 -0
- package/dist/functions/platform/tencent-cloud/getSecret.d.ts +4 -0
- package/dist/functions/platform/tencent-cloud/getSecret.js +19 -0
- package/dist/functions/platform/tencent-cloud/getSecret.js.map +1 -0
- package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.d.ts +27 -0
- package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.js +287 -0
- package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.js.map +1 -0
- package/dist/functions/platform/uniapp/build.d.ts +21 -0
- package/dist/functions/platform/uniapp/build.js +83 -0
- package/dist/functions/platform/uniapp/build.js.map +1 -0
- package/dist/functions/platform/uniapp/detectAndroidProjectStructure.d.ts +11 -0
- package/dist/functions/platform/uniapp/detectAndroidProjectStructure.js +30 -0
- package/dist/functions/platform/uniapp/detectAndroidProjectStructure.js.map +1 -0
- package/dist/functions/platform/uniapp/detectProjectType.d.ts +20 -0
- package/dist/functions/platform/uniapp/detectProjectType.js +68 -0
- package/dist/functions/platform/uniapp/detectProjectType.js.map +1 -0
- package/dist/functions/platform/uniapp/parseManifest.d.ts +18 -0
- package/dist/functions/platform/uniapp/parseManifest.js +49 -0
- package/dist/functions/platform/uniapp/parseManifest.js.map +1 -0
- package/dist/functions/platform/uniapp/waitForPages.d.ts +7 -0
- package/dist/functions/platform/uniapp/waitForPages.js +20 -0
- package/dist/functions/platform/uniapp/waitForPages.js.map +1 -0
- package/dist/functions/string/visualizeRegexSteps.d.ts +39 -0
- package/dist/functions/string/visualizeRegexSteps.js +446 -0
- package/dist/functions/string/visualizeRegexSteps.js.map +1 -0
- package/dist/functions/utils/createI18n.d.ts +2 -0
- package/dist/functions/utils/createI18n.js +97 -0
- package/dist/functions/utils/createI18n.js.map +1 -0
- package/dist/functions/utils/formatString.d.ts +5 -0
- package/dist/functions/utils/formatString.js +9 -0
- package/dist/functions/utils/formatString.js.map +1 -0
- package/dist/functions/vue/dynamicMount.d.ts +6 -4
- package/dist/functions/vue/isVNode.d.ts +1 -1
- package/dist/functions/vue/isVueComponent.d.ts +1 -1
- package/dist/hooks/usePermission.d.ts +7 -0
- package/dist/hooks/usePermission.js +123 -0
- package/dist/hooks/usePermission.js.map +1 -0
- package/dist/vue-hooks/browser/useBattery.d.ts +1 -1
- package/dist/vue-hooks/browser/useBluetooth.d.ts +1 -1
- package/dist/vue-hooks/browser/useCamera.d.ts +1 -1
- package/dist/vue-hooks/browser/useClipboard.d.ts +1 -1
- package/dist/vue-hooks/browser/useFileUpload.d.ts +1 -1
- package/dist/vue-hooks/browser/useFullscreen.d.ts +1 -1
- package/dist/vue-hooks/browser/useGamepad.d.ts +1 -1
- package/dist/vue-hooks/browser/useGeolocation.d.ts +1 -1
- package/dist/vue-hooks/browser/useMediaSession.d.ts +1 -1
- package/dist/vue-hooks/browser/useMicrophone.d.ts +1 -1
- package/dist/vue-hooks/browser/useNetwork.d.ts +1 -1
- package/dist/vue-hooks/browser/useOrientation.d.ts +1 -1
- package/dist/vue-hooks/browser/usePageVisibility.d.ts +1 -1
- package/dist/vue-hooks/browser/useScreenOrientation.d.ts +1 -1
- package/dist/vue-hooks/browser/useScreenWakeLock.d.ts +1 -1
- package/dist/vue-hooks/browser/useShare.d.ts +1 -1
- package/dist/vue-hooks/browser/useVibration.d.ts +1 -1
- package/dist/vue-hooks/dom/useAutoUpdate.d.ts +1 -1
- package/dist/vue-hooks/dom/useClickOutside.d.ts +1 -1
- package/dist/vue-hooks/dom/useDraggable.d.ts +4 -4
- package/dist/vue-hooks/dom/useEventListener.d.ts +1 -1
- package/dist/vue-hooks/dom/useKeyboard.d.ts +29 -0
- package/dist/vue-hooks/dom/useKeyboard.js +129 -0
- package/dist/vue-hooks/dom/useKeyboard.js.map +1 -0
- package/dist/vue-hooks/dom/useResizable.d.ts +8 -3
- package/dist/vue-hooks/history/useDebouncedRefHistory.d.ts +1 -1
- package/dist/vue-hooks/history/useManualRefHistory.d.ts +1 -1
- package/dist/vue-hooks/history/useRefHistory.d.ts +1 -1
- package/dist/vue-hooks/state/injectLocal.d.ts +1 -1
- package/dist/vue-hooks/state/provideLocal.d.ts +1 -1
- package/dist/vue-hooks/state/useAsyncState.d.ts +1 -1
- package/dist/vue-hooks/state/useCounter.d.ts +1 -1
- package/dist/vue-hooks/state/useFileUpload.d.ts +23 -0
- package/dist/vue-hooks/state/useFileUpload.js +93 -0
- package/dist/vue-hooks/state/useFileUpload.js.map +1 -0
- package/dist/vue-hooks/state/useToggle.d.ts +1 -1
- package/dist/vue-hooks/time/useInterval.d.ts +1 -1
- package/dist/vue-hooks/time/useTimeout.d.ts +1 -1
- package/dist/vue-hooks/worker/useWebWorker.d.ts +4 -4
- package/dist/vue-hooks/worker/useWorkerFunction.d.ts +4 -4
- package/dist/vue-hooks/worker/useWorkerPool.d.ts +4 -4
- package/package.json +1 -1
- package/types/vue.d.ts +1 -1
- package/dist/functions/algorithm/lcsVisual.d.ts +0 -6
- package/dist/functions/algorithm/lcsVisual.js +0 -88
- package/dist/functions/algorithm/lcsVisual.js.map +0 -1
- package/dist/functions/algorithm/mergeSortVisual.d.ts +0 -5
- package/dist/functions/algorithm/mergeSortVisual.js +0 -103
- package/dist/functions/algorithm/mergeSortVisual.js.map +0 -1
- package/dist/functions/algorithm/nQueensVisual.d.ts +0 -14
- package/dist/functions/algorithm/nQueensVisual.js +0 -94
- package/dist/functions/algorithm/nQueensVisual.js.map +0 -1
- package/dist/functions/algorithm/numIslandsVisual.d.ts +0 -17
- package/dist/functions/algorithm/numIslandsVisual.js +0 -102
- package/dist/functions/algorithm/numIslandsVisual.js.map +0 -1
- package/dist/functions/algorithm/quickSortVisual.d.ts +0 -18
- package/dist/functions/algorithm/quickSortVisual.js +0 -104
- package/dist/functions/algorithm/quickSortVisual.js.map +0 -1
- package/dist/functions/browser/detectDevice.d.ts +0 -10
- package/dist/functions/browser/detectDevice.js +0 -49
- package/dist/functions/browser/detectDevice.js.map +0 -1
- package/dist/functions/cookie/getCookie.d.ts +0 -5
- package/dist/functions/cookie/getCookie.js +0 -14
- package/dist/functions/cookie/getCookie.js.map +0 -1
- package/dist/functions/cookie/removeCookie.d.ts +0 -8
- package/dist/functions/cookie/removeCookie.js +0 -12
- package/dist/functions/cookie/removeCookie.js.map +0 -1
- package/dist/functions/cookie/setCookie.d.ts +0 -11
- package/dist/functions/cookie/setCookie.js +0 -23
- package/dist/functions/cookie/setCookie.js.map +0 -1
- package/dist/functions/data-structures/EventEmitter.d.ts +0 -32
- package/dist/functions/data-structures/EventEmitter.js +0 -108
- package/dist/functions/data-structures/EventEmitter.js.map +0 -1
- package/dist/functions/data-structures/MyPromise.d.ts +0 -32
- package/dist/functions/data-structures/MyPromise.js +0 -254
- package/dist/functions/data-structures/MyPromise.js.map +0 -1
- package/dist/functions/reactive/useReactiveCookie.d.ts +0 -19
- package/dist/functions/reactive/useReactiveCookie.js +0 -84
- package/dist/functions/reactive/useReactiveCookie.js.map +0 -1
- package/dist/hooks/useClickOutside.d.ts +0 -12
- package/dist/hooks/useClickOutside.js +0 -16
- package/dist/hooks/useClickOutside.js.map +0 -1
- package/dist/hooks/useClipboard.d.ts +0 -20
- package/dist/hooks/useClipboard.js +0 -33
- package/dist/hooks/useClipboard.js.map +0 -1
- package/dist/hooks/useCounter.d.ts +0 -19
- package/dist/hooks/useCounter.js +0 -44
- package/dist/hooks/useCounter.js.map +0 -1
- package/dist/hooks/useEventListener.d.ts +0 -14
- package/dist/hooks/useEventListener.js +0 -18
- package/dist/hooks/useEventListener.js.map +0 -1
- package/dist/hooks/useInterval.d.ts +0 -19
- package/dist/hooks/useInterval.js +0 -33
- package/dist/hooks/useInterval.js.map +0 -1
- package/dist/hooks/useTimeout.d.ts +0 -20
- package/dist/hooks/useTimeout.js +0 -40
- package/dist/hooks/useTimeout.js.map +0 -1
- package/dist/hooks/useToggle.d.ts +0 -15
- package/dist/hooks/useToggle.js +0 -23
- package/dist/hooks/useToggle.js.map +0 -1
- package/dist/reactive/createGlobalState.d.ts +0 -2
- package/dist/reactive/createGlobalState.js +0 -11
- package/dist/reactive/createGlobalState.js.map +0 -1
- package/dist/reactive/createSharedComposable.d.ts +0 -2
- package/dist/reactive/createSharedComposable.js +0 -13
- package/dist/reactive/createSharedComposable.js.map +0 -1
- package/dist/reactive/errorManager.d.ts +0 -63
- package/dist/reactive/errorManager.js +0 -199
- package/dist/reactive/errorManager.js.map +0 -1
- package/dist/reactive/i18n.d.ts +0 -27
- package/dist/reactive/i18n.js +0 -119
- package/dist/reactive/i18n.js.map +0 -1
- package/dist/reactive/permission.d.ts +0 -40
- package/dist/reactive/permission.js +0 -189
- package/dist/reactive/permission.js.map +0 -1
- package/dist/reactive/pinia.d.ts +0 -52
- package/dist/reactive/pinia.js +0 -183
- package/dist/reactive/pinia.js.map +0 -1
- package/dist/reactive/useAltool.d.ts +0 -39
- package/dist/reactive/useAltool.js +0 -350
- package/dist/reactive/useAltool.js.map +0 -1
- package/dist/reactive/useCache.d.ts +0 -18
- package/dist/reactive/useCache.js +0 -82
- package/dist/reactive/useCache.js.map +0 -1
- package/dist/reactive/useLocalStorage.d.ts +0 -8
- package/dist/reactive/useLocalStorage.js +0 -101
- package/dist/reactive/useLocalStorage.js.map +0 -1
- package/dist/reactive/usePluginSystem.d.ts +0 -11
- package/dist/reactive/usePluginSystem.js +0 -34
- package/dist/reactive/usePluginSystem.js.map +0 -1
- package/dist/reactive/useSessionStorage.d.ts +0 -8
- package/dist/reactive/useSessionStorage.js +0 -101
- package/dist/reactive/useSessionStorage.js.map +0 -1
- package/dist/reactive/useStorage.d.ts +0 -13
- package/dist/reactive/useStorage.js +0 -62
- package/dist/reactive/useStorage.js.map +0 -1
- package/dist/reactive/useStorageWithIndexedDB.d.ts +0 -8
- package/dist/reactive/useStorageWithIndexedDB.js +0 -132
- package/dist/reactive/useStorageWithIndexedDB.js.map +0 -1
- package/references/vue.d.ts +0 -242
package/README.md
CHANGED
|
@@ -71,11 +71,16 @@ playground/ # 测试和验证环境
|
|
|
71
71
|
#### 规则 1:不直接导入第三方库
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
// ❌ 错误:直接导入 Vue
|
|
74
|
+
// ❌ 错误:直接导入 Vue 运行时函数
|
|
75
75
|
import { ref, watch } from 'vue'
|
|
76
76
|
|
|
77
|
-
// ✅
|
|
77
|
+
// ✅ 正确:只能使用 import type 导入 Vue 类型
|
|
78
|
+
import type { Ref } from 'vue'
|
|
79
|
+
|
|
80
|
+
// ❌ 错误:不能从 references 导入 Vue 类型
|
|
78
81
|
import type { Ref } from '../../references/vue.d'
|
|
82
|
+
|
|
83
|
+
// 注意:Vue 类型只能从 'vue' 包直接导入,因为 Vue 的类型系统过于复杂,难以在 references 中完整定义
|
|
79
84
|
```
|
|
80
85
|
|
|
81
86
|
#### 规则 2:只传入实际使用的函数,不传入整个模块
|
|
@@ -121,7 +126,7 @@ export function myFunction(deps: MyFunctionDeps) {
|
|
|
121
126
|
}
|
|
122
127
|
```
|
|
123
128
|
|
|
124
|
-
#### 规则 4:类型定义在 references 中,使用 typeof
|
|
129
|
+
#### 规则 4:类型定义在 references 中,使用 typeof 或索引访问提取(Vue 类型除外)
|
|
125
130
|
|
|
126
131
|
```typescript
|
|
127
132
|
// ❌ 错误:在函数中定义类型
|
|
@@ -139,6 +144,24 @@ export interface MyFunctionDeps {
|
|
|
139
144
|
}
|
|
140
145
|
```
|
|
141
146
|
|
|
147
|
+
**Vue 类型特殊规则:**
|
|
148
|
+
|
|
149
|
+
Vue 的类型系统过于复杂,难以在 `references/` 中完整定义,因此 Vue 类型只能从 `'vue'` 包直接导入:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// ✅ 正确:Vue 类型只能从 'vue' 包直接导入
|
|
153
|
+
import type { Ref, Component, VNode } from 'vue'
|
|
154
|
+
|
|
155
|
+
export interface MyFunctionDeps {
|
|
156
|
+
ref: <T>(value: T) => Ref<T>
|
|
157
|
+
component: Component
|
|
158
|
+
node: VNode
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ❌ 错误:不能从 references 导入 Vue 类型
|
|
162
|
+
import type { Ref } from '../../references/vue.d' // Vue 没有 references 文件
|
|
163
|
+
```
|
|
164
|
+
|
|
142
165
|
#### 规则 5:每个函数维护自己完整的依赖,不要分散
|
|
143
166
|
|
|
144
167
|
```typescript
|
|
@@ -169,9 +192,13 @@ export function myFunction(path: string, deps: MyFunctionDeps) {
|
|
|
169
192
|
|
|
170
193
|
不仅是 Node.js 和浏览器 API,第三方 SDK 对象(Vue、微信、UniApp 等)也要遵循同样的规则。
|
|
171
194
|
|
|
195
|
+
**Vue 特殊说明:**
|
|
196
|
+
- Vue 类型只能通过 `import type {} from 'vue'` 导入,不能从 `references/` 导入
|
|
197
|
+
- Vue 运行时函数仍然需要通过依赖注入传入,不能直接导入
|
|
198
|
+
|
|
172
199
|
```typescript
|
|
173
200
|
// ❌ 错误:传入整个 Vue 运行时
|
|
174
|
-
import type { VueRuntime } from '
|
|
201
|
+
import type { VueRuntime } from 'vue'
|
|
175
202
|
|
|
176
203
|
export interface DynamicMountOptions {
|
|
177
204
|
vue: VueRuntime // 包含很多未使用的方法
|
|
@@ -182,8 +209,8 @@ export function dynamicMount(options: DynamicMountOptions) {
|
|
|
182
209
|
options.vue.render(...)
|
|
183
210
|
}
|
|
184
211
|
|
|
185
|
-
// ✅
|
|
186
|
-
import type { VueRuntime } from '
|
|
212
|
+
// ✅ 正确:只传入使用的函数,类型从 'vue' 导入
|
|
213
|
+
import type { VueRuntime } from 'vue'
|
|
187
214
|
|
|
188
215
|
export interface DynamicMountDeps {
|
|
189
216
|
createVNode: VueRuntime['createVNode']
|
|
@@ -279,6 +306,11 @@ export async function buildProject(
|
|
|
279
306
|
|
|
280
307
|
**references/** 目录定义环境API的抽象类型(接口、类型别名等),所有基础类型都应在此定义:
|
|
281
308
|
|
|
309
|
+
**注意:Vue 类型例外**
|
|
310
|
+
- Vue 的类型系统过于复杂,难以在 `references/` 中完整定义
|
|
311
|
+
- Vue 类型只能从 `'vue'` 包直接导入,使用 `import type {} from 'vue'`
|
|
312
|
+
- Vue 运行时函数仍然需要通过依赖注入传入,不能直接导入
|
|
313
|
+
|
|
282
314
|
```typescript
|
|
283
315
|
// references/node.d.ts
|
|
284
316
|
export interface FileSystem {
|
|
@@ -314,13 +346,6 @@ export interface Document {
|
|
|
314
346
|
head: HTMLElement
|
|
315
347
|
}
|
|
316
348
|
|
|
317
|
-
// references/vue.d.ts
|
|
318
|
-
export interface Ref<T = any> {
|
|
319
|
-
value: T
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export type InjectionKey<T> = symbol
|
|
323
|
-
|
|
324
349
|
// references/timer.d.ts
|
|
325
350
|
export declare const setTimeout: (callback: (...args: any[]) => void, ms?: number, ...args: any[]) => any
|
|
326
351
|
export declare const clearTimeout: (timeoutId: any) => void
|
|
@@ -372,9 +397,9 @@ const result = await buildProject(options, {
|
|
|
372
397
|
|
|
373
398
|
// 浏览器 Vue 环境
|
|
374
399
|
import { ref, shallowRef, watch } from 'vue'
|
|
375
|
-
import { useAsyncState } from 'shared/hooks/useAsyncState'
|
|
400
|
+
import { useAsyncState } from 'shared/vue-hooks/state/useAsyncState'
|
|
376
401
|
|
|
377
|
-
// 传入 Vue 运行时函数和浏览器 API
|
|
402
|
+
// 传入 Vue 运行时函数和浏览器 API(注意:运行时函数通过依赖注入传入,类型通过 import type 导入)
|
|
378
403
|
const { state, isLoading } = useAsyncState(
|
|
379
404
|
async () => fetch('/api/data').then(r => r.json()),
|
|
380
405
|
{
|
|
@@ -382,7 +407,7 @@ const { state, isLoading } = useAsyncState(
|
|
|
382
407
|
delay: 1000
|
|
383
408
|
},
|
|
384
409
|
{
|
|
385
|
-
vue: { ref, shallowRef, watch }, // Vue Composition API
|
|
410
|
+
vue: { ref, shallowRef, watch }, // Vue Composition API 运行时函数
|
|
386
411
|
host: { setTimeout } // 浏览器定时器
|
|
387
412
|
}
|
|
388
413
|
)
|
|
@@ -703,19 +728,15 @@ export function newFunction(
|
|
|
703
728
|
**Vue Hooks 开发模板:**
|
|
704
729
|
|
|
705
730
|
```typescript
|
|
706
|
-
// src/hooks/useNewHook.ts
|
|
707
|
-
|
|
731
|
+
// src/vue-hooks/useNewHook.ts
|
|
732
|
+
// ✅ Vue 类型只能从 'vue' 直接导入
|
|
733
|
+
import type { Ref } from 'vue'
|
|
708
734
|
import type { setTimeout } from '../../references/timer.d'
|
|
709
|
-
|
|
710
|
-
export interface VueCompositionAPI {
|
|
711
|
-
ref: <T>(value: T) => Ref<T>
|
|
712
|
-
watch: (source: any, callback: () => void, options?: any) => void
|
|
713
|
-
onMounted: (fn: () => void) => void
|
|
714
|
-
onUnmounted: (fn: () => void) => void
|
|
715
|
-
}
|
|
735
|
+
import type { VueCompositionAPI } from '../../types/vue.d'
|
|
716
736
|
|
|
717
737
|
export interface NewHookEnvironment {
|
|
718
|
-
|
|
738
|
+
/** Vue Composition API 运行时函数(通过依赖注入传入) */
|
|
739
|
+
vue: Pick<Required<VueCompositionAPI>, 'ref' | 'watch' | 'onMounted' | 'onUnmounted'>
|
|
719
740
|
host: {
|
|
720
741
|
setTimeout: typeof setTimeout
|
|
721
742
|
clearTimeout: typeof clearTimeout
|
|
@@ -750,13 +771,15 @@ export function useNewHook<T>(
|
|
|
750
771
|
在提交代码前,请确保:
|
|
751
772
|
|
|
752
773
|
#### ✅ 依赖注入检查
|
|
753
|
-
- [ ] 没有直接 `import`
|
|
774
|
+
- [ ] 没有直接 `import` 第三方库的运行时函数(如 `import { ref } from 'vue'`)
|
|
775
|
+
- [ ] Vue 类型只能使用 `import type {} from 'vue'` 导入,不能从 `references/` 导入
|
|
754
776
|
- [ ] 没有直接使用全局对象(`window`、`document`、`global`、`process`)
|
|
755
777
|
- [ ] 所有环境依赖都通过 `deps` 或 `env` 参数传入
|
|
756
778
|
- [ ] 使用 `deps.` 前缀访问依赖,没有解构
|
|
757
779
|
|
|
758
780
|
#### ✅ 类型定义检查
|
|
759
|
-
- [ ] 类型从 `references/` 导入,使用 `import type
|
|
781
|
+
- [ ] 类型从 `references/` 导入,使用 `import type`(Vue 类型除外)
|
|
782
|
+
- [ ] Vue 类型只能从 `'vue'` 包直接导入,使用 `import type {} from 'vue'`
|
|
760
783
|
- [ ] 依赖接口命名为 `{FunctionName}Deps` 或 `{HookName}Environment`
|
|
761
784
|
- [ ] 使用 `Interface['method']` 或 `typeof` 提取类型
|
|
762
785
|
- [ ] 每个依赖都有清晰的 JSDoc 注释
|
|
@@ -816,10 +839,11 @@ npm run publish:major # 主要版本
|
|
|
816
839
|
|
|
817
840
|
### 依赖管理
|
|
818
841
|
|
|
819
|
-
1.
|
|
820
|
-
2.
|
|
821
|
-
3.
|
|
822
|
-
4.
|
|
842
|
+
1. **不导入第三方库运行时函数**:不直接 `import { ref } from 'vue'`,而是通过 `env` 对象传入
|
|
843
|
+
2. **Vue 类型特殊规则**:Vue 类型只能使用 `import type {} from 'vue'` 导入,不能从 `references/` 导入
|
|
844
|
+
3. **不依赖全局对象**:不直接使用 `window`、`document`、`global`
|
|
845
|
+
4. **接口命名规范**:`{FunctionName}Deps`,例如 `BuildProjectDeps`、`ModifyManifestDeps`
|
|
846
|
+
5. **使用 deps. 前缀**:所有依赖访问都使用 `deps.methodName()`,不解构
|
|
823
847
|
|
|
824
848
|
### 测试要求
|
|
825
849
|
|
|
@@ -833,12 +857,13 @@ npm run publish:major # 主要版本
|
|
|
833
857
|
在编写新函数或修改现有函数时,快速检查以下要点:
|
|
834
858
|
|
|
835
859
|
**✅ 6大核心规则:**
|
|
836
|
-
1. ❌
|
|
837
|
-
2. ❌
|
|
838
|
-
3. ❌
|
|
839
|
-
4. ❌
|
|
840
|
-
5. ❌
|
|
841
|
-
6. ❌
|
|
860
|
+
1. ❌ 不直接导入第三方库运行时函数 → ✅ 从 `references/` 导入类型(Vue 类型除外)
|
|
861
|
+
2. ❌ Vue 类型不能从 `references/` 导入 → ✅ 只能使用 `import type {} from 'vue'`
|
|
862
|
+
3. ❌ 不传入整个模块对象 → ✅ 只传入实际使用的函数
|
|
863
|
+
4. ❌ 不解构 deps 对象 → ✅ 使用 `deps.` 前缀访问
|
|
864
|
+
5. ❌ 不重复定义类型 → ✅ 使用 `Interface['method']` 提取
|
|
865
|
+
6. ❌ 不分散依赖到多个参数 → ✅ 统一的 `Deps` 接口
|
|
866
|
+
7. ❌ 第三方 SDK 也不能整个传入 → ✅ Vue、Wx 等也要拆分
|
|
842
867
|
|
|
843
868
|
**✅ 命名规范:**
|
|
844
869
|
- 函数依赖接口:`{FunctionName}Deps`
|
|
@@ -853,23 +878,28 @@ npm run publish:major # 主要版本
|
|
|
853
878
|
|
|
854
879
|
### 常见错误和解决方案
|
|
855
880
|
|
|
856
|
-
#### ❌ 错误 1
|
|
881
|
+
#### ❌ 错误 1:直接导入第三方库运行时函数
|
|
857
882
|
```typescript
|
|
858
|
-
import { ref, watch } from 'vue' // ❌
|
|
883
|
+
import { ref, watch } from 'vue' // ❌ 错误:导入了运行时函数
|
|
859
884
|
```
|
|
860
885
|
**解决方案:**
|
|
861
886
|
```typescript
|
|
862
|
-
|
|
887
|
+
// ✅ 正确:Vue 类型只能从 'vue' 直接导入
|
|
888
|
+
import type { Ref } from 'vue'
|
|
889
|
+
import type { VueCompositionAPI } from '../../types/vue.d'
|
|
863
890
|
|
|
864
|
-
export interface
|
|
865
|
-
|
|
866
|
-
watch: (source: any, callback: () => void) => void
|
|
891
|
+
export interface UseMyHookEnvironment {
|
|
892
|
+
vue: Pick<Required<VueCompositionAPI>, 'ref' | 'watch'>
|
|
867
893
|
}
|
|
868
894
|
|
|
869
|
-
export function useMyHook(env:
|
|
870
|
-
const state = env.vue.ref(0)
|
|
895
|
+
export function useMyHook(env: UseMyHookEnvironment) {
|
|
896
|
+
const state = env.vue.ref(0) // 运行时函数通过依赖注入传入
|
|
871
897
|
env.vue.watch(state, () => {})
|
|
872
898
|
}
|
|
899
|
+
|
|
900
|
+
// 使用时:
|
|
901
|
+
// import { ref, watch } from 'vue'
|
|
902
|
+
// const result = useMyHook({ vue: { ref, watch } })
|
|
873
903
|
```
|
|
874
904
|
|
|
875
905
|
#### ❌ 错误 2:传入整个模块对象
|
|
@@ -942,7 +972,8 @@ export function myFunction(deps: MyFunctionDeps) {
|
|
|
942
972
|
|
|
943
973
|
#### ❌ 错误 6:传入整个第三方 SDK 对象
|
|
944
974
|
```typescript
|
|
945
|
-
|
|
975
|
+
// ❌ 错误:Vue 类型可以从 'vue' 导入,但不能传入整个运行时对象
|
|
976
|
+
import type { VueRuntime } from 'vue'
|
|
946
977
|
import type { Wx } from '../../references/wechat.d'
|
|
947
978
|
|
|
948
979
|
export interface MyFunctionDeps {
|
|
@@ -957,11 +988,12 @@ export function myFunction(deps: MyFunctionDeps) {
|
|
|
957
988
|
```
|
|
958
989
|
**解决方案:**
|
|
959
990
|
```typescript
|
|
960
|
-
|
|
991
|
+
// ✅ 正确:Vue 类型从 'vue' 导入,运行时函数通过依赖注入传入
|
|
992
|
+
import type { VueRuntime } from 'vue'
|
|
961
993
|
import type { Wx } from '../../references/wechat.d'
|
|
962
994
|
|
|
963
995
|
export interface MyFunctionDeps {
|
|
964
|
-
createVNode: VueRuntime['createVNode'] // ✅
|
|
996
|
+
createVNode: VueRuntime['createVNode'] // ✅ 正确:只传入使用的函数
|
|
965
997
|
downloadFile: Wx['downloadFile'] // ✅ 正确
|
|
966
998
|
USER_DATA_PATH: Wx['env']['USER_DATA_PATH'] // ✅ 嵌套属性也要精确提取
|
|
967
999
|
}
|
|
@@ -974,12 +1006,12 @@ export function myFunction(deps: MyFunctionDeps) {
|
|
|
974
1006
|
```
|
|
975
1007
|
|
|
976
1008
|
**常见第三方 SDK 对象拆分:**
|
|
977
|
-
- `VueRuntime` → 只传入 `createVNode`, `render`
|
|
978
|
-
- `Wx` (微信) → 只传入 `downloadFile`, `request`
|
|
979
|
-
- `UniApp` → 只传入 `getCurrentPages`
|
|
980
|
-
- `CryptoJS` → 只传入 `MD5`, `SHA256`
|
|
981
|
-
- `CloudBaseManager` → 只传入 `init`
|
|
982
|
-
- `Sharp` (图像处理) →
|
|
1009
|
+
- `VueRuntime` → 只传入 `createVNode`, `render` 等实际使用的方法(类型用 `import type {} from 'vue'` 导入)
|
|
1010
|
+
- `Wx` (微信) → 只传入 `downloadFile`, `request` 等实际使用的方法(类型从 `references/wechat.d` 导入)
|
|
1011
|
+
- `UniApp` → 只传入 `getCurrentPages` 等实际使用的方法(类型从 `references/uniapp.d` 导入)
|
|
1012
|
+
- `CryptoJS` → 只传入 `MD5`, `SHA256` 等实际使用的方法(类型从 `references/crypto-js.d` 导入)
|
|
1013
|
+
- `CloudBaseManager` → 只传入 `init` 等实际使用的方法(类型从 `references/tencent-cloud.d` 导入)
|
|
1014
|
+
- `Sharp` (图像处理) → 已经是函数,直接作为依赖(类型从 `references/sharp.d` 导入)
|
|
983
1015
|
|
|
984
1016
|
### 文档规范
|
|
985
1017
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DeployOptions, DeployResult, SecretType } from '../../../../types/tencent-cloud.d';
|
|
2
|
+
import type { TencentCloudSecret, CloudBaseManager } from '../../../../references/tencent-cloud.d';
|
|
3
|
+
import type { FileSystem } from '../../../../references/node.d';
|
|
4
|
+
import type { Console } from '../../../../references/console.d';
|
|
5
|
+
export interface DeployTCBDeps {
|
|
6
|
+
existsSync: FileSystem['existsSync'];
|
|
7
|
+
init: CloudBaseManager['init'];
|
|
8
|
+
log: Console['log'];
|
|
9
|
+
error: Console['error'];
|
|
10
|
+
getSecret: (type: SecretType) => TencentCloudSecret | null;
|
|
11
|
+
}
|
|
12
|
+
export declare function deployToTCB(options: DeployOptions, deps: DeployTCBDeps): Promise<DeployResult>;
|
|
13
|
+
export default deployToTCB;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export async function deployToTCB(options, deps) {
|
|
2
|
+
const { localPath, cloudPath = '/', envId, secretType, showProgress = true } = options;
|
|
3
|
+
try {
|
|
4
|
+
if (!deps.existsSync(localPath)) {
|
|
5
|
+
return {
|
|
6
|
+
success: false,
|
|
7
|
+
error: `本地路径不存在: ${localPath}`
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const secret = deps.getSecret(secretType);
|
|
11
|
+
if (!secret || !secret.secretId || !secret.secretKey) {
|
|
12
|
+
return {
|
|
13
|
+
success: false,
|
|
14
|
+
error: `无效的密钥类型: ${secretType}`
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const app = deps.init({
|
|
18
|
+
secretId: secret.secretId,
|
|
19
|
+
secretKey: secret.secretKey,
|
|
20
|
+
envId
|
|
21
|
+
});
|
|
22
|
+
const hosting = app.hosting;
|
|
23
|
+
await hosting.uploadFiles({
|
|
24
|
+
localPath,
|
|
25
|
+
cloudPath,
|
|
26
|
+
onProgress: showProgress ? (progressData) => {
|
|
27
|
+
deps.log(`上传进度: ${progressData.percent}%`);
|
|
28
|
+
} : undefined
|
|
29
|
+
});
|
|
30
|
+
deps.log('文件上传成功');
|
|
31
|
+
return {
|
|
32
|
+
success: true,
|
|
33
|
+
message: '部署成功'
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
38
|
+
deps.error('部署失败:', error);
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: `部署失败: ${errorMessage}`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export default deployToTCB;
|
|
46
|
+
//# sourceMappingURL=deploy.tcb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.tcb.js","sourceRoot":"","sources":["../../../../src/functions/platform/tencent-cloud/deploy.tcb.ts"],"names":[],"mappings":"AAuDA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAsB,EACtB,IAAmB;IAEnB,MAAM,EACJ,SAAS,EACT,SAAS,GAAG,GAAG,EACf,KAAK,EACL,UAAU,EACV,YAAY,GAAG,IAAI,EACpB,GAAG,OAAO,CAAA;IAEX,IAAI,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,SAAS,EAAE;aAC/B,CAAA;QACH,CAAC;QAGD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACzC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACrD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,UAAU,EAAE;aAChC,CAAA;QACH,CAAC;QAGD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK;SACN,CAAC,CAAA;QAGF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;QAG3B,MAAM,OAAO,CAAC,WAAW,CAAC;YACxB,SAAS;YACT,SAAS;YACT,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,YAAgC,EAAE,EAAE;gBAC7D,IAAI,CAAC,GAAG,CAAC,SAAS,YAAY,CAAC,OAAO,GAAG,CAAC,CAAA;YAC5C,CAAC,CAAC,CAAC,CAAC,SAAS;SACf,CAAC,CAAA;QAGF,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAClB,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,MAAM;SAChB,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3E,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC1B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,SAAS,YAAY,EAAE;SAC/B,CAAA;IACH,CAAC;AACH,CAAC;AAQD,eAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const secretMap = {
|
|
2
|
+
personal: {
|
|
3
|
+
secretId: 'AKIDKVQ5VjiQu73j9IBnFRN2QYQ2MQEl22mI',
|
|
4
|
+
secretKey: 'IL7cqoWy94lDsGSXP9gxzkGXcSFrDJ8h',
|
|
5
|
+
},
|
|
6
|
+
individual: {
|
|
7
|
+
secretId: 'AKID2A6oIZcT5TcWBetteARULxKSM1ResARl',
|
|
8
|
+
secretKey: 'INFtISN3VmocDZgYBZicIitpWyEG4f2B',
|
|
9
|
+
},
|
|
10
|
+
enterprise: {
|
|
11
|
+
secretId: 'AKIDRhqpgKn46uVvACzd7ORGTbaLtHSSEn8H',
|
|
12
|
+
secretKey: '95tV4Ql02wpY5QaaOzTlrjOr8OQFsHUW',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
export function getSecret(type) {
|
|
16
|
+
return secretMap[type];
|
|
17
|
+
}
|
|
18
|
+
export default getSecret;
|
|
19
|
+
//# sourceMappingURL=getSecret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSecret.js","sourceRoot":"","sources":["../../../../src/functions/platform/tencent-cloud/getSecret.ts"],"names":[],"mappings":"AAIA,MAAM,SAAS,GAA2C;IACxD,QAAQ,EAAE;QAER,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;IACD,UAAU,EAAE;QAEV,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;IACD,UAAU,EAAE;QAEV,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;CACF,CAAA;AAoCD,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAKD,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { UniAppAndroidBuildOptions, UniAppAndroidBuildResult } from '../../../../../types/uniapp-android-build.d';
|
|
2
|
+
import type { FileSystem, Path, ChildProcess } from '../../../../../references/node.d';
|
|
3
|
+
import type { XMLParserConstructor, XMLSerializerConstructor } from '../../../../../references/xml.d';
|
|
4
|
+
import type { JSON5Parser } from '../../../../../references/json5.d';
|
|
5
|
+
import type { XPath } from '../../../../../references/xpath.d';
|
|
6
|
+
import type { setTimeout } from '../../../../../references/timer.d';
|
|
7
|
+
export interface BuildAndroidAppDeps {
|
|
8
|
+
existsSync: FileSystem['existsSync'];
|
|
9
|
+
readFileSync: FileSystem['readFileSync'];
|
|
10
|
+
writeFileSync: FileSystem['writeFileSync'];
|
|
11
|
+
copyFileSync: FileSystem['copyFileSync'];
|
|
12
|
+
mkdirSync: FileSystem['mkdirSync'];
|
|
13
|
+
readdirSync: FileSystem['readdirSync'];
|
|
14
|
+
statSync: FileSystem['statSync'];
|
|
15
|
+
cp: FileSystem['promises']['cp'];
|
|
16
|
+
join: Path['join'];
|
|
17
|
+
dirname: Path['dirname'];
|
|
18
|
+
basename: Path['basename'];
|
|
19
|
+
exec: ChildProcess['exec'];
|
|
20
|
+
platform: string;
|
|
21
|
+
parse: JSON5Parser['parse'];
|
|
22
|
+
xmlParser: XMLParserConstructor;
|
|
23
|
+
xmlSerializer: XMLSerializerConstructor;
|
|
24
|
+
xpath: XPath;
|
|
25
|
+
setTimeout: typeof setTimeout;
|
|
26
|
+
}
|
|
27
|
+
export declare function buildAndroidApp(options: UniAppAndroidBuildOptions, deps: BuildAndroidAppDeps): Promise<UniAppAndroidBuildResult>;
|