# All files / src/cli target.js

63.92% Statements 62/97
30.95% Branches 13/42
47.83% Functions 11/23
66.67% Lines 48/72

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
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    1494x
    4x
    4x
    4x
    4x

    4x
    4x
    4x
    4x
    4x
    4x
    4x

    4x
    4x
    4x
    4x
    4x

    4x

    4x

    4x
    2x

    2x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    4x
    1x
    1x
    1x

    1x

    1x

    1x
    1x

    4x
    1x
    1x
    1x

    1x

    1x

    1x

    1x

    1x

    4x
     /* eslint-disable import/no-cycle */
    import chalk from 'chalk';
    import path from 'path';
    import inquirer from 'inquirer';
    import {
        isPlatformSupportedSync, getConfig, logTask, logComplete, logError,
        getAppFolder, isPlatformSupported, checkSdk
    } from '../common';
    import PlatformSetup from '../setupTools';
    import { IOS, ANDROID, TVOS, TIZEN, WEBOS, ANDROID_TV, ANDROID_WEAR, KAIOS, CLI_ANDROID_ADB, CLI_ANDROID_AVDMANAGER, CLI_ANDROID_EMULATOR, CLI_ANDROID_SDKMANAGER } from '../constants';
    import { launchTizenSimulator } from '../platformTools/tizen';
    import { launchWebOSimulator, listWebOSTargets } from '../platformTools/webos';
    import { launchAndroidSimulator, listAndroidTargets } from '../platformTools/android';
    import { listAppleDevices, launchAppleSimulator } from '../platformTools/apple';
    import { launchKaiOSSimulator } from '../platformTools/firefox';

    const CREATE = 'create';
    const REMOVE = 'remove';
    const LAUNCH = 'launch';
    const QUIT = 'quit';
    const LIST = 'list';

    const PIPES = {
        TARGET_CREATE_BEFORE: 'target:create:before',
        TARGET_CREATE_AFTER: 'target:create:after',
        TARGET_REMOVE_BEFORE: 'target:remove:before',
        TARGET_REMOVE_AFTER: 'target:remove:after',
        TARGET_LAUNCH_BEFORE: 'target:launch:before',
        TARGET_LAUNCH_AFTER: 'target:launch:after',
        TARGET_QUIT_BEFORE: 'target:quit:before',
        TARGET_QUIT_AFTER: 'target:quit:after',
        TARGET_LIST_BEFORE: 'target:list:before',
        TARGET_LIST_AFTER: 'target:list:after',
    };

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

    const run = c => new Promise((resolve, reject) => {
        logTask('run');

        switch (c.subCommand) {
        // case CREATE:
        //     return Promise.resolve();
        //     break;
        // case REMOVE:
        //     return Promise.resolve();
        //     break;
        case LAUNCH:
            isPlatformSupported(c)
                .then(() => _runLaunch(c))
                .then(() => resolve())
                .catch(e => reject(e));
            return;
            // case QUIT:
            //     return Promise.resolve();
            //     break;
        case LIST:
            isPlatformSupported(c)
                .then(() => _runList(c))
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        default:
            return Promise.reject(`cli:target Sub-Command ${chalk.white.bold(c.subCommand)} not supported!`);
        }
    });

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

    const _runLaunch = c => new Promise((resolve, reject) => {
        logTask('_runLaunch');
        const { platform, program } = c;
        const target = program.target || c.files.private.config.defaultTargets[platform];

        switch (platform) {
        case ANDROID:
        case ANDROID_TV:
        case ANDROID_WEAR:
            launchAndroidSimulator(c, platform, target)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case IOS:
        case TVOS:
            launchAppleSimulator(c, platform, target)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case TIZEN:
            launchTizenSimulator(c, target)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case WEBOS:
            launchWebOSimulator(c, target)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        case KAIOS:
            launchKaiOSSimulator(c, target)
                .then(() => resolve())
                .catch(e => reject(e));
            return;
        default:
            reject(
                `"target launch" command does not support ${chalk.white.bold(
                    platform
                )} platform yet. You will have to launch the emulator manually. Working on it!`
            );
        }
    });

    const _runList = async (c) => {
        logTask('_runLaunch');
        const { platform } = c;E
        if (!isPlatformSupportedSync(platform)) return;

        const throwError = (err) => {
            throw err;
        };

        switch (platform) {
        case ANDROID:
        case ANDROID_TV:
        case ANDROID_WEAR:
            if (!checkSdk(c, platform, logError)) {
                const setupInstance = PlatformSetup(c);
                await setupInstance.askToInstallSDK('android');
            }
            return listAndroidTargets(c, platform);
        case IOS:
        case TVOS:
            return listAppleDevices(c, platform);
        case WEBOS:I
            if (!checkSdk(c, platform, throwError)) return;
            return listWebOSTargets(c);
        default:
            throw `"target list" command does not support ${chalk.white.bold(platform)} platform yet. Working on it!`;
        }
    };

    export { PIPES };

    export default run;