|
@@ -35,7 +35,7 @@ var Config = {
|
|
|
currentDir : '',
|
|
|
outputDir : ''
|
|
|
}
|
|
|
-var ImageList = [],failureList = [],exceptExt = {},exceptFolder = {},workerCount = 0;
|
|
|
+var ImageList = [],OtherFileList = [],failureList = [],exceptExt = {},exceptFolder = {},workerCount = 0;
|
|
|
var processBar;
|
|
|
|
|
|
if(!Config.path) return program.outputHelp();
|
|
@@ -87,6 +87,8 @@ function analysisFolder(readPath){
|
|
|
let ext = path.extname(fileName);
|
|
|
if(ext.match(/jpg|jpeg|png|gif|bmp|raw/gi)){
|
|
|
ImageList.push(filePath);
|
|
|
+ }else{
|
|
|
+ OtherFileList.push(filePath);
|
|
|
}
|
|
|
}else{
|
|
|
if(exceptFolder[path.parse(filePath).name]) continue;
|
|
@@ -190,10 +192,26 @@ function minify(){
|
|
|
if(!program.silence) processBar.tick(1,{'image':`${subDir}/${fileName}.${imgExt}`});
|
|
|
|
|
|
workerCount--;
|
|
|
- if(workerCount==0 && ImageList.length==0) return finished();
|
|
|
+ if(workerCount==0 && ImageList.length==0) return moveOrtherFiles();
|
|
|
minify();
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+function moveOrtherFiles(){
|
|
|
+ if(OtherFileList.length==0) return finished();
|
|
|
+ for(var filePath of OtherFileList){
|
|
|
+ let pathParse = path.parse(filePath);
|
|
|
+ let fileDir = pathParse.dir;
|
|
|
+ let fileName = pathParse.name;
|
|
|
+ let subDir = fileDir.replace(Config.currentDir,'');
|
|
|
+ let fileExt = pathParse.ext.replace('.','');
|
|
|
+ let outputDir = Config.outputDir + subDir;
|
|
|
+ let outputFile = `${outputDir}/${fileName}.${fileExt}`;
|
|
|
+ fs.mkdirpSync(outputDir);
|
|
|
+ fs.moveSync(filePath,`${outputDir}/${fileName}.${fileExt}`);
|
|
|
+ }
|
|
|
+ finished();
|
|
|
+}
|
|
|
function finished(){
|
|
|
if(!program.silence) console.log('\nAll images minified');
|
|
|
if(!failureList.length) return;
|