@h-ai/deploy 0.1.0-alpha5
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/LICENSE +202 -0
- package/README.md +96 -0
- package/dist/index.d.ts +370 -0
- package/dist/index.js +1270 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [2026] [idealworld.group]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @h-ai/deploy
|
|
2
|
+
|
|
3
|
+
自动化部署模块,支持一键将 SvelteKit 应用部署到 Vercel,并自动开通所需的基础设施服务。
|
|
4
|
+
|
|
5
|
+
## 支持的服务
|
|
6
|
+
|
|
7
|
+
| 服务类型 | Provisioner | 说明 |
|
|
8
|
+
| -------- | ------------- | --------------------- |
|
|
9
|
+
| 部署 | Vercel | SvelteKit 应用部署 |
|
|
10
|
+
| 数据库 | Neon | PostgreSQL Serverless |
|
|
11
|
+
| 缓存 | Upstash | Redis REST API |
|
|
12
|
+
| 存储 | Cloudflare R2 | S3 兼容对象存储 |
|
|
13
|
+
| 邮件 | Resend | 邮件发送 API |
|
|
14
|
+
| 短信 | 阿里云 | 阿里云短信服务 |
|
|
15
|
+
|
|
16
|
+
## 快速开始
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { deploy } from '@h-ai/deploy'
|
|
20
|
+
|
|
21
|
+
// 初始化
|
|
22
|
+
await deploy.init({
|
|
23
|
+
provider: { type: 'vercel', token: 'vel_xxx' },
|
|
24
|
+
services: {
|
|
25
|
+
db: { provisioner: 'neon', apiKey: 'neon_xxx' },
|
|
26
|
+
cache: { provisioner: 'upstash', email: 'a@b.com', apiKey: 'up_xxx' },
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// 扫描应用依赖
|
|
31
|
+
const scan = await deploy.scan('./apps/my-app')
|
|
32
|
+
|
|
33
|
+
// 开通基础设施
|
|
34
|
+
const provisions = await deploy.provisionAll('my-app')
|
|
35
|
+
|
|
36
|
+
// 完整部署
|
|
37
|
+
const result = await deploy.deployApp('./apps/my-app')
|
|
38
|
+
|
|
39
|
+
await deploy.close()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 配置
|
|
43
|
+
|
|
44
|
+
通过 `config/_deploy.yml` 管理 git 安全的配置,密钥存放在 `~/.hai/credentials.yml`:
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
# config/_deploy.yml
|
|
48
|
+
provider:
|
|
49
|
+
type: vercel
|
|
50
|
+
token: ${HAI_DEPLOY_VERCEL_TOKEN}
|
|
51
|
+
|
|
52
|
+
services:
|
|
53
|
+
db:
|
|
54
|
+
provisioner: neon
|
|
55
|
+
apiKey: ${HAI_DEPLOY_NEON_API_KEY}
|
|
56
|
+
cache:
|
|
57
|
+
provisioner: upstash
|
|
58
|
+
email: ${HAI_DEPLOY_UPSTASH_EMAIL}
|
|
59
|
+
apiKey: ${HAI_DEPLOY_UPSTASH_API_KEY}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 错误处理
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const result = await deploy.deployApp('./apps/my-app')
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
switch (result.error.code) {
|
|
68
|
+
case HaiDeployError.PROVIDER_AUTH_FAILED.code:
|
|
69
|
+
// Vercel Token 无效
|
|
70
|
+
break
|
|
71
|
+
case HaiDeployError.BUILD_FAILED.code:
|
|
72
|
+
// 构建失败
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
常用错误码:
|
|
79
|
+
|
|
80
|
+
| 错误码 | code | 说明 |
|
|
81
|
+
| --------------------------------- | ---------------- | ------------ |
|
|
82
|
+
| `HaiDeployError.DEPLOY_FAILED` | `hai:deploy:001` | 部署失败 |
|
|
83
|
+
| `HaiDeployError.BUILD_FAILED` | `hai:deploy:002` | 构建失败 |
|
|
84
|
+
| `HaiDeployError.AUTH_FAILED` | `hai:deploy:005` | 认证失败 |
|
|
85
|
+
| `HaiDeployError.PROVISION_FAILED` | `hai:deploy:006` | 资源开通失败 |
|
|
86
|
+
| `HaiDeployError.NOT_INITIALIZED` | `hai:deploy:010` | 未初始化 |
|
|
87
|
+
|
|
88
|
+
## 测试
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pnpm --filter @h-ai/deploy test
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as _h_ai_core from '@h-ai/core';
|
|
3
|
+
import { HaiResult } from '@h-ai/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @h-ai/deploy — 部署配置 Schema
|
|
7
|
+
*
|
|
8
|
+
* 本文件定义部署模块的错误码、Zod Schema 和配置类型。
|
|
9
|
+
* @module deploy-config
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** 部署平台配置联合类型(后续可扩展更多平台) */
|
|
13
|
+
declare const ProviderConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
14
|
+
type: z.ZodLiteral<"vercel">;
|
|
15
|
+
token: z.ZodString;
|
|
16
|
+
}, z.core.$strip>], "type">;
|
|
17
|
+
/** 部署模块完整配置 Schema */
|
|
18
|
+
declare const DeployConfigSchema: z.ZodObject<{
|
|
19
|
+
provider: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
20
|
+
type: z.ZodLiteral<"vercel">;
|
|
21
|
+
token: z.ZodString;
|
|
22
|
+
}, z.core.$strip>], "type">;
|
|
23
|
+
services: z.ZodOptional<z.ZodObject<{
|
|
24
|
+
db: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
25
|
+
provisioner: z.ZodLiteral<"neon">;
|
|
26
|
+
apiKey: z.ZodString;
|
|
27
|
+
}, z.core.$strip>], "provisioner">>;
|
|
28
|
+
cache: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
29
|
+
provisioner: z.ZodLiteral<"upstash">;
|
|
30
|
+
email: z.ZodString;
|
|
31
|
+
apiKey: z.ZodString;
|
|
32
|
+
}, z.core.$strip>], "provisioner">>;
|
|
33
|
+
storage: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
34
|
+
provisioner: z.ZodLiteral<"cloudflare-r2">;
|
|
35
|
+
accountId: z.ZodString;
|
|
36
|
+
apiToken: z.ZodString;
|
|
37
|
+
}, z.core.$strip>], "provisioner">>;
|
|
38
|
+
email: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
39
|
+
provisioner: z.ZodLiteral<"resend">;
|
|
40
|
+
apiKey: z.ZodString;
|
|
41
|
+
}, z.core.$strip>], "provisioner">>;
|
|
42
|
+
sms: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
43
|
+
provisioner: z.ZodLiteral<"aliyun">;
|
|
44
|
+
accessKeyId: z.ZodString;
|
|
45
|
+
accessKeySecret: z.ZodString;
|
|
46
|
+
}, z.core.$strip>], "provisioner">>;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
/** 部署配置类型(parse 后) */
|
|
50
|
+
type DeployConfig = z.infer<typeof DeployConfigSchema>;
|
|
51
|
+
/** 部署配置输入类型(用户输入) */
|
|
52
|
+
type DeployConfigInput = z.input<typeof DeployConfigSchema>;
|
|
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
|
+
declare const HaiDeployError: {
|
|
115
|
+
readonly DEPLOY_FAILED: _h_ai_core.HaiErrorDef;
|
|
116
|
+
readonly PROJECT_CREATE_FAILED: _h_ai_core.HaiErrorDef;
|
|
117
|
+
readonly BUILD_FAILED: _h_ai_core.HaiErrorDef;
|
|
118
|
+
readonly UPLOAD_FAILED: _h_ai_core.HaiErrorDef;
|
|
119
|
+
readonly AUTH_REQUIRED: _h_ai_core.HaiErrorDef;
|
|
120
|
+
readonly AUTH_FAILED: _h_ai_core.HaiErrorDef;
|
|
121
|
+
readonly PROVISION_FAILED: _h_ai_core.HaiErrorDef;
|
|
122
|
+
readonly ADAPTER_MISSING: _h_ai_core.HaiErrorDef;
|
|
123
|
+
readonly SCAN_FAILED: _h_ai_core.HaiErrorDef;
|
|
124
|
+
readonly ENV_VAR_FAILED: _h_ai_core.HaiErrorDef;
|
|
125
|
+
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
126
|
+
readonly UNSUPPORTED_TYPE: _h_ai_core.HaiErrorDef;
|
|
127
|
+
readonly CONFIG_ERROR: _h_ai_core.HaiErrorDef;
|
|
128
|
+
readonly CREDENTIAL_ERROR: _h_ai_core.HaiErrorDef;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* 部署错误接口
|
|
132
|
+
*
|
|
133
|
+
* 所有部署操作返回的错误都遵循此接口。
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const result = await deploy.deployApp('./apps/my-app')
|
|
138
|
+
* if (!result.success) {
|
|
139
|
+
* const error: DeployError = result.error
|
|
140
|
+
* // 根据 error.code 处理
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
interface DeployError {
|
|
145
|
+
/** 错误定义 */
|
|
146
|
+
def: (typeof HaiDeployError)[keyof typeof HaiDeployError];
|
|
147
|
+
/** 错误消息 */
|
|
148
|
+
message: string;
|
|
149
|
+
/** 原始错误(可选) */
|
|
150
|
+
cause?: unknown;
|
|
151
|
+
}
|
|
152
|
+
/** 基础设施服务类型 */
|
|
153
|
+
type ServiceType = 'db' | 'cache' | 'storage' | 'email' | 'sms';
|
|
154
|
+
/**
|
|
155
|
+
* 应用扫描结果
|
|
156
|
+
*
|
|
157
|
+
* 由 scanner 分析应用目录后返回,描述应用的框架类型、依赖和部署需求。
|
|
158
|
+
*/
|
|
159
|
+
interface ScanResult {
|
|
160
|
+
/** 应用名称(来自 package.json name) */
|
|
161
|
+
appName: string;
|
|
162
|
+
/** 是否为 SvelteKit 项目 */
|
|
163
|
+
isSvelteKit: boolean;
|
|
164
|
+
/** 目标平台 adapter 是否已安装(如 @sveltejs/adapter-vercel) */
|
|
165
|
+
adapterInstalled: boolean;
|
|
166
|
+
/** 检测到的模块依赖需要的服务列表 */
|
|
167
|
+
requiredServices: ServiceType[];
|
|
168
|
+
/** 构建命令 */
|
|
169
|
+
buildCommand: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 部署结果
|
|
173
|
+
*
|
|
174
|
+
* 包含部署后的访问 URL、状态和已设置的环境变量。
|
|
175
|
+
*/
|
|
176
|
+
interface DeployResult {
|
|
177
|
+
/** 部署后的访问 URL */
|
|
178
|
+
url: string;
|
|
179
|
+
/** 部署 ID */
|
|
180
|
+
deploymentId: string;
|
|
181
|
+
/** 部署状态 */
|
|
182
|
+
status: 'ready' | 'building' | 'error';
|
|
183
|
+
/** 已设置的环境变量名列表 */
|
|
184
|
+
envVarsSet: string[];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 基础设施开通结果
|
|
188
|
+
*
|
|
189
|
+
* 由 Provisioner 开通服务后返回,包含要注入到部署平台的环境变量。
|
|
190
|
+
*/
|
|
191
|
+
interface ProvisionResult {
|
|
192
|
+
/** 服务类型 */
|
|
193
|
+
serviceType: ServiceType;
|
|
194
|
+
/** Provisioner 名称 */
|
|
195
|
+
provisionerName: string;
|
|
196
|
+
/** 要注入到部署平台的环境变量 */
|
|
197
|
+
envVars: Record<string, string>;
|
|
198
|
+
/** 资源标识信息(如项目名、数据库名等),用于日志和展示 */
|
|
199
|
+
resourceInfo: string;
|
|
200
|
+
}
|
|
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
|
+
/** 部署选项 */
|
|
265
|
+
interface DeployAppOptions {
|
|
266
|
+
/** 项目名称(默认从 package.json name 提取) */
|
|
267
|
+
projectName?: string;
|
|
268
|
+
/** 是否跳过基础设施开通 */
|
|
269
|
+
skipProvision?: boolean;
|
|
270
|
+
/** 是否跳过构建 */
|
|
271
|
+
skipBuild?: boolean;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Deploy 模块功能接口
|
|
275
|
+
*
|
|
276
|
+
* 提供自动化部署的完整 API:
|
|
277
|
+
* - `deploy.init()` — 初始化(加载配置、创建 Provider 和 Provisioner)
|
|
278
|
+
* - `deploy.scan()` — 扫描应用依赖
|
|
279
|
+
* - `deploy.provisionAll()` — 开通所有已配置的基础设施
|
|
280
|
+
* - `deploy.deployApp()` — 完整部署流程
|
|
281
|
+
* - `deploy.close()` — 关闭模块
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* import { deploy } from '@h-ai/deploy'
|
|
286
|
+
*
|
|
287
|
+
* await deploy.init({ provider: { type: 'vercel', token: 'xxx' } })
|
|
288
|
+
* const result = await deploy.deployApp('./apps/my-app')
|
|
289
|
+
* if (result.success) {
|
|
290
|
+
* console.log(`Deployed: ${result.data.url}`)
|
|
291
|
+
* }
|
|
292
|
+
* await deploy.close()
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
interface DeployFunctions {
|
|
296
|
+
/** 初始化模块(加载配置、创建 Provider 和 Provisioner 实例) */
|
|
297
|
+
init: (config: DeployConfigInput) => Promise<HaiResult<void>>;
|
|
298
|
+
/** 关闭模块 */
|
|
299
|
+
close: () => Promise<void>;
|
|
300
|
+
/** 当前配置 */
|
|
301
|
+
readonly config: DeployConfig | null;
|
|
302
|
+
/** 是否已初始化 */
|
|
303
|
+
readonly isInitialized: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* 扫描应用目录,检测依赖和所需服务
|
|
306
|
+
*
|
|
307
|
+
* @param appDir - 应用根目录路径
|
|
308
|
+
*/
|
|
309
|
+
scan: (appDir: string) => Promise<HaiResult<ScanResult>>;
|
|
310
|
+
/**
|
|
311
|
+
* 对所有已配置的 Provisioner 执行基础设施开通
|
|
312
|
+
*
|
|
313
|
+
* @param projectName - 用于资源命名的项目名
|
|
314
|
+
* @returns 所有 Provisioner 的结果列表
|
|
315
|
+
*/
|
|
316
|
+
provisionAll: (projectName: string) => Promise<HaiResult<ProvisionResult[]>>;
|
|
317
|
+
/**
|
|
318
|
+
* 执行完整部署流程(provision → build → deploy)
|
|
319
|
+
*
|
|
320
|
+
* @param appDir - 应用根目录路径
|
|
321
|
+
* @param options - 部署选项
|
|
322
|
+
*/
|
|
323
|
+
deployApp: (appDir: string, options?: DeployAppOptions) => Promise<HaiResult<DeployResult>>;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @h-ai/deploy — 模块主入口
|
|
328
|
+
*
|
|
329
|
+
* 提供 deploy 单例对象,暴露完整的自动化部署 API。
|
|
330
|
+
* @module deploy-main
|
|
331
|
+
*/
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Deploy 模块单例
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* import { deploy } from '@h-ai/deploy'
|
|
339
|
+
*
|
|
340
|
+
* await deploy.init({ provider: { type: 'vercel', token: 'xxx' } })
|
|
341
|
+
* const result = await deploy.deployApp('./apps/my-app')
|
|
342
|
+
* await deploy.close()
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
declare const deploy: DeployFunctions;
|
|
346
|
+
|
|
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 };
|