# All files / src/platformTools/firefox index.js

27.27% Statements 21/77
0% Branches 0/14
0% Functions 0/20
26.87% Lines 18/67

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

    2x
    2x

    2x
    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

    2x

     import path from 'path';
    import fs from 'fs';
    import chalk from 'chalk';
    import { execCLI } from '../../systemTools/exec';
    import {
        isPlatformSupportedSync,
        getConfig,
        logTask,
        logComplete,
        logError,
        getAppFolder,
        isPlatformActive,
        configureIfRequired,
        getAppConfigId,
        getAppVersion,
        getAppTitle,
        getAppVersionCode,
        writeCleanFile,
        getAppId,
        getAppTemplateFolder,
        getEntryFile,
        getAppDescription,
        getAppAuthor,
        getAppLicense,
        getConfigProp,
    } from '../../common';
    import { copyBuildsFolder, copyAssetsFolder } from '../../projectTools/projectParser';
    import {
        CLI_ANDROID_EMULATOR,
        CLI_ANDROID_ADB,
        CLI_TIZEN_EMULATOR,
        CLI_TIZEN,
        CLI_WEBOS_ARES,
        CLI_KAIOS_EMULATOR,
        CLI_WEBOS_ARES_PACKAGE,
        CLI_WEBOS_ARES_INSTALL,
        CLI_WEBOS_ARES_LAUNCH,
        KAIOS_SDK,
    } from '../../constants';
    import { cleanFolder, copyFolderContentsRecursiveSync, copyFolderRecursiveSync, copyFileSync, mkdirSync, getRealPath } from '../../systemTools/fileutils';
    import { buildWeb } from '../web';

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

        if (!c.files.workspace.config.sdks.KAIOS_SDK) {
            reject(
                `${KAIOS_SDK} is not configured in your ${c.paths.workspace.config} file. Make sure you add location to your Kaiosrt App path similar to: ${chalk.white.bold(
                    '"KAIOS_SDK": "/Applications/Kaiosrt.app"'
                )}`
            );
            return;
        }

        const ePath = getRealPath(path.join(c.files.workspace.config.sdks.KAIOS_SDK));

        if (!fs.existsSync(ePath)) {
            reject(`Can't find emulator at path: ${ePath}`);
            return;
        }

        const childProcess = require('child_process');
        childProcess.exec(`open ${ePath}`, (err, stdout, stderr) => {
            if (err) {
                reject(err);
                return;
            }
            resolve();
        });
    });

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

        if (!isPlatformActive(c, platform, resolve)) return;

        copyAssetsFolder(c, platform)
            .then(() => copyBuildsFolder(c, platform))
            .then(() => configureProject(c, platform))
            .then(() => resolve())
            .catch(e => reject(e));
    });

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

        if (!isPlatformActive(c, platform, resolve)) return;

        const appFolder = getAppFolder(c, platform);
        const templateFolder = getAppTemplateFolder(c, platform);
        const bundleIsDev = getConfigProp(c, platform, 'bundleIsDev') === true;
        const bundleAssets = getConfigProp(c, platform, 'bundleAssets') === true;

        const manifestFilePath = path.join(templateFolder, 'manifest.webapp');
        const manifestFilePath2 = path.join(appFolder, 'manifest.webapp');
        const manifestFile = JSON.parse(fs.readFileSync(manifestFilePath));

        manifestFile.name = `${getAppTitle(c, platform)}`;
        manifestFile.description = `${getAppDescription(c, platform)}`;
        manifestFile.developer = getAppAuthor(c, platform);

        fs.writeFileSync(manifestFilePath2, JSON.stringify(manifestFile, null, 2));

        if (bundleAssets) {
            if (bundleIsDev) {
                copyFileSync(
                    path.join(templateFolder, '_privateConfig', 'webpack.config.dev.js'),
                    path.join(appFolder, 'webpack.config.js')
                );
            } else {
                copyFileSync(
                    path.join(templateFolder, '_privateConfig', 'webpack.config.js'),
                    path.join(appFolder, 'webpack.config.js')
                );
            }
        } else {
            copyFileSync(
                path.join(templateFolder, '_privateConfig', 'webpack.config.dev.js'),
                path.join(appFolder, 'webpack.config.js')
            );
        }

        resolve();
    });

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

        buildWeb(c, platform)
            .then(() => launchKaiOSSimulator(c, platform))
            .then(() => resolve())
            .catch(e => reject(e));
    });

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

        buildWeb(c, platform)
            .then(() => resolve())
            .catch(e => reject(e));
    });

    export { launchKaiOSSimulator, configureKaiOSProject, runFirefoxProject, buildFirefoxProject };