All files / src/deployTools webTools.js

38.6% Statements 22/57
0% Branches 0/33
0% Functions 0/4
53.57% Lines 15/28

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 682x 2x 2x 2x   2x 2x 2x           2x   2x 2x 2x 2x   2x                                 2x                                         2x                  
import chalk from 'chalk';
import minimist from 'minimist';
import inquirer from 'inquirer';
import path from 'path';
 
import { deployToNow } from './now';
import { deployToFtp } from './ftp';
import {
    logTask,
    logComplete,
    logError,
    logInfo
} from '../common';
import { configureDeploymentIfRequired } from './configure';
 
const DEPLOY_TARGET_DOCKER = 'docker';
const DEPLOY_TARGET_FTP = 'ftp';
const DEPLOY_TARGET_NOW = 'now';
const DEPLOY_TARGET_NONE = 'none';
 
const _runDeployment = async (c, platform, deployType) => {
    switch (deployType) {
    case DEPLOY_TARGET_FTP:
        return deployToFtp(c, platform);
    case DEPLOY_TARGET_NOW:
        return deployToNow(c, platform);
    case DEPLOY_TARGET_NONE:
        return Promise.resolve();
    case DEPLOY_TARGET_DOCKER:
        // eslint-disable-next-line global-require, import/no-dynamic-require
        const deployToDocker = require(path.join(c.paths.project.nodeModulesDir, '/@rnv/deploy-docker')).default;
        return deployToDocker();
    default:
        return Promise.reject(new Error(`Deploy Type not supported ${deployType}`));
    }
};
 
const selectWebToolAndDeploy = async (c, platform) => {
    const argv = minimist(c.process.argv.slice(2));
    const deployType = argv.t;
    const targetConfig = c.buildConfig.platforms[platform];
 
    if (deployType || (targetConfig && targetConfig.deploy && targetConfig.deploy.type)) {
        await configureDeploymentIfRequired(deployType || targetConfig.deploy.type);
        return _runDeployment(c, platform, deployType || targetConfig.deploy.type);
    }
    const choices = [DEPLOY_TARGET_DOCKER, DEPLOY_TARGET_FTP, DEPLOY_TARGET_NOW, DEPLOY_TARGET_NONE];
 
    const { selectedDeployTarget } = await inquirer.prompt({
        name: 'selectedDeployTarget',
        type: 'list',
        choices,
        message: `Which type of deploy option would you like to use for ${chalk.white(platform)} deployment?`
    });
 
    await configureDeploymentIfRequired(selectedDeployTarget);
 
    logInfo(`Setting your appconfig for ${chalk.white(platform)} to include deploy type: ${chalk.white(selectedDeployTarget)} at ${chalk.white(c.paths.appConfig.config)}`);
    return _runDeployment(c, platform, selectedDeployTarget);
};
 
export {
    selectWebToolAndDeploy,
    DEPLOY_TARGET_FTP,
    DEPLOY_TARGET_NOW,
    DEPLOY_TARGET_NONE
};