2019-04-14 03:41:48 -04:00
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
const getUploadFiles = (argv = process.argv, cwd = process.cwd()) => {
|
|
|
|
let files = argv.slice(1)
|
2019-04-14 22:28:11 -04:00
|
|
|
if (files.length > 0 && files[0] === 'upload') {
|
|
|
|
if (files.length === 1) {
|
|
|
|
return null // for uploading images in clipboard
|
|
|
|
} else if (files.length > 1) {
|
|
|
|
files = argv.slice(1)
|
|
|
|
let result = []
|
|
|
|
if (files.length > 0) {
|
|
|
|
result = files.map(item => {
|
|
|
|
if (path.isAbsolute(item)) {
|
|
|
|
return {
|
|
|
|
path: item
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let tempPath = path.join(cwd, item)
|
|
|
|
if (fs.existsSync(tempPath)) {
|
|
|
|
return {
|
|
|
|
path: tempPath
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
2019-04-14 22:28:11 -04:00
|
|
|
}).filter(item => item !== null)
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
2019-04-14 22:28:11 -04:00
|
|
|
return result
|
|
|
|
}
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
2019-04-14 22:28:11 -04:00
|
|
|
return []
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
getUploadFiles
|
|
|
|
}
|