gulp-retina-resizer
Advanced tools
Comparing version 0.1.1 to 0.2.0
21
index.js
@@ -19,6 +19,7 @@ 'use strict'; | ||
}; | ||
const COPY = Boolean(arg && arg.copy); | ||
return through.obj(function(file, encoding, cb) { | ||
if(file.isNull() || file.isDirectory()) { | ||
return cb(); | ||
if(!file.isBuffer()) { | ||
return cb(null, file); | ||
} | ||
@@ -41,2 +42,6 @@ | ||
let getName = function(path, to) { | ||
return /[\\\/]+([^\\\/@]+)(@\dx)?\.[^\.\\\/]+$/.exec(path)[1] + '@' + to + 'x.png'; | ||
}; | ||
let makePromise = function(info, to) { | ||
@@ -49,3 +54,3 @@ let size = info.size; | ||
let path = info.path; | ||
let name = /[\\\/]+([^\\\/]+)\.[^\.\\\/]+$/.exec(path)[1] + '@' + to + 'x.png'; | ||
let name = getName(path, to); | ||
@@ -72,5 +77,13 @@ return new Promise(function(resolve, reject) { | ||
}) | ||
.then(() => cb()) | ||
.then(function() { | ||
if(COPY) { | ||
createFile({ | ||
name: getName(file.path, BASE), | ||
buffer: file.contents | ||
}); | ||
} | ||
return cb(); | ||
}) | ||
.catch(err => this.emit('error', err)); | ||
}); | ||
}; |
{ | ||
"name": "gulp-retina-resizer", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "resize images", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,4 +19,5 @@ 本插件用于在 Gulp 中转换图片大小,可从3倍图转换到2倍或1倍,也可从2倍转到1倍。 | ||
.pipe(resizer({ | ||
base: 2, | ||
to: 1 | ||
base: 3, | ||
to: [1, 2], | ||
copy: true | ||
})) | ||
@@ -35,3 +36,4 @@ .pipe(gulp.dest('dest')) | ||
base: 2, | ||
to: 1 | ||
to: 1, | ||
copy: false | ||
} | ||
@@ -42,2 +44,3 @@ ``` | ||
- `to`:数字或数组,生成图的倍数比 | ||
- `copy`: 布尔值,是否复制原图到目的文件夹 | ||
@@ -44,0 +47,0 @@ 计算方式: |
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
3799
73
50