@taole/deploy-helper 0.2.6 → 0.2.8
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/index.mjs +50 -15
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -34,7 +34,7 @@ async function initConfigJson() {
|
|
|
34
34
|
"dest": "../Static_2025",
|
|
35
35
|
"commit": "feat:部署资源文件",
|
|
36
36
|
"files": {
|
|
37
|
-
"dist/assets": "CHANGE_ME"
|
|
37
|
+
"dist/assets": "CHANGE_ME"
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"entry": {
|
|
@@ -58,11 +58,31 @@ function hasChangeMe(content) {
|
|
|
58
58
|
return content.includes("CHANGE_ME");
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
async function
|
|
61
|
+
async function getScpClient() {
|
|
62
|
+
let scpClient = null;
|
|
63
|
+
// 不能放密码。。残念
|
|
64
|
+
const scpClientConfig = {
|
|
65
|
+
host: '192.168.0.35',
|
|
66
|
+
username: 'root',
|
|
67
|
+
tryKeyboard: true,
|
|
68
|
+
}
|
|
69
|
+
const sshKeyPath = join(homedir(), ".ssh/id_rsa");
|
|
70
|
+
if (fs.existsSync(sshKeyPath)) {
|
|
71
|
+
scpClientConfig.privateKey = fs.readFileSync(sshKeyPath, "utf-8");
|
|
72
|
+
} else {
|
|
73
|
+
console.log(`${sshKeyPath}不存在, 建议配置本机ssh免密登录, 参考地址:https://foochane.cn/article/2019061601.html`);
|
|
74
|
+
}
|
|
75
|
+
scpClient = await Client(scpClientConfig);
|
|
76
|
+
return scpClient;
|
|
77
|
+
}
|
|
62
78
|
|
|
79
|
+
|
|
80
|
+
async function main() {
|
|
81
|
+
// console.log(`process.argv: ${process.argv[2]} ${process.argv[3]} ${process.argv[4]}`);
|
|
82
|
+
// return;
|
|
63
83
|
// other commands
|
|
64
84
|
let command = process.argv[2];
|
|
65
|
-
if (!["init", "prod", "test"].includes(command)) {
|
|
85
|
+
if (!["init", "prod", "test", "scp", "scpevt"].includes(command)) {
|
|
66
86
|
command = "help";
|
|
67
87
|
}
|
|
68
88
|
|
|
@@ -72,16 +92,41 @@ async function main() {
|
|
|
72
92
|
console.log(`command: init 初始化配置`);
|
|
73
93
|
console.log(`command: prod 生产环境部署`);
|
|
74
94
|
console.log(`command: test 测试环境部署`);
|
|
95
|
+
console.log(`command: scp {file} 复制文件{file}到OfficialSite测试服务器{file}`);
|
|
96
|
+
console.log(`command: scp {file} {dest} 复制文件{file}到OfficialSite测试服务器{dest}`);
|
|
97
|
+
console.log(`command: scpevt {file} 复制文件{file}到events测试服务器{file}`);
|
|
98
|
+
console.log(`command: scpevt {file} {dest} 复制文件{file}到events测试服务器{dest}`);
|
|
75
99
|
process.exit(0);
|
|
76
100
|
} else if (command === "init") {
|
|
77
101
|
await initConfigJson();
|
|
78
102
|
process.exit(0);
|
|
103
|
+
} else if (["scp", "scpevt"].includes(command)) {
|
|
104
|
+
const file = process.argv[3];
|
|
105
|
+
const dest = process.argv[4] || file;
|
|
106
|
+
if (!file) {
|
|
107
|
+
console.log(`file参数不能为空`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
const workDir = process.cwd(); // 当前项目根目录
|
|
111
|
+
|
|
112
|
+
const srcFilePath = join(workDir, file);
|
|
113
|
+
if (!fs.existsSync(srcFilePath)) {
|
|
114
|
+
console.log(`${srcFilePath}不存在`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
const destPath = "/home/web/website/tuwan_www/templets/static/play/" + (command === 'scp' ? '' : 'events/') + dest;
|
|
118
|
+
|
|
119
|
+
const scpClient = await getScpClient();
|
|
120
|
+
console.log(`scp: ${srcFilePath} -> ${destPath}`);
|
|
121
|
+
await scpClient.uploadFile(srcFilePath, destPath);
|
|
122
|
+
console.log(`scp done.`);
|
|
123
|
+
process.exit(0);
|
|
79
124
|
}
|
|
80
125
|
try {
|
|
81
126
|
const workDir = process.cwd(); // 当前项目根目录
|
|
82
127
|
const mode = process.argv[2] === 'prod' ? 'prod' : 'test'; // 部署环境
|
|
83
128
|
console.log(`deploy mode: ${mode}`);
|
|
84
|
-
console.log(`
|
|
129
|
+
console.log(`workDir: ${workDir}`);
|
|
85
130
|
|
|
86
131
|
// 读取配置
|
|
87
132
|
const config = await loadConfig();
|
|
@@ -255,17 +300,7 @@ async function main() {
|
|
|
255
300
|
// 8 测试环境将entry scp至测试环境
|
|
256
301
|
if (mode === 'test' && config.testSync) {
|
|
257
302
|
const syncTestFiles = config.testSync;
|
|
258
|
-
|
|
259
|
-
const scpClientConfig = {
|
|
260
|
-
host: '192.168.0.35',
|
|
261
|
-
username: 'root',
|
|
262
|
-
tryKeyboard: true,
|
|
263
|
-
}
|
|
264
|
-
const sshKeyPath = join(homedir(), ".ssh/id_rsa");
|
|
265
|
-
if (fs.existsSync(sshKeyPath)) {
|
|
266
|
-
scpClientConfig.privateKey = fs.readFileSync(sshKeyPath, "utf-8");
|
|
267
|
-
}
|
|
268
|
-
const scpClient = await Client(scpClientConfig);
|
|
303
|
+
const scpClient = await getScpClient();
|
|
269
304
|
for (const [src, dest] of Object.entries(syncTestFiles)) {
|
|
270
305
|
const srcPath = join(workDir, src);
|
|
271
306
|
const destPath = "/home/web/website/tuwan_www/templets/static/play/" + dest;
|