All files / src/serverless deploy-multiple.js

100% Statements 16/16
100% Branches 2/2
100% Functions 6/6
100% Lines 16/16
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    1x 1x 1x 1x   1x 15x   15x           6x     9x 3x 3x     9x       1x 7x   15x   15x                  
'use strict';
 
const Listr = require('listr');
const Sls = require('./command');
const { ServerlessCommandError } = require('../common/errors');
const { wrap } = require('../utils/child-process');
 
const deployOne = (path, flags, params, logStream) => {
    const sls = new Sls(path, flags);
 
    return wrap(
        sls.deploy(),
        // don't push logs to console when deploying multiple services
        params
    )
        .then(log => {
            logStream.write(log);
        })
        .catch(err => {
            if (err instanceof ServerlessCommandError) {
                logStream.write(err.errorLog);
                logStream.write(err.log);
            }
 
            return Promise.reject(err);
        });
};
 
module.exports = (paths, flags, params, logStream) => {
    return new Listr(
        paths.map(path => {
            return {
                title: path,
                task: () => deployOne(path, flags, params, logStream)
            };
        }),
        {
            concurrent: !params.runInBand,
            exitOnError: Boolean(params.exitOnFailure)
        }
    ).run();
};