Skip to content

Commit

Permalink
chore: update pack-qiniu deps
Browse files Browse the repository at this point in the history
  • Loading branch information
huixisheng committed Jun 17, 2019
1 parent 3773269 commit abc9fcf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wepy-plugin-image",
"version": "0.1.1",
"version": "0.1.2",
"description": "wepy插件根据图片大小转base64或者上传七牛",
"main": "src/index.js",
"scripts": {
Expand All @@ -15,7 +15,7 @@
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"mime": "^2.2.0",
"pack-qiniu": "^1.0.1",
"pack-qiniu": "^1.0.2",
"validator": "^10.2.0"
},
"husky": {
Expand All @@ -42,8 +42,7 @@
"eslint-import-resolver-webpack": "^0.8.4",
"husky": "^0.15.0-rc.13",
"mocha": "^5.0.4",
"node-plus-string": "^1.0.1",
"x-config-deploy": "^0.0.3"
"node-plus-string": "^1.0.1"
},
"engines": {
"node": ">= 4.0.0",
Expand Down
38 changes: 26 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// const path = require('path');
const path = require('path');
const fs = require('fs');
const mime = require('mime');
// TODO key 没有配置的提示
Expand All @@ -11,6 +11,8 @@ class ImageParse {
// TODO filter
this.config = Object.assign({
limit: 1024,
// TODO: 兼容wepy --log trace
// https://github.com/npm/npmlog/blob/master/log.js#L296-L304
debugMode: false,
}, cfg);
}
Expand All @@ -35,34 +37,44 @@ class ImageParse {
return Promise.resolve({ node, ctx });
}
const bgPaths = code.match(reg) || [];
if (debugMode) {
console.log('wepy-plugin-image bgPaths:\n', bgPaths);
}


const base64List = [];
const uploadList = [];
bgPaths.forEach((item) => {
const bgPathFilter = bgPaths.filter(item => item.indexOf('data:image/svg+xml') < 0 && item.indexOf('http') !== 0);
if (debugMode) {
console.log('wepy-plugin-image bgPaths:\n', bgPathFilter);
}
bgPathFilter.forEach((item) => {
const bgImage = item.replace(/'/g, '').replace(/"/g, '').replace('url(', '').replace(/\)$/g, '');
// 本身是绝对地址
const bgPath = bgImage;
let bgPath = bgImage;

if (debugMode) {
console.log('bgPathSouce:%s\n', bgPath);
}

// 绝对地址不存在,使用去除lessRootpath地址的相对地址
// if (!fs.existsSync(bgPath)) {
// bgPath = path.join(path.dirname(file.replace('dist', 'src')), bgImage.replace(lessRootpath, ''));
// }
// fix: http的链接不处理
if (!fs.existsSync(bgPath) && bgPath.indexOf('http') !== 0) {
bgPath = path.join(path.dirname(file), bgPath);
}

// less使用e('')传递的路径
// if (!fs.existsSync(bgPath)) {
// bgPath = path.join(path.dirname(file.replace('dist', 'src')), bgImage);
// }

if (debugMode) {
console.log('bgPath:', bgPath);
console.log('bgPathChange:%s\n', bgPath);
}

if (!fs.existsSync(bgPath) && debugMode) {
console.error('%s不存在', bgPath);
if (bgPath.indexOf('http') < 0) {
console.error('%s不存在', bgPath);
}
}
// TODO: https:// 开头的字体
if (!validator.isURL(bgImage, { require_protocol: true }) && fs.existsSync(bgPath)) {
const stats = fs.statSync(bgPath);
if (stats.size > config.limit) {
Expand All @@ -77,7 +89,9 @@ class ImageParse {
});
}
} else {
console.error('%路径格式不正确', bgPath);
if (bgPath.indexOf('http') < 0) {
console.error('不正确的路径', bgPath);
}
}
});

Expand Down

0 comments on commit abc9fcf

Please sign in to comment.