@qse/ssh-sftp 1.0.1 → 1.2.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/.sftprc.json +9 -0
- package/CHANGELOG.md +9 -0
- package/jsconfig.json +6 -0
- package/package.json +16 -23
- package/sftprc.schema.json +192 -0
- package/src/cli.js +125 -0
- package/src/index.js +471 -0
- package/{lib → src}/presets.js +12 -15
- package/{lib → src}/utils.js +11 -16
- package/lib/cli.js +0 -126
- package/lib/index.js +0 -494
package/.sftprc.json
ADDED
package/CHANGELOG.md
ADDED
package/jsconfig.json
ADDED
package/package.json
CHANGED
|
@@ -1,46 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qse/ssh-sftp",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "教育代码部署工具",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"author": "Ironkinoko <kinoko_main@outlook.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
|
-
"
|
|
10
|
-
"docs:build": "dumi build && cp sftprc.schema.json docs-dist",
|
|
10
|
+
"docs:build": "mkdir -p docs-dist && cp sftprc.schema.json docs-dist",
|
|
11
11
|
"docs:deploy": "node ./src/cli.js",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"release": "yarn build && npm publish && rm -rf lib",
|
|
12
|
+
"deploy": "npm run docs:build && npm run docs:deploy && rm -rf docs-dist",
|
|
13
|
+
"release": "npm publish &&",
|
|
15
14
|
"prettier": "prettier -c -w \"src/**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
|
16
15
|
"postversion": "npm run release"
|
|
17
16
|
},
|
|
18
17
|
"bin": {
|
|
19
|
-
"ssh-sftp": "
|
|
18
|
+
"ssh-sftp": "src/cli.js"
|
|
20
19
|
},
|
|
21
20
|
"keywords": [
|
|
22
21
|
"sftp"
|
|
23
22
|
],
|
|
24
|
-
"files": [
|
|
25
|
-
"lib"
|
|
26
|
-
],
|
|
27
23
|
"homepage": "http://www.zhidianbao.cn:8088/qsxxwapdev/edu-ssh-sftp/",
|
|
28
24
|
"publishConfig": {
|
|
29
25
|
"registry": "https://registry.npmjs.org/",
|
|
30
26
|
"access": "public"
|
|
31
27
|
},
|
|
32
28
|
"dependencies": {
|
|
33
|
-
"chalk": "^
|
|
34
|
-
"glob": "^
|
|
35
|
-
"inquirer": "^
|
|
36
|
-
"minimatch": "^
|
|
37
|
-
"ora": "^
|
|
38
|
-
"ssh2-sftp-client": "^
|
|
39
|
-
"update-notifier": "^
|
|
40
|
-
"yargs": "^
|
|
29
|
+
"chalk": "^5.6.2",
|
|
30
|
+
"glob": "^13.0.0",
|
|
31
|
+
"inquirer": "^13.1.0",
|
|
32
|
+
"minimatch": "^10.1.1",
|
|
33
|
+
"ora": "^9.0.0",
|
|
34
|
+
"ssh2-sftp-client": "^12.0.1",
|
|
35
|
+
"update-notifier": "^7.3.1",
|
|
36
|
+
"yargs": "^18.0.0"
|
|
41
37
|
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"dumi": "^1.1.42",
|
|
44
|
-
"father-build": "^1.22.3"
|
|
45
|
-
}
|
|
38
|
+
"devDependencies": {}
|
|
46
39
|
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"description": "ssh-sftp 配置项",
|
|
5
|
+
"default": {},
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"localPath": "/path/to/localDir",
|
|
9
|
+
"remotePath": "/path/to/remoteDir",
|
|
10
|
+
"connectOptions": {
|
|
11
|
+
"host": "127.0.0.1",
|
|
12
|
+
"port": 22,
|
|
13
|
+
"username": "",
|
|
14
|
+
"password": ""
|
|
15
|
+
},
|
|
16
|
+
"ignore": ["**/something[optional].js"],
|
|
17
|
+
"cleanRemoteFiles": false,
|
|
18
|
+
"securityLock": true,
|
|
19
|
+
"keepAlive": false,
|
|
20
|
+
"noWarn": false
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"required": [],
|
|
24
|
+
"properties": {
|
|
25
|
+
"localPath": {
|
|
26
|
+
"$id": "#/properties/localPath",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "本地 dist 地址",
|
|
29
|
+
"default": "dist",
|
|
30
|
+
"examples": ["dist"]
|
|
31
|
+
},
|
|
32
|
+
"remotePath": {
|
|
33
|
+
"$id": "#/properties/remotePath",
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "远程 dist 部署地址",
|
|
36
|
+
"default": "",
|
|
37
|
+
"examples": ["/path/to/remoteDir"]
|
|
38
|
+
},
|
|
39
|
+
"connectOptions": {
|
|
40
|
+
"$id": "#/properties/connectOptions",
|
|
41
|
+
"type": "object",
|
|
42
|
+
"description": "服务器连接信息",
|
|
43
|
+
"default": {},
|
|
44
|
+
"examples": [
|
|
45
|
+
{
|
|
46
|
+
"host": "127.0.0.1",
|
|
47
|
+
"port": 22,
|
|
48
|
+
"username": "",
|
|
49
|
+
"password": ""
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"required": ["host", "port", "username", "password"],
|
|
53
|
+
"properties": {
|
|
54
|
+
"host": {
|
|
55
|
+
"$id": "#/properties/connectOptions/properties/host",
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "主机",
|
|
58
|
+
"default": "",
|
|
59
|
+
"examples": ["127.0.0.1"]
|
|
60
|
+
},
|
|
61
|
+
"port": {
|
|
62
|
+
"$id": "#/properties/connectOptions/properties/port",
|
|
63
|
+
"type": "integer",
|
|
64
|
+
"description": "端口号",
|
|
65
|
+
"default": 0,
|
|
66
|
+
"examples": [22]
|
|
67
|
+
},
|
|
68
|
+
"username": {
|
|
69
|
+
"$id": "#/properties/connectOptions/properties/username",
|
|
70
|
+
"type": "string",
|
|
71
|
+
"description": "用户名",
|
|
72
|
+
"default": "",
|
|
73
|
+
"examples": [""]
|
|
74
|
+
},
|
|
75
|
+
"password": {
|
|
76
|
+
"$id": "#/properties/connectOptions/properties/password",
|
|
77
|
+
"type": "string",
|
|
78
|
+
"description": "密码",
|
|
79
|
+
"default": "",
|
|
80
|
+
"examples": [""]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"additionalProperties": false
|
|
84
|
+
},
|
|
85
|
+
"preset": {
|
|
86
|
+
"$id": "#/properties/preset",
|
|
87
|
+
"type": "object",
|
|
88
|
+
"description": "预设连接配置",
|
|
89
|
+
"default": {},
|
|
90
|
+
"examples": [
|
|
91
|
+
{
|
|
92
|
+
"context": "qsxxwapdev"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"properties": {
|
|
96
|
+
"context": {
|
|
97
|
+
"$id": "#/properties/preset/properties/context",
|
|
98
|
+
"type": "string",
|
|
99
|
+
"description": "v1部署前缀",
|
|
100
|
+
"examples": ["qsxxwapdev", "eduwebngv1", "qsxxadminv1"]
|
|
101
|
+
},
|
|
102
|
+
"folder": {
|
|
103
|
+
"$id": "#/properties/preset/properties/folder",
|
|
104
|
+
"type": "string",
|
|
105
|
+
"description": "部署文件夹名称,默认使用项目名称"
|
|
106
|
+
},
|
|
107
|
+
"server": {
|
|
108
|
+
"$id": "#/properties/preset/properties/server",
|
|
109
|
+
"type": "string",
|
|
110
|
+
"description": "部署的服务器",
|
|
111
|
+
"examples": ["19", "171"]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"additionalProperties": false
|
|
115
|
+
},
|
|
116
|
+
"ignore": {
|
|
117
|
+
"$id": "#/properties/ignore",
|
|
118
|
+
"type": "array",
|
|
119
|
+
"description": "忽略上传某些文件",
|
|
120
|
+
"default": [],
|
|
121
|
+
"examples": [["**/something[optional].js"]],
|
|
122
|
+
"additionalItems": true,
|
|
123
|
+
"items": {
|
|
124
|
+
"$id": "#/properties/ignore/items",
|
|
125
|
+
"type": "string"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"cleanRemoteFiles": {
|
|
129
|
+
"$id": "#/properties/cleanRemoteFiles",
|
|
130
|
+
"type": ["boolean", "array"],
|
|
131
|
+
"description": "清空远程数据",
|
|
132
|
+
"default": false,
|
|
133
|
+
"examples": [false, ["**/something[optional].js"]],
|
|
134
|
+
"items": {
|
|
135
|
+
"$id": "#/properties/cleanRemoteFiles/items",
|
|
136
|
+
"type": "string"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"securityLock": {
|
|
140
|
+
"$id": "#/properties/securityLock",
|
|
141
|
+
"type": "boolean",
|
|
142
|
+
"description": "启用安全锁",
|
|
143
|
+
"default": true,
|
|
144
|
+
"examples": [true]
|
|
145
|
+
},
|
|
146
|
+
"keepAlive": {
|
|
147
|
+
"$id": "#/properties/keepAlive",
|
|
148
|
+
"type": "boolean",
|
|
149
|
+
"description": "上传完毕后保持与连接",
|
|
150
|
+
"default": false,
|
|
151
|
+
"examples": [false]
|
|
152
|
+
},
|
|
153
|
+
"noWarn": {
|
|
154
|
+
"$id": "#/properties/noWarn",
|
|
155
|
+
"type": "boolean",
|
|
156
|
+
"description": "禁用控制台提示",
|
|
157
|
+
"default": false,
|
|
158
|
+
"examples": [false]
|
|
159
|
+
},
|
|
160
|
+
"skipPrompt": {
|
|
161
|
+
"$id": "#/properties/skipPrompt",
|
|
162
|
+
"type": "boolean",
|
|
163
|
+
"description": "不存在的目录不再询问,直接创建",
|
|
164
|
+
"default": false,
|
|
165
|
+
"examples": [false]
|
|
166
|
+
},
|
|
167
|
+
"targets": {
|
|
168
|
+
"$id": "#/properties/targets",
|
|
169
|
+
"type": "array",
|
|
170
|
+
"description": "多目标上传配置",
|
|
171
|
+
"default": [],
|
|
172
|
+
"examples": [[{ "remotePath": "/path/to/remoteDir" }]],
|
|
173
|
+
"items": {
|
|
174
|
+
"$id": "#/properties/targets/items",
|
|
175
|
+
"type": "object",
|
|
176
|
+
"properties": {
|
|
177
|
+
"remotePath": {
|
|
178
|
+
"$id": "#/properties/targets/items/properties/remotePath",
|
|
179
|
+
"$ref": "#/properties/remotePath"
|
|
180
|
+
},
|
|
181
|
+
"connectOptions": {
|
|
182
|
+
"$id": "#/properties/targets/items/properties/connectOptions",
|
|
183
|
+
"$ref": "#/properties/connectOptions"
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"required": ["remotePath"],
|
|
187
|
+
"additionalProperties": false
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
"additionalProperties": true
|
|
192
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { sshSftp, sshSftpLS, sshSftpShowUrl, sshSftpShowConfig } from './index.js'
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import ora from 'ora'
|
|
6
|
+
import { exitWithError } from './utils.js'
|
|
7
|
+
import updateNotifier from 'update-notifier'
|
|
8
|
+
import { presets } from './presets.js'
|
|
9
|
+
import Yargs from 'yargs'
|
|
10
|
+
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'))
|
|
12
|
+
|
|
13
|
+
updateNotifier({
|
|
14
|
+
pkg,
|
|
15
|
+
updateCheckInterval: 1000 * 60 * 60 * 24 * 7,
|
|
16
|
+
shouldNotifyInNpmScript: true,
|
|
17
|
+
}).notify()
|
|
18
|
+
|
|
19
|
+
Yargs(process.argv.slice(2))
|
|
20
|
+
.usage(
|
|
21
|
+
'使用: $0 [command] \n\n代码:svn://192.168.10.168/edu/code/A0.New-system/0A2.front-end-component/ssh-sftp/trunk'
|
|
22
|
+
)
|
|
23
|
+
.command(
|
|
24
|
+
'*',
|
|
25
|
+
'上传文件',
|
|
26
|
+
(yargs) =>
|
|
27
|
+
yargs.option('no-clear', { desc: '不删除文件' }).option('yes', {
|
|
28
|
+
alias: 'y',
|
|
29
|
+
desc: '不存在的目录不再询问,直接创建',
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
}),
|
|
32
|
+
upload
|
|
33
|
+
)
|
|
34
|
+
.command('init', '生成 .sftprc.json 配置文件', {}, generateDefaultConfigJSON)
|
|
35
|
+
.command(
|
|
36
|
+
['list', 'ls'],
|
|
37
|
+
'列出所有需要上传/忽略/删除的文件',
|
|
38
|
+
(yargs) =>
|
|
39
|
+
yargs
|
|
40
|
+
.option('u', { desc: '列出需要上传的文件' })
|
|
41
|
+
.option('d', { desc: '列出需要删除的文件' })
|
|
42
|
+
.option('i', { desc: '列出忽略的文件' }),
|
|
43
|
+
ls
|
|
44
|
+
)
|
|
45
|
+
.command(['show-config', 'sc'], '显示部署的完整信息', {}, showConfig)
|
|
46
|
+
.command(['show-presets', 'sp'], '显示预设配置', {}, showPresets)
|
|
47
|
+
.command(['show-url', 'su'], '显示部署网址', {}, showUrl)
|
|
48
|
+
.alias({ v: 'version', h: 'help' }).argv
|
|
49
|
+
|
|
50
|
+
function getOpts() {
|
|
51
|
+
isRoot()
|
|
52
|
+
if (!fs.existsSync('.sftprc.json')) {
|
|
53
|
+
return exitWithError('没找到 .sftprc.json 文件,请先执行 ssh-sftp init')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const opts = fs.readFileSync('.sftprc.json', 'utf-8')
|
|
57
|
+
return JSON.parse(opts)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isRoot() {
|
|
61
|
+
if (!fs.existsSync('package.json')) {
|
|
62
|
+
exitWithError('请在项目的根目录运行(package.json所在的目录)')
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function upload({ clear, yes }) {
|
|
67
|
+
const opts = getOpts()
|
|
68
|
+
if (clear === false) {
|
|
69
|
+
opts.cleanRemoteFiles = false
|
|
70
|
+
}
|
|
71
|
+
if (yes) {
|
|
72
|
+
opts.skipPrompt = true
|
|
73
|
+
}
|
|
74
|
+
sshSftp(opts)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function generateDefaultConfigJSON() {
|
|
78
|
+
isRoot()
|
|
79
|
+
|
|
80
|
+
if (fs.existsSync('.sftprc.json')) {
|
|
81
|
+
return exitWithError('已存在 .sftprc.json 文件,请勿重复生成')
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(
|
|
84
|
+
'.sftprc.json',
|
|
85
|
+
JSON.stringify(
|
|
86
|
+
{
|
|
87
|
+
$schema: 'http://www.zhidianbao.cn:8088/qsxxwapdev/edu-ssh-sftp/sftprc.schema.json',
|
|
88
|
+
localPath: '/path/to/localDir',
|
|
89
|
+
remotePath: '/path/to/remoteDir',
|
|
90
|
+
connectOptions: {
|
|
91
|
+
host: '127.0.0.1',
|
|
92
|
+
port: 22,
|
|
93
|
+
username: '',
|
|
94
|
+
password: '',
|
|
95
|
+
},
|
|
96
|
+
ignore: ['**/something[optional].js'],
|
|
97
|
+
cleanRemoteFiles: false,
|
|
98
|
+
},
|
|
99
|
+
null,
|
|
100
|
+
2
|
|
101
|
+
),
|
|
102
|
+
{ encoding: 'utf-8' }
|
|
103
|
+
)
|
|
104
|
+
ora().succeed('.sftprc.json 生成在项目根目录')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function ls(argv) {
|
|
108
|
+
if (!argv.u && !argv.d && !argv.i) {
|
|
109
|
+
argv.u = true
|
|
110
|
+
argv.d = true
|
|
111
|
+
argv.i = true
|
|
112
|
+
}
|
|
113
|
+
sshSftpLS(getOpts(), argv)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function showUrl() {
|
|
117
|
+
sshSftpShowUrl(getOpts())
|
|
118
|
+
}
|
|
119
|
+
function showConfig() {
|
|
120
|
+
sshSftpShowConfig(getOpts())
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function showPresets() {
|
|
124
|
+
console.log(JSON.stringify(presets, null, 2))
|
|
125
|
+
}
|