@qse/ssh-sftp 1.1.0 → 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/.sftprc.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "sftprc.schema.json",
3
+ "localPath": "docs-dist",
4
+ "preset": {
5
+ "context": "qsxxwapdev",
6
+ "folder": "edu-ssh-sftp"
7
+ },
8
+ "targets": []
9
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # 更新日志
2
+
3
+ ## 1.3.0 (2026-03-04)
4
+
5
+ - feat: 优化上传速度
6
+
7
+ ## 1.0.1 (2023-12-15)
8
+
9
+ - fix: 延长 timeout 时间
10
+
11
+ ## 1.0.0 (2022-09-28)
12
+
13
+ - feat: 修改包名,初始化版本
@@ -0,0 +1,3 @@
1
+ import config from '@qse/eslint-config'
2
+
3
+ export default config
package/jsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "moduleResolution": "nodenext"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,46 +1,42 @@
1
1
  {
2
2
  "name": "@qse/ssh-sftp",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "教育代码部署工具",
5
- "main": "lib/index.js",
5
+ "main": "src/index.js",
6
6
  "author": "Ironkinoko <kinoko_main@outlook.com>",
7
7
  "license": "MIT",
8
+ "type": "module",
8
9
  "scripts": {
9
- "start": "dumi dev",
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
- "build": "father-build",
13
- "deploy": "yarn docs:build && yarn docs:deploy && rm -rf docs-dist",
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": "lib/cli.js"
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": "^4.1.1",
34
- "glob": "^7.1.6",
35
- "inquirer": "^8.1.1",
36
- "minimatch": "^3.0.4",
37
- "ora": "^5.1.0",
38
- "ssh2-sftp-client": "^6.0.0",
39
- "update-notifier": "^5.1.0",
40
- "yargs": "^16.2.0"
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
+ "p-limit": "^7.3.0",
35
+ "ssh2-sftp-client": "^12.0.1",
36
+ "yargs": "^18.0.0"
41
37
  },
42
38
  "devDependencies": {
43
- "dumi": "^1.1.42",
44
- "father-build": "^1.22.3"
39
+ "eslint": "^9.39.3",
40
+ "@qse/eslint-config": "^1.0.0"
45
41
  }
46
42
  }
@@ -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,117 @@
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 { presets } from './presets.js'
8
+ import Yargs from 'yargs'
9
+
10
+ // eslint-disable-next-line no-unused-expressions
11
+ Yargs(process.argv.slice(2))
12
+ .usage(
13
+ '使用: $0 [command] \n\n代码:svn://192.168.10.168/edu/code/A0.New-system/0A2.front-end-component/ssh-sftp/trunk',
14
+ )
15
+ .command(
16
+ '*',
17
+ '上传文件',
18
+ (yargs) =>
19
+ yargs.option('no-clear', { desc: '不删除文件' }).option('yes', {
20
+ alias: 'y',
21
+ desc: '不存在的目录不再询问,直接创建',
22
+ type: 'boolean',
23
+ }),
24
+ upload,
25
+ )
26
+ .command('init', '生成 .sftprc.json 配置文件', {}, generateDefaultConfigJSON)
27
+ .command(
28
+ ['list', 'ls'],
29
+ '列出所有需要上传/忽略/删除的文件',
30
+ (yargs) =>
31
+ yargs
32
+ .option('u', { desc: '列出需要上传的文件' })
33
+ .option('d', { desc: '列出需要删除的文件' })
34
+ .option('i', { desc: '列出忽略的文件' }),
35
+ ls,
36
+ )
37
+ .command(['show-config', 'sc'], '显示部署的完整信息', {}, showConfig)
38
+ .command(['show-presets', 'sp'], '显示预设配置', {}, showPresets)
39
+ .command(['show-url', 'su'], '显示部署网址', {}, showUrl)
40
+ .alias({ v: 'version', h: 'help' }).argv
41
+
42
+ function getOpts() {
43
+ isRoot()
44
+ if (!fs.existsSync('.sftprc.json')) {
45
+ return exitWithError('没找到 .sftprc.json 文件,请先执行 ssh-sftp init')
46
+ }
47
+
48
+ const opts = fs.readFileSync('.sftprc.json', 'utf-8')
49
+ return JSON.parse(opts)
50
+ }
51
+
52
+ function isRoot() {
53
+ if (!fs.existsSync('package.json')) {
54
+ exitWithError('请在项目的根目录运行(package.json所在的目录)')
55
+ }
56
+ }
57
+
58
+ function upload({ clear, yes }) {
59
+ const opts = getOpts()
60
+ if (clear === false) {
61
+ opts.cleanRemoteFiles = false
62
+ }
63
+ if (yes) {
64
+ opts.skipPrompt = true
65
+ }
66
+ sshSftp(opts)
67
+ }
68
+
69
+ function generateDefaultConfigJSON() {
70
+ isRoot()
71
+
72
+ if (fs.existsSync('.sftprc.json')) {
73
+ return exitWithError('已存在 .sftprc.json 文件,请勿重复生成')
74
+ }
75
+ fs.writeFileSync(
76
+ '.sftprc.json',
77
+ JSON.stringify(
78
+ {
79
+ $schema: 'http://www.zhidianbao.cn:8088/qsxxwapdev/edu-ssh-sftp/sftprc.schema.json',
80
+ localPath: '/path/to/localDir',
81
+ remotePath: '/path/to/remoteDir',
82
+ connectOptions: {
83
+ host: '127.0.0.1',
84
+ port: 22,
85
+ username: '',
86
+ password: '',
87
+ },
88
+ ignore: ['**/something[optional].js'],
89
+ cleanRemoteFiles: false,
90
+ },
91
+ null,
92
+ 2,
93
+ ),
94
+ { encoding: 'utf-8' },
95
+ )
96
+ ora().succeed('.sftprc.json 生成在项目根目录')
97
+ }
98
+
99
+ function ls(argv) {
100
+ if (!argv.u && !argv.d && !argv.i) {
101
+ argv.u = true
102
+ argv.d = true
103
+ argv.i = true
104
+ }
105
+ sshSftpLS(getOpts(), argv)
106
+ }
107
+
108
+ function showUrl() {
109
+ sshSftpShowUrl(getOpts())
110
+ }
111
+ function showConfig() {
112
+ sshSftpShowConfig(getOpts())
113
+ }
114
+
115
+ function showPresets() {
116
+ console.log(JSON.stringify(presets, null, 2))
117
+ }