qdmp-cli 0.1.14 → 0.1.15
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/.claude/settings.local.json +9 -0
- package/actions.js +1 -1
- package/api.js +44 -20
- package/constants.js +2 -9
- package/package.json +1 -1
- package/utils/gitClone.js +3 -10
package/actions.js
CHANGED
|
@@ -125,7 +125,7 @@ export async function uploadAction(option) {
|
|
|
125
125
|
error(`压缩文件 ${localPath} 未生成`);
|
|
126
126
|
}
|
|
127
127
|
// 上传到oss;
|
|
128
|
-
await uploadApp(uploadPath, localPath);
|
|
128
|
+
await uploadApp(appId, uploadPath, localPath, option.env);
|
|
129
129
|
const isAccessible = await isUrlAccessible(url);
|
|
130
130
|
if (!isAccessible) {
|
|
131
131
|
error("上传链接不可用,请检查网络是否正常");
|
package/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getToken, saveToken } from "./utils/authorized.js";
|
|
2
2
|
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
3
4
|
import { promisify } from "util";
|
|
4
5
|
|
|
5
6
|
const readFile = promisify(fs.readFile);
|
|
@@ -104,19 +105,23 @@ export const getUserInfo = async (env = "prod") => {
|
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
107
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @returns {Promise}
|
|
108
|
+
* 获取版本包 PostPolicy 直传凭证
|
|
109
|
+
* @returns {Promise} PostPolicy 参数
|
|
109
110
|
*/
|
|
110
|
-
export const
|
|
111
|
+
export const getVersionUploadPolicy = async (appId, file, env = "prod") => {
|
|
111
112
|
try {
|
|
112
|
-
const result = await request(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
const result = await request(
|
|
114
|
+
"/mp/v1/platform/version/upload-policy",
|
|
115
|
+
{
|
|
116
|
+
method: "POST",
|
|
117
|
+
body: JSON.stringify({ appId, file }),
|
|
118
|
+
},
|
|
119
|
+
env,
|
|
120
|
+
);
|
|
121
|
+
if (result?.data?.host && result?.data?.policy) {
|
|
122
|
+
return result.data;
|
|
118
123
|
} else {
|
|
119
|
-
throw new Error(result
|
|
124
|
+
throw new Error(result?.message || "获取版本包上传凭证失败");
|
|
120
125
|
}
|
|
121
126
|
} catch (error) {
|
|
122
127
|
throw new Error(error?.message);
|
|
@@ -126,20 +131,39 @@ export const getSignInRecords = async (file) => {
|
|
|
126
131
|
* 上传版本
|
|
127
132
|
* @params {string} filename
|
|
128
133
|
*/
|
|
129
|
-
export const uploadApp = async (filename, localPath) => {
|
|
134
|
+
export const uploadApp = async (appId, filename, localPath, env = "prod") => {
|
|
130
135
|
try {
|
|
131
|
-
const signedUrl = await getSignInRecords(filename);
|
|
132
136
|
const fileBuffer = await readFile(localPath);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
if (fileBuffer.length === 0) {
|
|
138
|
+
throw new Error("版本包不能为空");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const uploadPolicy = await getVersionUploadPolicy(appId, filename, env);
|
|
142
|
+
if (fileBuffer.length > uploadPolicy.maxSize) {
|
|
143
|
+
throw new Error(`版本包大小不能超过 ${uploadPolicy.maxSize / 1024 / 1024}M`);
|
|
144
|
+
}
|
|
145
|
+
const form = new FormData();
|
|
146
|
+
form.append("key", uploadPolicy.key);
|
|
147
|
+
form.append("OSSAccessKeyId", uploadPolicy.ossAccessKeyId);
|
|
148
|
+
form.append("policy", uploadPolicy.policy);
|
|
149
|
+
form.append("Signature", uploadPolicy.signature);
|
|
150
|
+
form.append("success_action_status", uploadPolicy.successActionStatus);
|
|
151
|
+
form.append("Content-Type", uploadPolicy.contentType);
|
|
152
|
+
form.append(
|
|
153
|
+
"file",
|
|
154
|
+
new Blob([fileBuffer], { type: uploadPolicy.contentType }),
|
|
155
|
+
path.basename(localPath),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const response = await fetch(uploadPolicy.host, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
body: form,
|
|
139
161
|
});
|
|
140
|
-
if (response.
|
|
141
|
-
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
const detail = await response.text();
|
|
164
|
+
throw new Error(`OSS 上传失败(${response.status})${detail ? `: ${detail}` : ""}`);
|
|
142
165
|
}
|
|
166
|
+
return response;
|
|
143
167
|
} catch (error) {
|
|
144
168
|
throw new Error(error?.message);
|
|
145
169
|
}
|
package/constants.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
export const TEMPLATES = [
|
|
2
2
|
{
|
|
3
3
|
name: "default",
|
|
4
|
-
value: "git@github.com:EchoTechFE/qdmp-taro-template.git",
|
|
5
|
-
desc: "千岛小程序默认模版(2.0)",
|
|
6
|
-
emoji: "🟢",
|
|
7
|
-
fullUrl: true,
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
name: "qdmp",
|
|
11
4
|
value: "frontend/miniapp-taro-template",
|
|
12
|
-
desc: "千岛小程序默认模版
|
|
13
|
-
emoji: "
|
|
5
|
+
desc: "千岛小程序默认模版",
|
|
6
|
+
emoji: "🟢",
|
|
14
7
|
},
|
|
15
8
|
{
|
|
16
9
|
name: "h5",
|
package/package.json
CHANGED
package/utils/gitClone.js
CHANGED
|
@@ -38,13 +38,10 @@ export const download = async (projectName, repo) => {
|
|
|
38
38
|
const clone = async (repo, name) => {
|
|
39
39
|
const spinner = ora("正在拉取项目......").start();
|
|
40
40
|
try {
|
|
41
|
-
const repoUrl = repo.includes(":")
|
|
42
|
-
? repo
|
|
43
|
-
: `git@g.echo.tech:${repo}.git`;
|
|
44
41
|
await new Promise((resolve, reject) => {
|
|
45
42
|
const child = spawn(
|
|
46
43
|
"git",
|
|
47
|
-
["clone", "--depth", "1",
|
|
44
|
+
["clone", "--depth", "1", `git@g.echo.tech:${repo}.git`, name],
|
|
48
45
|
{
|
|
49
46
|
stdio: ["ignore", "pipe", "pipe"],
|
|
50
47
|
env: {
|
|
@@ -58,16 +55,12 @@ const clone = async (repo, name) => {
|
|
|
58
55
|
if (code === 0) {
|
|
59
56
|
resolve();
|
|
60
57
|
} else {
|
|
61
|
-
const isGitHub = repoUrl.includes("github.com");
|
|
62
58
|
reject(
|
|
63
59
|
new Error(
|
|
64
60
|
`git clone 失败 (退出码: ${code}),请检查:\n` +
|
|
65
61
|
` 1. 是否已配置 SSH 密钥:ssh-keygen -t ed25519\n` +
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
` 3. 网络是否能访问 github.com`
|
|
69
|
-
: ` 2. 是否已将公钥添加到 GitLab:cat ~/.ssh/id_ed25519.pub\n` +
|
|
70
|
-
` 3. 网络是否能访问 g.echo.tech`)
|
|
62
|
+
` 2. 是否已将公钥添加到 GitLab:cat ~/.ssh/id_ed25519.pub\n` +
|
|
63
|
+
` 3. 网络是否能访问 g.echo.tech`
|
|
71
64
|
)
|
|
72
65
|
);
|
|
73
66
|
}
|