<commit_before>const { readAppsFile, writeAppsFile } = require('./util');
const { CWD } = require('./constants');

/**
  * 保存应用
  * @param  {Object} options 参数
  * @param {String} options.domain 域名
  * @param {Number} options.port 端口号
  * @param {Number} options.pid 进程ID
  * @param {String} options.status 状态
  * @return {Promise<Object>}
  */
function save(options) {
  if (options == null) {
    return Promise.resolve(null);
  }

  let webapp = null;

  return readAppsFile()
    .then((file) => {
      const webapps = file.list;
      const {
        id, domain = '', port, pid, status
      } = options;
      webapp = webapps.find((o) => o.id === id || o.pathname === CWD);

      if (webapp) {
        webapp.domain = domain;
        webapp.port = port;
        webapp.pid = pid;
        webapp.status = status;
      } else {
        file.lastIndex += 1;
        webapp = {
          id: file.lastIndex,
          domain,
          port,
          pid,
          status,
          pathname: CWD
        };

        webapps.push(webapp);
      }

      return file;
    })
    .then(writeAppsFile)
    .then(() => webapp);
}

/**
 * 根据应用id, port查找对应的应用, 如果不传参数则通过当前工作目录查找对应的webapp
 * @param  {Object} options 参数
 * @param {String} optoins.id 应用ID
 * @param {Number} optoins.port 端口号
 * @return {Promise<Object>}
 */
function findOne(options) {
  if (options == null) {
    options = {};
  }
  // console.log(options)
  return readAppsFile()
    .then((file) => {
      const webapps = file.list;
      const { id, port } = options;

      for (let i = 0, webapp; webapp = webapps[i++];) {
        if (<commit_msg>delete useless code<commit_after>const { readAppsFile, writeAppsFile } = require('./util');
const { CWD } = require('./constants');

/**
  * 保存应用
  * @param  {Object} options 参数
  * @param {String} options.domain 域名
  * @param {Number} options.port 端口号
  * @param {Number} options.pid 进程ID
  * @param {String} options.status 状态
  * @return {Promise<Object>}
  */
function save(options) {
  if (options == null) {
    return Promise.resolve(null);
  }

  let webapp = null;

  return readAppsFile()
    .then((file) => {
      const webapps = file.list;
      const {
        id, domain = '', port, pid, status
      } = options;
      webapp = webapps.find((o) => o.id === id || o.pathname === CWD);

      if (webapp) {
        webapp.domain = domain;
        webapp.port = port;
        webapp.pid = pid;
        webapp.status = status;
      } else {
        file.lastIndex += 1;
        webapp = {
          id: file.lastIndex,
          domain,
          port,
          pid,
          status,
          pathname: CWD
        };

        webapps.push(webapp);
      }

      return file;
    })
    .then(writeAppsFile)
    .then(() => webapp);
}

/**
 * 根据应用id, port查找对应的应用, 如果不传参数则通过当前工作目录查找对应的webapp
 * @param  {Object} options 参数
 * @param {String} optoins.id 应用ID
 * @param {Number} optoins.port 端口号
 * @return {Promise<Object>}
 */
function findOne(options) {
  if (options == null) {
    options = {};
  }
  
  return readAppsFile()
    .then((file) => {
      const webapps = file.list;
      const { id, port } = options;

      for (let i = 0, webapp; webapp = webapps[i++];) {
        if (
{'fraction_non_alphanumeric': 0.15091416176014874, 'fraction_numerical': 0.0012395413696932136, 'mean_word_length': 2.1309408341416103, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '4184087', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1182, 'n_words': 259}