<commit_before>'use strict';

require('instapromise');

const escapeStringRegexp = require('escape-string-regexp');
const path = require('path');
const util = require('util');

const PRELUDE = '# [REM]';
const POSTLUDE = '# [/REM]';

class PodfileEditor {

  constructor(settings: Settings) {
    this.settings = settings;
  }

  addREMSection(contents: string): string {
    return contents + this._createREMSection();
  }

  updateREMSection(contents: string): string {
    return contents.replace(
      this._getSectionRegex(),
      this._createREMSection()
    );
  }

  hasREMSection(contents: string): boolean {
    return this._getSectionRegex().test(contents);
  }

  removeREMSection(contents: string): string {
    return contents.replace(this._getSectionRegex(), '');
  }

  _createREMSection(): string {
    let relativeBasePath = path.relative(
      this.settings.xcodeProjectDirectory,
      this.settings.baseDirectory
    );
    let relativeScriptPath = path.join(
      relativeBasePath,
      'node_modules/.bin/rem'
    );
    let command = util.format(
      'eval(`%s %s`)',
      relativeScriptPath,
      relativeBasePath
    );
    let lines = [PRELUDE, command, POSTLUDE];
    return '\n' + lines.join('\n');
  }

  _getSectionRegex(): RegExp {
    let pattern =
      '\\n?' +
      '^' + escapeStringRegexp(PRELUDE) +
      '[\\s\\S]*?' +
      '^' + escapeStringRegexp(POSTLUDE) + '.*';
    return new RegExp(pattern, 'gm');
  }
}

export default PodfileEditor;<commit_msg>Update command that is embedded in the Podfile<commit_after>'use strict';

require('instapromise');

const escapeStringRegexp = require('escape-string-regexp');
const path = require('path');
const util = require('util');

const PRELUDE = '# [REM]';
const POSTLUDE = '# [/REM]';

class PodfileEditor {

  constructor(settings: Settings) {
    this.settings = settings;
  }

  addREMSection(contents: string): string {
    return contents + this._createREMSection();
  }

  updateREMSection(contents: string): string {
    return contents.replace(
      this._getSectionRegex(),
      this._createREMSection()
    );
  }

  hasREMSection(contents: string): boolean {
    return this._getSectionRegex().test(contents);
  }

  removeREMSection(contents: string): string {
    return contents.replace(this._getSectionRegex(), '');
  }

  _createREMSection(): string {
    let relativeBasePath = path.relative(
      this.settings.xcodeProjectDirectory,
      this.settings.baseDirectory
    );
    let relativeScriptPath = path.join(
      relativeBasePath,
      'node_modules/.bin/rem'
    );
    let command = util.format(
      'eval(`%s podfile-fragment -d %s`)',
      relativeScriptPath,
      relativeBasePath
    );
    let lines = [PRELUDE, command, POSTLUDE];
    return '\n' + lines.join('\n');
  }

  _getSectionRegex(): RegExp {
    let pattern =
      '\\n?' +
      '^' + escapeStringRegexp(PRELUDE) +
      '[\\s\\S]*?' +
      '^' + escapeStringRegexp(POSTLUDE) + '.*';
    return new RegExp(pattern, 'gm');
  }
}

export default PodfileEditor;
{'fraction_non_alphanumeric': 0.1443972557987586, 'fraction_numerical': 0.0, 'mean_word_length': 3.3371104815864023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7619103', 'n_tokens_mistral': 983, 'n_tokens_neox': 947, 'n_words': 186}