-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
36 lines (29 loc) · 795 Bytes
/
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
'use strict'
const Client = require('scp2')
const client = new Client.Client()
const colors = require('colors')
class WebpackSftp {
constructor(options = {}) {
this.options = options
this.startTime = null
this.endTime = null
}
apply(compiler) {
compiler.plugin('done', compilation => {
if (!this.options.port) {
this.options.port = 22
}
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 = WebpackSftp