{"size": 957, "ext": "js", "max_stars_repo_path": "client/node_modules/es-beautifier/contrib/atom/index.js", "max_stars_repo_name": "Patrick-Erichsen/consensource", "max_stars_repo_stars_event_min_datetime": "2016-12-01T18:59:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T08:26:34.000Z", "max_issues_repo_path": "client/node_modules/es-beautifier/contrib/atom/index.js", "max_issues_repo_name": "alok2599/consensource", "max_issues_repo_issues_event_min_datetime": "2016-12-05T05:40:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-05T23:04:57.000Z", "max_forks_repo_path": "client/node_modules/es-beautifier/contrib/atom/index.js", "max_forks_repo_name": "trevormcdonald/consensource", "max_forks_repo_forks_event_min_datetime": "2016-12-15T00:43:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-23T20:29:11.000Z"}
{"max_stars_count": 132, "max_issues_count": 21, "max_forks_count": 11, "avg_line_length": 29.0, "max_line_length": 91, "alphanum_fraction": 0.696969697}
/* global atom */

const path = require('path');
const execFileSync = require('child_process').execFileSync;
const CompositeDisposable = require('atom').CompositeDisposable;

function execCLI(input, opts = []) {
  const cli = path.resolve(__dirname, 'node_modules/es-beautifier/lib/cli.js');
  return execFileSync('node', [cli, ...opts], { input, encoding: 'utf8' });
}

function beautify() {
  const opts = [];
  if (atom.config.get('es-beautifier.useEslintrc')) {
    opts.push('--use-eslintrc');
  }
  const editor = atom.workspace.getActiveTextEditor();
  if (editor) {
    const text = editor.getText();
    const beautified = execCLI(text, opts);
    editor.setText(beautified);
  }
}

exports.activate = function activate() {
  this.subscriptions = new CompositeDisposable();
  this.subscriptions.add(atom.commands.add('atom-text-editor', 'es-beautifier', beautify));
};

exports.deactivate = function activate() {
  this.subscriptions.dispose();
};
