<commit_before>/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

'use strict';

const fs = require('fs');
const path = require('path');
const semver = require('semver');
const Registry = require('npm-registry');
const child_process = require('child_process');
const validUrl = require('valid-url');

let npmConfReg = child_process.execSync('npm config get registry').toString().trim();
let NPM_REGISTRY_URL = validUrl.is_uri(npmConfReg) ? npmConfReg : 'http://registry.npmjs.org';

const REACT_NATIVE_PACKAGE_JSON_PATH = function() {
  return path.resolve(
    process.cwd(),
    'node_modules',
    'react-native',
    'package.json'
  );
};

const npm = new Registry({registry: NPM_REGISTRY_URL});

function getLatestVersion() {
  return new Promise(function (resolve, reject) {
    npm.packages.release('react-native-windows', 'latest', (err, releases) => {
      if (err) {
        reject(err);
      } else if (releases.length === 0) {
        reject(new Error('Could not find react-native-windows@latest.'));
      } else {
        resolve(releases[0].version);
      }
    });
  });
}

function getMatchingVersion(version) {
  console.log(`Checking for react-native-windows version matching ${version}...`);
  return new Promise(function (resolve, reject) {
    npm.packages.range('react-native-windows', version, (err, release) => {
      if (err) {
        return getLatestVersion()
          .then(latestVersion => {
            reject(new Error(`Could not find react-native-windows@${version}. ` +
              `Latest version of react-native-windows is ${latestVersion}, try switching to ` +
              `react-native@${semver.major(latestVersion)}.${semver.minor(latestVersion)}.*.`));
            }).catch(error => reject(new Error(`Could not find react-native-windows@${version}.`)));
      } else {
        resolve(release.version);
      }
    });
  });
}

const getInstallPackage = function (version) {
  let packageToInstall = 'react-native-windows';

  const validVersion = semver.valid(version);
  const validRange = semver.validRange(version);
  if ((validVersion && !semver.gtr(validVersion, '0.26.*')) ||
      (!validVersion && validRange && semver.gtr('0.27.0', validRange))) {
    console.error(<commit_msg>fix(CLI): Better output if missing version of react-native-windows<commit_after>/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

'use strict';

const fs = require('fs');
const path = require('path');
const semver = require('semver');
const Registry = require('npm-registry');
const child_process = require('child_process');
const validUrl = require('valid-url');

let npmConfReg = child_process.execSync('npm config get registry').toString().trim();
let NPM_REGISTRY_URL = validUrl.is_uri(npmConfReg) ? npmConfReg : 'http://registry.npmjs.org';

const REACT_NATIVE_PACKAGE_JSON_PATH = function() {
  return path.resolve(
    process.cwd(),
    'node_modules',
    'react-native',
    'package.json'
  );
};

const npm = new Registry({registry: NPM_REGISTRY_URL});

function getLatestVersion() {
  return new Promise(function (resolve, reject) {
    npm.packages.release('react-native-windows', 'latest', (err, releases) => {
      if (err) {
        reject(err);
      } else if (!releases || releases.length === 0) {
        reject(new Error('Could not find react-native-windows@latest.'));
      } else {
        resolve(releases[0].version);
      }
    });
  });
}

function getMatchingVersion(version) {
  console.log(`Checking for react-native-windows version matching ${version}...`);
  return new Promise(function (resolve, reject) {
    npm.packages.range('react-native-windows', version, (err, release) => {
      if (err || !release) {
        return getLatestVersion()
          .then(latestVersion => {
            reject(new Error(`Could not find react-native-windows@${version}. ` +
              `Latest version of react-native-windows is ${latestVersion}, try switching to ` +
              `react-native@${semver.major(latestVersion)}.${semver.minor(latestVersion)}.*.`));
            }).catch(error => reject(new Error(`Could not find react-native-windows@${version}.`)));
      } else {
        resolve(release.version);
      }
    });
  });
}

const getInstallPackage = function (version) {
  let packageToInstall = 'react-native-windows';

  const validVersion = semver.valid(version);
  const validRange = semver.validRange(version);
  if ((validVersion && !semver.gtr(validVersion, '0.26.*')) ||
      (!validVersion && validRange && semver.gtr('0.27.0', validRange))) {
    console.error(
{'fraction_non_alphanumeric': 0.1484621451104101, 'fraction_numerical': 0.005126182965299685, 'mean_word_length': 3.6286496350364965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2960295', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1469, 'n_words': 378}