Browse Source

Fix something

HonorLee 11 months ago
parent
commit
ac0bf5b240
2 changed files with 23 additions and 16 deletions
  1. 15 13
      ImageMinify.js
  2. 8 3
      README.md

+ 15 - 13
ImageMinify.js

@@ -138,13 +138,15 @@ function prepareTask(){
 }
 
 function startTask(){
-    console.log('-----------------------------------------------------------------');
-    console.log(`[ Path ] ${Config.path}`);
-    console.log(`[Folder] ${Config.isFolder}\t[Quality] ${Config.quality}\t[OutputExtension] ${Config.ext}\t[Amount] ${ImageList.length}\t[Worker] ${Config.worker}`);
-    console.log('-----------------------------------------------------------------');
-    console.log(`[OutputDirectory] ${Config.outputDir}`);
-    console.log('-----------------------------------------------------------------');
-    processBar = new ProgressBar('Minifying: [:bar][:current/:total] [:image]', { total: ImageList.length, width: 20, complete: '*' });
+    if(!program.silence){
+        console.log('-----------------------------------------------------------------');
+        console.log(`[ Path ] ${Config.path}`);
+        console.log(`[Folder] ${Config.isFolder}\t[Quality] ${Config.quality}\t[OutputExtension] ${Config.ext}\t[Amount] ${ImageList.length}\t[Worker] ${Config.worker}`);
+        console.log('-----------------------------------------------------------------');
+        console.log(`[OutputDirectory] ${Config.outputDir}`);
+        console.log('-----------------------------------------------------------------');
+        processBar = new ProgressBar('Minifying: [:bar][:current/:total] [:image]', { total: ImageList.length, width: 20, complete: '*' });
+    }
     for(let i = 0;i<Config.worker;i++){
         minify();
     }
@@ -172,7 +174,7 @@ function minify(){
         }else{
             fs.copySync(image,`${outputDir}/${fileName}.${imgExt}`);
         }
-        processBar.total--;
+        if(!program.silence) processBar.total--;
         workerCount--;
         if(ImageList.length==1) return finished();
         return minify();
@@ -180,12 +182,12 @@ function minify(){
 
     exec(`export OMP_NUM_THREADS=4 && gm convert -strip -format '${outputExt}' -quality ${Config.quality} -depth 8 "${image}" "${outputFile}"`,function(err,stdout,stderr){
         if(err || stdout || stderr){
-            console.log(err,stdout,stderr)
+            // console.log(err,stdout,stderr)
             failureList.push(image);
         }else{
             if(program.removeOrigin) fs.removeSync(image);
         }
-        processBar.tick(1,{'image':`${subDir}/${fileName}.${imgExt}`});
+        if(!program.silence) processBar.tick(1,{'image':`${subDir}/${fileName}.${imgExt}`});
 
         workerCount--;
         if(workerCount==0 && ImageList.length==0) return finished();
@@ -196,9 +198,9 @@ function finished(){
     if(!program.silence) console.log('\nAll images minified');
     if(!failureList.length) return;
     let log = '';
-    log += ('\n-----------------------------------------------------------------');
+    log += ('\n-----------------------------------------------------------------\n');
     log += ('These image(s) minified failed!');
-    log += ('-----------------------------------------------------------------');
+    log += ('-----------------------------------------------------------------\n');
 
     for(let image of failureList){
         log += image + '\n';
@@ -206,7 +208,7 @@ function finished(){
     log += ('-----------------------------------------------------------------\n');
 
     fs.writeFileSync(`${Config.outputDir}/error.log`,log,'UTF-8');
-    console.log(log);
+    console.error(log);
 }
 
 

+ 8 - 3
README.md

@@ -10,7 +10,14 @@ Waiting...
 
 ## Features
 ```
-Waiting...
+    + 单张压缩
+    + 文件夹批量压缩
+    + 输出目录自定义
+    + 输出图片格式自定义
+    + 输出图片质量自定义
+    + 排除(多个)后缀
+    + 排除指定目录
+    + 并发处理
 ```
 
 ## Tutorials
@@ -37,8 +44,6 @@ Options:
 ```
 ## TODO
 ```
-    - 后缀排除
-    - 目录排除
     - 图片缩放
     - 水印添加
     - 上架NPM仓库