@taole/deploy-helper 1.0.2 → 1.0.4

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.
Files changed (32) hide show
  1. package/README.md +1 -4
  2. package/index.mjs +2 -39
  3. package/lib/pipelineApi.mjs +17 -16
  4. package/lib/util.mjs +0 -40
  5. package/lib/yunxiaoFlowApi.mjs +115 -0
  6. package/package.json +4 -7
  7. package/lib/offlinePkg.mjs +0 -333
  8. package/lib/upload.js +0 -49
  9. package/modules/alibabacloud-devops-mcp-server/dist/common/errors.js +0 -69
  10. package/modules/alibabacloud-devops-mcp-server/dist/common/modularTemplates.js +0 -483
  11. package/modules/alibabacloud-devops-mcp-server/dist/common/pipelineTemplates.js +0 -19
  12. package/modules/alibabacloud-devops-mcp-server/dist/common/types.js +0 -1119
  13. package/modules/alibabacloud-devops-mcp-server/dist/common/utils.js +0 -353
  14. package/modules/alibabacloud-devops-mcp-server/dist/common/version.js +0 -1
  15. package/modules/alibabacloud-devops-mcp-server/dist/index.js +0 -1067
  16. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/branches.js +0 -144
  17. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/changeRequestComments.js +0 -89
  18. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/changeRequests.js +0 -203
  19. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/compare.js +0 -26
  20. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/files.js +0 -233
  21. package/modules/alibabacloud-devops-mcp-server/dist/operations/codeup/repositories.js +0 -64
  22. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/hostGroup.js +0 -48
  23. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipeline.js +0 -514
  24. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipelineJob.js +0 -113
  25. package/modules/alibabacloud-devops-mcp-server/dist/operations/flow/serviceConnection.js +0 -23
  26. package/modules/alibabacloud-devops-mcp-server/dist/operations/organization/members.js +0 -94
  27. package/modules/alibabacloud-devops-mcp-server/dist/operations/organization/organization.js +0 -73
  28. package/modules/alibabacloud-devops-mcp-server/dist/operations/packages/artifacts.js +0 -64
  29. package/modules/alibabacloud-devops-mcp-server/dist/operations/packages/repositories.js +0 -35
  30. package/modules/alibabacloud-devops-mcp-server/dist/operations/projex/project.js +0 -206
  31. package/modules/alibabacloud-devops-mcp-server/dist/operations/projex/sprint.js +0 -30
  32. package/modules/alibabacloud-devops-mcp-server/dist/operations/projex/workitem.js +0 -264
