Commit 1046fea4 authored by haiyoucuv's avatar haiyoucuv

init

parent 867d7740
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@types/fs-extra": "^5.0.4", "@types/fs-extra": "^5.0.4",
"@types/node": "^14.5.2", "@types/node": "^18.17.1",
"ali-oss": "^6.19.0", "ali-oss": "^6.19.0",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
"jszip": "^3.10.1", "jszip": "^3.10.1",
...@@ -27,10 +27,12 @@ ...@@ -27,10 +27,12 @@
} }
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "14.18.63", "version": "18.19.110",
"resolved": "http://npm.dui88.com:80/@types%2fnode/-/node-14.18.63.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.110.tgz",
"integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==", "integrity": "sha512-WW2o4gTmREtSnqKty9nhqF/vA0GKd0V/rbC0OyjSk9Bz6bzlsXKT+i7WDdS/a0z74rfT2PO4dArVCSnapNLA5Q==",
"license": "MIT" "dependencies": {
"undici-types": "~5.26.4"
}
}, },
"node_modules/address": { "node_modules/address": {
"version": "1.2.2", "version": "1.2.2",
...@@ -946,6 +948,11 @@ ...@@ -946,6 +948,11 @@
"node": ">=14.17" "node": ">=14.17"
} }
}, },
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
"node_modules/unescape": { "node_modules/unescape": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "http://npm.dui88.com:80/unescape/-/unescape-1.0.1.tgz", "resolved": "http://npm.dui88.com:80/unescape/-/unescape-1.0.1.tgz",
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
}, },
"dependencies": { "dependencies": {
"@types/fs-extra": "^5.0.4", "@types/fs-extra": "^5.0.4",
"@types/node": "^14.5.2", "@types/node": "^18.17.1",
"ali-oss": "^6.19.0", "ali-oss": "^6.19.0",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
"jszip": "^3.10.1", "jszip": "^3.10.1",
......
...@@ -53,6 +53,48 @@ export async function compressAllImage(paths = [], root) { ...@@ -53,6 +53,48 @@ export async function compressAllImage(paths = [], root) {
getImages(root + "/" + dir, imgs); getImages(root + "/" + dir, imgs);
}); });
// let completed = 0;
//
// const chunkSize = 20;
//
// const userHomeDir = Os.homedir();
// const cacheDir = path.join(userHomeDir, ".image_compress_cache");
//
// if (!fs.existsSync(cacheDir)) await fs.mkdir(cacheDir, { recursive: true });
//
// const now = Date.now();
// const tempDir = path.join(userHomeDir, `.image_compress_temp/${now}`);
//
// for (let i = 0; i < paths.length; i += chunkSize) {
// const chunk = paths.slice(i, i + chunkSize);
//
// const ps = chunk.map(async (imgPath, idx) => {
// const tempName = `${tempDir}/${i + idx}.png`;
//
// // 检查缓存
// const fileBuffer = await fs.readFile(imgPath);
// const md5Hash = crypto.createHash("md5").update(fileBuffer).digest("hex");
// const cachedFilePath = path.join(cacheDir, `${md5Hash}.png`);
//
// if (fs.existsSync(cachedFilePath)) {
// // 如果缓存文件存在,直接复制到目标路径
// await fs.copyFile(cachedFilePath, imgPath);
// } else {
// // 如果缓存文件不存在,执行压缩操作并缓存
// await fs.copyFile(imgPath, tempName);
// execSync(`"${pngquantPath}" ${compressOptions} "${tempName}"`);
// await fs.copyFile(tempName, imgPath);
// await fs.copyFile(tempName, cachedFilePath);
// }
//
// completed++;
// });
//
// await Promise.all(ps);
// }
//
// await fs.rm(tempDir, { recursive: true });
if (platform == "win32") { if (platform == "win32") {
const now = Date.now(); const now = Date.now();
...@@ -104,33 +146,4 @@ export async function compressAllImage(paths = [], root) { ...@@ -104,33 +146,4 @@ export async function compressAllImage(paths = [], root) {
} }
// const tasks = imgs.map((imgPath) => {
// return new Promise<void>((resolve) => {
// try {
// const command = `"${pngquantPath}" ${compressOptions} "${imgPath}"`;
//
// console.log(command);
//
// const originSize = fs.statSync(imgPath).size / 1000;
//
// exec(command, (error, stdout, stderr) => {
// if (error) {
// // console.error(error);
// } else {
// const size = fs.statSync(imgPath).size / 1000;
// // 计算压缩率
// const rate = ((originSize - size) / originSize) * 100;
// console.log(`%c压缩图片成功, ${originSize}k -> ${size}k 压缩率:${rate.toFixed(2)}%`, "color: green");
// }
// resolve();
// });
// } catch (e) {
// console.error(e);
// resolve();
// }
// });
// });
//
// await Promise.all(tasks);
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment