<commit_before>import os from 'os';
import path from 'path';
import chalk from 'chalk';
import fs from 'fs-extra';
import xcode from 'xcode';
import semver from 'semver';
import inquirer from 'inquirer';
import glob from 'glob-promise';
import JsonFile from '@expo/json-file';
import spawnAsync from '@expo/spawn-async';
import { Command } from '@expo/commander';

import * as Directories from '../Directories';
import * as Npm from '../Npm';

interface ActionOptions {
  list: boolean;
  listOutdated: boolean;
  module: string;
  platform: 'ios' | 'android' | 'all';
  commit: string;
  pbxproj: boolean;
  semverPrefix: string;
}

interface VendoredModuleUpdateStep {
  iosPrefix?: string;
  sourceIosPath?: string;
  targetIosPath?: string;
  sourceAndroidPath?: string;
  targetAndroidPath?: string;
  sourceAndroidPackage?: string;
  targetAndroidPackage?: string;
  recursive?: boolean;
  updatePbxproj?: boolean;
}

interface VendoredModuleConfig {
  repoUrl: string;
  packageName?: string;
  packageJsonPath?: string;
  installableInManagedApps?: boolean;
  semverPrefix?: '~' | '^';
  skipCleanup?: boolean;
  steps: VendoredModuleUpdateStep[];
  warnings?: string[];
}

const IOS_DIR = Directories.getIosDir();
const ANDROID_DIR = Directories.getAndroidDir();
const PACKAGES_DIR = Directories.getPackagesDir();
const BUNDLED_NATIVE_MODULES_PATH = path.join(PACKAGES_DIR, 'expo', 'bundledNativeModules.json');

