feat: add builder configuration file
feat: add cocos-service configuration file feat: add device configuration file feat: add engine configuration file feat: add information configuration file feat: add program configuration file feat: add project configuration file feat: add TypeScript configuration file
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "mozjpeg",
|
||||
"version": "8.0.0",
|
||||
"description": "mozjpeg wrapper that makes it seamlessly available as a local dependency",
|
||||
"license": "MIT",
|
||||
"repository": "imagemin/mozjpeg-bin",
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"bin": "cli.js",
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node lib/install.js",
|
||||
"test": "xo && ava --timeout=120s",
|
||||
"build-linux": "docker build --tag imagemin/mozjpeg docker && docker run --rm --volume $(pwd)/vendor/linux:/src/out imagemin/mozjpeg cp cjpeg /src/out"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"cli.js",
|
||||
"lib",
|
||||
"vendor/source"
|
||||
],
|
||||
"keywords": [
|
||||
"imagemin",
|
||||
"jpeg",
|
||||
"jpg",
|
||||
"img",
|
||||
"image",
|
||||
"compress",
|
||||
"minify",
|
||||
"mozjpeg",
|
||||
"optimize"
|
||||
],
|
||||
"dependencies": {
|
||||
"bin-build": "^3.0.0",
|
||||
"bin-wrapper": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^3.8.0",
|
||||
"bin-check": "^4.1.0",
|
||||
"compare-size": "^3.0.0",
|
||||
"execa": "^5.1.1",
|
||||
"tempy": "^2.0.0",
|
||||
"xo": "^0.45.0"
|
||||
},
|
||||
"ava": {
|
||||
"serial": true
|
||||
}
|
||||
}
|
||||
13098
extensions/quick-compress-image/lib/imagemin.min.js
vendored
Normal file
13098
extensions/quick-compress-image/lib/imagemin.min.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
/*!
|
||||
* fill-range <https://github.com/jonschlinkert/fill-range>
|
||||
*
|
||||
* Copyright (c) 2014-present, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* is-extglob <https://github.com/jonschlinkert/is-extglob>
|
||||
*
|
||||
* Copyright (c) 2014-2016, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* is-glob <https://github.com/jonschlinkert/is-glob>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* is-number <https://github.com/jonschlinkert/is-number>
|
||||
*
|
||||
* Copyright (c) 2014-present, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* to-regex-range <https://github.com/micromatch/to-regex-range>
|
||||
*
|
||||
* Copyright (c) 2015-present, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/*! run-parallel. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
77
extensions/quick-compress-image/lib/imageminApi.js
Normal file
77
extensions/quick-compress-image/lib/imageminApi.js
Normal file
@@ -0,0 +1,77 @@
|
||||
let Path = require('path')
|
||||
let Fs = require('fs');
|
||||
let imageminApi = require('../lib/imagemin.min')
|
||||
let packageCfg = require('../package.json')
|
||||
|
||||
module.exports = {
|
||||
|
||||
async getZipRate(){
|
||||
let rate = parseInt(await Editor.Profile.getConfig(packageCfg.name,'zipRate')) || 30;
|
||||
if(rate<0){
|
||||
rate = 1;
|
||||
}else if(rate>100){
|
||||
rate = 100
|
||||
}
|
||||
|
||||
return rate;
|
||||
},
|
||||
|
||||
/**
|
||||
* 调用压缩工具api
|
||||
* @param {Array<{file:string,uuid:string}>} fileInfo
|
||||
*/
|
||||
async compressPicture(arrList,imageFileList){
|
||||
let rate = await this.getZipRate();
|
||||
let pngRate = rate*0.01;
|
||||
|
||||
console.log("压缩值:",rate+"%");
|
||||
|
||||
imageminApi.imagemin(arrList, {
|
||||
plugins: [
|
||||
imageminApi.imageminMozjpeg({ quality: rate }), //压缩质量(0,1)
|
||||
imageminApi.imageminPngquant({
|
||||
quality: [pngRate, Math.min(pngRate+0.25,1)] //压缩质量(0,1)
|
||||
})
|
||||
]
|
||||
|
||||
}).then((arrRes) => {
|
||||
console.log("压缩成功,详情:\n")
|
||||
for (let i = 0; i < arrRes.length; i++) {
|
||||
const res = arrRes[i];
|
||||
this.onCompressedSucceed(imageFileList,res)
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
console.log("压缩失败:",err)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 压缩成功
|
||||
* @param {Array<{file:string,uuid:string,size:number}>} imageFileList
|
||||
* @param {Object<{data:Buffer,sourcePath:string}>} res
|
||||
*/
|
||||
onCompressedSucceed(imageFileList,res){
|
||||
let desc = ""
|
||||
for (let i = 0; i < imageFileList.length; i++) {
|
||||
const fileInfo = imageFileList[i];
|
||||
if(fileInfo.file.replace(/\\/g,'/') == res.sourcePath){
|
||||
const fileName = Path.basename(fileInfo.file);
|
||||
const newSize = res.data.byteLength;
|
||||
const rate = (fileInfo.size-newSize)/fileInfo.size;
|
||||
const oldMb = (fileInfo.size / 1024).toFixed(1) + " KB";
|
||||
const newMb = (newSize / 1024).toFixed(1) + " KB";
|
||||
if(newSize < fileInfo.size){
|
||||
Fs.writeFileSync(res.sourcePath, res.data)
|
||||
desc += `${fileName}、压缩率:${parseInt(rate*100)}%、压缩前后大小:${newMb} / ${oldMb}`
|
||||
}else{
|
||||
desc += `${fileName}、无法继续压缩`
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
console.log(desc);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
89
extensions/quick-compress-image/lib/tinypngApi.js
Normal file
89
extensions/quick-compress-image/lib/tinypngApi.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const https = require("https");
|
||||
const URL = require("url").URL;
|
||||
const EventEmitter = require("events");
|
||||
const err = (msg) => new EventEmitter().emit("error", msg);
|
||||
|
||||
/**
|
||||
* TinyPng 远程压缩 HTTPS 请求的配置生成方法
|
||||
*/
|
||||
|
||||
function getAjaxOptions() {
|
||||
return {
|
||||
method: "POST",
|
||||
hostname: "tinypng.com",
|
||||
path: "/web/shrink",
|
||||
headers: {
|
||||
rejectUnauthorized: false,
|
||||
"X-Forwarded-For": Array(4)
|
||||
.fill(1)
|
||||
.map(() => parseInt(Math.random() * 254 + 1))
|
||||
.join("."),
|
||||
"Postman-Token": Date.now(),
|
||||
"Cache-Control": "no-cache",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* TinyPng 远程压缩 HTTPS 请求
|
||||
* @param {string} img 待处理的文件
|
||||
* @success {
|
||||
* "input": { "size": 887, "type": "image/png" },
|
||||
* "output": { "size": 785, "type": "image/png", "width": 81, "height": 81, "ratio": 0.885, "url": "https://tinypng.com/web/output/7aztz90nq5p9545zch8gjzqg5ubdatd6" }
|
||||
* }
|
||||
* @error {"error": "Bad request", "message" : "Request is invalid"}
|
||||
*/
|
||||
function fileUpload(imgPath) {
|
||||
let req = https.request(getAjaxOptions(), (res) => {
|
||||
res.on("data", (buf) => {
|
||||
let obj = JSON.parse(buf.toString());
|
||||
if (obj.error)
|
||||
console.log(`压缩失败!\n 当前文件:${imgPath} \n ${obj.message}`);
|
||||
else fileUpdate(imgPath, obj);
|
||||
});
|
||||
});
|
||||
|
||||
req.write(fs.readFileSync(imgPath), "binary");
|
||||
req.on("error", (e) =>
|
||||
console.log(`请求错误! 当前文件:${path.basename(imgPath)} \n`, e)
|
||||
);
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 该方法被循环调用,请求图片数据
|
||||
function fileUpdate(entryImgPath, obj) {
|
||||
let options = new URL(obj.output.url);
|
||||
let req = https.request(options, (res) => {
|
||||
let body = "";
|
||||
res.setEncoding("binary");
|
||||
res.on("data", (data) => (body += data));
|
||||
res.on("end", () => {
|
||||
fs.writeFile(entryImgPath, body, "binary", (err) => {
|
||||
if (err) return console.error(err);
|
||||
let log = `压缩成功:`;
|
||||
log += `${path.basename(entryImgPath)}、压缩率:${ ((1 - obj.output.ratio) * 100).toFixed(2) }%、压缩前后大小:${(obj.output.size / 1024).toFixed(2)} / ${(obj.input.size / 1024).toFixed(2)}`
|
||||
console.log(log);
|
||||
});
|
||||
});
|
||||
});
|
||||
req.on("error", (e) => console.warn('压缩失败:',path.basename(entryImgPath) ,e));
|
||||
req.end();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 调用压缩工具api
|
||||
* @param {Array<{file:string,uuid:string}>} fileInfo
|
||||
*/
|
||||
async compressPicture(arrList,imageFileList){
|
||||
for (let i = 0; i < arrList.length; i++) {
|
||||
const imgPath = arrList[i];
|
||||
fileUpload(imgPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
extensions/quick-compress-image/lib/vendor/cjpeg
vendored
Normal file
BIN
extensions/quick-compress-image/lib/vendor/cjpeg
vendored
Normal file
Binary file not shown.
BIN
extensions/quick-compress-image/lib/vendor/cjpeg.exe
vendored
Normal file
BIN
extensions/quick-compress-image/lib/vendor/cjpeg.exe
vendored
Normal file
Binary file not shown.
BIN
extensions/quick-compress-image/lib/vendor/pngquant
vendored
Normal file
BIN
extensions/quick-compress-image/lib/vendor/pngquant
vendored
Normal file
Binary file not shown.
BIN
extensions/quick-compress-image/lib/vendor/pngquant-ppc
vendored
Normal file
BIN
extensions/quick-compress-image/lib/vendor/pngquant-ppc
vendored
Normal file
Binary file not shown.
BIN
extensions/quick-compress-image/lib/vendor/pngquant.exe
vendored
Normal file
BIN
extensions/quick-compress-image/lib/vendor/pngquant.exe
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user