@@ -1,333 +0,0 @@
1
- import fs from 'fs';
2
- import archiver from 'archiver';
3
- import { join } from "node:path"
4
- import { log, getOssToken, getUserDeployHelperConfig } from './util.mjs';
5
- import { uploadFile } from './upload.js';
6
- import md5File from 'md5-file';
7
-
8
-
9
-
10
- function genArchive(outputPath, dir) {
11
- return new Promise((resolve, reject) => {
12
- const output = fs.createWriteStream(outputPath);
13
- const archive = archiver('zip', {
14
- zlib: { level: 1 } // Sets the compression level.
15
- });
16
- let settled = false;
17
- const onError = (err) => {
18
- if (settled) return;
19
- settled = true;
20
- try {
21
- archive.abort();
22
- } catch {
23
- // ignore
24
- }
25
- output.destroy(err);
26
- reject(err);
27
- };
28
- archive.on('error', onError);
29
- output.on('error', onError);
30
- // 必须等目标文件流关闭后再继续:仅 archive 'finish' 时缓冲区可能尚未完全刷盘,
31
- // 后续 md5/上传会读到缺 END 中央目录的截断 zip(如 ADM-ZIP: No END header found)。
32
- output.on('close', () => {
33
- if (settled) return;
34
- settled = true;
35
- resolve();
36
- });
37
- archive.pipe(output);
38
- archive.directory(dir, false);
39
- archive.finalize();
40
- })
41
- }
42
-
43
- /**
44
- * json配置
45
- * @param {string} workDir 项目工作目录
46
- * @returns {Object|null} 配置
47
- */
48
- export function getJsonConfig(workDir, name) {
49
- const filePath = join(workDir, name);
50
- if (fs.existsSync(filePath)) {
51
- try {
52
- return JSON.parse(fs.readFileSync(filePath, "utf-8"));
53
- } catch (_error) {
54
- // pass
55
- }
56
- }
57
- return null;
58
- }
59
-
60
- /**
61
- * 同步离线包列表到api
62
- * @param {{offlineApi: {get: string, set: string}}} userDeployHelperConfig 用户配置
63
- * @param {"prod"|"test"} mode 部署模式 prod: 线上, test: 测试
64
- * @param {{name: string, remove: boolean}} offlineConfig 离线包配置
65
- * @param {any} packageDescJson 离线包描述json
66
- */
67
- export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packageDescJson) {
68
- // 根据部署模式,决定更新调用哪个接口
69
- const doAction = offlineConfig.remove ? "remove" : "add";
70
- const apiDomain = mode === "prod" ? "https://yapi.tuwan.com" : "https://yapi-test.tuwan.com";
71
- const getPath = userDeployHelperConfig.offlineApi.get;
72
- const setPath = userDeployHelperConfig.offlineApi.set;
73
- const getUrl = `${apiDomain}${getPath}`;
74
- const setUrl = `${apiDomain}${setPath}`;
75
- const envPrefix = `${mode === "prod" ? "线上环境" : "测试环境"}[platform=${offlineConfig.platform}]`;
76
- const nowRes = await fetch(getUrl, {
77
- headers: {
78
- platform: String(offlineConfig.platform),
79
- }
80
- });
81
- const nowData = await nowRes.json();
82
- let needSetData = true;
83
- let finalJsonData = null;
84
- if (!nowData || nowData.error !== 0) {
85
- throw new Error(`获取离线包列表失败, 获取离线包当前配置失败: ${nowData.error_msg || "未知错误"}`);
86
- }
87
- const jsonData = JSON.parse(nowData.data.json || "{}");
88
- finalJsonData = jsonData;
89
- jsonData.packages = jsonData.packages || [];
90
- if (doAction === "add") {
91
- const idx = jsonData.packages.findIndex(item => item.name === offlineConfig.name);
92
- if (idx !== -1) {
93
- log(`离线包${offlineConfig.name}已存在, 更新离线包`);
94
- jsonData.packages[idx] = packageDescJson;
95
- } else {
96
- log(`离线包${offlineConfig.name}不存在, 添加离线包`);
97
- jsonData.packages.push(packageDescJson);
98
- }
99
- } else {
100
- const idx = jsonData.packages.findIndex(item => item.name === offlineConfig.name);
101
- if (idx === -1) {
102
- log(`离线包${offlineConfig.name}不存在, 无需删除`);
103
- needSetData = false;
104
- }
105
- jsonData.packages = jsonData.packages.filter(item => item.name !== offlineConfig.name);
106
- }
107
- jsonData.packages = jsonData.packages.filter(item => item.name);
108
- if (needSetData) {
109
- // console.log('jsonData', jsonData);
110
- var formdata = new FormData();
111
- formdata.append("json", JSON.stringify(jsonData));
112
- const setRes = await fetch(setUrl, {
113
- method: "POST",
114
- body: formdata,
115
- headers: {
116
- platform: String(offlineConfig.platform),
117
- }
118
- });
119
- const setData = await setRes.json();
120
- if (!setData || setData.error !== 0) {
121
- throw new Error(`更新离线包列表失败, 更新离线包当前配置失败: ${setData.error_msg || "未知错误"}`);
122
- }
123
- log(`${envPrefix}离线包列表更新完成: ${JSON.stringify(setData)}`);
124
- // 再次获取列表,确保更新成功
125
- const nowRes2 = await fetch(getUrl, {
126
- headers: {
127
- platform: String(offlineConfig.platform),
128
- }
129
- });
130
- const nowData2 = await nowRes2.json();
131
- if (!nowData2 || nowData2.error !== 0) {
132
- throw new Error(`再次获取离线包列表失败, 获取离线包当前配置失败: ${nowData2.error_msg || "未知错误"}`);
133
- }
134
- finalJsonData = JSON.parse(nowData2.data.json || "{}");
135
- }
136
-
137
- const packages = finalJsonData.packages || [];
138
- console.log(`${envPrefix}当前离线包列表:`, packages.map(item => ({ ...item, items: '省略' + item.items.length + '个条目' })));
139
- }
140
-
141
- /**
142
- * @deprecated 不再需要这个函数, 如果插件使用的是@taole/vite-plugin-dynamic-base, 则不需要这个函数
143
- * hack
144
- * 由于vite-plugin-dynamic-base插件和legacy插件同时使用, 生存的入口文件中代码有点问题,这里直接修改有问题的代码
145
- */
146
- function fixEntryHtml(config, offlineConfig) {
147
- if (!offlineConfig || !config) return;
148
- const entryHtmlPath = join(config.workDir, offlineConfig.distDir, "index.html");
149
- if (!fs.existsSync(entryHtmlPath)) {
150
- throw new Error(`构建产物${entryHtmlPath}不存在`);
151
- }
152
- const markLine = "} else if (item.tagName == 'script') {";
153
- const replaceLine = `} else if (item.tagName == 'script')/*injected by deploy-helper*/{
154
- if(item.attrs.id=='vite-legacy-polyfill')childNode.onload=function(){System.import(window.__dynamic_base__ + document.getElementById('vite-legacy-entry').getAttribute('data-src'))};
155
- `;
156
- let entryHtml = fs.readFileSync(entryHtmlPath, "utf-8");
157
- entryHtml = entryHtml.replace(markLine, replaceLine);
158
- fs.writeFileSync(entryHtmlPath, entryHtml);
159
- }
160
-
161
- /**
162
- * @typedef {Object} CheckOfflinePkgResult
163
- * @property {string} workDir 工作目录
164
- * @property {boolean} canBuild 是否可以构建离线包
165
- * @property {string} errorMsg 错误信息
166
- * @property {function} hookPostBuild 构建后钩子
167
- * @property {function} hookPostDeployTest 部署到测试环境后钩子
168
- * @property {function} hookPostDeployProd 部署到生产环境后钩子
169
- */
170
-
171
- /**
172
- * 在项目构建好之后,将项目打包成离线包,并上传到指定服务器
173
- * @param {Object} config 配置
174
- * @param {string} config.workDir 工作目录
175
- * @param {"prod"|"test"} config.mode 部署模式
176
- * @returns {CheckOfflinePkgResult} 结果
177
- */
178
- export function checkOfflinePkg(config) {
179
- let canBuildOfflinePkg = true;
180
- let errorMsg = "";
181
- const offlineConfig = getJsonConfig(config.workDir, "offline.config.json");
182
- if (offlineConfig) {
183
- offlineConfig.distDir = offlineConfig.distDir || "dist";
184
- offlineConfig.platform = offlineConfig.platform || 3; // 3,4是点点
185
- }
186
- const packageJson = getJsonConfig(config.workDir, "package.json");
187
- const userDeployHelperConfig = getUserDeployHelperConfig();
188
- const distPath = join(config.workDir, offlineConfig && offlineConfig.distDir ? offlineConfig.distDir : "dist");
189
- const allDeps = {
190
- ...packageJson.devDependencies,
191
- ...packageJson.dependencies,
192
- };
193
- const useOldPDB = !!allDeps['vite-plugin-dynamic-base'];
194
-
195
- // 如果offlineConfig.remove为true,则不构建离线包
196
- const willRemovePkg = offlineConfig && offlineConfig.name && offlineConfig.remove === true && offlineConfig.skip !== true;
197
- const willSkip = !offlineConfig || !offlineConfig.name || offlineConfig.skip === true || (offlineConfig.onlyTest === true && config.mode === "prod");
198
- if (willRemovePkg) {
199
- return {
200
- canBuild: true,
201
- errorMsg: "",
202
- hookPostBuild: async () => {
203
- if (useOldPDB) {
204
- fixEntryHtml(config, offlineConfig);
205
- }
206
- log(`开始删除离线包${offlineConfig.name}`);
207
- await syncApi(userDeployHelperConfig, config.mode, offlineConfig, null);
208
- }
209
- }
210
- }
211
- if (!fs.existsSync(distPath)) {
212
- errorMsg = `构建产物${distPath}不存在, 请先构建项目`;
213
- canBuildOfflinePkg = false;
214
- } else if (offlineConfig && !offlineConfig.name) {
215
- errorMsg = "离线包配置文件中未配置name, 请先配置";
216
- canBuildOfflinePkg = false;
217
- } else if (!userDeployHelperConfig || !userDeployHelperConfig.offlineApi || !userDeployHelperConfig.offlineApi.get || !userDeployHelperConfig.offlineApi.set) {
218
- errorMsg = "未配置离线包接口, 请移步看配置文档: https://alidocs.dingtalk.com/i/nodes/R1zknDm0WRkbz13oHn0LDz3ZVBQEx5rG?doc_type=wiki_doc";
219
- canBuildOfflinePkg = false;
220
- } else if (!packageJson) {
221
- errorMsg = "啊没有package.json?";
222
- canBuildOfflinePkg = false;
223
- } else {
224
- if (!allDeps['vite-plugin-dynamic-base'] && !allDeps['@taole/vite-plugin-dynamic-base']) {
225
- errorMsg = "检查到项目中未安装依赖@taole/vite-plugin-dynamic-base, 请先安装依赖并调整构建代码以支持离线化,相关文档:https://alidocs.dingtalk.com/i/nodes/ydxXB52LJqexwD71F9K5XNMrJqjMp697?doc_type=wiki_doc";
226
- canBuildOfflinePkg = false;
227
- }
228
- }
229
- if (willSkip) {
230
- if (!offlineConfig) {
231
- return {
232
- canBuild: false,
233
- errorMsg: ""
234
- }
235
- }
236
- if (offlineConfig.onlyTest === true && config.mode === "prod") {
237
- console.log(`离线包${offlineConfig.name}只用于测试环境, 跳过构建线上环境的离线包构建`);
238
- }
239
- return {
240
- canBuild: true,
241
- errorMsg: "",
242
- hookPostBuild: async () => {
243
- if (useOldPDB) {
244
- fixEntryHtml(config, offlineConfig);
245
- }
246
- }
247
- }
248
- }
249
- let ossToken = "";
250
- if (canBuildOfflinePkg) {
251
- ossToken = getOssToken();
252
- if (!ossToken) {
253
- errorMsg = "获取ossToken失败";
254
- canBuildOfflinePkg = false;
255
- }
256
- }
257
- if (!canBuildOfflinePkg) {
258
- return {
259
- canBuild: false,
260
- errorMsg: errorMsg
261
- }
262
- }
263
- const hookPostBuild = async () => {
264
- if (!offlineConfig || !config) return;
265
- // 在构建完成后,执行一些操作
266
- if (useOldPDB) {
267
- fixEntryHtml(config, offlineConfig);
268
- }
269
- // 开始进行打包流程
270
- const offlinePkgDir = join(config.workDir, "./offlinepkgDist");
271
- if (fs.existsSync(offlinePkgDir)) {
272
- fs.rmSync(offlinePkgDir, { recursive: true });
273
- } else {
274
- fs.mkdirSync(offlinePkgDir, { recursive: true });
275
- }
276
-
277
- const packageDir = join(offlinePkgDir, "./package");
278
- fs.mkdirSync(packageDir, { recursive: true });
279
- // cp dist到offlinepkgDist目录下
280
- fs.cpSync(join(config.workDir, offlineConfig.distDir), join(packageDir, offlineConfig.distDir), { recursive: true });
281
-
282
- const targetArchive = join(offlinePkgDir, `./${packageJson.version}.zip`);
283
- await genArchive(targetArchive, packageDir);
284
- log(`离线包zip包打包完成: ${targetArchive}`);
285
-
286
- const packageDescJson = { // 包描述json,之后会通过接口更新
287
- name: offlineConfig.name,
288
- version: packageJson.version,
289
- md5: "",
290
- packageUrl: "",
291
- items: [],
292
- updateTime: String(Math.floor(Date.now() / 1000)),
293
- cacheTime: offlineConfig.cacheTime || "7200",
294
- isLazy: offlineConfig.isLazy || 0,
295
- openType: offlineConfig.openType || "file",
296
- };
297
- Object.keys(offlineConfig.entry || {}).forEach(key => {
298
- const val = offlineConfig.entry[key];
299
- let vals = [];
300
- if (typeof val === 'string') {
301
- vals.push(val);
302
- } else if (Array.isArray(val)) {
303
- vals = val;
304
- }
305
- vals.forEach(v => {
306
- packageDescJson.items.push({
307
- "path": key,
308
- "mimeType": "text/html",
309
- "remoteUrl": v,
310
- "isEntrance": 1
311
- });
312
- });
313
- });
314
- packageDescJson.md5 = await md5File(targetArchive);
315
- const uploadResult = await uploadFile(ossToken, targetArchive, packageDescJson.md5);
316
- packageDescJson.packageUrl = uploadResult.url;
317
- fs.writeFileSync(join(offlinePkgDir, "./offline.package.json"), JSON.stringify(packageDescJson, null, 2));
318
- log(`离线包描述json写入完成: ${join(offlinePkgDir, "./offline.package.json")}`);
319
-
320
- if (config.mode !== "prod") {
321
- packageDescJson.items.forEach(item => {
322
- item.remoteUrl = item.remoteUrl.replace("https://y.tuwan.com", "https://y-test.tuwan.com");
323
- });
324
- }
325
- await syncApi(userDeployHelperConfig, config.mode, offlineConfig, packageDescJson);
326
- }
327
- return {
328
- canBuild: canBuildOfflinePkg,
329
- errorMsg: errorMsg,
330
- hookPostBuild: hookPostBuild,
331
- }
332
- }
333
-
package/lib/upload.js DELETED
@@ -1,49 +0,0 @@
1
- import OSS from "ali-oss";
2
-
3
-
4
- function UUIDNOCA() {
5
- return "xxxxxxxxxxxxxxxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) {
6
- var r = (Math.random() * 16) | 0;
7
- var v = c === "x" ? r : (r & 0x3) | 0x8;
8
- return v.toString(16);
9
- });
10
- };
11
-
12
- let keyConfig = null;
13
- async function getKeyConfig(ossToken) {
14
- if (keyConfig) {
15
- return keyConfig;
16
- }
17
- const reqUrl = `https://u.tuwan.com/Oss/sts?token=${ossToken}`;
18
- const res = await fetch(reqUrl);
19
- const resText = await res.text();
20
- let fmtJson = resText.substring(1, resText.length - 1).replace("'", '"');
21
- const realData = JSON.parse(fmtJson).data;
22
- keyConfig = realData;
23
- return keyConfig;
24
- }
25
-
26
- let ossClient = null;
27
- async function getUploadConfig(ossToken) {
28
- if (ossClient) {
29
- return ossClient;
30
- }
31
- const keyConfig = await getKeyConfig(ossToken);
32
- ossClient = new OSS({
33
- endpoint: "oss-cn-qingdao.aliyuncs.com",
34
- accessKeyId: keyConfig.AccessKeyId,
35
- accessKeySecret: keyConfig.AccessKeySecret,
36
- bucket: "tuwanpicshare",
37
- stsToken: keyConfig.SecurityToken,
38
- secure: true,
39
- });
40
- return ossClient;
41
- }
42
-
43
- export async function uploadFile(ossToken, filePath, name) {
44
- const str = filePath;
45
- const ext = str.substr(str.lastIndexOf(".") + 1);
46
- const fileName = `offlinepkg/${name || UUIDNOCA()}.${ext}`;
47
- const ossClient = await getUploadConfig(ossToken);
48
- return ossClient.put(fileName, filePath);
49
- }
@@ -1,69 +0,0 @@
1
- export class YunxiaoError extends Error {
2
- status;
3
- response;
4
- constructor(message, status, response) {
5
- super(message);
6
- this.status = status;
7
- this.response = response;
8
- this.name = "YunxiaoError";
9
- }
10
- }
11
- export class YunxiaoValidationError extends YunxiaoError {
12
- constructor(message, status, response) {
13
- super(message, status, response);
14
- this.name = "YunxiaoValidationError";
15
- }
16
- }
17
- export class YunxiaoResourceNotFoundError extends YunxiaoError {
18
- constructor(resource) {
19
- super(`Resource not found: ${resource}`, 404, { message: `${resource} not found` });
20
- this.name = "YunxiaoResourceNotFoundError";
21
- }
22
- }
23
- export class YunxiaoAuthenticationError extends YunxiaoError {
24
- constructor(message = "Authentication failed") {
25
- super(message, 401, { message });
26
- this.name = "YunxiaoAuthenticationError";
27
- }
28
- }
29
- export class YunxiaoPermissionError extends YunxiaoError {
30
- constructor(message = "Insufficient permissions") {
31
- super(message, 403, { message });
32
- this.name = "YunxiaoPermissionError";
33
- }
34
- }
35
- export class YunxiaoRateLimitError extends YunxiaoError {
36
- resetAt;
37
- constructor(message = "Rate limit exceeded", resetAt) {
38
- super(message, 429, { message, reset_at: resetAt.toISOString() });
39
- this.resetAt = resetAt;
40
- this.name = "YunxiaoRateLimitError";
41
- }
42
- }
43
- export class YunxiaoConflictError extends YunxiaoError {
44
- constructor(message) {
45
- super(message, 409, { message });
46
- this.name = "YunxiaoConflictError";
47
- }
48
- }
49
- export function isYunxiaoError(error) {
50
- return error instanceof YunxiaoError;
51
- }
52
- export function createYunxiaoError(status, response) {
53
- switch (status) {
54
- case 401:
55
- return new YunxiaoAuthenticationError(response?.message);
56
- case 403:
57
- return new YunxiaoPermissionError(response?.message);
58
- case 404:
59
- return new YunxiaoResourceNotFoundError(response?.message || "Resource");
60
- case 409:
61
- return new YunxiaoConflictError(response?.message || "Conflict occurred");
62
- case 422:
63
- return new YunxiaoValidationError(response?.message || "Validation failed", status, response);
64
- case 429:
65
- return new YunxiaoRateLimitError(response?.message, new Date(response?.reset_at || Date.now() + 60000));
66
- default:
67
- return new YunxiaoError(response?.message || "Yunxiao API error", status, response);
68
- }
69
- }