const vendoredModulesConfig: { [key: string]: VendoredModuleConfig } = {
  'react-native-gesture-handler': {
    repoUrl: 'https://github.com/software-mansion/react-native-gesture-handler.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        sourceAndroidPath: 'android/lib/src/main/java/com/swmansion/gesturehandler',
        targetAndroidPath: 'modules/api/components/gesturehandler',
        sourceAndroidPackage: 'com.swmansion.gesturehandler',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.components.gesturehandler',
      },
      {
        recursive: true,
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Components/GestureHandler',
        sourceAndroidPath: 'android/src/main/java/com/swmansion/gesturehandler/react',
        targetAndroidPath: 'modules/api/components/gesturehandler/react',
        sourceAndroidPackage: 'com.swmansion.gesturehandler',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.components.gesturehandler',
      },
    ],
    warnings: [
      `NOTE: Any files in ${chalk.magenta(
        'com.facebook.react'
      )} will not be updated -- you'll need to add these to expoview manually!`,
    ],
  },
  'react-native-reanimated': {
    repoUrl: 'https://github.com/software-mansion/react-native-reanimated.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        recursive: true,
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Reanimated',
        sourceAndroidPath: 'android/src/main/java/com/swmansion/reanimated',
        targetAndroidPath: 'modules/api/reanimated',
        sourceAndroidPackage: 'com.swmansion.reanimated',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.reanimated',
      },
    ],
    warnings: [
      `NOTE: Any files in ${chalk.magenta(
        'com.facebook.react'
      )} will not be updated -- you'll need to add these to expoview manually!`,
    ],
  },
  'react-native-screens': {
    repoUrl: 'https://github.com/software-mansion/react-native-screens.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Screens',
        sourceAndroidPath: 'android/src/main/java/com/swmansion/rnscreens',
        targetAndroidPath: 'modules/api/screens',
        sourceAndroidPackage: 'com.swmansion.rnscreens',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.screens',
      },
    ],
  },
  'react-native-appearance': {
    repoUrl: 'https://github.com/expo/react-native-appearance.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        sourceIosPath: 'ios/Appearance',
        targetIosPath: 'Api/Appearance',
        sourceAndroidPath: 'android/src/main/java/io/expo/appearance',
        targetAndroidPath: 'modules/api/appearance/rncappearance',
        sourceAndroidPackage: 'io.expo.appearance',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.appearance.rncappearance',
      },
    ],
  },
  'amazon-cognito-identity-js': {
    repoUrl: 'https://github.com/aws/amazon-cognito-identity-js.git',
    installableInManagedApps: false,
    steps: [
      {
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Cognito',
        sourceAndroidPath: 'android/src/main/java/com/amazonaws',
        targetAndroidPath: 'modules/api/cognito',
        sourceAndroidPackage: 'com.amazonaws',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.cognito',
      },<commit_msg>[expotools] Update configuration of the vendored cognito module (#9615)<commit_after>import os from 'os';
import path from 'path';
import chalk from 'chalk';
import fs from 'fs-extra';
import xcode from 'xcode';
import semver from 'semver';
import inquirer from 'inquirer';
import glob from 'glob-promise';
import JsonFile from '@expo/json-file';
import spawnAsync from '@expo/spawn-async';
import { Command } from '@expo/commander';

import * as Directories from '../Directories';
import * as Npm from '../Npm';

interface ActionOptions {
  list: boolean;
  listOutdated: boolean;
  module: string;
  platform: 'ios' | 'android' | 'all';
  commit: string;
  pbxproj: boolean;
  semverPrefix: string;
}

interface VendoredModuleUpdateStep {
  iosPrefix?: string;
  sourceIosPath?: string;
  targetIosPath?: string;
  sourceAndroidPath?: string;
  targetAndroidPath?: string;
  sourceAndroidPackage?: string;
  targetAndroidPackage?: string;
  recursive?: boolean;
  updatePbxproj?: boolean;
}

interface VendoredModuleConfig {
  repoUrl: string;
  packageName?: string;
  packageJsonPath?: string;
  installableInManagedApps?: boolean;
  semverPrefix?: '~' | '^';
  skipCleanup?: boolean;
  steps: VendoredModuleUpdateStep[];
  warnings?: string[];
}

const IOS_DIR = Directories.getIosDir();
const ANDROID_DIR = Directories.getAndroidDir();
const PACKAGES_DIR = Directories.getPackagesDir();
const BUNDLED_NATIVE_MODULES_PATH = path.join(PACKAGES_DIR, 'expo', 'bundledNativeModules.json');

const vendoredModulesConfig: { [key: string]: VendoredModuleConfig } = {
  'react-native-gesture-handler': {
    repoUrl: 'https://github.com/software-mansion/react-native-gesture-handler.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        sourceAndroidPath: 'android/lib/src/main/java/com/swmansion/gesturehandler',
        targetAndroidPath: 'modules/api/components/gesturehandler',
        sourceAndroidPackage: 'com.swmansion.gesturehandler',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.components.gesturehandler',
      },
      {
        recursive: true,
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Components/GestureHandler',
        sourceAndroidPath: 'android/src/main/java/com/swmansion/gesturehandler/react',
        targetAndroidPath: 'modules/api/components/gesturehandler/react',
        sourceAndroidPackage: 'com.swmansion.gesturehandler',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.components.gesturehandler',
      },
    ],
    warnings: [
      `NOTE: Any files in ${chalk.magenta(
        'com.facebook.react'
      )} will not be updated -- you'll need to add these to expoview manually!`,
    ],
  },
  'react-native-reanimated': {
    repoUrl: 'https://github.com/software-mansion/react-native-reanimated.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        recursive: true,
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Reanimated',
        sourceAndroidPath: 'android/src/main/java/com/swmansion/reanimated',
        targetAndroidPath: 'modules/api/reanimated',
        sourceAndroidPackage: 'com.swmansion.reanimated',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.reanimated',
      },
    ],
    warnings: [
      `NOTE: Any files in ${chalk.magenta(
        'com.facebook.react'
      )} will not be updated -- you'll need to add these to expoview manually!`,
    ],
  },
  'react-native-screens': {
    repoUrl: 'https://github.com/software-mansion/react-native-screens.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        sourceIosPath: 'ios',
        targetIosPath: 'Api/Screens',
        sourceAndroidPath: 'android/src/main/java/com/swmansion/rnscreens',
        targetAndroidPath: 'modules/api/screens',
        sourceAndroidPackage: 'com.swmansion.rnscreens',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.screens',
      },
    ],
  },
  'react-native-appearance': {
    repoUrl: 'https://github.com/expo/react-native-appearance.git',
    installableInManagedApps: true,
    semverPrefix: '~',
    steps: [
      {
        sourceIosPath: 'ios/Appearance',
        targetIosPath: 'Api/Appearance',
        sourceAndroidPath: 'android/src/main/java/io/expo/appearance',
        targetAndroidPath: 'modules/api/appearance/rncappearance',
        sourceAndroidPackage: 'io.expo.appearance',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.appearance.rncappearance',
      },
    ],
  },
  'amazon-cognito-identity-js': {
    repoUrl: 'https://github.com/aws-amplify/amplify-js.git',
    installableInManagedApps: false,
    steps: [
      {
        sourceIosPath: 'packages/amazon-cognito-identity-js/ios',
        targetIosPath: 'Api/Cognito',
        sourceAndroidPath: 'packages/amazon-cognito-identity-js/android/src/main/java/com/amazonaws',
        targetAndroidPath: 'modules/api/cognito',
        sourceAndroidPackage: 'com.amazonaws',
        targetAndroidPackage: 'versioned.host.exp.exponent.modules.api.cognito',
      },
{'fraction_non_alphanumeric': 0.13061465721040189, 'fraction_numerical': 0.0003940110323089047, 'mean_word_length': 3.5325892857142858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, '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': '974911', 'n_tokens_mistral': 3245, 'n_tokens_neox': 3231, 'n_words': 552}