async function installIosDependencies()

in provider-utils/awscloudformation/utils/video-player-utils.js [204:245]


async function installIosDependencies(context, dependency) {
  const { amplify } = context;
  const projectRootPath = amplify.pathManager.searchProjectRootPath();

  try {
    fs.readFileSync(`${projectRootPath}/Podfile`, { encoding: 'utf-8' });
    let podFileData = await exec('pod', ['ipc', 'podfile-json', 'Podfile'], false);
    podFileData = JSON.parse(podFileData);
    const pod = readPodFile(`${projectRootPath}/Podfile`);
    const targets = listTargets(pod);
    const chooseTarget = [
      {
        type: 'list',
        name: 'podTarget',
        message: 'Choose which pod target you want to set up a player for?',
        choices: targets,
      },
    ];
    const props = await inquirer.prompt(chooseTarget);
    if (isDependencyInstalled(podFileData, props.podTarget.target, dependency.podName)) {
      context.print.info(`Podfile already contains ${dependency.podName}`);
      const spinner = ora('Installing dependencies...');
      spinner.start();
      await exec('pod', ['install'], true);
      spinner.succeed('Configuration complete.');
    } else {
      if (dependency.podVersion) {
        addPodEntry(pod, props.podTarget, dependency.platformVersion,
          dependency.podName, dependency.podVersion);
      } else {
        addPodEntry(pod, props.podTarget, '', dependency.podName, '');
      }
      savePodFile(`${projectRootPath}/Podfile`, pod);
      const spinner = ora(`Installing ${dependency.podName} with CocoaPods...`);
      spinner.start();
      await exec('pod', ['install'], true);
      spinner.succeed('Configuration complete.');
    }
  } catch (error) {
    throw new Error(error);
  }
}