# All files / src/cli tools.js

46.91% Statements 38/81
0% Branches 0/11
0% Functions 0/21
46.48% Lines 33/71

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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    1381x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x

    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x
     import path from 'path';
    import fs from 'fs';
    import shell from 'shelljs';
    import {
        isPlatformSupported,
        isBuildSchemeSupported,
        isPlatformSupportedSync,
        getConfig,
        logTask,
        logComplete,
        checkSdk,
        logError,
        getAppFolder,
        logDebug,
        logErrorPlatform,
        isSdkInstalled,
        logWarning,
        configureIfRequired,
        cleanPlatformIfRequired,
    } from '../common';
    import { IOS } from '../constants';
    import { executeAsync, execCLI } from '../systemTools/exec';
    import { cleanProjectModules } from '../systemTools/cleaner';
    import { logStatus } from '../systemTools/logger';
    import { fixPackageJson } from '../systemTools/doctor';
    import { encrypt, decrypt, installProfiles, updateProfiles, installCerts } from '../systemTools/crypto';
    import { updateProfile } from '../platformTools/apple/fastlane';
    import { executePipe } from '../projectTools/buildHooks';
    import { cleanNodeModules } from '../projectTools/projectParser';
    import {
        packageAndroid,
        runAndroid,
        configureGradleProject,
        buildAndroid,
        runAndroidLog,
    } from '../platformTools/android';
    import appRunner, { copyRuntimeAssets } from './app';

    // COMMANDS
    const FIX = 'fix';
    const CLEAN = 'clean';
    const STATUS = 'status';
    const CRYPTO = 'crypto';

    // SUB_COMMANDS
    const FIX_PACKAGE = 'fixPackage';
    const ENCRYPT = 'encrypt';
    const DECRYPT = 'decrypt';
    const INSTALL_PROFILES = 'installProfiles';
    const UPDATE_PROFILES = 'updateProfiles';
    const UPDATE_PROFILE = 'updateProfile';
    const INSTALL_CERTS = 'installCerts';

    const PIPES = {
        FIX_BEFORE: 'fix:before',
        FIX_AFTER: 'fix:after',
    };

    // ##########################################
    // PUBLIC API
    // ##########################################

    const run = (c) => {
        logTask('run');

        switch (c.command) {
        case FIX:
            return _fix(c);
        case CLEAN:
            return cleanProjectModules(c);
        case STATUS:
            return _status(c);
        case CRYPTO:
            return _crypto(c);
        }

        switch (c.subCommand) {
        case FIX_PACKAGE:
            return fixPackageJson(c);
        }

        return Promise.reject(`cli:tools: Command ${c.command} ${c.subCommand} not supported`);
    };

    // ##########################################
    // PRIVATE
    // ##########################################

    const _fix = c => new Promise((resolve, reject) => {
        cleanNodeModules(c).then(() => resolve()).catch(e => reject(e));
    });

    const _crypto = c => new Promise((resolve, reject) => {
        switch (c.subCommand) {
        case ENCRYPT:
            encrypt(c)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case DECRYPT:
            decrypt(c)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case INSTALL_PROFILES:
            installProfiles(c)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case UPDATE_PROFILES:
            updateProfiles(c)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case UPDATE_PROFILE:
            updateProfile(c)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case INSTALL_CERTS:
            installCerts(c)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        }

        reject(`cli:tools: Command ${c.command} ${c.subCommand} not supported`);
    });

    const _status = c => new Promise((resolve, reject) => {
        logStatus();
        resolve();
    });

    export { PIPES };

    export default run;