all files / lib/ index.js

44.12% Statements 15/34
27.78% Branches 5/18
50% Functions 2/4
45.45% Lines 15/33
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 841×               1× 17×     1× 26× 1×     25× 1×     24× 24×   24× 24×           1×                                   1×                                       1×                            
const semver = require('semver'),
      config = require('./config'),
      Build = require('./data').Build,
      Release = require('./data').Release,
      deployMethods = require('./deploy-methods'),
      archive = require('./archive'),
      s3 = require('./s3-helpers');
 
function getProjects() {
    return Promise.resolve(config.remote.projects);
}
 
function release(build, reporter) {
    if (!config.remote.projects[build.project]) {
        return Promise.reject(`Project '${build.project}' not found`);
    }
 
    if (!config.remote.projects[build.project].channels[build.channel]) {
        return Promise.reject(`Channel '${build.channel}' not found in project '${build.project}'`);
    }
 
    let opts = config.remote.projects[build.project].channels[build.channel].deploy;
    opts.reporter = reporter;
 
    Eif (deployMethods[opts.method]) {
        return deployMethods[opts.method].release(build, opts);
    } else {
        return Promise.reject('Deploy method not supported.');
    }
}
 
function status(project, channel) {
    if (!config.remote.projects[project]) {
        return Promise.reject(`Project '${project}' not found`);
    }
 
    if (!config.remote.projects[project].channels[channel]) {
        return Promise.reject(`Channel '${channel}' not found in project '${project}'`);
    }
 
    let opts = config.remote.projects[project].channels[channel].deploy;
 
    if (deployMethods[opts.method]) {
        return deployMethods[opts.method].status(project, channel);
    } else {
        return Promise.reject(`Deploy method ${opts.method} not supported`);
    }
}
 
function getMOTD() {
    let motd = null;
 
    if (config.remote.motd) {
        if (Array.isArray(config.remote.motd)) {
            motd = config.remote.motd.join("\n");
        } else {
            motd = config.remote.motd;
        }
    }
 
    if (motd) {
        motd = motd.replace("\\n", "\n");
        motd = motd.split("\n").map(l => `[${'MOTD'.green}]: ${l}`).join("\n");
    }
 
    return Promise.resolve(motd);
}
 
 
module.exports = {
    configure: config.configure,
    archive: {
        store: config.guard(archive.store),
        remove: config.guard(archive.remove),
        list: config.guard(archive.list),
    },
    getProjects: config.guard(getProjects),
    getMOTD: config.guard(getMOTD),
    release: config.guard(release),
    status: config.guard(status),
 
    /* For testing only */
    __mockS3API: s3.__mockAPI
};