# All files / src/platformTools/apple podfileParser.js

21.43% Statements 12/56
0% Branches 0/36
0% Functions 0/8
17.31% Lines 9/52

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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    1082x
    2x
    2x
    2x

    2x
    2x

    2x

    2x

    2x

     import path from 'path';
    import fs from 'fs';
    import chalk from 'chalk';
    import {
        logTask,
        logError,
        logWarning,
        getAppFolder,
        isPlatformActive,
        logDebug,
        getAppVersion,
        getAppTitle,
        getEntryFile,
        writeCleanFile,
        getAppTemplateFolder,
        getAppId,
        getConfigProp,
        getIP,
        getBuildFilePath,
        logSuccess,
        getBuildsFolder
    } from '../../common';
    import { copyBuildsFolder } from '../../projectTools/projectParser';
    import { getMergedPlugin, parsePlugins } from '../../pluginTools';

    export const parsePodFile = (c, platform) => new Promise((resolve, reject) => {
        logTask(`parsePodFileSync:${platform}`);

        const appFolder = getAppFolder(c, platform);
        let pluginSubspecs = '';
        let pluginInject = '';

        // PLUGINS
        c.pluginConfigiOS.podfileInject = '';
        parsePlugins(c, platform, (plugin, pluginPlat, key) => {
            if (pluginPlat.podName) {
                pluginInject += _injectPod(pluginPlat.podName, pluginPlat, plugin, key);
            }
            if (pluginPlat.podNames) {
                pluginPlat.podNames.forEach((v) => {
                    pluginInject += _injectPod(v, pluginPlat, plugin, key);
                });
            }

            if (pluginPlat.reactSubSpecs) {
                pluginPlat.reactSubSpecs.forEach((v) => {
                    if (!pluginSubspecs.includes(`'${v}'`)) {
                        pluginSubspecs += `  '${v}',\n`;
                    }
                });
            }

            if (pluginPlat.Podfile) {
                const { injectLines } = pluginPlat.Podfile;
                // INJECT LINES
                if (injectLines) {
                    injectLines.forEach((v) => {
                        c.pluginConfigiOS.podfileInject += `${v}\n`;
                    });
                }
            }
        });

        // WARNINGS
        const ignoreWarnings = getConfigProp(c, platform, 'ignoreWarnings');
        const podWarnings = ignoreWarnings ? 'inhibit_all_warnings!' : '';

        // SOURCES
        c.pluginConfigiOS.podfileSources = '';
        const podfileSources = c.buildConfig?.platforms?.ios?.Podfile?.sources;
        if (podfileSources && podfileSources.length) {
            podfileSources.forEach((v) => {
                c.pluginConfigiOS.podfileSources += `source '${v}'\n`;
            });
        }

        // DEPLOYMENT TARGET
        const deploymentTarget = getConfigProp(c, platform, 'deploymentTarget', '10.0');
        c.pluginConfigiOS.deploymentTarget = deploymentTarget;

        writeCleanFile(path.join(getAppTemplateFolder(c, platform), 'Podfile'), path.join(appFolder, 'Podfile'), [
            { pattern: '{{PLUGIN_PATHS}}', override: pluginInject },
            { pattern: '{{PLUGIN_SUBSPECS}}', override: pluginSubspecs },
            { pattern: '{{PLUGIN_WARNINGS}}', override: podWarnings },
            { pattern: '{{PLUGIN_PODFILE_INJECT}}', override: c.pluginConfigiOS.podfileInject },
            { pattern: '{{PLUGIN_PODFILE_SOURCES}}', override: c.pluginConfigiOS.podfileSources },
            { pattern: '{{PLUGIN_DEPLOYMENT_TARGET}}', override: c.pluginConfigiOS.deploymentTarget }
        ]);
        resolve();
    });

    const _injectPod = (podName, pluginPlat, plugin, key) => {
        let pluginInject = '';
        const isNpm = plugin['no-npm'] !== true;
        if (isNpm) {
            const podPath = pluginPlat.path ? `../../${pluginPlat.path}` : `../../node_modules/${key}`;
            pluginInject += `  pod '${podName}', :path => '${podPath}'\n`;
        } else if (pluginPlat.git) {
            const commit = pluginPlat.commit ? `, :commit => '${pluginPlat.commit}'` : '';
            pluginInject += `  pod '${podName}', :git => '${pluginPlat.git}'${commit}\n`;
        } else if (pluginPlat.version) {
            pluginInject += `  pod '${podName}', '${pluginPlat.version}'\n`;
        } else {
            pluginInject += `  pod '${podName}'\n`;
        }
        return pluginInject;
    };