#!/usr/bin/env node

import iniparser from 'iniparser';
import FindFiles from 'node-find-files';

import {fileExists, fileNotEmpty, filterFiles, editorconfigPath} from './utils/file-utils';
import {log, info, error} from './logger/logger';

// No editorconfig no fun
/* eslint-disable no-unused-expressions */
!fileExists(editorconfigPath()) && (error(`ERROR: no .editorconfig found: ${editorconfigPath()}`) || process.exit(1));
/* eslint-enable */

const editorconfig = iniparser.parseSync(editorconfigPath());

const filterOptions = {
	regex: '.git|node_modules|coverage|dist',
	dots: true
};

const finder = new FindFiles({
	rootFolder: '.',
	filterFunction: (file, stat) => fileNotEmpty(stat) && filterFiles(file, filterOptions)
});

finder.on('match', (strPath, stat) => {
	log(strPath);
	info('just test output');
	error(stat.size);
});

finder.on('patherror', (err, strPath) => {
	error(`Error for Path ${strPath} ${err}`);
});

finder.on('error', err => {
	error(`Global Error ${err}`);
});

log(editorconfig);

finder.startSearch();

@@ -264,51 +264,12 @@
 fun%0A
-/* eslint-disable no-unused-expressions */%0A
+if (
 !fil
@@ -299,13 +299,13 @@
 h())
- && (
+) %7B%0A%09
 erro
@@ -365,12 +365,11 @@
 )%7D%60)
- %7C%7C 
+;%0A%09
 proc
@@ -383,30 +383,11 @@
 t(1)
-)
 ;%0A
-/* eslint-enable */
+%7D
 %0A%0Aco
@@ -445,16 +445,56 @@
 Path());
+%0Alet checkedFiles = 0;%0Aconst errors = 1;
 %0A%0Aconst 
@@ -813,16 +813,33 @@
 .size);%0A
+%09checkedFiles++;%0A
 %7D);%0A%0Afin
@@ -951,24 +951,24 @@
 ', err =%3E %7B%0A
-
 %09error(%60Glob
@@ -991,16 +991,299 @@
 );%0A%7D);%0A%0A
+finder.on('complete', () =%3E %7B%0A%09log('all done');%0A%09if (errors === 0) %7B%0A%09%09log(%60sucessfully checked $%7BcheckedFiles%7D files%60);%0A%09%7D else %7B%0A%09%09error(%60$%7Berrors%7D occured! See log above and fix errors%60);%0A%09%09if (errors %3C 254) %7B%0A%09%09%09process.exit(errors);%0A%09%09%7D else %7B%0A%09%09%09process.exit(254);%0A%09%09%7D%0A%09%7D%0A%7D);%0A%0A
 log(edit

add pretty finish output