@taole/deploy-helper 0.2.8 → 0.2.10
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 +24 -6
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { Client } from 'node-scp'
|
|
4
4
|
import fs from 'fs';
|
|
5
|
-
import { join } from "path";
|
|
5
|
+
import { join, basename, dirname } from "path";
|
|
6
6
|
import { simpleGit } from 'simple-git';
|
|
7
7
|
import { homedir } from 'os'
|
|
8
8
|
|
|
9
|
+
const TEST_SERVER_HOST = "192.168.0.35";
|
|
9
10
|
/**
|
|
10
11
|
* 加载配置
|
|
11
12
|
* @returns 配置对象
|
|
@@ -62,7 +63,7 @@ async function getScpClient() {
|
|
|
62
63
|
let scpClient = null;
|
|
63
64
|
// 不能放密码。。残念
|
|
64
65
|
const scpClientConfig = {
|
|
65
|
-
host:
|
|
66
|
+
host: TEST_SERVER_HOST,
|
|
66
67
|
username: 'root',
|
|
67
68
|
tryKeyboard: true,
|
|
68
69
|
}
|
|
@@ -102,7 +103,6 @@ async function main() {
|
|
|
102
103
|
process.exit(0);
|
|
103
104
|
} else if (["scp", "scpevt"].includes(command)) {
|
|
104
105
|
const file = process.argv[3];
|
|
105
|
-
const dest = process.argv[4] || file;
|
|
106
106
|
if (!file) {
|
|
107
107
|
console.log(`file参数不能为空`);
|
|
108
108
|
process.exit(1);
|
|
@@ -114,10 +114,28 @@ async function main() {
|
|
|
114
114
|
console.log(`${srcFilePath}不存在`);
|
|
115
115
|
process.exit(1);
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
if (fs.statSync(srcFilePath).isDirectory()) {
|
|
118
|
+
console.log(`${srcFilePath}是目录, 不支持scp目录`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
// 获取srcFilePath的目录
|
|
122
|
+
const fileDir = dirname(srcFilePath);
|
|
123
|
+
const fileName = basename(srcFilePath);
|
|
124
|
+
const dest = process.argv[4] || fileName;
|
|
125
|
+
if(dest.includes("/") || dest.includes("\\")){
|
|
126
|
+
console.log(`dest不能包含/或\\`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if(workDir !== fileDir){
|
|
131
|
+
console.log(`仅支持scp当前目录下的文件(不带子目录)`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const destPath = "/home/web/website/tuwan_www/templets/static/play/" + (command === 'scp' ? '' : 'events/') + dest;
|
|
118
136
|
|
|
119
137
|
const scpClient = await getScpClient();
|
|
120
|
-
console.log(`scp: ${srcFilePath} -> ${destPath}`);
|
|
138
|
+
console.log(`scp: ${srcFilePath} -> ${TEST_SERVER_HOST}:${destPath}`);
|
|
121
139
|
await scpClient.uploadFile(srcFilePath, destPath);
|
|
122
140
|
console.log(`scp done.`);
|
|
123
141
|
process.exit(0);
|
|
@@ -304,7 +322,7 @@ async function main() {
|
|
|
304
322
|
for (const [src, dest] of Object.entries(syncTestFiles)) {
|
|
305
323
|
const srcPath = join(workDir, src);
|
|
306
324
|
const destPath = "/home/web/website/tuwan_www/templets/static/play/" + dest;
|
|
307
|
-
console.log(`scp: ${srcPath} -> ${destPath}`);
|
|
325
|
+
console.log(`scp: ${srcPath} -> ${TEST_SERVER_HOST}:${destPath}`);
|
|
308
326
|
await scpClient.uploadFile(srcPath, destPath)
|
|
309
327
|
}
|
|
310
328
|
}
|