@taole/deploy-helper 1.0.0 → 1.0.1
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 +8 -8
- package/index.mjs +557 -557
- package/lib/login.mjs +167 -167
- package/lib/offlinePkg.mjs +314 -314
- package/lib/pipelineApi.mjs +364 -364
- package/lib/project.mjs +345 -345
- package/lib/upload.js +49 -49
- package/lib/util.mjs +101 -101
- package/package.json +36 -36
package/lib/upload.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
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
|
+
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
|
+
}
|
package/lib/util.mjs
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { join } from "node:path"
|
|
3
|
-
import { homedir } from "node:os"
|
|
4
|
-
import { exec } from 'child_process';
|
|
5
|
-
|
|
6
|
-
let _isDebug = false;
|
|
7
|
-
export function setDebug(debug) {
|
|
8
|
-
_isDebug = debug;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isDebug() {
|
|
12
|
-
return _isDebug;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function log(...args) {
|
|
16
|
-
if (_isDebug) {
|
|
17
|
-
// 打印时间
|
|
18
|
-
console.log(`[${new Date().toLocaleTimeString()}]`, ...args);
|
|
19
|
-
} else {
|
|
20
|
-
console.log(...args);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getOssToken() {
|
|
25
|
-
let token = "";
|
|
26
|
-
token = process.env.TW_DH_OSS_TOKEN || ""
|
|
27
|
-
if (token) {
|
|
28
|
-
log(`将使用来自环境变量TW_DH_OSS_TOKEN的token`);
|
|
29
|
-
return token;
|
|
30
|
-
}
|
|
31
|
-
const userDeployHelperDir = join(homedir(), "deploy-helper.config.json");
|
|
32
|
-
if (fs.existsSync(userDeployHelperDir)) {
|
|
33
|
-
try {
|
|
34
|
-
const userDeployHelperConfig = JSON.parse(fs.readFileSync(userDeployHelperDir, "utf-8"));
|
|
35
|
-
token = userDeployHelperConfig.ossToken || "";
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.error(`读取${userDeployHelperDir}配置失败: ${error}`);
|
|
38
|
-
}
|
|
39
|
-
if (token) {
|
|
40
|
-
log(`将使用来自${userDeployHelperDir}的ossToken`);
|
|
41
|
-
return token;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return token;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 读取dh用户配置文件deploy-helper.config.json
|
|
49
|
-
* @returns {Object|null} 用户配置
|
|
50
|
-
*/
|
|
51
|
-
export function getUserDeployHelperConfig() {
|
|
52
|
-
const userDeployHelperDir = join(homedir(), "deploy-helper.config.json");
|
|
53
|
-
if (fs.existsSync(userDeployHelperDir)) {
|
|
54
|
-
try {
|
|
55
|
-
const userDeployHelperConfig = JSON.parse(fs.readFileSync(userDeployHelperDir, "utf-8"));
|
|
56
|
-
return userDeployHelperConfig;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error(`读取${userDeployHelperDir}配置失败: ${error}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* json配置
|
|
65
|
-
* @param {string} workDir 项目工作目录
|
|
66
|
-
* @returns {Object|null} 配置
|
|
67
|
-
*/
|
|
68
|
-
export function getJsonConfig(workDir, name) {
|
|
69
|
-
const filePath = join(workDir, name);
|
|
70
|
-
if (fs.existsSync(filePath)) {
|
|
71
|
-
try {
|
|
72
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
73
|
-
} catch (_error) {
|
|
74
|
-
// pass
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 执行命令
|
|
82
|
-
* @param {*} cmd string 命令
|
|
83
|
-
* @param {*} options { cwd: string, env: object } 可选参数
|
|
84
|
-
* @returns Promise<string> 命令执行结果
|
|
85
|
-
*/
|
|
86
|
-
export async function runCmdAsync(cmd, options) {
|
|
87
|
-
log("执行命令:", cmd);
|
|
88
|
-
return new Promise((resolve, reject) => {
|
|
89
|
-
exec(cmd, options, (error, stdout, stderr) => {
|
|
90
|
-
if (error) {
|
|
91
|
-
reject(error);
|
|
92
|
-
}
|
|
93
|
-
if(stdout){
|
|
94
|
-
console.log(stdout);
|
|
95
|
-
}
|
|
96
|
-
if (stderr) {
|
|
97
|
-
console.error(stderr);
|
|
98
|
-
}
|
|
99
|
-
resolve(stdout);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
import { homedir } from "node:os"
|
|
4
|
+
import { exec } from 'child_process';
|
|
5
|
+
|
|
6
|
+
let _isDebug = false;
|
|
7
|
+
export function setDebug(debug) {
|
|
8
|
+
_isDebug = debug;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isDebug() {
|
|
12
|
+
return _isDebug;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function log(...args) {
|
|
16
|
+
if (_isDebug) {
|
|
17
|
+
// 打印时间
|
|
18
|
+
console.log(`[${new Date().toLocaleTimeString()}]`, ...args);
|
|
19
|
+
} else {
|
|
20
|
+
console.log(...args);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getOssToken() {
|
|
25
|
+
let token = "";
|
|
26
|
+
token = process.env.TW_DH_OSS_TOKEN || ""
|
|
27
|
+
if (token) {
|
|
28
|
+
log(`将使用来自环境变量TW_DH_OSS_TOKEN的token`);
|
|
29
|
+
return token;
|
|
30
|
+
}
|
|
31
|
+
const userDeployHelperDir = join(homedir(), "deploy-helper.config.json");
|
|
32
|
+
if (fs.existsSync(userDeployHelperDir)) {
|
|
33
|
+
try {
|
|
34
|
+
const userDeployHelperConfig = JSON.parse(fs.readFileSync(userDeployHelperDir, "utf-8"));
|
|
35
|
+
token = userDeployHelperConfig.ossToken || "";
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(`读取${userDeployHelperDir}配置失败: ${error}`);
|
|
38
|
+
}
|
|
39
|
+
if (token) {
|
|
40
|
+
log(`将使用来自${userDeployHelperDir}的ossToken`);
|
|
41
|
+
return token;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return token;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 读取dh用户配置文件deploy-helper.config.json
|
|
49
|
+
* @returns {Object|null} 用户配置
|
|
50
|
+
*/
|
|
51
|
+
export function getUserDeployHelperConfig() {
|
|
52
|
+
const userDeployHelperDir = join(homedir(), "deploy-helper.config.json");
|
|
53
|
+
if (fs.existsSync(userDeployHelperDir)) {
|
|
54
|
+
try {
|
|
55
|
+
const userDeployHelperConfig = JSON.parse(fs.readFileSync(userDeployHelperDir, "utf-8"));
|
|
56
|
+
return userDeployHelperConfig;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(`读取${userDeployHelperDir}配置失败: ${error}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* json配置
|
|
65
|
+
* @param {string} workDir 项目工作目录
|
|
66
|
+
* @returns {Object|null} 配置
|
|
67
|
+
*/
|
|
68
|
+
export function getJsonConfig(workDir, name) {
|
|
69
|
+
const filePath = join(workDir, name);
|
|
70
|
+
if (fs.existsSync(filePath)) {
|
|
71
|
+
try {
|
|
72
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
73
|
+
} catch (_error) {
|
|
74
|
+
// pass
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 执行命令
|
|
82
|
+
* @param {*} cmd string 命令
|
|
83
|
+
* @param {*} options { cwd: string, env: object } 可选参数
|
|
84
|
+
* @returns Promise<string> 命令执行结果
|
|
85
|
+
*/
|
|
86
|
+
export async function runCmdAsync(cmd, options) {
|
|
87
|
+
log("执行命令:", cmd);
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
exec(cmd, options, (error, stdout, stderr) => {
|
|
90
|
+
if (error) {
|
|
91
|
+
reject(error);
|
|
92
|
+
}
|
|
93
|
+
if(stdout){
|
|
94
|
+
console.log(stdout);
|
|
95
|
+
}
|
|
96
|
+
if (stderr) {
|
|
97
|
+
console.error(stderr);
|
|
98
|
+
}
|
|
99
|
+
resolve(stdout);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
102
|
}
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@taole/deploy-helper",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
|
|
5
|
-
"main": "index.mjs",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "node index.mjs",
|
|
9
|
-
"test": "node test.mjs"
|
|
10
|
-
},
|
|
11
|
-
"bin": {
|
|
12
|
-
"deploy-helper": "index.mjs",
|
|
13
|
-
"dh": "index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public",
|
|
17
|
-
"registry": "https://registry.npmjs.org/"
|
|
18
|
-
},
|
|
19
|
-
"files": [
|
|
20
|
-
"index.mjs",
|
|
21
|
-
"lib",
|
|
22
|
-
"modules/alibabacloud-devops-mcp-server/dist"
|
|
23
|
-
],
|
|
24
|
-
"keywords": [],
|
|
25
|
-
"author": "",
|
|
26
|
-
"license": "ISC",
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"ali-oss": "^6.23.0",
|
|
29
|
-
"alibabacloud-devops-mcp-server": "*",
|
|
30
|
-
"archiver": "^7.0.1",
|
|
31
|
-
"form-data": "^4.0.5",
|
|
32
|
-
"md5-file": "^5.0.0",
|
|
33
|
-
"node-scp": "^0.0.25",
|
|
34
|
-
"simple-git": "^3.28.0"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@taole/deploy-helper",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
|
|
5
|
+
"main": "index.mjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "node index.mjs",
|
|
9
|
+
"test": "node test.mjs"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"deploy-helper": "index.mjs",
|
|
13
|
+
"dh": "index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"index.mjs",
|
|
21
|
+
"lib",
|
|
22
|
+
"modules/alibabacloud-devops-mcp-server/dist"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"ali-oss": "^6.23.0",
|
|
29
|
+
"alibabacloud-devops-mcp-server": "*",
|
|
30
|
+
"archiver": "^7.0.1",
|
|
31
|
+
"form-data": "^4.0.5",
|
|
32
|
+
"md5-file": "^5.0.0",
|
|
33
|
+
"node-scp": "^0.0.25",
|
|
34
|
+
"simple-git": "^3.28.0"
|
|
35
|
+
}
|
|
36
|
+
}
|