#!/usr/bin/env node

/**
 * @description File size checker.
 * @author sota1235
 */

"use strict";

import { isUndefined, isEmpty } from 'lodash';
import clc from 'cli-color';
import glob from 'glob';
import program from 'commander';
import checkFiles from '../cli';

// get arguments
program
  .option('--files <target>', 'target files for lint')
  .option('--limit <Byte>', 'limit size', parseInt)
  .parse(process.argv);

const targetFiles = program.files
const limitSize   = program.limit;

if (isUndefined(targetFiles)) {
  console.log(`${clc.red('Error')}: Please add -f option`);
  console.log('Try again please!');
  process.exit(1);
}

if (isUndefined(limitSize)) {
  console.log(`${clc.red('Error')}: Please add -l option`);
  console.log('Try again please!');
  process.exit(1);
}

glob(targetFiles, (err, files) => {
  if (err) {
    console.log(`Error: ${err.message}\n`);
    console.log('Try again please!\n');
    process.exit(1);
  }

  if (isEmpty(files)) {
    console.log('Target file is nothing :(');
    process.exit(0);
  }

  checkFiles(files, limitSize)
    .then(result => {
      const exitStatus = result ? 0 : 1;
      process.exit(exitStatus);
    })
    .catch(err => {
      console.error(`something error, ${err}`)
      process.exit(1);
    });
});

@@ -82,23 +82,8 @@
 */%0A%0A
-%22use strict%22;%0A%0A
 impo
@@ -436,16 +436,17 @@
 am.files
+;
 %0Aconst l
@@ -1029,16 +1029,86 @@
 %0A  %7D%0A%0A  
+const promises = %5B%5D;%0A%0A  for (const file of files) %7B%0A    promises.push(
 checkFil
@@ -1112,15 +1112,17 @@
 File
-s
+Size
 (file
-s
 , li
@@ -1133,109 +1133,90 @@
 ize)
+);
 %0A  
-  .then(result =%3E %7B%0A      const exitStatus = result ? 0 : 1;%0A      process.exit(exitStatus);%0A    %7D
+%7D%0A%0A  Promise.all(promises)%0A    .then(() =%3E console.log('All check finished!')
 )%0A  
@@ -1225,18 +1225,16 @@
 .catch(e
-rr
  =%3E %7B%0A  
@@ -1276,13 +1276,12 @@
  $%7Be
-rr
 %7D%60)
+;
 %0A   

fix for eslint