@h-ai/deploy 0.1.0-alpha.18 → 0.1.0-alpha.20
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 +22 -4
- package/dist/index.d.ts +24 -150
- package/dist/index.js +259 -101
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
```typescript
|
|
19
19
|
import { deploy } from '@h-ai/deploy'
|
|
20
20
|
|
|
21
|
+
// 可选:从 ~/.hai/credentials.yml 注入 HAI_DEPLOY_* 环境变量
|
|
22
|
+
deploy.credentials.load()
|
|
23
|
+
|
|
21
24
|
// 初始化
|
|
22
25
|
await deploy.init({
|
|
23
26
|
provider: { type: 'vercel', token: 'vel_xxx' },
|
|
@@ -59,13 +62,27 @@ services:
|
|
|
59
62
|
apiKey: ${HAI_DEPLOY_UPSTASH_API_KEY}
|
|
60
63
|
```
|
|
61
64
|
|
|
65
|
+
如需在脚本或 CLI 中显式管理凭证文件,请通过 `deploy.credentials.*` 访问:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
deploy.credentials.load()
|
|
69
|
+
deploy.credentials.save('HAI_DEPLOY_VERCEL_TOKEN', 'vel_xxx')
|
|
70
|
+
deploy.credentials.saveAll({
|
|
71
|
+
HAI_DEPLOY_NEON_API_KEY: 'neon_xxx',
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
> `deploy.scan()` 与 `deploy.credentials.*()` 都是本地文件系统能力,不依赖 `deploy.init()`。
|
|
76
|
+
|
|
62
77
|
## 错误处理
|
|
63
78
|
|
|
64
79
|
```typescript
|
|
80
|
+
import { HaiDeployError } from '@h-ai/deploy'
|
|
81
|
+
|
|
65
82
|
const result = await deploy.deployApp('./apps/my-app')
|
|
66
83
|
if (!result.success) {
|
|
67
84
|
switch (result.error.code) {
|
|
68
|
-
case HaiDeployError.
|
|
85
|
+
case HaiDeployError.AUTH_FAILED.code:
|
|
69
86
|
// Vercel Token 无效
|
|
70
87
|
break
|
|
71
88
|
case HaiDeployError.BUILD_FAILED.code:
|
|
@@ -80,10 +97,11 @@ if (!result.success) {
|
|
|
80
97
|
| 错误码 | code | 说明 |
|
|
81
98
|
| --------------------------------- | ---------------- | ------------ |
|
|
82
99
|
| `HaiDeployError.DEPLOY_FAILED` | `hai:deploy:001` | 部署失败 |
|
|
83
|
-
| `HaiDeployError.BUILD_FAILED` | `hai:deploy:
|
|
84
|
-
| `HaiDeployError.AUTH_FAILED` | `hai:deploy:
|
|
85
|
-
| `HaiDeployError.PROVISION_FAILED` | `hai:deploy:
|
|
100
|
+
| `HaiDeployError.BUILD_FAILED` | `hai:deploy:003` | 构建失败 |
|
|
101
|
+
| `HaiDeployError.AUTH_FAILED` | `hai:deploy:006` | 认证失败 |
|
|
102
|
+
| `HaiDeployError.PROVISION_FAILED` | `hai:deploy:007` | 资源开通失败 |
|
|
86
103
|
| `HaiDeployError.NOT_INITIALIZED` | `hai:deploy:010` | 未初始化 |
|
|
104
|
+
| `HaiDeployError.ENV_VAR_FAILED` | `hai:deploy:011` | 环境变量失败 |
|
|
87
105
|
|
|
88
106
|
## 测试
|
|
89
107
|
|
package/dist/index.d.ts
CHANGED
|
@@ -51,66 +51,6 @@ type DeployConfig = z.infer<typeof DeployConfigSchema>;
|
|
|
51
51
|
/** 部署配置输入类型(用户输入) */
|
|
52
52
|
type DeployConfigInput = z.input<typeof DeployConfigSchema>;
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* @h-ai/deploy — 凭证管理
|
|
56
|
-
*
|
|
57
|
-
* 管理全局凭证文件 `~/.hai/credentials.yml`。 CLI 在加载 `_deploy.yml` 之前调用 `loadCredentials()` 将凭证注入 process.env, 使 core 的 `interpolateEnv()` 能自动解析 `${HAI_DEPLOY_*}` 变量。
|
|
58
|
-
* @module deploy-credentials
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 获取凭证文件路径
|
|
63
|
-
*
|
|
64
|
-
* @returns `~/.hai/credentials.yml` 的绝对路径
|
|
65
|
-
*/
|
|
66
|
-
declare function getCredentialsPath(): string;
|
|
67
|
-
/**
|
|
68
|
-
* 加载全局凭证文件并注入到 process.env
|
|
69
|
-
*
|
|
70
|
-
* 读取 `~/.hai/credentials.yml` 中的所有键值对,
|
|
71
|
-
* 将每个 key-value 设置到 `process.env` 中,
|
|
72
|
-
* 使后续 core 配置加载时自动解析 `${HAI_DEPLOY_*}` 变量。
|
|
73
|
-
*
|
|
74
|
-
* @returns 成功返回加载的凭证键名列表
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* const result = loadCredentials()
|
|
79
|
-
* if (result.success) {
|
|
80
|
-
* console.log(`Loaded ${result.data.length} credentials`)
|
|
81
|
-
* }
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
declare function loadCredentials(): HaiResult<string[]>;
|
|
85
|
-
/**
|
|
86
|
-
* 保存单个凭证到全局凭证文件
|
|
87
|
-
*
|
|
88
|
-
* 读取已有凭证 → 合并新凭证 → 写回文件。已有同名 key 会被覆盖。
|
|
89
|
-
*
|
|
90
|
-
* @param key - 环境变量名(如 HAI_DEPLOY_VERCEL_TOKEN)
|
|
91
|
-
* @param value - 凭证值
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```ts
|
|
95
|
-
* saveCredential('HAI_DEPLOY_VERCEL_TOKEN', 'vel_xxx')
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
declare function saveCredential(key: string, value: string): HaiResult<void>;
|
|
99
|
-
/**
|
|
100
|
-
* 批量保存凭证到全局凭证文件
|
|
101
|
-
*
|
|
102
|
-
* @param entries - 凭证键值对
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```ts
|
|
106
|
-
* saveCredentials({
|
|
107
|
-
* HAI_DEPLOY_VERCEL_TOKEN: 'vel_xxx',
|
|
108
|
-
* HAI_DEPLOY_NEON_API_KEY: 'neon_xxx',
|
|
109
|
-
* })
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
declare function saveCredentials(entries: Record<string, string>): HaiResult<void>;
|
|
113
|
-
|
|
114
54
|
declare const HaiDeployError: {
|
|
115
55
|
readonly DEPLOY_FAILED: _h_ai_core.HaiErrorDef;
|
|
116
56
|
readonly PROJECT_CREATE_FAILED: _h_ai_core.HaiErrorDef;
|
|
@@ -121,8 +61,8 @@ declare const HaiDeployError: {
|
|
|
121
61
|
readonly PROVISION_FAILED: _h_ai_core.HaiErrorDef;
|
|
122
62
|
readonly ADAPTER_MISSING: _h_ai_core.HaiErrorDef;
|
|
123
63
|
readonly SCAN_FAILED: _h_ai_core.HaiErrorDef;
|
|
124
|
-
readonly ENV_VAR_FAILED: _h_ai_core.HaiErrorDef;
|
|
125
64
|
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
65
|
+
readonly ENV_VAR_FAILED: _h_ai_core.HaiErrorDef;
|
|
126
66
|
readonly UNSUPPORTED_TYPE: _h_ai_core.HaiErrorDef;
|
|
127
67
|
readonly CONFIG_ERROR: _h_ai_core.HaiErrorDef;
|
|
128
68
|
readonly CREDENTIAL_ERROR: _h_ai_core.HaiErrorDef;
|
|
@@ -198,69 +138,6 @@ interface ProvisionResult {
|
|
|
198
138
|
/** 资源标识信息(如项目名、数据库名等),用于日志和展示 */
|
|
199
139
|
resourceInfo: string;
|
|
200
140
|
}
|
|
201
|
-
/**
|
|
202
|
-
* 部署平台 Provider 接口(Vercel / Cloudflare Pages 等)
|
|
203
|
-
*
|
|
204
|
-
* 通过工厂函数创建(如 `createVercelProvider()`),负责将构建产物部署到目标平台。
|
|
205
|
-
*/
|
|
206
|
-
interface DeployProvider {
|
|
207
|
-
/** Provider 名称 */
|
|
208
|
-
readonly name: string;
|
|
209
|
-
/**
|
|
210
|
-
* 验证凭证有效性
|
|
211
|
-
*
|
|
212
|
-
* @param token - 平台 API Token
|
|
213
|
-
* @returns 用户信息摘要(如邮箱/用户名)
|
|
214
|
-
*/
|
|
215
|
-
authenticate: (token: string) => Promise<HaiResult<string>>;
|
|
216
|
-
/**
|
|
217
|
-
* 创建平台项目(幂等:已存在则返回现有项目 ID)
|
|
218
|
-
*
|
|
219
|
-
* @param projectName - 项目名称
|
|
220
|
-
* @returns 项目 ID
|
|
221
|
-
*/
|
|
222
|
-
createProject: (projectName: string) => Promise<HaiResult<string>>;
|
|
223
|
-
/**
|
|
224
|
-
* 批量设置项目环境变量
|
|
225
|
-
*
|
|
226
|
-
* @param projectId - 平台项目 ID
|
|
227
|
-
* @param envVars - 环境变量键值对
|
|
228
|
-
*/
|
|
229
|
-
setEnvVars: (projectId: string, envVars: Record<string, string>) => Promise<HaiResult<void>>;
|
|
230
|
-
/**
|
|
231
|
-
* 上传构建产物并触发部署
|
|
232
|
-
*
|
|
233
|
-
* @param projectId - 平台项目 ID
|
|
234
|
-
* @param outputDir - 构建产物目录(如 .vercel/output/)
|
|
235
|
-
* @returns 部署结果
|
|
236
|
-
*/
|
|
237
|
-
deploy: (projectId: string, outputDir: string) => Promise<HaiResult<DeployResult>>;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* 基础设施服务 Provisioner 接口(Neon / Upstash / R2 / Resend / Aliyun)
|
|
241
|
-
*
|
|
242
|
-
* 通过工厂函数创建(如 `createNeonProvisioner(config)`),负责开通/验证云服务。
|
|
243
|
-
*/
|
|
244
|
-
interface ServiceProvisioner {
|
|
245
|
-
/** Provisioner 名称 */
|
|
246
|
-
readonly name: string;
|
|
247
|
-
/** 对应的服务类型 */
|
|
248
|
-
readonly serviceType: ServiceType;
|
|
249
|
-
/**
|
|
250
|
-
* 验证凭证有效性
|
|
251
|
-
*
|
|
252
|
-
* @param credentials - 凭证键值对
|
|
253
|
-
* @returns 账户标识信息
|
|
254
|
-
*/
|
|
255
|
-
authenticate: (credentials: Record<string, string>) => Promise<HaiResult<string>>;
|
|
256
|
-
/**
|
|
257
|
-
* 开通/查找服务资源(幂等:按项目名查找已有资源)
|
|
258
|
-
*
|
|
259
|
-
* @param projectName - 项目名称,用作资源命名
|
|
260
|
-
* @returns 开通结果(含环境变量映射)
|
|
261
|
-
*/
|
|
262
|
-
provision: (projectName: string) => Promise<HaiResult<ProvisionResult>>;
|
|
263
|
-
}
|
|
264
141
|
/** 部署选项 */
|
|
265
142
|
interface DeployAppOptions {
|
|
266
143
|
/** 项目名称(默认从 package.json name 提取) */
|
|
@@ -270,12 +147,28 @@ interface DeployAppOptions {
|
|
|
270
147
|
/** 是否跳过构建 */
|
|
271
148
|
skipBuild?: boolean;
|
|
272
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Deploy 凭证文件操作。
|
|
152
|
+
*
|
|
153
|
+
* 这些方法仅操作 `~/.hai/credentials.yml`,不依赖 `deploy.init()`。
|
|
154
|
+
*/
|
|
155
|
+
interface DeployCredentialOperations {
|
|
156
|
+
/** 获取凭证文件绝对路径。 */
|
|
157
|
+
getPath: () => string;
|
|
158
|
+
/** 加载凭证文件并注入 `process.env`。 */
|
|
159
|
+
load: () => HaiResult<string[]>;
|
|
160
|
+
/** 保存单个凭证。 */
|
|
161
|
+
save: (key: string, value: string) => HaiResult<void>;
|
|
162
|
+
/** 批量保存凭证。 */
|
|
163
|
+
saveAll: (entries: Record<string, string>) => HaiResult<void>;
|
|
164
|
+
}
|
|
273
165
|
/**
|
|
274
166
|
* Deploy 模块功能接口
|
|
275
167
|
*
|
|
276
168
|
* 提供自动化部署的完整 API:
|
|
169
|
+
* - `deploy.credentials.*()` — 凭证文件读写(不依赖 init)
|
|
277
170
|
* - `deploy.init()` — 初始化(加载配置、创建 Provider 和 Provisioner)
|
|
278
|
-
* - `deploy.scan()` —
|
|
171
|
+
* - `deploy.scan()` — 扫描应用依赖(纯文件系统能力,不依赖 init)
|
|
279
172
|
* - `deploy.provisionAll()` — 开通所有已配置的基础设施
|
|
280
173
|
* - `deploy.deployApp()` — 完整部署流程
|
|
281
174
|
* - `deploy.close()` — 关闭模块
|
|
@@ -293,6 +186,8 @@ interface DeployAppOptions {
|
|
|
293
186
|
* ```
|
|
294
187
|
*/
|
|
295
188
|
interface DeployFunctions {
|
|
189
|
+
/** 全局部署凭证文件操作。 */
|
|
190
|
+
readonly credentials: DeployCredentialOperations;
|
|
296
191
|
/** 初始化模块(加载配置、创建 Provider 和 Provisioner 实例) */
|
|
297
192
|
init: (config: DeployConfigInput) => Promise<HaiResult<void>>;
|
|
298
193
|
/** 关闭模块 */
|
|
@@ -302,7 +197,9 @@ interface DeployFunctions {
|
|
|
302
197
|
/** 是否已初始化 */
|
|
303
198
|
readonly isInitialized: boolean;
|
|
304
199
|
/**
|
|
305
|
-
*
|
|
200
|
+
* 扫描应用目录,检测依赖和所需服务。
|
|
201
|
+
*
|
|
202
|
+
* 这是纯文件系统分析能力,不依赖云端认证状态,可在 `deploy.init()` 之前调用。
|
|
306
203
|
*
|
|
307
204
|
* @param appDir - 应用根目录路径
|
|
308
205
|
*/
|
|
@@ -344,27 +241,4 @@ interface DeployFunctions {
|
|
|
344
241
|
*/
|
|
345
242
|
declare const deploy: DeployFunctions;
|
|
346
243
|
|
|
347
|
-
|
|
348
|
-
* @h-ai/deploy — 应用扫描器
|
|
349
|
-
*
|
|
350
|
-
* 扫描应用目录,检测框架类型、模块依赖和所需基础设施。
|
|
351
|
-
* @module deploy-scanner
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* 扫描应用目录,检测框架类型、模块依赖和所需基础设施
|
|
356
|
-
*
|
|
357
|
-
* @param appDir - 应用根目录绝对路径
|
|
358
|
-
* @returns 扫描结果(ScanResult)
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* ```ts
|
|
362
|
-
* const result = await scanApp('/path/to/my-app')
|
|
363
|
-
* if (result.success) {
|
|
364
|
-
* const { appName, isSvelteKit, requiredServices } = result.data
|
|
365
|
-
* }
|
|
366
|
-
* ```
|
|
367
|
-
*/
|
|
368
|
-
declare function scanApp(appDir: string): Promise<HaiResult<ScanResult>>;
|
|
369
|
-
|
|
370
|
-
export { type DeployAppOptions, type DeployConfig, type DeployConfigInput, DeployConfigSchema, type DeployError, type DeployFunctions, type DeployProvider, type DeployResult, HaiDeployError, ProviderConfigSchema, type ProvisionResult, type ScanResult, type ServiceProvisioner, type ServiceType, deploy, getCredentialsPath, loadCredentials, saveCredential, saveCredentials, scanApp };
|
|
244
|
+
export { type DeployAppOptions, type DeployConfig, type DeployConfigInput, DeployConfigSchema, type DeployCredentialOperations, type DeployError, type DeployFunctions, type DeployResult, HaiDeployError, ProviderConfigSchema, type ProvisionResult, type ScanResult, type ServiceType, deploy };
|