# All files / src/setupTools windows.js

19.57% Statements 27/138
0% Branches 0/55
5% Functions 1/20
22.86% Lines 16/70

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
    1482x
    2x
    2x
    2x
    2x
    2x

    2x
    2x
    2x
    2x
    2x
    2x

    2x

    2x

    2x

    2x
     import shell from 'shelljs';
    import { getInstalledPathSync } from 'get-installed-path';
    import path from 'path';
    import { exec } from 'child_process';
    import inquirer from 'inquirer';
    import fs from 'fs';

    import { commandExistsSync, executeAsync, openCommand } from '../systemTools/exec';
    import { logInfo, logDebug } from '../common';
    import { replaceHomeFolder } from '../systemTools/fileutils';
    import BasePlatformSetup from './base';
    import setupConfig from './config';
    import {
        CLI_ANDROID_ADB,
        CLI_ANDROID_AVDMANAGER,
        CLI_ANDROID_EMULATOR,
        CLI_ANDROID_SDKMANAGER,
    } from '../constants';

    class LinuxPlatformSetup extends BasePlatformSetup {
        constructor(c) {
            super('win32', c);
            this.scoopInstalled = false;
        }

        checkPrereqs() {
            logInfo(`Platform ${this.os}`);
            logInfo('Checking wget is installed');
            if (commandExistsSync('wget')) {
                this.availableDownloader = 'wget';
            }

            // check if scoop is installed
            if (commandExistsSync('scoop')) {
                this.scoopInstalled = true;
            }
        }

        async installSoftware(software) {
            await shell.exec(replaceHomeFolder(`~/scoop/shims/scoop install ${software}`));
            await this.reloadPathEnv();
            return true;
        }

        addScoopBucket(bucket) {
            return shell.exec(replaceHomeFolder(`~/scoop/shims/scoop bucket add ${bucket}`));
        }

        async reloadPathEnv() {
            await shell.exec(`${getInstalledPathSync('rnv')}/scripts/resetPath.vbs`);
            await shell.exec('%TEMP%/resetvars.bat');
            return true;
        }

        async installPrereqs() {
            if (!this.scoopInstalled) {
                logInfo('Installing Scoop...');
                await shell.exec(`powershell -executionpolicy remotesigned "& ""${getInstalledPathSync('rnv')}/scripts/installPackageManager.ps1"""`);
                await this.reloadPathEnv();
            }
            if (!this.availableDownloader) {
                logInfo('Looks like you don\'t have wget or curl installed. We\'ll install wget for you');
                await this.installSoftware('wget');
                this.availableDownloader = 'wget';
            }

            if (!commandExistsSync('unzip')) {
                logInfo('Looks like you don\'t have unzip installed. We\'ll install it for you');
                await this.installSoftware('unzip');
            }

            if (!commandExistsSync('javac')) {
                logInfo('Looks like you don\'t have java installed. We\'ll install it for you');
                await this.installSoftware('shellcheck');
                await this.addScoopBucket('java');
                await this.installSoftware('ojdkbuild8');
            }

            return true;
        }

        async installSdksAndEmulator() {
            logDebug('Accepting licenses');
            await executeAsync({}, `${this.androidSdkLocation}/tools/bin/sdkmanager.bat --licenses`);
            logDebug('Installing SDKs', this.sdksToInstall);
            await executeAsync({}, `${this.androidSdkLocation}/tools/bin/sdkmanager.bat ${this.sdksToInstall}`);
        }

        async installTizenSdk() {
            let downloadDir = setupConfig.tizen.downloadLocation.split('/');
            downloadDir.pop();
            downloadDir = downloadDir.join('/');
            logInfo(`Opening ${downloadDir}. Please install the SDK then continue after it finished installing.`);
            exec(`start "" "${downloadDir}"`);

            const res = await inquirer.prompt({
                type: 'input',
                name: 'sdkPath',
                message: "Where did you install the SDK? (if you haven't changed the default just press enter)",
                default: 'C:\\tizen-studio',
                validate(value) {
                    if (fs.existsSync(value)) return true;
                    return 'Path does not exist';
                }
            });

            await inquirer.prompt({
                type: 'confirm',
                name: 'toolsInstalled',
                message: 'Please open Package Manager and install: Tizen SDK Tools (Main SDK), TV Extensions-* (Extension SDK). Continue after you finished installing them.',
                validate() {
                    return fs.existsSync(path.join(res.sdkPath, 'tools/ide/bin/tizen.bat')) || 'This does not look like a Tizen SDK path';
                }
            });

            this.tizenSdkPath = res.sdkPath;
        }

        async installWebosSdk() {
            const { downloadLink } = setupConfig.webos;
            logInfo(`Opening ${downloadLink}. Please download and install the SDK then continue after it finished installing. Make sure you also install the CLI and Emulator components`);
            exec(`${openCommand} ${downloadLink}`);
            const res = await inquirer.prompt({
                type: 'input',
                name: 'sdkPath',
                message: "Where did you install the SDK? (if you haven't changed the default just press enter)",
                default: 'C:\\webOS_TV_SDK',
                validate(value) {
                    if (fs.existsSync(value)) return true;
                    return 'Path does not exist';
                }
            });

            await inquirer.prompt({
                type: 'confirm',
                name: 'toolsInstalled',
                message: 'Are the CLI and Emulator components installed?',
                validate() {
                    return fs.existsSync(path.join(res.sdkPath, 'tools/ide/bin/tizen.bat')) || 'This does not look like a Tizen SDK path';
                }
            });

            this.webosSdkPath = res.sdkPath;
        }
    }

    export default LinuxPlatformSetup;