Comparing version 1.0.5 to 1.0.7
66
core.js
@@ -58,2 +58,8 @@ let path = require('path') | ||
// return new Promise(res => { | ||
// this.ftp.mkdir('webApp/women/xxx', true, err=>{ | ||
// console.log(err) | ||
// }) | ||
// }) | ||
let list = getDirList(localDir) | ||
@@ -90,3 +96,3 @@ | ||
console.log('上传成功:', localP , '--->', remoteP); | ||
resolve('上传成功') | ||
resolve() | ||
}) | ||
@@ -96,3 +102,2 @@ }) | ||
}, | ||
// 创建文件夹 | ||
mkdir(remoteP){ | ||
@@ -104,7 +109,11 @@ let p = remoteP.split('/').map(item => item.trim()).filter(item => item) | ||
p.forEach(item => pathArr.push(pathStr += item+ '/')) | ||
// 直接创建文件夹, | ||
return new Promise((res, rej) => { | ||
let LIST = pathArr | ||
return new Promise(res => { | ||
// 我先直接创建一下,看路径是否存在 | ||
let P = p.join('/') | ||
this.ftp.mkdir(P, err=>{ | ||
this.ftp.mkdir(remoteP, true, err=>{ | ||
let success = !err || err.message.toLowerCase().match('file exists') | ||
@@ -115,30 +124,33 @@ if(success) { | ||
} else { | ||
Promise.all( | ||
pathArr.map(item=>{ | ||
return new Promise((resolve, reject) => { | ||
this.ftp.mkdir(item, err=>{ | ||
let success = !err || err.message.toLowerCase().match('file exists') | ||
if(success){ | ||
console.log('创建文件夹', item); | ||
resolve() | ||
}else{ | ||
console.log(item, err.message); | ||
reject(err) | ||
} | ||
}) | ||
}) | ||
}) | ||
).then(success => { | ||
res() | ||
}, fail => { | ||
rej() | ||
}) | ||
console.log('路径创建失败', err) | ||
res() | ||
// | ||
// console.log(`路径创建失败,从根目录开始创建 -->`, LIST) | ||
// | ||
// this.mkdirList(LIST, 0, res) | ||
} | ||
}) | ||
}) | ||
}, | ||
mkdirList(LIST, index, res){ | ||
if(index == LIST.length) { | ||
console.log('LIST upload end!!!!!!!!!!') | ||
res() | ||
} else { | ||
let P = LIST[index] | ||
} | ||
let ff = this.ftp.mkdir(P, true, err=>{ | ||
console.log('??????????????????') | ||
let success = !err || err.message.toLowerCase().match('file exists') | ||
if(success){ | ||
console.log('创建文件夹', P); | ||
this.mkdirList(LIST, ++index, res) | ||
}else{ | ||
console.log('创建失败', P, err.message); | ||
} | ||
}) | ||
} | ||
}, | ||
} | ||
module.exports = Core |
45
index.js
@@ -10,6 +10,5 @@ #!/usr/bin/env node | ||
const CONFIG_NAME = '.ftprc' | ||
function searchConfig(dir){ | ||
function searchConfig(dir) { | ||
// 在当前目录寻找,寻找不到就到上级目录寻找 | ||
@@ -24,5 +23,5 @@ | ||
} else { | ||
const PARENT_DIR = path.resolve(dir, '../') | ||
const PARENT_DIR = path.resolve(dir, '../') | ||
// 如果上一级路径和当前路径相同,就退出 | ||
if (PARENT_DIR == dir){ | ||
if (PARENT_DIR == dir) { | ||
return null | ||
@@ -35,7 +34,6 @@ } | ||
// 校验config是否正确 | ||
function checkConfig(){ | ||
} | ||
function checkConfig() {} | ||
// process.cwd() 表示命令被调用处的路径 | ||
const [config, configPath] = searchConfig(process.cwd()) || [] | ||
const [config, | ||
configPath] = searchConfig(process.cwd()) || [] | ||
// console.log(config); | ||
@@ -66,24 +64,17 @@ | ||
let list = config.upload.default | ||
upload(list) | ||
ftp.on('ready', ()=>{ | ||
list.map(localPath => { | ||
localPath = path.resolve(configPath, localPath) | ||
lftp.put(localPath, remotePath) | ||
.then(msg => { | ||
console.log(msg); | ||
process.exit() | ||
} ) | ||
}) | ||
}) | ||
} else { | ||
let list = config.upload[KEY] | ||
ftp.on('ready', ()=>{ | ||
list.map(localPath => { | ||
upload(list) | ||
} | ||
function upload(list){ | ||
ftp.on('ready', () => { | ||
Promise.all(list.map(localPath => { | ||
localPath = path.resolve(configPath, localPath) | ||
lftp.put(localPath, remotePath) | ||
.then(msg => { | ||
console.log(msg); | ||
process.exit() | ||
} ) | ||
return lftp.put(localPath, remotePath) | ||
})).then(msg => { | ||
console.log('上传完毕!') | ||
process.exit() | ||
}) | ||
@@ -93,2 +84,4 @@ }) | ||
config.keepalive = 1000000000 | ||
ftp.connect(config) |
{ | ||
"name": "lyftp", | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"description": "lyftp is ftp package, you can upload an entire folder or a file", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199
7892