-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (47 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* @Descripttion:
* @version:
* @Author: Shuai XUE
* @Date: 2019-08-21 17:46:07
* @LastEditors: Shuai XUE
* @LastEditTime: 2021-01-15 18:36:08
*/
'use strict'
const Client = require('scp2')
const client = new Client.Client()
const colors = require('colors')
class EasyUpload {
// options = {
// host: 'host',
// port: 'post', // default: 22
// username: 'user',
// password: 'password',
// local: 'local path', // eg. path.join(__dirname, 'dist')
// path: 'remote path', // eg. /var/www/ftp/
// handleMode: false //true表示使用单独使用模式,false表示使用wabpack命令参数模式
// }
constructor(options = {}) {
this.options = options
this.startTime = null
this.endTime = null
}
apply(compiler) {
compiler.hooks.done.tapAsync('EasyUpload', (compilation, callback) => {
callback()
this.options.handleMode ? this.doUpload() : process.argv.includes('--easy-upload') && this.doUpload()
})
}
doUpload() {
this.startTime = Date.now()
console.log('\nStart upload, please wait...'.green)
this.upload(this.options.local, this.options)
}
upload(local, obj) {
Client.scp(local, obj, err => {
if (err) throw err
this.endTime = Date.now()
console.log(`Uploaded ${local} successfully in ${this.endTime - this.startTime}ms`.green)
})
}
}
module.exports = EasyUpload