All files / src/deployTools webTools.js

47.62% Statements 20/42
0% Branches 0/12
0% Functions 0/7
41.18% Lines 14/34

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 623x 3x 3x 3x 3x 3x           3x 3x   3x 3x 3x   3x                               3x                                     3x                
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
import { deployToNow } from './now';
import { deployToFtp } from './ftp';
import {
    logTask,
    logComplete,
    logError,
    logInfo
} from '../common';
import { askQuestion, generateOptions, finishQuestion } from '../systemTools/prompt';
import { RENATIVE_CONFIG_NAME } from '../constants';
 
const DEPLOY_TARGET_FTP = 'ftp';
const DEPLOY_TARGET_NOW = 'now';
const DEPLOY_TARGET_NONE = 'none';
 
const _runDeployment = (c, platform, deployType) => new Promise((resolve, reject) => {
    switch (deployType) {
    case DEPLOY_TARGET_FTP:
        deployToFtp(c, platform).then(resolve).catch(reject);
        return;
    case DEPLOY_TARGET_NOW:
        deployToNow(c, platform).then(resolve).catch(reject);
        return;
    case DEPLOY_TARGET_NONE:
        resolve();
        return;
    default:
        reject(new Error(`Deploy Type not supported ${deployType}`));
    }
});
 
const selectWebToolAndDeploy = (c, platform) => new Promise((resolve, reject) => {
    const argv = require('minimist')(c.process.argv.slice(2));
    const deployType = argv.t;
    const targetConfig = c.buildConfig.platforms[platform];
 
    if (deployType || (targetConfig && targetConfig.deploy && targetConfig.deploy.type)) {
        _runDeployment(c, platform, deployType || targetConfig.deploy.type)
            .then(resolve).catch(reject);
    } else {
        const opts = generateOptions([DEPLOY_TARGET_FTP, DEPLOY_TARGET_NOW, DEPLOY_TARGET_NONE]);
        askQuestion(`Which type of deploy option would you like to use for ${chalk.white(platform)} deployment:\n${opts.asString}`)
            .then(v => opts.pick(v))
            .then((selectedDeployTarget) => {
                finishQuestion();
                logInfo(`Setting your appconfig for ${chalk.white(platform)} to include deploy type: ${chalk.white(selectedDeployTarget)} at ${chalk.white(c.paths.appConfig.config)}`);
                _runDeployment(c, platform, selectedDeployTarget).then(resolve).catch(reject);
            })
            .catch(e => reject(e));
    }
});
 
export {
    selectWebToolAndDeploy,
    DEPLOY_TARGET_FTP,
    DEPLOY_TARGET_NOW,
    DEPLOY_TARGET_NONE
};