<commit_before>"use strict";

var child_process = require('child_process');

var ADB_PATH = 'adb';

exports.execAsync = function (command, deviceId) {
  var adbCommand = getAdbCommand(command, deviceId);

  // TODO: this only works on windows machines, fix later
  return child_process.spawn('cmd', ['/c', adbCommand], { env: process.env });
};

exports.execSync = function (command, deviceId) {
  command = sanitizeAdbCommand(command);
  var adbCommand = getAdbCommand(command, deviceId);
  return child_process.execSync(adbCommand).toString();
};

/**
 * Removes trailing "adb" keyword from command.
 * @param  {string} command   adb command to execute,
 *                            leading "adb" keyword is optional
 * @return {string}           sanitized command string
 */
function sanitizeAdbCommand(command) {
  // TODO: refactor this function and getAdbCommand
  return command.replace(/^adb /, '');
}

function getAdbCommand(command, deviceId) {
  var adbCommand = ADB_PATH;
  if (deviceId) {
    adbCommand += ' -s ' + deviceId;
  }
  adbCommand += ' ' + command;
  return adbCommand;
}<commit_msg>documented and refactored adbBridge module<commit_after>"use strict";

/** @module adbBridge */

var child_process = require('child_process');

/**
 * Path to global adb installation. It is assumed that the adb
 * command is part of the sytsmes PATH.
 * @type {String}
 * @const
 */
var ADB_PATH = 'adb';

/**
 * RexExp to match {@link module:adbBridge~ADB_PATH} at the beginning of a command.
 * @type {RegExp}
 * @const
 */
var REPLACE_ADB_REGEX = new RegExp('^' + ADB_PATH);

/**
 * Executes an adb command on the connected device with the given id.
 * @param  {String} command     adb command to execute,
 *                              leading "adb" keyword is optional
 * @param  {String} [deviceId]  unique device id as reported by adb
 * @return {String}             stdout / result of executing the command
 */
exports.execSync = function (command, deviceId) {
  var adbCommand = getAdbCommand(command, deviceId);
  return child_process.execSync(adbCommand).toString();
};

/**
 * Gets a clean adb command for the given device if present.
 * @param  {String} command     adb command to execute,
 *                              leading "adb" keyword is optional
 * @param  {String} [deviceId]  unique device id as reported by adb
 * @return {String}             adb command ready to be executed
 */
function getAdbCommand(command, deviceId) {
  var adbCommand = ADB_PATH;
  if (deviceId) {
    adbCommand += ' -s ' + deviceId;
  }
  adbCommand += ' ' + sanitizeAdbCommand(command);
  return adbCommand;
}

/**
 * Removes trailing "adb" keyword from command.
 * @param  {String} command   adb command to execute,
 *                            leading "adb" keyword is optional
 * @return {String}           sanitized command string
 */
function sanitizeAdbCommand(command) {
  return command.replace(REPLACE_ADB_REGEX, '');
}
{'fraction_non_alphanumeric': 0.1125467528051683, 'fraction_numerical': 0.0, 'mean_word_length': 3.2761627906976742, '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': '6470707', 'n_tokens_mistral': 903, 'n_tokens_neox': 892, 'n_words': 280}