@taole/deploy-helper 1.1.8-beta.1 → 1.1.8-beta.2
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/lib/project.mjs +56 -6
- package/package.json +2 -1
package/lib/project.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { simpleGit } from "simple-git";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
|
+
import inquirer from "inquirer";
|
|
5
6
|
import { log, getJsonConfig, runCmdAsync } from "./util.mjs";
|
|
6
7
|
import { getCache as getLoginCache } from "./login.mjs";
|
|
7
8
|
import { genProjectArchiveBuffer } from "./archive.mjs";
|
|
@@ -55,13 +56,36 @@ async function apiDeployProject(name, version, env, userCache) {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
async function
|
|
59
|
+
async function apiGetTemplateProjects(userCache) {
|
|
59
60
|
try {
|
|
61
|
+
const res = await fetch(`${apiHost}/h5projects/template`, {
|
|
62
|
+
headers: {
|
|
63
|
+
Cookie: `Tuwan_Passport=${userCache.Tuwan_Passport}`,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const resJson = await res.json();
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
const error = (resJson && resJson.message) || "获取模板列表失败";
|
|
69
|
+
throw new Error(error);
|
|
70
|
+
}
|
|
71
|
+
if (!Array.isArray(resJson)) {
|
|
72
|
+
throw new Error("获取模板列表失败: 响应格式不正确");
|
|
73
|
+
}
|
|
74
|
+
return resJson;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw new Error(`获取模板列表失败: ${error.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function apiCreateProject(name, userCache, templateId) {
|
|
81
|
+
try {
|
|
82
|
+
const body = { name };
|
|
83
|
+
if (templateId) {
|
|
84
|
+
body.templateId = templateId;
|
|
85
|
+
}
|
|
60
86
|
const res = await fetch(`${apiHost}/h5projects`, {
|
|
61
87
|
method: "POST",
|
|
62
|
-
body: JSON.stringify(
|
|
63
|
-
name: name,
|
|
64
|
-
}),
|
|
88
|
+
body: JSON.stringify(body),
|
|
65
89
|
headers: {
|
|
66
90
|
"Content-Type": "application/json",
|
|
67
91
|
Cookie: `Tuwan_Passport=${userCache.Tuwan_Passport}`,
|
|
@@ -144,7 +168,6 @@ async function apiGetProjectVersion(name, userCache) {
|
|
|
144
168
|
*/
|
|
145
169
|
export const cmdProjectCreate = async () => {
|
|
146
170
|
const name = process.argv[3];
|
|
147
|
-
const projectDir = path.join(process.cwd(), name);
|
|
148
171
|
if (!name) {
|
|
149
172
|
log("请输入项目名称");
|
|
150
173
|
process.exit(1);
|
|
@@ -158,6 +181,7 @@ export const cmdProjectCreate = async () => {
|
|
|
158
181
|
log("项目名称不能是纯数字");
|
|
159
182
|
process.exit(1);
|
|
160
183
|
}
|
|
184
|
+
const projectDir = path.join(process.cwd(), name);
|
|
161
185
|
if (fs.existsSync(projectDir)) {
|
|
162
186
|
log(`项目目录${projectDir}已存在`);
|
|
163
187
|
process.exit(1);
|
|
@@ -167,7 +191,33 @@ export const cmdProjectCreate = async () => {
|
|
|
167
191
|
log("请先登录");
|
|
168
192
|
process.exit(1);
|
|
169
193
|
}
|
|
170
|
-
|
|
194
|
+
|
|
195
|
+
const templates = await apiGetTemplateProjects(userCache);
|
|
196
|
+
if (!templates.length) {
|
|
197
|
+
log("没有可用的项目模板");
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
const templateChoices = templates.map((item) => ({
|
|
201
|
+
name: item.description ? `${item.name} - ${item.description}` : item.name,
|
|
202
|
+
value: item.id,
|
|
203
|
+
}));
|
|
204
|
+
const { templateId } = await inquirer.prompt([
|
|
205
|
+
{
|
|
206
|
+
type: "list",
|
|
207
|
+
name: "templateId",
|
|
208
|
+
message: "请选择项目模板",
|
|
209
|
+
choices: templateChoices,
|
|
210
|
+
},
|
|
211
|
+
]);
|
|
212
|
+
|
|
213
|
+
const selectedTemplate = templates.find((item) => item.id === templateId);
|
|
214
|
+
if (!selectedTemplate) {
|
|
215
|
+
log("选择的项目模板不存在");
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
log(`将以模板: ${selectedTemplate.name} 创建项目`);
|
|
219
|
+
// process.exit(0);
|
|
220
|
+
const createResult = await apiCreateProject(name, userCache, templateId);
|
|
171
221
|
const repoUrl = createResult.repoUrl;
|
|
172
222
|
log(`获得项目仓库地址: ${repoUrl}`);
|
|
173
223
|
const httpRepoUrl = repoUrl + ".git";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taole/deploy-helper",
|
|
3
|
-
"version": "1.1.8-beta.
|
|
3
|
+
"version": "1.1.8-beta.2",
|
|
4
4
|
"description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"archiver": "^7.0.1",
|
|
29
29
|
"form-data": "^4.0.5",
|
|
30
|
+
"inquirer": "^12.11.1",
|
|
30
31
|
"node-scp": "^0.0.25",
|
|
31
32
|
"simple-git": "^3.28.0"
|
|
32
33
|
}
|