@imgcook/cli-loader-images
Advanced tools
Comparing version 0.0.2-alpha.2 to 0.0.2-alpha.4
48
index.js
@@ -35,2 +35,8 @@ const fs = require('fs'); | ||
const imgPath = `${filePath}/images`; | ||
let imgObj = []; | ||
const imgrc = `${imgPath}/.imgrc`; | ||
if (fs.existsSync(imgrc)) { | ||
let imgConfig = fs.readFileSync(imgrc, 'utf8'); | ||
imgObj = JSON.parse(imgConfig) || []; | ||
} | ||
for (let idx = 0; idx < imgArr.length; idx++) { | ||
@@ -44,15 +50,39 @@ if (!fs.existsSync(imgPath)) { | ||
const imgPathItem = `${imgPath}/${imgName}`; | ||
await downloadImg(imgArr[idx], imgPathItem); | ||
let curImgObj = {}; | ||
for (const item of imgObj) { | ||
if (item.imgUrl === imgArr[idx]) { | ||
curImgObj = item; | ||
} | ||
} | ||
const reg = new RegExp(imgArr[idx], 'g'); | ||
if (option.config && option.config.uploadUrl !== '') { | ||
const udata = await uploadData( | ||
imgPathItem, | ||
`imgcook-cli/${temporaryImages}/`, | ||
option.config | ||
); | ||
fileValue = fileValue.replace(reg, udata.url); | ||
if (!curImgObj.imgPath) { | ||
await downloadImg(imgArr[idx], imgPathItem); | ||
let newImgUrl = ''; | ||
if (option.config && option.config.uploadUrl !== '') { | ||
const udata = await uploadData( | ||
imgPathItem, | ||
`imgcook-cli/${temporaryImages}/`, | ||
option.config | ||
); | ||
fileValue = fileValue.replace(reg, udata.url); | ||
newImgUrl = udata.url; | ||
} else { | ||
fileValue = fileValue.replace(reg, `./images/${imgName}`); | ||
} | ||
imgObj.push({ | ||
newImgUrl, | ||
imgUrl: imgArr[idx], | ||
imgPath: `./images/${imgName}` | ||
}); | ||
} else { | ||
fileValue = fileValue.replace(reg, `./images/${imgName}`); | ||
if (option.config && option.config.uploadUrl !== '') { | ||
fileValue = fileValue.replace(reg, curImgObj.newImgUrl); | ||
} else { | ||
fileValue = fileValue.replace(reg, curImgObj.imgPath); | ||
} | ||
} | ||
} | ||
if (imgObj.length > 0) { | ||
fs.writeFileSync(imgrc, JSON.stringify(imgObj), 'utf8'); | ||
} | ||
} | ||
@@ -59,0 +89,0 @@ return fileValue; |
{ | ||
"name": "@imgcook/cli-loader-images", | ||
"version": "0.0.2-alpha.2", | ||
"version": "0.0.2-alpha.4", | ||
"description": "", | ||
@@ -35,3 +35,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "9d1c2f9ab77122908ef8247198fbf802cba8ba05" | ||
"gitHead": "5413f8e186ce00734847a4044545f54d7c2bf48e" | ||
} |
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
5236
6
145