@tols/gm-base
Advanced tools
Comparing version 1.0.0 to 1.0.1
67
index.js
@@ -33,32 +33,30 @@ const fs = require('fs-extra') | ||
// 裁切图片 | ||
const handleImage = async srcFile => { | ||
return new Promise(resolve => { | ||
// 将路径中的 \ 转换成 / | ||
let prettySrcPath = srcPath.replace(/\\/g, '/') | ||
// 映射src文件成dist文件 | ||
let distFile = srcFile.replace(prettySrcPath, distPath) | ||
// 源文件相对路径,这里是为了美观的在命令行显示简短的文件路径 | ||
// 相对路径如:src/images/banner.jpg | ||
const relativeFile = srcFile.replace(path.join(distPath, '../../'), '') | ||
fileNames[relativeFile] = relativeFile | ||
const handleImage = (srcFile, callBack) => { | ||
// 将路径中的 \ 转换成 / | ||
let prettySrcPath = srcPath.replace(/\\/g, '/') | ||
// 映射src文件成dist文件 | ||
let distFile = srcFile.replace(prettySrcPath, distPath) | ||
// 源文件相对路径,这里是为了美观的在命令行显示简短的文件路径 | ||
// 相对路径如:src/images/banner.jpg | ||
const relativeFile = srcFile.replace(path.join(distPath, '../../'), '') | ||
fileNames[relativeFile] = relativeFile | ||
// 确保输出的目标文件目录存在 | ||
const imgInfo = distFile.match(/.*\/(.*)\.(jpg|jpeg|gif|png)$/i) | ||
const fileName = imgInfo[1] | ||
const extName = imgInfo[2] | ||
const targetPath = distFile.replace(fileName + '.' + extName, '') | ||
fs.ensureDirSync(targetPath) | ||
// 确保输出的目标文件目录存在 | ||
const imgInfo = distFile.match(/.*\/(.*)\.(jpg|jpeg|gif|png)$/i) | ||
const fileName = imgInfo[1] | ||
const extName = imgInfo[2] | ||
const targetPath = distFile.replace(fileName + '.' + extName, '') | ||
fs.ensureDirSync(targetPath) | ||
// 批处理实时抛出的钩子。(每处理一张图片触发一次) | ||
const {_data, batching} = baseOpts | ||
batching({ | ||
data: _data, | ||
gm, | ||
warnings, | ||
srcFile, | ||
distFile, | ||
next () { | ||
resolve({relativeFile}) | ||
} | ||
}) | ||
// 批处理实时抛出的钩子。(每处理一张图片触发一次) | ||
const {_data, batching} = baseOpts | ||
batching({ | ||
data: _data, | ||
gm, | ||
warnings, | ||
srcFile, | ||
distFile, | ||
next () { | ||
callBack && callBack({relativeFile}) | ||
} | ||
}) | ||
@@ -75,3 +73,3 @@ } | ||
let srcFile = srcImages.shift() | ||
handleImage(srcFile).then(({relativeFile}) => { | ||
handleImage(srcFile, ({relativeFile}) => { | ||
num ++ | ||
@@ -85,5 +83,10 @@ // 更新进度条 | ||
} else { | ||
// 批处理实时抛出的钩子。(每处理一张图片触发一次) | ||
const {afterBatch} = baseOpts | ||
afterBatch({distPath, chalk, warnings}) | ||
// 更新进度条 | ||
pb.render({completed: num, total: fileLength, fileNames: Object.keys(fileNames)}) | ||
// 批处理完成 | ||
if (!Object.keys(fileNames).length) { | ||
// 批量处理完毕之后的钩子 | ||
const {afterBatch} = baseOpts | ||
afterBatch({distPath, chalk, warnings}) | ||
} | ||
} | ||
@@ -90,0 +93,0 @@ } |
{ | ||
"name": "@tols/gm-base", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "用于@tols gm工具的基础类。具有数据定义,生命周期等能力", | ||
@@ -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
9345
146