add auto deploy process
This commit is contained in:
99
deploy/plugin/ftp.js
Normal file
99
deploy/plugin/ftp.js
Normal file
@ -0,0 +1,99 @@
|
||||
async function getList (ftp, src) {
|
||||
return new Promise(resolve => {
|
||||
ftp.list(src, (err, list) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(list)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function rmDir (ftp, src, recusive = true) {
|
||||
return new Promise(resolve => {
|
||||
ftp.rmdir(src, recusive, err => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteFile (ftp, src) {
|
||||
return new Promise(resolve => {
|
||||
ftp.delete(src, err => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function emptyDir (ftp, src, except = []) {
|
||||
const list = await getList(ftp, src)
|
||||
|
||||
for (let i = 0, listNum = list.length; i < listNum; i++) {
|
||||
const { type, name } = list[i]
|
||||
|
||||
if (type === 'd' && (name === '.' || name === '..')) continue
|
||||
if (except.find(n => n === name)) continue
|
||||
|
||||
const fullSrc = `${src}${name}`
|
||||
|
||||
if (type === 'd') {
|
||||
if (!await rmDir(ftp, fullSrc, true)) return false
|
||||
} else {
|
||||
if (!await deleteFile(ftp, fullSrc)) return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async function put (ftp, src, dest) {
|
||||
return new Promise(resolve => {
|
||||
ftp.put(src, dest, err => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function mkDir (ftp, src, recusive = true) {
|
||||
return new Promise(resolve => {
|
||||
ftp.mkdir(src, recusive, err => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
put,
|
||||
rmDir,
|
||||
mkDir,
|
||||
getList,
|
||||
emptyDir,
|
||||
deleteFile
|
||||
}
|
13
deploy/plugin/nodeParams.js
Normal file
13
deploy/plugin/nodeParams.js
Normal file
@ -0,0 +1,13 @@
|
||||
function getNodeParams () {
|
||||
const params = {}
|
||||
|
||||
process.argv.slice(2).forEach(param => {
|
||||
param = param.split('=')
|
||||
|
||||
params[param[0]] = param[1]
|
||||
})
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
module.exports = getNodeParams
|
22
deploy/plugin/print.js
Normal file
22
deploy/plugin/print.js
Normal file
@ -0,0 +1,22 @@
|
||||
const print = {
|
||||
log (info) {
|
||||
console.log(info)
|
||||
},
|
||||
warn (info) {
|
||||
console.log('\033[31;33m' + info + '\033[0m')
|
||||
},
|
||||
error (info) {
|
||||
console.log('\033[31;40m' + info + '\033[0m')
|
||||
},
|
||||
tip (info) {
|
||||
console.log('\033[40;32m' + info + '\033[0m')
|
||||
},
|
||||
success (info) {
|
||||
console.log('\033[42;30m' + info + '\033[0m')
|
||||
},
|
||||
yellow (info) {
|
||||
console.log('\033[31;33m' + info + '\033[0m')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = print
|
Reference in New Issue
Block a user