All files / src/ios Info.plist.ts

81.82% Statements 9/11
50% Branches 1/2
100% Functions 3/3
81.82% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39            2x           3x 3x 3x   3x       3x     3x 3x                       3x    
import fs from 'fs-extra';
import path from 'path';
 
import StateManager from '../StateManager';
import { replace, insert } from '../string-helpers';
 
const INFO_PLIST_FILE_PATH = 'Info.plist';
 
/**
 * Configures [INFO_PLIST] to show [STORYBOARD] filename as Splash/Launch Screen.
 */
export default async function configureInfoPlist(iosProjectPath: string) {
  const filePath = path.resolve(iosProjectPath, INFO_PLIST_FILE_PATH);
  const fileContent = await fs.readFile(filePath, 'utf-8');
  const { state: newContent } = new StateManager<string, boolean>(fileContent)
    .applyAction(content => {
      const [succeeded, newContent] = replace(content, {
        replaceContent: '<string>SplashScreen</string>',
        replacePattern: /(?<=<key>UILaunchStoryboardName<\/key>(.|\n)*?)<string>.*?<\/string>/m,
      });
      return [newContent, 'replaced', succeeded];
    })
    .applyAction((content, { replaced }) => {
      Eif (replaced) {
        return [content, 'inserted', false];
      }
      const [succeeded, newContent] = insert(
        content,
        {
          insertContent: `  <key>UILaunchStoryboardName</key>\n  <string>SplashScreen</string>\n`,
          insertPattern: /<\/dict>/gm,
        },
        true
      );
      return [newContent, 'inserted', succeeded];
    });
  await fs.writeFile(filePath, newContent);
}