@taole/deploy-helper 0.2.7 → 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.
Files changed (2) hide show
  1. package/index.mjs +48 -13
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -58,11 +58,31 @@ function hasChangeMe(content) {
58
58
  return content.includes("CHANGE_ME");
59
59
  }
60
60
 
61
- async function main() {
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,10 +92,35 @@ 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(); // 当前项目根目录
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",