var chalk = require('chalk');
var glob = require('glob');
var Checker = require('jscs');
var exit = require('exit');
var fs = require('fs');
var glob = require('glob');
var extend = require('extend');
var logSymbols = require('log-symbols');

var data, parsedCode, checker, parser;

module.exports = function (config) {
  extend(config, {
    files: config.files || [],
    write: config.write || false,
    jscs: config.jscs,
    parser: config.parser || 'ast',
    preset: config.preset || 'jquery'
  });

  if (typeof config.jscs === 'undefined') {
    config.jscs = true;
  }

  try {
    parser = require('./' + config.parser);
  } catch (e) {
    console.log(logSymbols.error + ' ' +
      chalk.bold.red('Failed to load parser: %s'), config.parser);
    console.log(logSymbols.info,
      chalk.bold.yellow('Info: Parser should be either ast/regex'));
    console.log(e.toString());
    exit();
  }

  if (config.files.length === 0) {
    console.log(logSymbols.error, chalk.bold.red('No files passed!'));
    console.log(logSymbols.info, chalk.bold.yellow('Use -h for help'));
    exit();
  }

  if (config.jscs) {
    checker = new Checker();
    var jscsConfig = config.jscsConfig || {};
    extend(jscsConfig, {
      preset: config.preset,
      fix: true
    });

    checker.registerDefaultRules();
    checker.configure(jscsConfig);
  }

  if (Array.isArray(config.files)) {
    parseFiles(null, config.files);
  } else {
    glob(config.files, parseFiles);
  }


  function parseFiles(error, files) {
    if (error) {
      console.log(logSymbols.error, chalk.bold.red('Error in Globbing pattern!'));
      console.log(error.toString());
      exit();
    }

    var errors = [], passed = [];

    files.forEach(function (file) {
      try {
        data = fs.readFileSync(file);
        parsedCode = parser(data);

        if (config.jscs) {
          parsedCode = checker.fixString(parsedCode);
          parsedCode = parsedCode.output;
        }

        if (config.write) {
          fs.writeFileSync(file, parsedCode);
        } else {
          console.log(logSymbols.success +
            ' ' + chalk.bold.green('Output for %s:\n'), file);
          console.log(parsedCode);
        }

        passed.push(file);
      } catch (e) {
        console.log(logSymbols.error + ' ' +
          chalk.bold.red('Error occured while fixing file: %s'), file);

        console.log(e.toString());
        errors.push(file);
      }
    });

    if (errors.length) {
      console.log(chalk.bold.red('Following files were not converted:'));
      errors.forEach(function (error) {
        console.log(logSymbols.error, chalk.red(error));
      });
    }

    if (passed.length) {
      console.log(chalk.bold.green('Following files were successfully converted:'));
      passed.forEach(function (pass) {
        console.log(logSymbols.success, chalk.green(pass));
      });
    }
  }
};

@@ -1,860 +1,62 @@
 var 
-chalk = require('chalk');%0Avar glob = require('glob');%0Avar Checker = require('jscs');%0Avar exit = require('exit');%0Avar fs = require('fs');%0Avar glob = require('glob');%0Avar extend = require('extend');%0Avar logSymbols = require('log-symbols');%0A%0Avar data, parsedCode, checker, parser;%0A%0Amodule.exports = function (config) %7B%0A  extend(config, %7B%0A    files: config.files %7C%7C %5B%5D,%0A    write: config.write %7C%7C false,%0A    jscs: config.jscs,%0A    parser: config.parser %7C%7C 'ast',%0A    preset: config.preset %7C%7C 'jquery'%0A  %7D);%0A%0A  if (typeof config.jscs === 'undefined') %7B%0A    config.jscs = true;%0A  %7D%0A%0A  try %7B%0A    parser = require('./' + config.parser);%0A  %7D catch (e) %7B%0A    console.log(logSymbols.error + ' ' +%0A      chalk.bold.red('Failed to load parser: %25s'), config.parser);%0A    console.log(logSymbols.info,%0A      chalk.bold.yellow('Info: Parser should be either ast
+ast = require('./ast');%0Avar regex = require('.
 /regex')
 );%0A 
@@ -55,2046 +55,56 @@
 ex')
-)
 ;%0A
-    console.log(e.toString());%0A    exit();%0A  %7D%0A%0A  if (config.files.length === 0) %7B%0A    console.log(logSymbols.error, chalk.bold.red('No files passed!'));%0A    console.log(logSymbols.info, chalk.bold.yellow('Use -h for help'));%0A    exit();%0A  %7D%0A%0A  if (config.jscs) %7B%0A    checker = new Checker();%0A    var jscsConfig = config.jscsConfig %7C%7C %7B%7D;%0A    extend(jscsConfig, %7B%0A      preset: config.preset,%0A      fix: true%0A    %7D);%0A%0A    checker.registerDefaultRules();%0A    checker.configure(jscsConfig);%0A  %7D%0A%0A  if (Array.isArray(config.files)) %7B%0A    parseFiles(null, config.files);%0A  %7D else %7B%0A    glob(config.files, parseFiles);%0A  %7D%0A%0A%0A  function parseFiles(error, files) %7B%0A    if (error) %7B%0A      console.log(logSymbols.error, chalk.bold.red('Error in Globbing pattern!'));%0A      console.log(error.toString());%0A      exit();%0A    %7D%0A%0A    var errors = %5B%5D, passed = %5B%5D;%0A%0A    files.forEach(function (file) %7B%0A      try %7B%0A        data = fs.readFileSync(file);%0A        parsedCode = parser(data);%0A%0A        if (config.jscs) %7B%0A          parsedCode = checker.fixString(parsedCode);%0A          parsedCode = parsedCode.output;%0A        %7D%0A%0A        if (config.write) %7B%0A          fs.writeFileSync(file, parsedCode);%0A        %7D else %7B%0A          console.log(logSymbols.success +%0A            ' ' + chalk.bold.green('Output for %25s:%5Cn'), file);%0A          console.log(parsedCode);%0A        %7D%0A%0A        passed.push(file);%0A      %7D catch (e) %7B%0A        console.log(logSymbols.error + ' ' +%0A          chalk.bold.red('Error occured while fixing file: %25s'), file);%0A%0A        console.log(e.toString());%0A        errors.push(file);%0A      %7D%0A    %7D);%0A%0A    if (errors.length) %7B%0A      console.log(chalk.bold.red('Following files were not converted:'));%0A      errors.forEach(function (error) %7B%0A        console.log(logSymbols.error, chalk.red(error));%0A      %7D);%0A    %7D%0A%0A    if (passed.length) %7B%0A      console.log(chalk.bold.green('Following files were successfully converted:'));%0A      passed.forEach(function (pass) %7B%0A        console.log(logSymbols.success, chalk.green(pass));%0A      %7D);%0A    %7D%0A  %7D
+%0Amodule.exports = %7B%0A  ast: ast,%0A  regex: regex
 %0A%7D;%0A

Add api src for codebases