<commit_before>// This is a CLI tool, using console is OK
/* eslint no-console: 0 */
import {spawn, exec} from 'child_process';
import {isAbsolute, resolve} from 'path';
import {existsSync} from 'fs';
import {version} from '../app/package.json';
import pify from 'pify';
import args from 'args';
import chalk from 'chalk';
import open from 'open';
import columnify from 'columnify';
import got from 'got';
import ora from 'ora';
import * as api from './api';

const PLUGIN_PREFIX = 'hyper-';

let commandPromise: Promise<void>;

const assertPluginName = (pluginName: string) => {
  if (!pluginName) {
    console.error(chalk.red('Plugin name is required'));
    process.exit(1);
  }
};

const checkConfig = () => {
  if (api.exists()) {
    return true;
  }
  let msg = chalk.red(`Error! Config file not found: ${api.configPath}\n`);
  msg += 'Please launch Hyper and retry.';
  console.error(msg);
  process.exit(1);
};

args.command(
  'install',
  'Install a plugin',
  (name, args_) => {
    checkConfig();
    const pluginName = args_[0];
    assertPluginName(pluginName);
    commandPromise = api
      .install(pluginName)
      .then(() => console.log(chalk.green(`${pluginName} installed successfully!`)))
      .catch((err: any) => console.error(chalk.red(err)));
  },
  ['i']
);

args.command(
  'uninstall',
  'Uninstall a plugin',
  (name, args_) => {
    checkConfig();
    const pluginName = args_[0];
    assertPluginName(pluginName);
    commandPromise = api
      .uninstall(pluginName)
      .then(() => console.log(chalk.green(`${pluginName} uninstalled successfully!`)))
      .catch((err) => console.log(chalk.red(err)));
  },
  ['u', 'rm', 'remove']
);

args.command(
  'list',
  'List installed plugins',
  () => {
    checkConfig();
    const plugins = api.list();

    if (plugins) {
      console.log(plugins);
    } else {
      console.log(chalk.red(`No plugins installed yet.`));
    }
    process.exit(0);
  },
  ['ls']
);

const lsRemote = (pattern?: string) => {
  // note that no errors are catched by this function
  const URL = `https://api.npms.io/v2/search?q=${(pattern && `${pattern}+`) || ''}keywords:hyper-plugin,hyper-theme`;
  return got(URL)
    .then((response) => JSON.parse(response.body).results as any[])
    .then((entries) => entries.map((entry) => entry.package))
    .then((entries) => entries.filter((entry) => entry.name.indexOf(PLUGIN_PREFIX) === 0))
    .then((entries) =>
      entries.map(({name, description}) => {
        return {name, description};<commit_msg>Show more plugins when use command list-remote<commit_after>// This is a CLI tool, using console is OK
/* eslint no-console: 0 */
import {spawn, exec} from 'child_process';
import {isAbsolute, resolve} from 'path';
import {existsSync} from 'fs';
import {version} from '../app/package.json';
import pify from 'pify';
import args from 'args';
import chalk from 'chalk';
import open from 'open';
import columnify from 'columnify';
import got from 'got';
import ora from 'ora';
import * as api from './api';

let commandPromise: Promise<void>;

const assertPluginName = (pluginName: string) => {
  if (!pluginName) {
    console.error(chalk.red('Plugin name is required'));
    process.exit(1);
  }
};

const checkConfig = () => {
  if (api.exists()) {
    return true;
  }
  let msg = chalk.red(`Error! Config file not found: ${api.configPath}\n`);
  msg += 'Please launch Hyper and retry.';
  console.error(msg);
  process.exit(1);
};

args.command(
  'install',
  'Install a plugin',
  (name, args_) => {
    checkConfig();
    const pluginName = args_[0];
    assertPluginName(pluginName);
    commandPromise = api
      .install(pluginName)
      .then(() => console.log(chalk.green(`${pluginName} installed successfully!`)))
      .catch((err: any) => console.error(chalk.red(err)));
  },
  ['i']
);

args.command(
  'uninstall',
  'Uninstall a plugin',
  (name, args_) => {
    checkConfig();
    const pluginName = args_[0];
    assertPluginName(pluginName);
    commandPromise = api
      .uninstall(pluginName)
      .then(() => console.log(chalk.green(`${pluginName} uninstalled successfully!`)))
      .catch((err) => console.log(chalk.red(err)));
  },
  ['u', 'rm', 'remove']
);

args.command(
  'list',
  'List installed plugins',
  () => {
    checkConfig();
    const plugins = api.list();

    if (plugins) {
      console.log(plugins);
    } else {
      console.log(chalk.red(`No plugins installed yet.`));
    }
    process.exit(0);
  },
  ['ls']
);

const lsRemote = (pattern?: string) => {
  // note that no errors are catched by this function
  const URL = `https://api.npms.io/v2/search?q=${
    (pattern && `${pattern}+`) || ''
  }keywords:hyper-plugin,hyper-theme&size=250`;
  return got(URL)
    .then((response) => JSON.parse(response.body).results as any[])
    .then((entries) => entries.map((entry) => entry.package))
    .then((entries) =>
      entries.map(({name, description}) => {
        return {name, description};
{'fraction_non_alphanumeric': 0.18048289738430584, 'fraction_numerical': 0.0036217303822937627, 'mean_word_length': 3.607043558850788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1618198', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1607, 'n_words': 411}