@infinity-cli/ipublish 1.2.3 → 1.3.0
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/dist/command/config.d.ts +14 -4
- package/dist/command/config.js +7 -2
- package/dist/command/upload.js +69 -31
- package/package.json +4 -4
- package/readme.md +5 -0
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/command/config.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { Static } from '@sinclair/typebox';
|
|
2
1
|
import { RuntimeConfig } from '@infinity-cli/shared';
|
|
2
|
+
import { Static } from '@sinclair/typebox';
|
|
3
3
|
declare const TypeBox_PublishConfig: import("@sinclair/typebox").TObject<{
|
|
4
|
+
jumpIp: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
5
|
+
jumpUser: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
jumpLoginType: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"password">, import("@sinclair/typebox").TLiteral<"privateKey">]>>;
|
|
7
|
+
jumpPassword: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
|
+
jumpPrivateKey: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
4
9
|
ip: import("@sinclair/typebox").TString;
|
|
5
10
|
user: import("@sinclair/typebox").TString;
|
|
6
11
|
loginType: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"password">, import("@sinclair/typebox").TLiteral<"privateKey">]>>;
|
|
@@ -11,16 +16,21 @@ declare const TypeBox_PublishConfig: import("@sinclair/typebox").TObject<{
|
|
|
11
16
|
cmd: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
12
17
|
cwd: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
13
18
|
}>;
|
|
14
|
-
export type Type_PublishConfig = Static<typeof TypeBox_PublishConfig>;
|
|
19
|
+
export declare type Type_PublishConfig = Static<typeof TypeBox_PublishConfig>;
|
|
15
20
|
export declare const runtimeConfig: RuntimeConfig<{
|
|
16
|
-
|
|
21
|
+
jumpIp?: string | undefined;
|
|
22
|
+
jumpUser?: string | undefined;
|
|
23
|
+
jumpLoginType?: "password" | "privateKey" | undefined;
|
|
17
24
|
password?: string | undefined;
|
|
18
25
|
privateKey?: string | undefined;
|
|
26
|
+
jumpPassword?: string | undefined;
|
|
27
|
+
jumpPrivateKey?: string | undefined;
|
|
28
|
+
loginType?: "password" | "privateKey" | undefined;
|
|
19
29
|
cmd?: string | undefined;
|
|
20
30
|
cwd?: string | undefined;
|
|
21
31
|
ip: string;
|
|
22
32
|
user: string;
|
|
23
|
-
from:
|
|
33
|
+
from: import("@sinclair/typebox").StaticArray<import("@sinclair/typebox").TString>;
|
|
24
34
|
to: string;
|
|
25
35
|
}>;
|
|
26
36
|
export {};
|
package/dist/command/config.js
CHANGED
|
@@ -4,10 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.runtimeConfig = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const typebox_1 = require("@sinclair/typebox");
|
|
9
7
|
const shared_1 = require("@infinity-cli/shared");
|
|
8
|
+
const typebox_1 = require("@sinclair/typebox");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const TypeBox_PublishConfig = typebox_1.Type.Object({
|
|
11
|
+
jumpIp: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
12
|
+
jumpUser: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
13
|
+
jumpLoginType: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.Literal('password'), typebox_1.Type.Literal('privateKey')])),
|
|
14
|
+
jumpPassword: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
15
|
+
jumpPrivateKey: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
11
16
|
ip: typebox_1.Type.String(),
|
|
12
17
|
user: typebox_1.Type.String(),
|
|
13
18
|
loginType: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.Literal('password'), typebox_1.Type.Literal('privateKey')])),
|
package/dist/command/upload.js
CHANGED
|
@@ -18,43 +18,82 @@ const node_ssh_1 = require("node-ssh");
|
|
|
18
18
|
const ora_1 = __importDefault(require("ora"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const rimraf_1 = __importDefault(require("rimraf"));
|
|
21
|
+
const ssh2_1 = require("ssh2");
|
|
21
22
|
const util_1 = require("../util");
|
|
22
23
|
const config_1 = require("./config");
|
|
23
24
|
const uploadRemoteWithConfig = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
25
|
let spinner;
|
|
25
|
-
const { ip, user, loginType, password, privateKey, from, to, cmd, cwd } = config;
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
const { jumpIp, jumpUser, jumpLoginType, jumpPassword, jumpPrivateKey, ip, user, loginType, password, privateKey, from, to, cmd, cwd, } = config;
|
|
27
|
+
if (['', '/'].includes(to.trim())) {
|
|
28
|
+
console.error((0, shared_1.red)('to:不允许在服务器根目录操作'));
|
|
29
|
+
process.exit(1);
|
|
28
30
|
}
|
|
29
|
-
spinner = (0, ora_1.default)(
|
|
31
|
+
spinner = (0, ora_1.default)().start();
|
|
30
32
|
const { zipPath, zipName, dir } = yield (0, util_1.zip)(from);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
const targetSSH = new node_ssh_1.NodeSSH();
|
|
34
|
+
try {
|
|
35
|
+
const targetConfig = {
|
|
36
|
+
host: ip,
|
|
37
|
+
username: user,
|
|
38
|
+
password,
|
|
39
|
+
privateKey,
|
|
40
|
+
};
|
|
41
|
+
if (password && privateKey) {
|
|
42
|
+
if (loginType === 'password') {
|
|
43
|
+
delete targetConfig.privateKey;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
delete targetConfig.password;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
console.log(`开始连接并上传:${ip} ${to}`);
|
|
50
|
+
if (typeof jumpIp === 'string') {
|
|
51
|
+
spinner.text = '使用跳板机连接';
|
|
52
|
+
const jumpConfig = {
|
|
53
|
+
host: jumpIp,
|
|
54
|
+
username: jumpUser,
|
|
55
|
+
password: jumpPassword,
|
|
56
|
+
privateKey: jumpPrivateKey,
|
|
57
|
+
};
|
|
58
|
+
if (jumpPassword && jumpPrivateKey) {
|
|
59
|
+
if (jumpLoginType === 'password') {
|
|
60
|
+
delete jumpConfig.privateKey;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
delete jumpConfig.password;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const jumpClient = new ssh2_1.Client();
|
|
67
|
+
const stream = yield new Promise((resolve, reject) => {
|
|
68
|
+
jumpClient
|
|
69
|
+
.on('ready', () => {
|
|
70
|
+
spinner.text = '跳板机连接成功,尝试端口转发';
|
|
71
|
+
jumpClient.forwardOut('127.0.0.1', 0, ip, 22, (err, stream) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
return reject(new Error(`端口转发失败: ${err.message}`));
|
|
74
|
+
}
|
|
75
|
+
resolve(stream);
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
.on('error', (err) => {
|
|
79
|
+
reject(new Error(`跳板机连接错误: ${err.message}`));
|
|
80
|
+
})
|
|
81
|
+
.connect(jumpConfig);
|
|
82
|
+
});
|
|
83
|
+
yield targetSSH.connect(Object.assign(Object.assign({}, targetConfig), { sock: stream }));
|
|
42
84
|
}
|
|
43
85
|
else {
|
|
44
|
-
|
|
86
|
+
spinner.text = '直接连接';
|
|
87
|
+
yield targetSSH.connect(targetConfig);
|
|
45
88
|
}
|
|
46
|
-
|
|
47
|
-
spinner = (0, ora_1.default)(`连接并上传:${ip} ${to}`).start();
|
|
48
|
-
try {
|
|
49
|
-
yield ssh.connect(connectConfig);
|
|
50
|
-
yield ssh.putFile(zipPath, path_1.default.join(to, zipName));
|
|
89
|
+
yield targetSSH.putFile(zipPath, path_1.default.join(to, zipName));
|
|
51
90
|
(0, rimraf_1.default)(zipPath, () => { });
|
|
52
|
-
spinner.succeed();
|
|
91
|
+
spinner.succeed('文件上传成功');
|
|
53
92
|
}
|
|
54
93
|
catch (error) {
|
|
55
94
|
(0, rimraf_1.default)(zipPath, () => { });
|
|
56
|
-
spinner.fail();
|
|
57
|
-
|
|
95
|
+
spinner.fail('文件上传失败');
|
|
96
|
+
process.exit(1);
|
|
58
97
|
}
|
|
59
98
|
function execCmd() {
|
|
60
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -79,32 +118,31 @@ const uploadRemoteWithConfig = (config) => __awaiter(void 0, void 0, void 0, fun
|
|
|
79
118
|
}
|
|
80
119
|
}
|
|
81
120
|
for (const cmd of cmds) {
|
|
82
|
-
console.log(
|
|
83
|
-
const result = yield
|
|
121
|
+
console.log(`执行远程命令:${cmd}`);
|
|
122
|
+
const result = yield targetSSH.execCommand(cmd, {
|
|
84
123
|
cwd: cwd ? cwd : to,
|
|
85
124
|
});
|
|
86
125
|
result.stdout && console.log('STDOUT: ' + result.stdout);
|
|
87
126
|
result.stderr && console.log('STDERR: ' + result.stderr);
|
|
88
127
|
if (result.code) {
|
|
89
128
|
console.error((0, shared_1.red)('Command failed with exit code: ' + result.code));
|
|
90
|
-
|
|
129
|
+
process.exit(1);
|
|
91
130
|
}
|
|
92
131
|
}
|
|
93
132
|
});
|
|
94
133
|
}
|
|
95
|
-
spinner = (0, ora_1.default)(`执行远程命令`).start();
|
|
96
134
|
try {
|
|
97
135
|
yield execCmd();
|
|
98
|
-
spinner.succeed();
|
|
136
|
+
spinner.succeed('执行命令成功');
|
|
99
137
|
process.exit(0);
|
|
100
138
|
}
|
|
101
139
|
catch (error) {
|
|
102
|
-
spinner.fail();
|
|
140
|
+
spinner.fail('执行命令失败');
|
|
103
141
|
process.exit(1);
|
|
104
142
|
}
|
|
105
143
|
});
|
|
106
144
|
exports.uploadRemoteWithConfig = uploadRemoteWithConfig;
|
|
107
|
-
const uploadRemoteAction = (
|
|
145
|
+
const uploadRemoteAction = (LABEL_ENV, { config: configName } = { config: undefined }, { args } = { args: undefined }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
146
|
const config = yield config_1.runtimeConfig.getConfig(args, configName, LABEL_ENV);
|
|
109
147
|
if (!config.password && !config.privateKey) {
|
|
110
148
|
console.error('password和privateKey至少设置一项');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infinity-cli/ipublish",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"description": "上传服务器文件",
|
|
6
6
|
"main": "dist/lib/index.js",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"infinity-cli"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@infinity-cli/shared": "^1.2.
|
|
31
|
-
"@sinclair/typebox": "
|
|
30
|
+
"@infinity-cli/shared": "^1.2.3",
|
|
31
|
+
"@sinclair/typebox": "0.23.5",
|
|
32
32
|
"archiver": "^5.3.0",
|
|
33
33
|
"commander": "^8.2.0",
|
|
34
34
|
"node-ssh": "^12.0.3",
|
|
35
35
|
"ora": "5",
|
|
36
36
|
"rimraf": "^3.0.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6f31e897257bb8b1a59a62fea6f455b80bef4b9f"
|
|
39
39
|
}
|
package/readme.md
CHANGED
|
@@ -18,6 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
```javascript
|
|
20
20
|
{
|
|
21
|
+
jumpIp: Type.Optional(Type.String()), // [选填, 默认从全局配置读取] 跳板机的ip
|
|
22
|
+
jumpUser: Type.Optional(Type.String()), // [选填, 默认从全局配置读取] 跳板机的账户
|
|
23
|
+
jumpLoginType: Type.Optional(Type.Union([Type.Literal('password'), Type.Literal('privateKey')])), // [选填] privateKey和password都有值才有意义,否则哪个值设置了就用哪个
|
|
24
|
+
jumpPassword: Type.Optional(Type.String()), // [选填, 默认从全局配置读取] 跳板机的密码,与privateKey填一个就可以了
|
|
25
|
+
jumpPrivateKey: Type.Optional(Type.String()), // [选填, 默认从全局配置读取] 跳板机的privateKey,与password填一个就可以了
|
|
21
26
|
ip: Type.String(), // [选填, 默认从全局配置读取] 服务器的ip
|
|
22
27
|
user: Type.String(), // [选填, 默认从全局配置读取] 登录服务器的账户
|
|
23
28
|
loginType: Type.Optional(Type.Union([Type.Literal('password'), Type.Literal('privateKey')])), // [选填] privateKey和password都有值才有意义,否则哪个值设置了就用哪个
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../src/bin.ts","../src/util.ts","../src/command/config.ts","../src/command/upload.ts","../src/lib/index.ts"],"version":"5.6.2"}
|