|
@@ -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);
|
|
|
}
|
|
|
|
|
|
|